aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-04-12 13:20:18 +0300
committerayalaben <ayala.benzvi@amdocs.com>2018-04-12 16:37:18 +0300
commit8da1beb7fb630954a0c7adfc7ae6fbb175877b49 (patch)
treeb6353cb051d382e3774e9a319a88160b9d028521 /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src
parentc7941c2287c3858e4006f3a15ffd6e5a2f33af2e (diff)
Filter in onboarding - BE
Change-Id: I519ef44889de5314cf6675055cd15beef84dfb6f Issue-ID: SDC-1213 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src')
-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.java478
1 files changed, 231 insertions, 247 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/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 2761c85502..0e645dd4e9 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
@@ -17,6 +17,21 @@
package org.openecomp.sdcrests.vendorlicense.rest.services;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+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 static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
import org.openecomp.core.dao.UniqueValueDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.sdc.activitylog.ActivityLogManager;
@@ -47,12 +62,12 @@ 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.ItemStatus;
import org.openecomp.sdc.versioning.types.NotificationEventTypes;
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;
@@ -65,285 +80,254 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
-import java.util.*;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
-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 static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit;
-
@Named
@Service("vendorLicenseModels")
@Scope(value = "prototype")
@Validated
public class VendorLicenseModelsImpl implements VendorLicenseModels {
- private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
- private static final String SUBMIT_HEALED_VERSION_ERROR =
- "VLM Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
- private static final Logger LOGGER = LoggerFactory.getLogger(VendorLicenseModelsImpl.class);
- private PermissionsManager permissionsManager = PermissionsManagerFactory.getInstance()
- .createInterface();
- private NotificationPropagationManager notifier =
- NotificationPropagationManagerFactory.getInstance().createInterface();
-
- private AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance().createInterface();
- private VersioningManager versioningManager =
- VersioningManagerFactory.getInstance().createInterface();
- private VendorLicenseManager vendorLicenseManager =
- VendorLicenseManagerFactory.getInstance().createInterface();
- private ActivityLogManager activityLogManager =
- ActivityLogManagerFactory.getInstance().createInterface();
- private UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance()
- .createInterface());
-
- @Override
- public Response listLicenseModels(String versionStatus,String itemStatus, String user) {
- Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user);
-
- MapItemToDto mapper = new MapItemToDto();
- GenericCollectionWrapper<ItemDto> results = new GenericCollectionWrapper<>(asdcItemManager.list(itemPredicate)
- .stream().sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
- .map(item ->mapper.applyMapping(item, ItemDto.class)).collect(Collectors.toList()));
-
- return Response.ok(results).build();
- }
-
- @Override
- public Response createLicenseModel(VendorLicenseModelRequestDto request, String user) {
-
- Item item = new Item();
- item.setType(ItemType.vlm.name());
- item.setOwner(user);
- item.setStatus(ItemStatus.ACTIVE);
- item.setName(request.getVendorName());
- item.setDescription(request.getDescription());
-
- uniqueValueUtil
- .validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
- item = asdcItemManager.create(item);
- uniqueValueUtil
- .createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
-
- Version version = versioningManager.create(item.getId(), new Version(), null);
-
- VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
- .applyMapping(request, VendorLicenseModelEntity.class);
- vlm.setId(item.getId());
- vlm.setVersion(version);
-
- vendorLicenseManager.createVendorLicenseModel(vlm);
- versioningManager.publish(item.getId(), version, "Initial vlm:" + vlm.getVendorName());
-
- ItemCreationDto itemCreationDto = new ItemCreationDto();
- itemCreationDto.setItemId(item.getId());
- itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
-
- activityLogManager.logActivity(new ActivityLogEntity(vlm.getId(), version,
- ActivityType.Create, user, true, "", ""));
- return Response.ok(itemCreationDto).build();
- }
-
- @Override
- public Response updateLicenseModel(VendorLicenseModelRequestDto request, String vlmId,
- String versionId, String user) {
- VendorLicenseModelEntity vlm =
- new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
- .applyMapping(request, VendorLicenseModelEntity.class);
- vlm.setId(vlmId);
- vlm.setVersion(new Version(versionId));
-
- vendorLicenseManager.updateVendorLicenseModel(vlm);
- return Response.ok().build();
- }
-
- @Override
- public Response getLicenseModel(String vlmId, String versionId, String user) {
- Version version = versioningManager.get(vlmId, new Version(versionId));
- VendorLicenseModelEntity vlm = vendorLicenseManager.getVendorLicenseModel(vlmId, version);
- vlm.setWritetimeMicroSeconds(version.getModificationTime().getTime());
-
- try {
- Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
- .healItemVersion(vlmId, version, ItemType.vlm, false);
-
- if (healedVersion.isPresent()) {
- vlm.setVersion(healedVersion.get());
- if (version.getStatus() == VersionStatus.Certified) {
- submitHealedVersion(vlmId, healedVersion.get(), versionId, user);
- }
- }
- } catch (Exception e) {
- LOGGER.error(
- String.format("Error while auto healing VLM with Id %s and version %s", vlmId, versionId),
- e);
- }
+ private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
+ private static final String SUBMIT_HEALED_VERSION_ERROR =
+ "VLM Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
+ private static final Logger LOGGER = LoggerFactory.getLogger(VendorLicenseModelsImpl.class);
+ private PermissionsManager permissionsManager = PermissionsManagerFactory.getInstance().createInterface();
+ private NotificationPropagationManager notifier =
+ NotificationPropagationManagerFactory.getInstance().createInterface();
+
+ private AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance().createInterface();
+ private VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
+ private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface();
+ private ActivityLogManager activityLogManager = ActivityLogManagerFactory.getInstance().createInterface();
+ private UniqueValueUtil uniqueValueUtil =
+ new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface());
- VendorLicenseModelEntityDto vlmDto =
- new MapVendorLicenseModelEntityToDto().applyMapping(vlm, VendorLicenseModelEntityDto.class);
- return Response.ok(vlmDto).build();
- }
+ @Override
+ public Response listLicenseModels(String versionStatus, String itemStatus, String user) {
+ Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user);
- @Override
- public Response deleteLicenseModel(String vlmId, String user) {
- Item vlm = asdcItemManager.get(vlmId);
+ GenericCollectionWrapper<ItemDto> results = new GenericCollectionWrapper<>();
+ MapItemToDto mapper = new MapItemToDto();
+ asdcItemManager.list(itemPredicate).stream()
+ .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
+ .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class)));
- if (!vlm.getType().equals(ItemType.vlm.name())){
- throw new CoreException((new ErrorCode.ErrorCodeBuilder()
- .withMessage(String.format("Vlm with id %s does not exist.",
- vlmId)).build()));
+ return Response.ok(results).build();
}
- Integer certifiedVersionsCounter = vlm.getVersionStatusCounters().get(VersionStatus.Certified);
- if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) {
- asdcItemManager.delete(vlm);
- permissionsManager.deleteItemPermissions(vlmId);
- uniqueValueUtil
- .deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vlm.getName());
- notifyUsers(vlmId, vlm.getName(), null, null, user,
- NotificationEventTypes.DELETE);
-
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.FORBIDDEN)
- .entity(new Exception(Messages.DELETE_VLM_ERROR.getErrorMessage())).build();
- }
- }
+ @Override
+ public Response createLicenseModel(VendorLicenseModelRequestDto request, String user) {
- @Override
- public Response actOnLicenseModel(VendorLicenseModelActionRequestDto request, String vlmId,
- String versionId, String user) {
- Version version = new Version(versionId);
+ Item item = new Item();
+ item.setType(ItemType.vlm.name());
+ item.setOwner(user);
+ item.setStatus(ItemStatus.ACTIVE);
+ item.setName(request.getVendorName());
+ item.setDescription(request.getDescription());
- if (request.getAction() == Submit) {
- if (!permissionsManager.isAllowed(vlmId, user, SUBMIT_ITEM_ACTION)) {
- return Response.status(Response.Status.FORBIDDEN)
- .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
- }
- String message =
- request.getSubmitRequest() == null ? "Submit" : request.getSubmitRequest().getMessage();
- submit(vlmId, version, message, user);
+ uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
+ item = asdcItemManager.create(item);
+ uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName());
- notifyUsers(vlmId, null, version, message, user, NotificationEventTypes.SUBMIT);
+ Version version = versioningManager.create(item.getId(), new Version(), null);
+ VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
+ .applyMapping(request, VendorLicenseModelEntity.class);
+ vlm.setId(item.getId());
+ vlm.setVersion(version);
+
+ vendorLicenseManager.createVendorLicenseModel(vlm);
+ versioningManager.publish(item.getId(), version, "Initial vlm:" + vlm.getVendorName());
+
+ ItemCreationDto itemCreationDto = new ItemCreationDto();
+ itemCreationDto.setItemId(item.getId());
+ itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
+
+ activityLogManager
+ .logActivity(new ActivityLogEntity(vlm.getId(), version, ActivityType.Create, user, true, "", ""));
+ return Response.ok(itemCreationDto).build();
}
- return Response.ok().build();
- }
-
- private void submit(String vlmId, Version version, String message, String user) {
-
- vendorLicenseManager.validate(vlmId, version);
- versioningManager.submit(vlmId, version, message);
-
- activityLogManager.logActivity(
- new ActivityLogEntity(vlmId, version, ActivityType.Submit, user, true, "", message));
- }
-
- private void submitHealedVersion(String vlmId, Version healedVersion, String baseVersionId,
- String user) {
- try {
- submit(vlmId, healedVersion, "Submit after heal", user);
- } catch (Exception ex) {
- LOGGER.error(
- String.format(SUBMIT_HEALED_VERSION_ERROR, vlmId, healedVersion.getId(), baseVersionId),
- ex);
- }
- }
-
- private void notifyUsers(String itemId, String itemName, Version version, String message,
- String userName, NotificationEventTypes eventType) {
- Map<String, Object> eventProperties = new HashMap<>();
- eventProperties.put(ITEM_NAME, itemName == null ? asdcItemManager.get(itemId).getName() : itemName);
- eventProperties.put(ITEM_ID, itemId);
-
- if (version != null) {
- eventProperties.put(VERSION_NAME, version.getName() == null
- ? versioningManager.get(itemId, version).getName()
- : version.getName());
- eventProperties.put(VERSION_ID, version.getId());
+
+ @Override
+ public Response updateLicenseModel(VendorLicenseModelRequestDto request, String vlmId, String versionId,
+ String user) {
+ VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
+ .applyMapping(request, VendorLicenseModelEntity.class);
+ vlm.setId(vlmId);
+ vlm.setVersion(new Version(versionId));
+
+ vendorLicenseManager.updateVendorLicenseModel(vlm);
+ return Response.ok().build();
}
- eventProperties.put(SUBMIT_DESCRIPTION, message);
- eventProperties.put(PERMISSION_USER, userName);
+ @Override
+ public Response getLicenseModel(String vlmId, String versionId, String user) {
+ Version version = versioningManager.get(vlmId, new Version(versionId));
+ VendorLicenseModelEntity vlm = vendorLicenseManager.getVendorLicenseModel(vlmId, version);
+ vlm.setWritetimeMicroSeconds(version.getModificationTime().getTime());
+
+ try {
+ Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
+ .healItemVersion(vlmId, version, ItemType.vlm,
+ false);
+
+ if (healedVersion.isPresent()) {
+ vlm.setVersion(healedVersion.get());
+ if (version.getStatus() == VersionStatus.Certified) {
+ submitHealedVersion(vlmId, healedVersion.get(), versionId, user);
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.error(String.format("Error while auto healing VLM with Id %s and version %s", vlmId, versionId), e);
+ }
- 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 o item '" + itemId);
+ VendorLicenseModelEntityDto vlmDto =
+ new MapVendorLicenseModelEntityToDto().applyMapping(vlm, VendorLicenseModelEntityDto.class);
+ return Response.ok(vlmDto).build();
}
- }
- private class SyncEvent implements Event {
+ @Override
+ public Response deleteLicenseModel(String vlmId, String user) {
+ Item vlm = asdcItemManager.get(vlmId);
- private String eventType;
- private String originatorId;
- private Map<String, Object> attributes;
- private String entityId;
+ if (!vlm.getType().equals(ItemType.vlm.name())) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder()
+ .withMessage(String.format("Vlm with id %s does not exist.", vlmId))
+ .build()));
+ }
- SyncEvent(String eventType, String originatorId,
- Map<String, Object> attributes, String entityId) {
- this.eventType = eventType;
- this.originatorId = originatorId;
- this.attributes = attributes;
- this.entityId = entityId;
+ Integer certifiedVersionsCounter = vlm.getVersionStatusCounters().get(VersionStatus.Certified);
+ if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) {
+ asdcItemManager.delete(vlm);
+ permissionsManager.deleteItemPermissions(vlmId);
+ uniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vlm.getName());
+ notifyUsers(vlmId, vlm.getName(), null, null, user, NotificationEventTypes.DELETE);
+
+ return Response.ok().build();
+ } else {
+ return Response.status(Response.Status.FORBIDDEN)
+ .entity(new Exception(Messages.DELETE_VLM_ERROR.getErrorMessage())).build();
+ }
}
@Override
- public String getEventType() {
- return eventType;
+ public Response actOnLicenseModel(VendorLicenseModelActionRequestDto request, String vlmId, String versionId,
+ String user) {
+ Version version = new Version(versionId);
+
+ if (request.getAction() == Submit) {
+ if (!permissionsManager.isAllowed(vlmId, user, SUBMIT_ITEM_ACTION)) {
+ return Response.status(Response.Status.FORBIDDEN)
+ .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
+ }
+ String message = request.getSubmitRequest() == null ? "Submit" : request.getSubmitRequest().getMessage();
+ submit(vlmId, version, message, user);
+
+ notifyUsers(vlmId, null, version, message, user, NotificationEventTypes.SUBMIT);
+
+ }
+ return Response.ok().build();
}
- @Override
- public String getOriginatorId() {
- return originatorId;
+ private void submit(String vlmId, Version version, String message, String user) {
+
+ vendorLicenseManager.validate(vlmId, version);
+ versioningManager.submit(vlmId, version, message);
+
+ activityLogManager
+ .logActivity(new ActivityLogEntity(vlmId, version, ActivityType.Submit, user, true, "", message));
}
- @Override
- public Map<String, Object> getAttributes() {
- return attributes;
+ private void submitHealedVersion(String vlmId, Version healedVersion, String baseVersionId, String user) {
+ try {
+ submit(vlmId, healedVersion, "Submit after heal", user);
+ } catch (Exception ex) {
+ LOGGER.error(String.format(SUBMIT_HEALED_VERSION_ERROR, vlmId, healedVersion.getId(), baseVersionId), ex);
+ }
}
- @Override
- public String getEntityId() {
- return entityId;
+ private void notifyUsers(String itemId, String itemName, Version version, String message, String userName,
+ NotificationEventTypes eventType) {
+ Map<String, Object> eventProperties = new HashMap<>();
+ eventProperties.put(ITEM_NAME, itemName == null ? asdcItemManager.get(itemId).getName() : itemName);
+ eventProperties.put(ITEM_ID, itemId);
+
+ if (version != null) {
+ eventProperties.put(VERSION_NAME,
+ version.getName() == null ? versioningManager.get(itemId, version).getName() : version.getName());
+ eventProperties.put(VERSION_ID, version.getId());
+ }
+
+ 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 o 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 boolean userHasPermission(String itemId, String userId) {
- String permission = permissionsManager.getUserItemPermission(itemId, userId);
- 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));
- }
+
+ private boolean userHasPermission(String itemId, String userId) {
+ String permission = permissionsManager.getUserItemPermission(itemId, userId);
+ 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;
}
- return itemPredicate;
- }
}