Enhance MRN in EP & LKG 23/56023/2
authorshrikantawachar <shrikant.awachar@amdocs.com>
Mon, 9 Jul 2018 13:23:28 +0000 (18:53 +0530)
committerOren Kleks <orenkle@amdocs.com>
Tue, 10 Jul 2018 07:43:39 +0000 (07:43 +0000)
Enhance MRN in EP & LKG , handling healing , unit tests

Change-Id: I60b9ec73bfcdd9a53aa507c6401deab372fdcf58
Issue-ID: SDC-1485
Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
27 files changed:
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapEntitlementPoolEntityToEntitlementPoolEntityDto.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapEntitlementPoolRequestDtoToEntitlementPoolEntity.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapFeatureGroupDescriptorDtoToFeatureGroupEntity.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapFeatureGroupEntityToFeatureGroupDescriptorDto.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/EntitlementPoolsImpl.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/FeatureGroupsImpl.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapEntitlementPoolEntityToEntitlementPoolEntityDtoTest.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapEntitlementPoolRequestDtoToEntitlementPoolEntityTest.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapFeatureGroupDescriptorDtoToFeatureGroupEntityTest.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapFeatureGroupEntityToFeatureGroupDescriptorDtoTest.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDtoTest.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/mapping/MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntityTest.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-types/src/main/java/org/openecomp/sdcrests/vendorlicense/types/EntitlementPoolRequestDto.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-types/src/main/java/org/openecomp/sdcrests/vendorlicense/types/FeatureGroupDescriptorDto.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-types/src/main/java/org/openecomp/sdcrests/vendorlicense/types/LicenseKeyGroupRequestDto.java
openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/togglz/ToggleableFeature.java
openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json
openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceImpl.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/FeatureGroupForArtifact.java [deleted file]

index ba23b8c..18435b3 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
 
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
 import org.openecomp.sdcrests.mapping.MappingBase;
 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
@@ -46,5 +47,8 @@ public class MapEntitlementPoolEntityToEntitlementPoolEntityDto
     target.setStartDate(source.getStartDate());
     target.setExpiryDate(source.getExpiryDate());
     target.setVersionUUID(source.getVersionUuId());
+    if (ToggleableFeature.MRN.isActive()) {
+      target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    }
   }
 }
index 9b215d6..bed7e69 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
 
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
 import org.openecomp.sdcrests.mapping.MappingBase;
@@ -30,6 +31,9 @@ public class MapEntitlementPoolRequestDtoToEntitlementPoolEntity
   @Override
   public void doMapping(EntitlementPoolRequestDto source, EntitlementPoolEntity target) {
     target.setName(source.getName());
+    if (ToggleableFeature.MRN.isActive()) {
+      target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    }
     target.setDescription(source.getDescription());
     target.setThresholdValue(source.getThresholdValue());
     target.setThresholdUnit(source.getThresholdUnits());
index dedc2a0..2325887 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
 
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
 import org.openecomp.sdcrests.mapping.MappingBase;
 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupDescriptorDto;
@@ -31,6 +32,8 @@ public class MapFeatureGroupDescriptorDtoToFeatureGroupEntity
     target.setName(source.getName());
     target.setDescription(source.getDescription());
     target.setPartNumber(source.getPartNumber());
-    target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    if (!ToggleableFeature.MRN.isActive()) {
+      target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    }
   }
 }
\ No newline at end of file
index ce69384..e103b27 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
 
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
 import org.openecomp.sdcrests.mapping.MappingBase;
 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupDescriptorDto;
@@ -31,6 +32,8 @@ public class MapFeatureGroupEntityToFeatureGroupDescriptorDto
     target.setName(source.getName());
     target.setDescription(source.getDescription());
     target.setPartNumber(source.getPartNumber());
-    target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    if (!ToggleableFeature.MRN.isActive()) {
+      target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    }
   }
 }
index 2b314b7..a7d4b5b 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
 
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
 import org.openecomp.sdcrests.mapping.MappingBase;
 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
@@ -42,5 +43,8 @@ public class MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto
     target.setThresholdValue(source.getThresholdValue());
     target.setIncrements(source.getIncrements());
     target.setVersionUUID(source.getVersionUuId());
+    if (ToggleableFeature.MRN.isActive()) {
+      target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    }
   }
 }
index 4682a46..0eeda4a 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
 
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
 import org.openecomp.sdcrests.mapping.MappingBase;
