| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.services; |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.util.Date; |
|---|
| 4 | +import java.util.HashSet; |
|---|
| 4 | 5 | import java.util.List; |
|---|
| 5 | 6 | import java.util.Set; |
|---|
| 6 | 7 | |
|---|
| .. | .. |
|---|
| 148 | 149 | return Response.ok(lt).build(); |
|---|
| 149 | 150 | } |
|---|
| 150 | 151 | |
|---|
| 152 | + private Set<String> getMdKeys(Set<LicenseTypeMetadata> mds) { |
|---|
| 153 | + Set<String> ids = new HashSet<String>(); |
|---|
| 154 | + if (mds != null) { |
|---|
| 155 | + for (LicenseTypeMetadata md : mds) { |
|---|
| 156 | + ids.add(md.getKey()); |
|---|
| 157 | + } |
|---|
| 158 | + } |
|---|
| 159 | + return ids; |
|---|
| 160 | + } |
|---|
| 161 | + |
|---|
| 151 | 162 | @PUT |
|---|
| 152 | 163 | @POST |
|---|
| 153 | 164 | @Path("/{ltid}") |
|---|
| .. | .. |
|---|
| 179 | 190 | currentlt.setDescription(lt.getDescription()); |
|---|
| 180 | 191 | |
|---|
| 181 | 192 | Set<LicenseTypeMetadata> newMD = lt.getMetadata(); |
|---|
| 193 | + Set<String> newMdKeys = getMdKeys(newMD); |
|---|
| 182 | 194 | for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) { |
|---|
| 183 | | - if (newMD == null || !newMD.contains(currentMd)) { |
|---|
| 195 | + if (!newMdKeys.contains(currentMd.getKey())) { |
|---|
| 184 | 196 | em.remove(currentMd); |
|---|
| 185 | 197 | LOG.info("Removing MD: {}", currentMd); |
|---|
| 186 | 198 | } |
|---|
| .. | .. |
|---|
| 188 | 200 | |
|---|
| 189 | 201 | if (newMD != null) { |
|---|
| 190 | 202 | Set<LicenseTypeMetadata> oldMD = currentlt.getMetadata(); |
|---|
| 203 | + Set<String> oldMdKeys = getMdKeys(oldMD); |
|---|
| 191 | 204 | |
|---|
| 192 | 205 | for (LicenseTypeMetadata md : newMD) { |
|---|
| 193 | | - if (oldMD.contains(md)) { |
|---|
| 206 | + if (oldMdKeys.contains(md.getKey())) { |
|---|
| 194 | 207 | em.merge(md); |
|---|
| 195 | 208 | } else { |
|---|
| 196 | 209 | md.setLicenseType(currentlt); |
|---|