diff options
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest')
2 files changed, 38 insertions, 21 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java index dc17b49454..f27de5e297 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java @@ -57,12 +57,15 @@ public interface VendorLicenseModels { @ApiOperation(value = "List vendor license models", response = ItemDto.class, responseContainer = "List") - Response listLicenseModels(@ApiParam(value = - "Currently supported value: 'Certified' - only vendor License models with final versions " - + "will be return - with their latest final version") - @QueryParam("versionFilter") String versionStatus, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(RestConstants.USER_ID_HEADER_PARAM) String user); + Response listLicenseModels(@ApiParam(value = "Filter to return only Vendor License Models with at" + + " least one version at this status. Currently supported values: 'Certified' , 'Draft'") + @QueryParam("versionFilter") String versionStatus, + @ApiParam(value = "Filter to only return Vendor License Models at this status." + + "Currently supported values: 'ACTIVE' , 'ARCHIVED'." + + "Default value = 'ACTIVE'.") + @QueryParam("Status") String itemStatus, + @NotNull(message = USER_MISSING_ERROR_MSG) + @HeaderParam(RestConstants.USER_ID_HEADER_PARAM) String user); @POST @Path("/") diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java index b9c2ea3bb8..2f64a5018f 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java @@ -52,6 +52,7 @@ import org.openecomp.sdcrests.item.rest.mapping.MapItemToDto; import org.openecomp.sdcrests.item.rest.mapping.MapVersionToDto; import org.openecomp.sdcrests.item.types.ItemCreationDto; import org.openecomp.sdcrests.item.types.ItemDto; +import org.openecomp.sdc.versioning.types.ItemStatus; import org.openecomp.sdcrests.item.types.VersionDto; import org.openecomp.sdcrests.vendorlicense.rest.VendorLicenseModels; import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapVendorLicenseModelEntityToDto; @@ -106,20 +107,8 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { .createInterface()); @Override - public Response listLicenseModels(String versionStatus, String user) { - Predicate<Item> itemPredicate; - if (VersionStatus.Certified.name().equals(versionStatus)) { - itemPredicate = item -> ItemType.vlm.name().equals(item.getType()) && - item.getVersionStatusCounters().containsKey(VersionStatus.Certified); - - } else if (VersionStatus.Draft.name().equals(versionStatus)) { - itemPredicate = item -> ItemType.vlm.name().equals(item.getType()) && - item.getVersionStatusCounters().containsKey(VersionStatus.Draft) && - userHasPermission(item.getId(), user); - - } else { - itemPredicate = item -> ItemType.vlm.name().equals(item.getType()); - } + public Response listLicenseModels(String versionStatus,String itemStatus, String user) { + Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user); GenericCollectionWrapper<ItemDto> results = new GenericCollectionWrapper<>(); MapItemToDto mapper = new MapItemToDto(); @@ -135,6 +124,7 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { Item item = new Item(); item.setType(ItemType.vlm.name()); item.setOwner(user); + item.setStatus(ItemStatus.ACTIVE); item.setName(request.getVendorName()); item.setDescription(request.getDescription()); @@ -219,7 +209,7 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { permissionsManager.deleteItemPermissions(vlmId); uniqueValueUtil .deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vlm.getName()); - notifyUsers(vlmId, vlm.getName(), null, "VLM was deleted", user, + notifyUsers(vlmId, vlm.getName(), null, null, user, NotificationEventTypes.DELETE); return Response.ok().build(); @@ -334,4 +324,28 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { return (permission != null && permission .matches(PermissionTypes.Contributor.name() + "|" + PermissionTypes.Owner.name())); } + + private Predicate<Item> createItemPredicate(String versionStatus, + String itemStatus, + String user) { + Predicate<Item> itemPredicate = item -> ItemType.vlm.name().equals(item.getType()); + + if (ItemStatus.ARCHIVED.name().equals(itemStatus)) { + itemPredicate = itemPredicate.and(item -> ItemStatus.ARCHIVED.equals(item.getStatus())); + } else { + itemPredicate = itemPredicate.and(item -> ItemStatus.ACTIVE.equals(item.getStatus())); + + if (VersionStatus.Certified.name().equals(versionStatus)) { + itemPredicate = itemPredicate + .and(item -> item.getVersionStatusCounters().containsKey(VersionStatus.Certified)); + + } else if (VersionStatus.Draft.name().equals(versionStatus)) { + itemPredicate = itemPredicate.and( + item -> item.getVersionStatusCounters().containsKey(VersionStatus.Draft) + && userHasPermission(item.getId(), user)); + } + } + return itemPredicate; + } + } |