| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.util.Date; |
|---|
| 4 | 4 | import java.util.List; |
|---|
| 5 | +import java.util.Set; |
|---|
| 5 | 6 | |
|---|
| 6 | 7 | import javax.inject.Inject; |
|---|
| 7 | 8 | import javax.inject.Provider; |
|---|
| .. | .. |
|---|
| 26 | 27 | import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 27 | 28 | import net.curisit.securis.SeCurisException; |
|---|
| 28 | 29 | import net.curisit.securis.db.Application; |
|---|
| 30 | +import net.curisit.securis.db.ApplicationMetadata; |
|---|
| 29 | 31 | import net.curisit.securis.db.LicenseType; |
|---|
| 32 | +import net.curisit.securis.db.LicenseTypeMetadata; |
|---|
| 30 | 33 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 31 | 34 | |
|---|
| 32 | 35 | import org.apache.logging.log4j.LogManager; |
|---|
| .. | .. |
|---|
| 123 | 126 | |
|---|
| 124 | 127 | lt.setCreationTimestamp(new Date()); |
|---|
| 125 | 128 | em.persist(lt); |
|---|
| 129 | + Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 130 | + |
|---|
| 131 | + if (newMD != null) { |
|---|
| 132 | + for (LicenseTypeMetadata md : newMD) { |
|---|
| 133 | + md.setLicenseType(lt); |
|---|
| 134 | + em.persist(md); |
|---|
| 135 | + } |
|---|
| 136 | + } |
|---|
| 137 | + lt.setMetadata(newMD); |
|---|
| 126 | 138 | |
|---|
| 127 | 139 | return Response.ok(lt).build(); |
|---|
| 128 | 140 | } |
|---|
| .. | .. |
|---|
| 155 | 167 | currentlt.setName(lt.getName()); |
|---|
| 156 | 168 | currentlt.setDescription(lt.getDescription()); |
|---|
| 157 | 169 | em.persist(currentlt); |
|---|
| 170 | + |
|---|
| 171 | + Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 172 | + for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) { |
|---|
| 173 | + if (newMD == null || !newMD.contains(currentMd)); |
|---|
| 174 | + em.remove(currentMd); |
|---|
| 175 | + } |
|---|
| 176 | + |
|---|
| 177 | + if (newMD != null) { |
|---|
| 178 | + for (LicenseTypeMetadata md : newMD) { |
|---|
| 179 | + md.setLicenseType(currentlt); |
|---|
| 180 | + em.persist(md); |
|---|
| 181 | + } |
|---|
| 182 | + } |
|---|
| 183 | + currentlt.setMetadata(newMD); |
|---|
| 158 | 184 | |
|---|
| 159 | 185 | return Response.ok(currentlt).build(); |
|---|
| 160 | 186 | } |
|---|