Entities are not ordered by Name user feedback 30/69830/2
authorayalaben <ayala.benzvi@amdocs.com>
Thu, 4 Oct 2018 11:24:58 +0000 (14:24 +0300)
committerayalaben <ayala.benzvi@amdocs.com>
Sun, 7 Oct 2018 10:15:53 +0000 (13:15 +0300)
Change-Id: I937b744c13d3cdf08a2ba23e365c7138494ac491
Issue-ID: SDC-1818
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.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/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/LicenseAgreementsImpl.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/LicenseKeyGroupsImpl.java

index 076ae45..8351919 100644 (file)
 
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
+import java.util.Comparator;
+import java.util.stream.Collectors;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
@@ -34,10 +38,6 @@ import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
-import java.util.Collection;
-
 @Named
 @Service("entitlementPools")
 @Scope(value = "prototype")
@@ -54,17 +54,18 @@ public class EntitlementPoolsImpl implements EntitlementPools {
    * @return the response
    */
   public Response listEntitlementPools(String vlmId, String versionId, String user) {
-    Collection<EntitlementPoolEntity> entitlementPools =
-        vendorLicenseManager.listEntitlementPools(vlmId, new Version(versionId));
 
-    GenericCollectionWrapper<EntitlementPoolEntityDto> result = new GenericCollectionWrapper<>();
-    MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper =
-        new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
-    for (EntitlementPoolEntity ep : entitlementPools) {
-      result.add(outputMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
+        MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper =
+                new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
+
+        GenericCollectionWrapper<EntitlementPoolEntityDto> result = new GenericCollectionWrapper<>(
+                vendorLicenseManager.listEntitlementPools(vlmId, new Version(versionId)).stream()
+                                    .sorted(Comparator.comparing(EntitlementPoolEntity::getName))
+                                    .map(item -> outputMapper.applyMapping(item, EntitlementPoolEntityDto.class))
+                                    .collect(Collectors.toList()));
+
+        return Response.ok(result).build();
     }
-    return Response.ok(result).build();
-  }
 
   /**
    * Create entitlement pool response.
index b2f7e88..4ea35d3 100644 (file)
 
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
-import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashSet;
-
+import java.util.stream.Collectors;
 import javax.inject.Named;
 import javax.ws.rs.core.Response;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
@@ -60,22 +59,15 @@ public class FeatureGroupsImpl implements FeatureGroups {
 
     @Override
     public Response listFeatureGroups(String vlmId, String versionId, String user) {
-        Collection<FeatureGroupEntity> featureGroupEntities =
-                vendorLicenseManager.listFeatureGroups(vlmId, new Version(versionId));
 
         MapFeatureGroupEntityToFeatureGroupDescriptorDto outputMapper =
                 new MapFeatureGroupEntityToFeatureGroupDescriptorDto();
-        GenericCollectionWrapper<FeatureGroupEntityDto> results = new GenericCollectionWrapper<>();
-
-        for (FeatureGroupEntity fg : featureGroupEntities) {
-            FeatureGroupEntityDto fgDto = new FeatureGroupEntityDto();
-            fgDto.setId(fg.getId());
-            fgDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds());
-            fgDto.setEntitlementPoolsIds(fg.getEntitlementPoolIds());
-            fgDto.setReferencingLicenseAgreements(fg.getReferencingLicenseAgreements());
-            outputMapper.doMapping(fg, fgDto);
-            results.add(fgDto);
-        }
+
+        GenericCollectionWrapper<FeatureGroupEntityDto> results = new GenericCollectionWrapper<>(
+                vendorLicenseManager.listFeatureGroups(vlmId, new Version(versionId)).stream()
+                                    .sorted(Comparator.comparing(FeatureGroupEntity::getName))
+                                    .map(fg -> getFeatureGroupEntityDto(outputMapper,fg)).collect(Collectors.toList()));
+
         return Response.ok(results).build();
     }
 
@@ -168,4 +160,14 @@ public class FeatureGroupsImpl implements FeatureGroups {
         return Response.ok().build();
     }
 
+    private FeatureGroupEntityDto getFeatureGroupEntityDto(MapFeatureGroupEntityToFeatureGroupDescriptorDto mapper,FeatureGroupEntity fg) {
+        FeatureGroupEntityDto fgDto = new FeatureGroupEntityDto();
+        fgDto.setId(fg.getId());
+        fgDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds());
+        fgDto.setEntitlementPoolsIds(fg.getEntitlementPoolIds());
+        fgDto.setReferencingLicenseAgreements(fg.getReferencingLicenseAgreements());
+        mapper.doMapping(fg, fgDto);
+        return fgDto;
+    }
+
 }
index 05da964..7c05399 100644 (file)
 
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
-import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashSet;
-
+import java.util.stream.Collectors;
 import javax.inject.Named;
 import javax.ws.rs.core.Response;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
@@ -64,22 +63,20 @@ public class LicenseAgreementsImpl implements LicenseAgreements {
      * @return the response
      */
     public Response listLicenseAgreements(String vlmId, String versionId, String user) {
-        Collection<LicenseAgreementEntity> licenseAgreements =
-                vendorLicenseManager.listLicenseAgreements(vlmId, new Version(versionId));
 
-        GenericCollectionWrapper<LicenseAgreementEntityDto> results = new GenericCollectionWrapper<>();
         MapLicenseAgreementEntityToLicenseAgreementDescriptorDto outputMapper =
                 new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto();
-        for (LicenseAgreementEntity lae : licenseAgreements) {
-            LicenseAgreementEntityDto laeDto = new LicenseAgreementEntityDto();
-            laeDto.setId(lae.getId());
-            laeDto.setFeatureGroupsIds(lae.getFeatureGroupIds());
-            outputMapper.doMapping(lae, laeDto);
-            results.add(laeDto);
-        }
+
+        GenericCollectionWrapper<LicenseAgreementEntityDto> results = new GenericCollectionWrapper<>(
+                vendorLicenseManager.listLicenseAgreements(vlmId, new Version(versionId)).stream()
+                                    .sorted(Comparator.comparing(LicenseAgreementEntity::getName))
+                                    .map(lae -> getLicenseAgreementEntityDto(outputMapper, lae))
+                                    .collect(Collectors.toList()));
+
         return Response.ok(results).build();
     }
 
+
     /**
      * Create license agreement response.
      *
@@ -184,4 +181,13 @@ public class LicenseAgreementsImpl implements LicenseAgreements {
         vendorLicenseManager.deleteLicenseAgreement(vlmId, new Version(versionId), licenseAgreementId);
         return Response.ok().build();
     }
+
+    private LicenseAgreementEntityDto getLicenseAgreementEntityDto(
+            MapLicenseAgreementEntityToLicenseAgreementDescriptorDto mapper, LicenseAgreementEntity lae) {
+        LicenseAgreementEntityDto laeDto = new LicenseAgreementEntityDto();
+        laeDto.setId(lae.getId());
+        laeDto.setFeatureGroupsIds(lae.getFeatureGroupIds());
+        mapper.doMapping(lae, laeDto);
+        return laeDto;
+    }
 }
index 5f37d39..3edee02 100644 (file)
 
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
+import java.util.Comparator;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
@@ -35,10 +40,6 @@ import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
-import java.util.Collection;
-
 @Named
 @Service("licenseKeyGroups")
 @Scope(value = "prototype")
@@ -56,15 +57,16 @@ public class LicenseKeyGroupsImpl implements LicenseKeyGroups {
    * @return the response
    */
   public Response listLicenseKeyGroups(String vlmId, String versionId, String user) {
-    Collection<LicenseKeyGroupEntity> licenseKeyGroups =
-        vendorLicenseManager.listLicenseKeyGroups(vlmId, new Version(versionId));
 
-    GenericCollectionWrapper<LicenseKeyGroupEntityDto> result = new GenericCollectionWrapper<>();
     MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper =
-        new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
-    for (LicenseKeyGroupEntity ep : licenseKeyGroups) {
-      result.add(outputMapper.applyMapping(ep, LicenseKeyGroupEntityDto.class));
-    }
+            new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
+
+    GenericCollectionWrapper<LicenseKeyGroupEntityDto> result = new GenericCollectionWrapper<>(
+            vendorLicenseManager.listLicenseKeyGroups(vlmId, new Version(versionId)).stream()
+                                .sorted(Comparator.comparing(LicenseKeyGroupEntity::getName))
+                                .map(item -> outputMapper.applyMapping(item, LicenseKeyGroupEntityDto.class))
+                                .collect(Collectors.toList()));
+
     return Response.ok(result).build();
   }