@@ -30,6 +31,9 @@ public class MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity
   @Override
   public void doMapping(LicenseKeyGroupRequestDto source, LicenseKeyGroupEntity target) {
     target.setName(source.getName());
+    if (ToggleableFeature.MRN.isActive()) {
+      target.setManufacturerReferenceNumber(source.getManufacturerReferenceNumber());
+    }
     target.setDescription(source.getDescription());
     target.setType(source.getType());
     target.setOperationalScope(new MapMultiChoiceOrOtherDtoToMultiChoiceOrOther()
index 076ae45..292b4a0 100644 (file)
@@ -20,6 +20,9 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
@@ -37,6 +40,7 @@ import org.springframework.stereotype.Service;
 import javax.inject.Named;
 import javax.ws.rs.core.Response;
 import java.util.Collection;
+import java.util.Objects;
 
 @Named
 @Service("entitlementPools")
@@ -76,6 +80,12 @@ public class EntitlementPoolsImpl implements EntitlementPools {
    */
   public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
                                         String versionId, String user) {
+    if (ToggleableFeature.MRN.isActive()) {
+      if (Objects.isNull(request.getManufacturerReferenceNumber())) {
+        throw new CoreException((new ErrorCode.ErrorCodeBuilder().withMessage("Field does not conform to "
+            + "predefined criteria : manufacturerReferenceNumber : is mandatory and should not be empty").build()));
+      }
+    }
     EntitlementPoolEntity entitlementPoolEntity =
         new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
             .applyMapping(request, EntitlementPoolEntity.class);
index cd11a45..1c967ff 100644 (file)
@@ -21,6 +21,9 @@
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
 import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
@@ -48,6 +51,7 @@ import javax.inject.Named;
 import javax.ws.rs.core.Response;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Objects;
 
 @Named
 @Service("featureGroups")
@@ -71,7 +75,6 @@ public class FeatureGroupsImpl implements FeatureGroups {
       fgDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds());
       fgDto.setEntitlementPoolsIds(fg.getEntitlementPoolIds());
       fgDto.setReferencingLicenseAgreements(fg.getReferencingLicenseAgreements());
-      fgDto.setManufacturerReferenceNumber(fg.getManufacturerReferenceNumber());
       outputMapper.doMapping(fg, fgDto);
       results.add(fgDto);
     }
@@ -81,6 +84,15 @@ public class FeatureGroupsImpl implements FeatureGroups {
   @Override
   public Response createFeatureGroup(FeatureGroupRequestDto request, String vlmId, String versionId,
                                      String user) {
+    //Below if block is introduced to have feature toggleable. This if block needs to remove when
+    // we remove toggle.
+    if (!ToggleableFeature.MRN.isActive()) {
+      if (Objects.isNull(request.getManufacturerReferenceNumber())) {
+        throw new CoreException((new ErrorCode.ErrorCodeBuilder().withMessage("Field does not " +
+            "conform to predefined criteria : manufacturerReferenceNumber : is mandatory and should not be empty").build()));
+      }
+    }
+
     FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity()
         .applyMapping(request, FeatureGroupEntity.class);
     featureGroupEntity.setVendorLicenseModelId(vlmId);
index 0d03c19..a00c010 100644 (file)
@@ -141,4 +141,17 @@ public class MapEntitlementPoolEntityToEntitlementPoolEntityDtoTest {
         mapper.doMapping(source, target);
         assertEquals(target.getStartDate(), param);
     }
+
+    @Test
+    public void testManufacturerReferenceNumber() {
+        EntitlementPoolEntity source = new EntitlementPoolEntity();
+        EntitlementPoolEntityDto target = new EntitlementPoolEntityDto();
+        MapEntitlementPoolEntityToEntitlementPoolEntityDto mapper = new
+            MapEntitlementPoolEntityToEntitlementPoolEntityDto();
+
+        String param = "02402e1e-7092-485a-9574-46e2d49cca97";
+        source.setManufacturerReferenceNumber(param);
+        mapper.doMapping(source, target);
+        assertEquals(target.getManufacturerReferenceNumber(), param);
+    }
 }
index 86e9451..d927dc4 100644 (file)
@@ -114,6 +114,18 @@ public class MapEntitlementPoolRequestDtoToEntitlementPoolEntityTest {
         assertEquals(target.getStartDate(), param);
     }
 
+    @Test
+    public void testManufacturerReferenceNumber() {
+        EntitlementPoolRequestDto source = new EntitlementPoolRequestDto();
+        EntitlementPoolEntity target = new EntitlementPoolEntity();
+        MapEntitlementPoolRequestDtoToEntitlementPoolEntity mapper = new
+            MapEntitlementPoolRequestDtoToEntitlementPoolEntity();
+        String param = "02402e1e-7092-485a-9574-46e2d49cca97";
+        source.setManufacturerReferenceNumber(param);
+        mapper.doMapping(source, target);
+        assertEquals(target.getManufacturerReferenceNumber(), param);
+    }
+
     enum TestEnum {
         Yes
     }
index ea8c59b..7024931 100644 (file)
@@ -49,18 +49,6 @@ public class MapFeatureGroupDescriptorDtoToFeatureGroupEntityTest {
         assertEquals(target.getDescription(), param);
     }
 
-    @Test
-    public void testManufacturerReferenceNumber() {
-        FeatureGroupDescriptorDto source = new FeatureGroupDescriptorDto();
-        FeatureGroupEntity target = new FeatureGroupEntity();
-        MapFeatureGroupDescriptorDtoToFeatureGroupEntity mapper =
-                new MapFeatureGroupDescriptorDtoToFeatureGroupEntity();
-        String param = "6751e741-ffc2-4034-863b-f0083f62c033";
-        source.setManufacturerReferenceNumber(param);
-        mapper.doMapping(source, target);
-        assertEquals(target.getManufacturerReferenceNumber(), param);
-    }
-
     @Test
     public void testPartNumber() {
         FeatureGroupDescriptorDto source = new FeatureGroupDescriptorDto();
index b575feb..2a9c18f 100644 (file)
@@ -25,18 +25,6 @@ import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupDescriptorDto;
 
 public class MapFeatureGroupEntityToFeatureGroupDescriptorDtoTest {
 
-    @Test
-    public void testManufacturerReferenceNumber() {
-        FeatureGroupEntity source = new FeatureGroupEntity();
-        FeatureGroupDescriptorDto target = new FeatureGroupDescriptorDto();
-        MapFeatureGroupEntityToFeatureGroupDescriptorDto mapper =
-                new MapFeatureGroupEntityToFeatureGroupDescriptorDto();
-        String param = "02402e1e-7092-485a-9574-46e2d49cca97";
-        source.setManufacturerReferenceNumber(param);
-        mapper.doMapping(source, target);
-        assertEquals(target.getManufacturerReferenceNumber(), param);
-    }
-
     @Test
     public void testDescription() {
         FeatureGroupEntity source = new FeatureGroupEntity();
index ce8363d..0b17f60 100644 (file)
@@ -167,6 +167,18 @@ public class MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDtoTest {
         assertEquals(target.getStartDate(), param);
     }
 
+    @Test
+    public void testManufacturerReferenceNumber() {
+        LicenseKeyGroupEntity source = new LicenseKeyGroupEntity();
+        LicenseKeyGroupEntityDto target = new LicenseKeyGroupEntityDto();
+        MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto mapper = new
+            MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
+        String param = "02402e1e-7092-485a-9574-46e2d49cca97";
+        source.setManufacturerReferenceNumber(param);
+        mapper.doMapping(source, target);
+        assertEquals(target.getManufacturerReferenceNumber(), param);
+    }
+
     enum TestEnum {
         Yes
     }
index 8d0769a..a1e617e 100644 (file)
@@ -137,4 +137,16 @@ public class MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntityTest {
         mapper.doMapping(source, target);
         assertEquals(target.getStartDate(), param);
     }
+
+    @Test
+    public void testManufacturerReferenceNumber() {
+        LicenseKeyGroupRequestDto source = new LicenseKeyGroupRequestDto();
+        LicenseKeyGroupEntity target = new LicenseKeyGroupEntity();
+        MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity mapper = new
+            MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity();
+        String param = "02402e1e-7092-485a-9574-46e2d49cca97";
+        source.setManufacturerReferenceNumber(param);
+        mapper.doMapping(source, target);
+        assertEquals(target.getManufacturerReferenceNumber(), param);
+    }
 }
index 18488ab..8fa34b8 100644 (file)
@@ -30,13 +30,16 @@ import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
 @ApiModel(value = "EntitlementPoolRequest")
-@JsonIgnoreProperties({"manufacturerReferenceNumber", "time", "aggregationFunction", "entitlementMetric"})
+@JsonIgnoreProperties({"time", "aggregationFunction", "entitlementMetric"})
 public class EntitlementPoolRequestDto {
 
   @NotNull
   @Size(max = 120)
   private String name;
 
+  @Size(max = 100)
+  private String manufacturerReferenceNumber;
+
   @Size(max = 1000)
   private String description;
 
@@ -60,6 +63,14 @@ public class EntitlementPoolRequestDto {
     this.name = name;
   }
 
+  public String getManufacturerReferenceNumber() {
+    return manufacturerReferenceNumber;
+  }
+
+  public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
+    this.manufacturerReferenceNumber = manufacturerReferenceNumber;
+  }
+
   public String getDescription() {
     return description;
   }
index 56b3c25..4270ffe 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.openecomp.sdcrests.vendorlicense.types;
 
-import org.hibernate.validator.constraints.NotBlank;
 
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
@@ -35,7 +34,7 @@ public class FeatureGroupDescriptorDto {
   @NotNull
   private String partNumber;
 
-  @NotBlank(message = "is mandatory and should not be empty")
+
   @Size(max = 100)
   private String manufacturerReferenceNumber;
 
index fb56f85..c1e2ef0 100644 (file)
@@ -32,8 +32,13 @@ public class LicenseKeyGroupRequestDto {
   @NotNull
   @Size(max = 120)
   private String name;
+
+  @Size(max = 100)
+  private String manufacturerReferenceNumber;
+
   @Size(max = 1000)
   private String description;
+
   @NotNull
   private LicenseKeyType type;
 
@@ -58,6 +63,14 @@ public class LicenseKeyGroupRequestDto {
     this.name = name;
   }
 
+  public String getManufacturerReferenceNumber() {
+    return manufacturerReferenceNumber;
+  }
+
+  public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
+    this.manufacturerReferenceNumber = manufacturerReferenceNumber;
+  }
+
   public String getDescription() {
     return description;
   }
index 74623d5..493b891 100644 (file)
@@ -10,7 +10,10 @@ public enum ToggleableFeature implements Feature {
   ARCHIVE_ITEM,
 
   @Label("Filter")
-  FILTER;
+  FILTER,
+
+  @Label(("MRN"))
+  MRN;
 
   public boolean isActive() {
     return FeatureContext.getFeatureManager().isActive(this);
index d8f6986..a70c4af 100644 (file)
@@ -12,6 +12,9 @@
   "vlm": {
     "structure": [
       "org.openecomp.sdc.healing.healers.OwnerHealer"
+    ],
+    "data": [
+      "org.openecomp.sdc.healing.healers.ManufacturerReferenceNumberHealer"
     ]
   }
 }
\ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java
new file mode 100644 (file)
index 0000000..237e4bf
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.healing.healers;
+
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
+import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
+import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
+import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
+import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
+import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
+import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
+
+public class ManufacturerReferenceNumberHealer implements Healer {
+
+  private static final String manufacturerReferenceNumber = "MRN";
+  private VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance()
+      .createInterface();
+  private static final FeatureGroupDao featureGroupDao =
+      FeatureGroupDaoFactory.getInstance().createInterface();
+
+  @Override
+  public boolean isHealingNeeded(String itemId, Version version) {
+    return Objects.isNull(vendorLicenseFacade.listEntitlementPools
+        (itemId, version).iterator().next().getManufacturerReferenceNumber()) ? true :
+        false;
+  }
+
+  @Override
+  public void heal(String itemId, Version version) throws Exception {
+
+    healEntitlementPools(itemId, version);
+    healLicenseKeyGroups(itemId, version);
+    healFeatureGroups(itemId, version);
+  }
+
+  private void healEntitlementPools(String itemId, Version version) {
+    Collection<EntitlementPoolEntity> entitlementPoolEntities = vendorLicenseFacade
+        .listEntitlementPools(itemId, version);
+
+    for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
+      Set<String> referencingFeatureGroup = entitlementPoolEntity.getReferencingFeatureGroups();
+
+      if (referencingFeatureGroup.size() == 1) {
+        entitlementPoolEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
+            referencingFeatureGroup));
+      } else {
+        entitlementPoolEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber);
+      }
+      vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
+    }
+  }
+
+  private void healLicenseKeyGroups(String itemId, Version version) {
+    Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities = vendorLicenseFacade
+        .listLicenseKeyGroups(itemId, version);
+
+    for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
+      Set<String> referencingFeatureGroup = licenseKeyGroupEntity.getReferencingFeatureGroups();
+      if (referencingFeatureGroup.size() == 1) {
+        licenseKeyGroupEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
+            referencingFeatureGroup));
+      } else {
+        licenseKeyGroupEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber);
+      }
+      vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
+    }
+  }
+
+  private String getMRN(String itemId, Version
+      version, Set<String> referencingFeatureGroup) {
+    FeatureGroupEntity featureGroupEntity = vendorLicenseFacade.getFeatureGroup(new
+        FeatureGroupEntity(itemId, version, referencingFeatureGroup.iterator().next()));
+    return featureGroupEntity.getManufacturerReferenceNumber();
+  }
+
+  private void healFeatureGroups(String itemId, Version version) {
+
+    Collection<FeatureGroupEntity> featureGroupEntities = vendorLicenseFacade.listFeatureGroups
+        (itemId, version);
+
+    for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
+      featureGroupEntity.setManufacturerReferenceNumber("");
+      featureGroupDao.update(featureGroupEntity);
+    }
+  }
+}
index be073ab..b3adddb 100644 (file)
@@ -225,6 +225,7 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao {
     info.addProperty("operational_scope", entitlementPool.getOperationalScope());
     info.addProperty("startDate", entitlementPool.getStartDate());
     info.addProperty("expiryDate", entitlementPool.getExpiryDate());
+    info.addProperty("manufacturerReferenceNumber", entitlementPool.getManufacturerReferenceNumber());
     entitlementPoolElement.setInfo(info);
 
     if (entitlementPool.getReferencingFeatureGroups() != null
index d302ab4..1b458f3 100644 (file)
@@ -209,6 +209,7 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao {
     info.addProperty("thresholdValue", licenseKeyGroup.getThresholdValue());
     info.addProperty("thresholdUnits", licenseKeyGroup.getThresholdUnits());
     info.addProperty("increments", licenseKeyGroup.getIncrements());
+    info.addProperty("manufacturerReferenceNumber", licenseKeyGroup.getManufacturerReferenceNumber());
     lkgElement.setInfo(info);
 
     if (licenseKeyGroup.getReferencingFeatureGroups() != null
index 75fc6f2..c789545 100644 (file)
@@ -68,6 +68,7 @@ public class ElementToEntitlementPoolConvertor extends ElementConvertor {
         getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
     entitlementPool.setStartDate(info.getProperty("startDate"));
     entitlementPool.setExpiryDate(info.getProperty("expiryDate"));
+    entitlementPool.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber"));
   }
 
   private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool,
index 633de71..576cb63 100644 (file)
@@ -26,6 +26,7 @@ import org.openecomp.core.util.UniqueValueUtil;
 import org.openecomp.core.utilities.CommonMethods;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
@@ -95,8 +96,10 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade {
     FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
     VersioningUtil
         .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
-    if (retrieved.getManufacturerReferenceNumber() == null) {
-      updateManufacturerNumberInFeatureGroup(retrieved);
+    if (!ToggleableFeature.MRN.isActive()) { //Remove updateManufacturerNumberInFeatureGroup() while removing remove toggle
+      if (retrieved.getManufacturerReferenceNumber() == null) {
+        updateManufacturerNumberInFeatureGroup(retrieved);
+      }
     }
     return retrieved;
   }
index db745a1..b9fd403 100644 (file)
@@ -18,6 +18,7 @@ package org.openecomp.sdc.vendorlicense.licenseartifacts.impl;
 
 import org.apache.commons.collections.CollectionUtils;
 import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.vendorlicense.HealingServiceFactory;
 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
@@ -34,6 +35,7 @@ import org.openecomp.sdc.versioning.dao.types.Version;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -63,36 +65,63 @@ public class VendorLicenseArtifactsServiceImpl implements VendorLicenseArtifacts
       for (String featureGroupId : featureGroups) {
         FeatureGroupModel featureGroupModel = vendorLicenseFacade
             .getFeatureGroupModel(new FeatureGroupEntity(vlmId, vlmVersion, featureGroupId));
-        Set<EntitlementPoolEntity> entitlementPoolEntities =
-            featureGroupModel.getEntitlementPools();
-        for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
-          entitlementPoolEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion,
-              entitlementPoolEntity.getId()));
-          entitlementPoolEntity.setManufacturerReferenceNumber(featureGroupModel.
-              getEntityManufacturerReferenceNumber());
-        }
 
-        Set<LicenseKeyGroupEntity> licenseKeyGroupEntities =
-            featureGroupModel.getLicenseKeyGroups();
-        for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
-          licenseKeyGroupEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion,
-              licenseKeyGroupEntity.getId()));
-          licenseKeyGroupEntity.setManufacturerReferenceNumber(featureGroupModel.
-              getEntityManufacturerReferenceNumber());
-        }
+        updateEntitlementPools(vlmId, vlmVersion, featureGroupModel);
+        updateLicenseKeyGroupEntities(vlmId, vlmVersion, featureGroupModel);
 
