| .. | .. |
|---|
| 132 | 132 | |
|---|
| 133 | 133 | lt.setCreationTimestamp(new Date()); |
|---|
| 134 | 134 | em.persist(lt); |
|---|
| 135 | | - Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 136 | | - |
|---|
| 135 | + Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 136 | + |
|---|
| 137 | 137 | if (newMD != null) { |
|---|
| 138 | 138 | for (LicenseTypeMetadata md : newMD) { |
|---|
| 139 | 139 | md.setLicenseType(lt); |
|---|
| .. | .. |
|---|
| 174 | 174 | currentlt.setCode(lt.getCode()); |
|---|
| 175 | 175 | currentlt.setName(lt.getName()); |
|---|
| 176 | 176 | currentlt.setDescription(lt.getDescription()); |
|---|
| 177 | | - em.persist(currentlt); |
|---|
| 178 | | - |
|---|
| 179 | | - Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 177 | + |
|---|
| 178 | + Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 180 | 179 | for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) { |
|---|
| 181 | | - if (newMD == null || !newMD.contains(currentMd)); |
|---|
| 180 | + if (newMD == null || !newMD.contains(currentMd)) { |
|---|
| 182 | 181 | em.remove(currentMd); |
|---|
| 182 | + LOG.info("Removing MD: {}", currentMd); |
|---|
| 183 | + } |
|---|
| 183 | 184 | } |
|---|
| 184 | | - |
|---|
| 185 | + |
|---|
| 185 | 186 | if (newMD != null) { |
|---|
| 187 | + Set<LicenseTypeMetadata> oldMD = currentlt.getMetadata(); |
|---|
| 188 | + |
|---|
| 186 | 189 | for (LicenseTypeMetadata md : newMD) { |
|---|
| 187 | | - md.setLicenseType(currentlt); |
|---|
| 188 | | - em.persist(md); |
|---|
| 190 | + if (oldMD.contains(md)) { |
|---|
| 191 | + em.merge(md); |
|---|
| 192 | + } else { |
|---|
| 193 | + md.setLicenseType(currentlt); |
|---|
| 194 | + em.persist(md); |
|---|
| 195 | + } |
|---|
| 189 | 196 | } |
|---|
| 190 | 197 | } |
|---|
| 191 | 198 | currentlt.setMetadata(newMD); |
|---|
| 199 | + em.merge(currentlt); |
|---|
| 192 | 200 | |
|---|
| 193 | 201 | return Response.ok(currentlt).build(); |
|---|
| 194 | 202 | } |
|---|