From 705fc2b672d5802696074be94b446a89d228b94d Mon Sep 17 00:00:00 2001 From: ayalaben Date: Thu, 15 Mar 2018 15:59:25 +0200 Subject: Archive Item Change-Id: Idd5eedc3b0ca9e3cc72f7de9fd432cdbbf77631d Issue-ID: SDC-1086 Signed-off-by: ayalaben --- .../org/openecomp/sdcrests/item/rest/Items.java | 55 ++++++ .../sdcrests/item/rest/mapping/MapItemToDto.java | 2 + .../sdcrests/item/rest/services/ItemsImpl.java | 191 +++++++++++++++++++++ .../openecomp/sdcrests/item/types/ItemAction.java | 6 + .../sdcrests/item/types/ItemActionRequestDto.java | 29 ++++ .../org/openecomp/sdcrests/item/types/ItemDto.java | 9 + .../src/main/webapp/WEB-INF/beans-services.xml | 2 + .../vendorlicense/rest/VendorLicenseModels.java | 15 +- .../rest/services/VendorLicenseModelsImpl.java | 44 +++-- .../sdcrests/vsp/rest/VendorSoftwareProducts.java | 14 +- .../vsp/rest/mapping/MapItemToVspDetailsDto.java | 1 + .../rest/services/VendorSoftwareProductsImpl.java | 120 ++++++++----- .../types/VspDetailsDto.java | 9 + .../org/openecomp/sdc/common/errors/Messages.java | 1 + .../sdc/common/togglz/ToggleableFeature.java | 8 +- .../sdc/activitylog/dao/type/ActivityType.java | 2 + .../openecomp/sdc/versioning/AsdcItemManager.java | 22 +-- .../org/openecomp/sdc/versioning/ItemManager.java | 6 +- .../sdc/versioning/dao/types/Version.java | 2 +- .../org/openecomp/sdc/versioning/types/Item.java | 9 + .../openecomp/sdc/versioning/types/ItemStatus.java | 6 + .../versioning/types/NotificationEventTypes.java | 2 + .../dao/impl/zusammen/ItemZusammenDaoImpl.java | 14 ++ .../sdc/versioning/impl/ItemManagerImpl.java | 31 +++- .../dao/impl/zusammen/ItemZusammenDaoImplTest.java | 4 + .../sdc/versioning/impl/ItemManagerImplTest.java | 96 +++++++++++ .../org/openecomp/core/tools/commands/HealAll.java | 2 +- 27 files changed, 603 insertions(+), 99 deletions(-) create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemAction.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemActionRequestDto.java create mode 100644 openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/ItemStatus.java create mode 100644 openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java (limited to 'openecomp-be') 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 { 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 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 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 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 attributes; + private String entityId; + + SyncEvent(String eventType, String originatorId, + Map 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 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 @@ + @@ -73,6 +74,7 @@ + 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 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 itemPredicate = createItemPredicate(versionStatus, itemStatus, user); GenericCollectionWrapper 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 createItemPredicate(String versionStatus, + String itemStatus, + String user) { + Predicate 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 { 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 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 results = new GenericCollectionWrapper<>(); + MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto(); - GenericCollectionWrapper 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 VspsIds = + getVspList(null, status != null ? ItemStatus.valueOf(status).name(): null, user) + .stream().map(Item::getId).collect(Collectors.toList()); + List packageInfoList = vendorSoftwareProductManager.listPackages(category, subCategory); + packageInfoList = packageInfoList.stream(). + filter(packageInfo -> VspsIds.contains(packageInfo.getVspId())) + .collect(Collectors.toList()); + GenericCollectionWrapper 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 createItemPredicate(String versionStatus, + String itemStatus, + String user) { + Predicate 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 getVspList(String versionStatus, String itemStatus, String user) { + + Predicate 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; + } } diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java index 21636690f7..0bf8796910 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java @@ -42,6 +42,7 @@ public enum Messages { DELETE_VSP_ERROR("VSP has been certified and cannot be deleted."), DELETE_VLM_ERROR("VLM has been certified and cannot be deleted."), + ZIP_SHOULD_NOT_CONTAIN_FOLDERS("Zip file should not contain folders"), VES_ZIP_SHOULD_CONTAIN_YML_ONLY( "Wrong VES EVENT Artifact was uploaded - all files contained in Artifact must be YAML files" + diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/togglz/ToggleableFeature.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/togglz/ToggleableFeature.java index c3cac50ebe..5080e00ea3 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/togglz/ToggleableFeature.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/togglz/ToggleableFeature.java @@ -10,7 +10,13 @@ public enum ToggleableFeature implements Feature { VLAN_TAGGING, @Label ("Annotations") - ANNOTATIONS; + ANNOTATIONS, + + @Label("Archive Item") + ARCHIVE_ITEM, + + @Label("Filter") + FILTER; public boolean isActive() { return FeatureContext.getFeatureManager().isActive(this); diff --git a/openecomp-be/lib/openecomp-sdc-activity-log-lib/openecomp-sdc-activity-log-api/src/main/java/org/openecomp/sdc/activitylog/dao/type/ActivityType.java b/openecomp-be/lib/openecomp-sdc-activity-log-lib/openecomp-sdc-activity-log-api/src/main/java/org/openecomp/sdc/activitylog/dao/type/ActivityType.java index 620113e2b5..3f5b1b6235 100644 --- a/openecomp-be/lib/openecomp-sdc-activity-log-lib/openecomp-sdc-activity-log-api/src/main/java/org/openecomp/sdc/activitylog/dao/type/ActivityType.java +++ b/openecomp-be/lib/openecomp-sdc-activity-log-lib/openecomp-sdc-activity-log-api/src/main/java/org/openecomp/sdc/activitylog/dao/type/ActivityType.java @@ -2,6 +2,8 @@ package org.openecomp.sdc.activitylog.dao.type; public enum ActivityType { Create, + Archive, + Restore, Create_Version, Commit, Submit, diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/AsdcItemManager.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/AsdcItemManager.java index a4ea65fa08..ad3d1f304c 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/AsdcItemManager.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/AsdcItemManager.java @@ -16,25 +16,7 @@ package org.openecomp.sdc.versioning; -import java.util.Collection; -import java.util.function.Predicate; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; +public interface AsdcItemManager extends ItemManager { -public interface AsdcItemManager { - - Collection list(Predicate predicate); - - Item get(String itemId); - - Item create(Item item); - - void updateVersionStatus(String itemId, VersionStatus addedVersionStatus, - VersionStatus removedVersionStatus); - - void updateOwner(String itemId, String owner); - - void updateName(String itemId, String name); - - void delete(Item item); + void updateOwner(String itemId, String owner); } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java index 41a2c12058..0448ee782f 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java @@ -32,9 +32,11 @@ public interface ItemManager { void updateVersionStatus(String itemId, VersionStatus addedVersionStatus, VersionStatus removedVersionStatus); - void delete(Item item); + void archive(Item item); + + void restore(Item item); - void updateName(String itemId, String name); + void delete(Item item); void update(Item item); } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java index b1f0b71d90..4d4c194972 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java @@ -209,7 +209,7 @@ public class Version { return major == version.major && minor == version.minor; } - public int compateTo(Version other){ + public int compareTo(Version other){ if (this.major>other.major) { return 1; } else if(this.major properties = new HashMap<>(); private Map versionStatusCounters = new EnumMap<>(VersionStatus.class); @@ -50,6 +51,14 @@ public class Item { this.owner = owner; } + public ItemStatus getStatus() { + return status; + } + + public void setStatus(ItemStatus status) { + this.status = status; + } + public String getDescription() { return description; } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/ItemStatus.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/ItemStatus.java new file mode 100644 index 0000000000..413c5a7f29 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/ItemStatus.java @@ -0,0 +1,6 @@ +package org.openecomp.sdc.versioning.types; + +public enum ItemStatus { + ACTIVE, + ARCHIVED +} diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/NotificationEventTypes.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/NotificationEventTypes.java index 336db6496c..da53d8d6ed 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/NotificationEventTypes.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/NotificationEventTypes.java @@ -7,6 +7,8 @@ package org.openecomp.sdc.versioning.types; public enum NotificationEventTypes { SUBMIT("submit"), DELETE("delete"), + ARCHIVE("archive"), + RESTORE("restore"), COMMIT("commit"); private String eventName; diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java index 5a212afc8e..665bf06b91 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java @@ -7,6 +7,7 @@ import org.openecomp.core.zusammen.api.ZusammenUtil; import org.openecomp.sdc.versioning.dao.ItemDao; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; import java.util.Collection; import java.util.Map; @@ -67,6 +68,12 @@ public class ItemZusammenDaoImpl implements ItemDao { item.setCreationTime(zusammenItem.getCreationTime()); item.setModificationTime(zusammenItem.getModificationTime()); + + if(item.getStatus() == null){ + item.setStatus(ItemStatus.ACTIVE); + update(item); + } + return item; } @@ -78,6 +85,9 @@ public class ItemZusammenDaoImpl implements ItemDao { case InfoPropertyName.ITEM_OWNER: item.setOwner((String) propertyValue); break; + case InfoPropertyName.ITEM_STATUS: + item.setStatus(ItemStatus.valueOf((String)propertyValue)); + break; case InfoPropertyName.ITEM_VERSIONS_STATUSES: for (Map.Entry statusCounter : ((Map) propertyValue).entrySet()) { @@ -96,6 +106,9 @@ public class ItemZusammenDaoImpl implements ItemDao { info.setDescription(item.getDescription()); info.addProperty(InfoPropertyName.ITEM_TYPE, item.getType()); info.addProperty(InfoPropertyName.ITEM_OWNER,item.getOwner()); + if (item.getStatus() != null) { + info.addProperty(InfoPropertyName.ITEM_STATUS, item.getStatus()); + } info.addProperty(InfoPropertyName.ITEM_VERSIONS_STATUSES, item.getVersionStatusCounters()); item.getProperties().entrySet() .forEach(property -> info.addProperty(property.getKey(), property.getValue())); @@ -106,6 +119,7 @@ public class ItemZusammenDaoImpl implements ItemDao { private static final String ITEM_TYPE = "item_type"; private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses"; private static final String ITEM_OWNER = "Owner"; + private static final String ITEM_STATUS = "status"; private InfoPropertyName() { throw new IllegalStateException("Constants class"); diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java index dadf456ad4..3b7b018678 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java @@ -19,10 +19,14 @@ package org.openecomp.sdc.versioning.impl; import java.util.Collection; import java.util.function.Predicate; import java.util.stream.Collectors; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.versioning.ItemManager; import org.openecomp.sdc.versioning.dao.ItemDao; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; public class ItemManagerImpl implements ItemManager { @@ -72,16 +76,33 @@ public class ItemManagerImpl implements ItemManager { } @Override - public void updateName(String itemId, String name) { - Item item = get(itemId); - if (item == null) { - return; + public void archive(Item item) { + + if (item.getStatus() == ItemStatus.ARCHIVED) { + throw new CoreException(new ErrorCode.ErrorCodeBuilder() + .withCategory(ErrorCategory.APPLICATION) + .withMessage(String.format("Archive item failed, item %s is already Archived", item.getId())) + .build()); } - item.setName(name); + item.setStatus(ItemStatus.ARCHIVED); itemDao.update(item); } + @Override + public void restore(Item item) { + + if (item.getStatus() == ItemStatus.ACTIVE) { + throw new CoreException(new ErrorCode.ErrorCodeBuilder() + .withCategory(ErrorCategory.APPLICATION) + .withMessage(String.format("Restore item failed, item %s is already Active", item.getId())) + .build()); + } + + item.setStatus(ItemStatus.ACTIVE); + itemDao.update(item); + } + @Override public void update(Item item) { itemDao.update(item); diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java index bfa660a5a1..e67dc57de2 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java @@ -10,6 +10,7 @@ import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.common.session.SessionContextProviderFactory; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -28,6 +29,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext; +import static org.testng.Assert.assertEquals; public class ItemZusammenDaoImplTest { @@ -114,6 +116,8 @@ public class ItemZusammenDaoImplTest { Assert.assertNotNull(item); assertItemEquals(item, toBeReturned); + assertEquals(item.getStatus(), ItemStatus.ACTIVE); + } @Test diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java new file mode 100644 index 0000000000..fadfe3686e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java @@ -0,0 +1,96 @@ +package org.openecomp.sdc.versioning.impl; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.itempermissions.PermissionsServices; +import org.openecomp.sdc.notification.services.SubscriptionService; +import org.openecomp.sdc.versioning.dao.ItemDao; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.mockito.Mockito.verify; +import static org.testng.Assert.assertEquals; + +public class ItemManagerImplTest { + + private static final String USER = "user1"; + private static final String ITEM_ID = "item1"; + private static final String ITEM_NAME = "item 1 name"; + private static final String ITEM_TYPE_A = "A"; + private static final String ITEM_TYPE_B = "B"; + private static final String tenant = "dox"; + @Mock + private ItemDao itemDao; + @Mock + private PermissionsServices permissionsServices; + @Mock + private SubscriptionService subscriptionService; + @InjectMocks + private ItemManagerImpl itemManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @AfterMethod + public void tearDown(){ + itemManager = null; + } + + @Test + public void ArchiveTest(){ + + Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_A); + itemManager.archive(item); + + verify(itemDao).update(item); + assertEquals(item.getStatus(), ItemStatus.ARCHIVED); + } + + @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp = + "Archive item failed, item .* is already Archived") + public void ArchiveTestNegative(){ + + Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_B); + item.setStatus(ItemStatus.ARCHIVED); + itemManager.archive(item); + + } + + @Test + public void RestoreTest(){ + + Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_A); + item.setStatus(ItemStatus.ARCHIVED); + itemManager.restore(item); + + verify(itemDao).update(item); + assertEquals(item.getStatus(), ItemStatus.ACTIVE); + } + + @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp = + "Restore item failed, item .* is already Active") + public void RestoreTestNegative(){ + + Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_B); + item.setStatus(ItemStatus.ACTIVE); + itemManager.restore(item); + + } + + + private Item createItem(String id, String name, String type) { + Item item = new Item(); + item.setId(id); + item.setName(name); + item.setType(type); + return item; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java index 8bcfcbacde..d6344f75bd 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java @@ -99,7 +99,7 @@ public class HealAll { return versionInfoEntity.getCandidate().getVersion(); } else if (!CollectionUtils.isEmpty(versionInfoEntity.getViewableVersions())) { - return versionInfoEntity.getViewableVersions().stream().max(Version::compateTo) + return versionInfoEntity.getViewableVersions().stream().max(Version::compareTo) .orElse(new Version()); } return versionInfoEntity.getActiveVersion(); -- cgit 1.2.3-korg