-        featureGroupModel.setEntitlementPools(entitlementPoolEntities.stream().map(
-            entitlementPoolEntity -> (EntitlementPoolEntity) healingService
-                .heal(entitlementPoolEntity)).collect(Collectors.toSet()));
-        featureGroupModel.setLicenseKeyGroups(licenseKeyGroupEntities.stream().map(
-            licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService
-                .heal(licenseKeyGroupEntity)).collect(Collectors.toSet()));
         artifact.getFeatureGroups().add(featureGroupModel);
       }
     }
     return artifact.toXml().getBytes();
   }
 
+  private static void updateEntitlementPools(String vlmId, Version vlmVersion, FeatureGroupModel featureGroupModel) {
+
+    Set<EntitlementPoolEntity> entitlementPoolEntities =
+        featureGroupModel.getEntitlementPools();
+
+    for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
+      entitlementPoolEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion,
+          entitlementPoolEntity.getId()));
+      String manuFacturerReferenceNumber = featureGroupModel.getEntityManufacturerReferenceNumber();
+      if (ToggleableFeature.MRN.isActive()) {
+        if (Objects.nonNull(manuFacturerReferenceNumber)
+            && !manuFacturerReferenceNumber.trim().isEmpty()) {
+          entitlementPoolEntity.setManufacturerReferenceNumber(manuFacturerReferenceNumber);
+        }
+      } else {
+        entitlementPoolEntity.setManufacturerReferenceNumber(manuFacturerReferenceNumber);
+      }
+    }
+    featureGroupModel.setEntitlementPools(entitlementPoolEntities.stream().map(
+        entitlementPoolEntity -> (EntitlementPoolEntity) healingService
+            .heal(entitlementPoolEntity)).collect(Collectors.toSet()));
+  }
+
+  private static void updateLicenseKeyGroupEntities(String vlmId, Version vlmVersion, FeatureGroupModel featureGroupModel) {
+
+    Set<LicenseKeyGroupEntity> licenseKeyGroupEntities =
+        featureGroupModel.getLicenseKeyGroups();
+    for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
+      licenseKeyGroupEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion,
+          licenseKeyGroupEntity.getId()));
+      String manuFacturerReferenceNumber = featureGroupModel.getEntityManufacturerReferenceNumber();
+      if (ToggleableFeature.MRN.isActive()) {
+        if (Objects.nonNull(manuFacturerReferenceNumber)
+            && !manuFacturerReferenceNumber.trim().isEmpty()) {
+          licenseKeyGroupEntity.setManufacturerReferenceNumber(manuFacturerReferenceNumber);
+        }
+      } else {
+        licenseKeyGroupEntity.setManufacturerReferenceNumber(manuFacturerReferenceNumber);
+      }
+    }
+
+    featureGroupModel.setLicenseKeyGroups(licenseKeyGroupEntities.stream().map(
+        licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService
+            .heal(licenseKeyGroupEntity)).collect(Collectors.toSet()));
+
+  }
+
   private static byte[] createVendorLicenseArtifact(String vlmId, String vendorName) {
     VendorLicenseArtifact vendorLicenseArtifact = new VendorLicenseArtifact();
     vendorLicenseArtifact.setVendorName(vendorName);
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/FeatureGroupForArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/FeatureGroupForArtifact.java
deleted file mode 100644 (file)
index 61eb474..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types;
-
-import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
-import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-public class FeatureGroupForArtifact {
-  Collection<EntitlementPoolEntity> entitlementPoolEntities = new ArrayList<>();
-  Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities = new ArrayList<>();
-  private String name;
-  private String description;
-  private String partNumber;
-  private String manufacturerReferenceNumber;
-  private String id;
-
-  public String getName() {
-    return name;
-  }
-
-  public String getDescription() {
-    return description;
-  }
-
-  public String getPartNumber() {
-    return partNumber;
-  }
-
-  public String getManufacturerReferenceNumber(){
-    return manufacturerReferenceNumber;
-  }
-
-  public String getId() {
-    return id;
-  }
-
-  public Collection<EntitlementPoolEntity> getEntitlementPoolEntities() {
-    return entitlementPoolEntities;
-  }
-
-  public Collection<LicenseKeyGroupEntity> getLicenseKeyGroupEntities() {
-    return licenseKeyGroupEntities;
-  }
-}