aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java55
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java2
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java191
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemAction.java6
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemActionRequestDto.java29
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java9
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml2
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/VendorLicenseModels.java15
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java44
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java14
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java1
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java120
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java9
13 files changed, 428 insertions, 69 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java
new file mode 100644
index 0000000000..de63c4efdc
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 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.sdcrests.item.rest;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.openecomp.sdcrests.item.types.ItemActionRequestDto;
+import org.springframework.validation.annotation.Validated;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM;
+import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG;
+
+@Path("/v1.0/items")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@Api(value = "Items")
+@Validated
+public interface Items {
+
+ @GET
+ @Path("/{itemId}")
+ @ApiOperation(value = "Get details of a item")
+ Response getItem(@PathParam("itemId") String itemId,
+ @NotNull(message = USER_MISSING_ERROR_MSG)
+ @HeaderParam(USER_ID_HEADER_PARAM) String user);
+
+ @PUT
+ @Path("/{itemId}/actions")
+ @ApiOperation(value = "Acts on item version")
+ Response actOn(ItemActionRequestDto request,
+ @PathParam("itemId") String itemId,
+ @NotNull(message = USER_MISSING_ERROR_MSG)
+ @HeaderParam(USER_ID_HEADER_PARAM) String user);
+
+
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java
index 0448407b99..1886dc462c 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java
@@ -1,6 +1,7 @@
package org.openecomp.sdcrests.item.rest.mapping;
import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.types.ItemStatus;
import org.openecomp.sdcrests.item.types.ItemDto;
import org.openecomp.sdcrests.mapping.MappingBase;
@@ -12,5 +13,6 @@ public class MapItemToDto extends MappingBase<Item, ItemDto> {
target.setName(source.getName());
target.setDescription(source.getDescription());
target.setOwner(source.getOwner());
+ target.setStatus(source.getStatus().name());
}
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
new file mode 100644
index 0000000000..21c1f5199d
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright © 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.sdcrests.item.rest.services;
+
+import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
+import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
+import org.openecomp.sdc.activitylog.dao.type.ActivityType;
+import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.notification.dtos.Event;
+import org.openecomp.sdc.notification.factories.NotificationPropagationManagerFactory;
+import org.openecomp.sdc.notification.services.NotificationPropagationManager;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.ItemManagerFactory;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.VersioningManagerFactory;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.types.NotificationEventTypes;
+import org.openecomp.sdcrests.item.rest.Items;
+import org.openecomp.sdcrests.item.rest.mapping.MapItemToDto;
+import org.openecomp.sdcrests.item.types.ItemAction;
+import org.openecomp.sdcrests.item.types.ItemActionRequestDto;
+import org.openecomp.sdcrests.item.types.ItemDto;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.*;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
+
+@Named
+@Service("items")
+@Scope(value = "prototype")
+public class ItemsImpl implements Items {
+
+ private ItemManager itemManager =
+ ItemManagerFactory.getInstance().createInterface();
+
+ private static ActivityLogManager activityLogManager =
+ ActivityLogManagerFactory.getInstance().createInterface();
+
+ private VersioningManager versioningManager =
+ VersioningManagerFactory.getInstance().createInterface();
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ItemsImpl.class);
+
+ private NotificationPropagationManager notifier =
+ NotificationPropagationManagerFactory.getInstance().createInterface();
+
+ private Map<ItemAction, ActionSideAffects> actionSideAffectsMap = new EnumMap<>(ItemAction.class);
+
+ {
+ actionSideAffectsMap.put(ItemAction.ARCHIVE, new ActionSideAffects(ActivityType.Archive,
+ NotificationEventTypes.ARCHIVE));
+ actionSideAffectsMap.put(ItemAction.RESTORE, new ActionSideAffects(ActivityType.Restore,
+ NotificationEventTypes.RESTORE));
+ }
+
+ @Override
+ public Response actOn(ItemActionRequestDto request, String itemId, String user) {
+
+ Item item = itemManager.get(itemId);
+ if( item == null){
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity(new Exception("Item does not exist.")).build();
+ }
+
+ switch (request.getAction()) {
+ case ARCHIVE:
+ itemManager.archive(item);
+ break;
+ case RESTORE:
+ itemManager.restore(item);
+ break;
+ default:
+ }
+
+ actionSideAffectsMap.get(request.getAction()).execute(item,user);
+
+ return Response.ok().build();
+ }
+
+ @Override
+ public Response getItem(String itemId, String user) {
+ Item item = itemManager.get(itemId);
+ ItemDto itemDto = new MapItemToDto().applyMapping(item, ItemDto.class);
+
+ return Response.ok(itemDto).build();
+ }
+
+ private Version getLatestVersion(String itemId){
+ List<Version> list = versioningManager.list(itemId);
+ return list.stream().max(Version::compareTo).get();
+ }
+
+ private void notifyUsers(String itemId, String itemName, String message,
+ String userName, NotificationEventTypes eventType) {
+ Map<String, Object> eventProperties = new HashMap<>();
+ eventProperties.put(ITEM_NAME, itemName == null ? itemManager.get(itemId).getName() : itemName);
+ eventProperties.put(ITEM_ID, itemId);
+
+ eventProperties.put(SUBMIT_DESCRIPTION, message);
+ eventProperties.put(PERMISSION_USER, userName);
+
+ Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId);
+ try {
+ notifier.notifySubscribers(syncEvent, userName);
+ } catch (Exception e) {
+ LOGGER.error("Failed to send sync notification to users subscribed to item '" + itemId);
+ }
+ }
+
+ private class SyncEvent implements Event {
+
+ private String eventType;
+ private String originatorId;
+ private Map<String, Object> attributes;
+ private String entityId;
+
+ SyncEvent(String eventType, String originatorId,
+ Map<String, Object> attributes, String entityId) {
+ this.eventType = eventType;
+ this.originatorId = originatorId;
+ this.attributes = attributes;
+ this.entityId = entityId;
+ }
+
+ @Override
+ public String getEventType() {
+ return eventType;
+ }
+
+ @Override
+ public String getOriginatorId() {
+ return originatorId;
+ }
+
+ @Override
+ public Map<String, Object> getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public String getEntityId() {
+ return entityId;
+ }
+
+ }
+
+ private class ActionSideAffects{
+ private ActivityType activityType;
+ private NotificationEventTypes notificationType;
+
+ public ActionSideAffects(ActivityType activityType, NotificationEventTypes notificationType){
+ this.activityType = activityType;
+ this.notificationType = notificationType;
+
+ }
+ public void execute(Item item, String user){
+ notifyUsers(item.getId(), item.getName(), null, user,
+ this.notificationType);
+ activityLogManager.logActivity(new ActivityLogEntity(item.getId(), getLatestVersion(item.getId()),
+ this.activityType, user, true, "", ""));
+ }
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemAction.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemAction.java
new file mode 100644
index 0000000000..55b8cf82d0
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemAction.java
@@ -0,0 +1,6 @@
+package org.openecomp.sdcrests.item.types;
+
+public enum ItemAction {
+ ARCHIVE,
+ RESTORE
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemActionRequestDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemActionRequestDto.java
new file mode 100644
index 0000000000..00032b62ab
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemActionRequestDto.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 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.sdcrests.item.types;
+
+public class ItemActionRequestDto {
+ private ItemAction action;
+
+ public ItemAction getAction() {
+ return action;
+ }
+
+ public void setAction(ItemAction action) {
+ this.action = action;
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java
index 3ca77c27b3..22bea01c35 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java
@@ -6,6 +6,7 @@ public class ItemDto {
private String name;
private String description;
private String owner;
+ private String status;
public String getId() {
return id;
@@ -46,4 +47,12 @@ public class ItemDto {
public void setOwner(String owner) {
this.owner = owner;
}
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
index 495cd3f843..7710032cbc 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
@@ -40,6 +40,7 @@
<bean id = "itemPermissions" class="org.openecomp.sdcrests.itempermissions.rest.services.ItemPermissionsImpl"/>
<bean id = "notifications" class="org.openecomp.sdcrests.notifications.rest.services.impl.NotificationsImpl"/>
<bean id = "togglz" class="org.openecomp.sdcrests.togglz.rest.services.TogglzFeaturesImpl"/>
+ <bean id = "items" class="org.openecomp.sdcrests.item.rest.services.ItemsImpl"/>
<!-- RESTful Services -->
<jaxrs:server id="restContainer" address="/">
@@ -73,6 +74,7 @@
<ref bean="itemPermissions"/>
<ref bean="notifications"/>
<ref bean="togglz"/>
+ <ref bean="items"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
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;
+ }
+
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
index 60c68ef302..996b389829 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
@@ -69,10 +69,13 @@ public interface VendorSoftwareProducts extends VspEntities {
@Path("/")
@ApiOperation(value = "Get list of vendor software products and their description",
responseContainer = "List")
- Response listVsps(@ApiParam(
- value = "Currently supported values: 'Certified' - only vendor software products with final "
- + " version will be return - with their latest final version")
+ Response listVsps(@ApiParam(value = "Filter to return only Vendor Software Products with at" +
+ " least one version at this status. Currently supported values: 'Certified' , 'Draft'")
@QueryParam("versionFilter") String versionStatus,
+ @ApiParam(value = "Filter to only return Vendor Software Products at this status." +
+ "Currently supported values: 'ACTIVE' , 'ARCHIVED'." +
+ "Default value = 'ACTIVE'.")
+ @QueryParam("Status") String itemStatus,
@NotNull(message = USER_MISSING_ERROR_MSG)
@HeaderParam(USER_ID_HEADER_PARAM) String user);
@@ -105,7 +108,10 @@ public interface VendorSoftwareProducts extends VspEntities {
@ApiOperation(value = "Get list of translated CSAR files details",
response = PackageInfoDto.class,
responseContainer = "List")
- Response listPackages(@ApiParam("Category") @QueryParam("category") String category,
+ Response listPackages(@ApiParam("Vendor Software Product status filter. " +
+ "Currently supported values: 'ACTIVE', 'ARCHIVED'")
+ @QueryParam("Status") String status,
+ @ApiParam("Category") @QueryParam("category") String category,
@ApiParam("Sub-category") @QueryParam("subCategory") String subCategory,
@NotNull(message = USER_MISSING_ERROR_MSG)
@HeaderParam(USER_ID_HEADER_PARAM) String user);
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java
index caa05391c8..93ee1590f0 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java
@@ -15,5 +15,6 @@ public class MapItemToVspDetailsDto extends MappingBase<Item, VspDetailsDto> {
target.setVendorName((String) source.getProperties().get(VspItemProperty.VENDOR_NAME));
target.setOnboardingMethod((String) source.getProperties().get(VspItemProperty.ONBOARDING_METHOD));
target.setOwner(source.getOwner());
+ target.setStatus(source.getStatus().name());
}
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
index be196bf326..37804ff865 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
@@ -16,6 +16,29 @@
package org.openecomp.sdcrests.vsp.rest.services;
+import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.VALIDATION_VSP_NAME;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.dao.UniqueValueDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
@@ -62,6 +85,7 @@ import org.openecomp.sdc.versioning.types.Item;
import org.openecomp.sdc.versioning.types.NotificationEventTypes;
import org.openecomp.sdcrests.item.rest.mapping.MapVersionToDto;
import org.openecomp.sdcrests.item.types.ItemCreationDto;
+import org.openecomp.sdc.versioning.types.ItemStatus;
import org.openecomp.sdcrests.item.types.VersionDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.PackageInfoDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
@@ -85,29 +109,6 @@ import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-
-import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
-import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
-import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
-import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.VALIDATION_VSP_NAME;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
-
@Named
@Service("vendorSoftwareProducts")
@Scope(value = "prototype")
@@ -166,6 +167,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
Item item = new MapVspDescriptionDtoToItem().applyMapping(vspRequestDto, Item.class);
item.setType(ItemType.vsp.name());
item.setOwner(user);
+ item.setStatus(ItemStatus.ACTIVE);
item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name());
uniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
@@ -197,27 +199,14 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
throw new CoreException(onboardingMethodUpdateErrorCode, e);
}
- @Override
- public Response listVsps(String versionStatus, String user) {
- Predicate<Item> itemPredicate;
- if (VersionStatus.Certified.name().equals(versionStatus)) {
- itemPredicate = item -> ItemType.vsp.name().equals(item.getType())
- && item.getVersionStatusCounters().containsKey(VersionStatus.Certified);
-
- } else if (VersionStatus.Draft.name().equals(versionStatus)) {
- itemPredicate = item -> ItemType.vsp.name().equals(item.getType())
- && item.getVersionStatusCounters().containsKey(VersionStatus.Draft)
- && userHasPermission(item.getId(), user);
+ @Override
+ public Response listVsps(String versionStatus, String itemStatus, String user) {
- } else {
- itemPredicate = item -> ItemType.vsp.name().equals(item.getType());
- }
+ GenericCollectionWrapper<VspDetailsDto> results = new GenericCollectionWrapper<>();
+ MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto();
- GenericCollectionWrapper<VspDetailsDto> results = new GenericCollectionWrapper<>();
- MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto();
- itemManager.list(itemPredicate).stream()
- .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
- .forEach(vspItem -> results.add(mapper.applyMapping(vspItem, VspDetailsDto.class)));
+ getVspList(versionStatus,itemStatus,user)
+ .forEach(vspItem -> results.add(mapper.applyMapping(vspItem, VspDetailsDto.class)));
return Response.ok(results).build();
}
@@ -299,7 +288,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
itemManager.delete(vsp);
permissionsManager.deleteItemPermissions(vspId);
uniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName());
- notifyUsers(vspId, vsp.getName(), null, "VSP was deleted", user,
+ notifyUsers(vspId, vsp.getName(), null, null, user,
NotificationEventTypes.DELETE);
return Response.ok().build();
@@ -386,10 +375,19 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
}
@Override
- public Response listPackages(String category, String subCategory, String user) {
+ public Response listPackages(String status, String category, String subCategory, String user) {
+
+ List<String> VspsIds =
+ getVspList(null, status != null ? ItemStatus.valueOf(status).name(): null, user)
+ .stream().map(Item::getId).collect(Collectors.toList());
+
List<PackageInfo> packageInfoList =
vendorSoftwareProductManager.listPackages(category, subCategory);
+ packageInfoList = packageInfoList.stream().
+ filter(packageInfo -> VspsIds.contains(packageInfo.getVspId()))
+ .collect(Collectors.toList());
+
GenericCollectionWrapper<PackageInfoDto> results = new GenericCollectionWrapper<>();
MapPackageInfoToPackageInfoDto mapper = new MapPackageInfoToPackageInfoDto();
@@ -611,4 +609,38 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
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.vsp.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;
+ }
+
+ private List<Item> getVspList(String versionStatus, String itemStatus, String user) {
+
+ Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user);
+
+ return itemManager.list(itemPredicate).stream()
+ .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())).
+ collect(Collectors.toList());
+
+ }
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java
index 745b930fbc..38e70a9225 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java
@@ -36,6 +36,7 @@ public class VspDetailsDto extends VspRequestDto {
private String onboardingOrigin;
private String networkPackageName;
private String owner;
+ private String status;
public String getId() {
return id;
@@ -92,4 +93,12 @@ public class VspDetailsDto extends VspRequestDto {
public void setOwner(String owner) {
this.owner = owner;
}
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
}