aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-08-20 01:27:45 +0300
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-09-05 08:37:54 +0000
commit5c9769c3e3a6d6675c5ec1bd450720791ef2793c (patch)
tree91ca1c456ed703dacfd46ded2ac5918711c8ce1a /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main
parent828ee221b1d186e637bffffaeea1684e752ceb36 (diff)
fix merge issue
restore activity log add clean up to the onboarding back end docker Issue-ID: SDC-1664 Change-Id: Ib7994ca12439bc842650c3cacddb0e4d87215390 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main')
-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.java7
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java339
2 files changed, 180 insertions, 166 deletions
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
index eae8e4220e..b00e4594b3 100644
--- 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
@@ -16,6 +16,9 @@
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.datatypes.model.ItemType;
import org.openecomp.sdc.itempermissions.PermissionsManager;
@@ -64,6 +67,7 @@ public class ItemsImpl implements Items {
private ItemManager itemManager = ItemManagerFactory.getInstance().createInterface();
+ private static ActivityLogManager activityLogManager = ActivityLogManagerFactory.getInstance().createInterface();
private VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
@@ -200,6 +204,9 @@ public class ItemsImpl implements Items {
private void execute(Item item, String user) {
notifyUsers(item.getId(), item.getName(), user, this.notificationType);
+ activityLogManager.logActivity(
+ new ActivityLogEntity(item.getId(), getLatestVersion(item.getId()), this.activityType, user, true,
+ "", ""));
}
private void notifyUsers(String itemId, String itemName, String userName, NotificationEventTypes eventType) {
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java
index fd46e7f274..cd6364f145 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java
@@ -16,6 +16,10 @@
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.CoreException;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.conflicts.ConflictsManager;
@@ -60,199 +64,202 @@ import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.*;
@Scope(value = "prototype")
public class VersionsImpl implements Versions {
- private static final String COMMIT_ITEM_ACTION = "Commit_Item";
- private static final Logger LOGGER = LoggerFactory.getLogger(VersionsImpl.class);
-
- private PermissionsManager permissionsManager =
- PermissionsManagerFactory.getInstance().createInterface();
- private AsdcItemManager asdcItemManager =
- AsdcItemManagerFactory.getInstance().createInterface();
- private VersioningManager versioningManager =
- VersioningManagerFactory.getInstance().createInterface();
- private ConflictsManager conflictsManager =
- ConflictsManagerFactory.getInstance().createInterface();
- private NotificationPropagationManager notifier =
- NotificationPropagationManagerFactory.getInstance().createInterface();
-
- @Override
- public Response list(String itemId, String user) {
- GenericCollectionWrapper<VersionDto> results = new GenericCollectionWrapper<>();
- MapVersionToDto mapper = new MapVersionToDto();
-
- versioningManager.list(itemId)
- .forEach(version -> results.add(mapper.applyMapping(version, VersionDto.class)));
- return Response.ok(results).build();
- }
-
- @Override
- public Response create(VersionRequestDto request, String itemId, String baseVersionId,
- String user) {
- Version version = new Version();
- version.setBaseId(baseVersionId);
- version.setDescription(request.getDescription());
-
- version = versioningManager.create(itemId, version, VersionCreationMethod.valueOf(request
- .getCreationMethod().name()));
-
- VersionDto versionDto = new MapVersionToDto().applyMapping(version, VersionDto.class);
-
- return Response.ok(versionDto).build();
- }
-
- @Override
- public Response get(String itemId, String versionId, String user) {
- Version version = getVersion(itemId, new Version(versionId));
- VersionDto versionDto = new MapVersionToDto().applyMapping(version, VersionDto.class);
- return Response.ok(versionDto).build();
- }
-
- @Override
- public Response getActivityLog(String itemId, String versionId, String user) {
- GenericCollectionWrapper<ActivityLogDto> results = new GenericCollectionWrapper<>();
- MapActivityLogEntityToDto mapper = new MapActivityLogEntityToDto();
- return Response.ok(results).build();
- }
-
- @Override
- public Response listRevisions(String itemId, String versionId, String user) {
- List<Revision> revisions = versioningManager.listRevisions(itemId, new Version(versionId));
- filterRevisions(revisions);
-
- GenericCollectionWrapper<RevisionDto> results = new GenericCollectionWrapper<>();
- MapRevisionToDto mapper = new MapRevisionToDto();
- revisions.forEach(revision -> results.add(mapper.applyMapping(revision, RevisionDto.class)));
- return Response.ok(results).build();
- }
-
- @Override
- public Response actOn(VersionActionRequestDto request, String itemId, String versionId,
- String user) {
- Version version = new Version(versionId);
- switch (request.getAction()) {
- case Sync:
- sync(itemId, version);
- break;
- case Commit:
- if (!permissionsManager.isAllowed(itemId, user, COMMIT_ITEM_ACTION)) {
- return Response.status(Response.Status.FORBIDDEN)
- .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
- }
- commit(request.getCommitRequest(), itemId, version, user);
- break;
- case Revert:
- revert(request.getRevisionRequest(), itemId, versionId);
- break;
- case Clean:
- versioningManager.clean(itemId, version);
- break;
- default:
- throw new UnsupportedOperationException(String.format("Action %s not supported.", request.getAction()));
+ private static final String COMMIT_ITEM_ACTION = "Commit_Item";
+ private static final Logger LOGGER = LoggerFactory.getLogger(VersionsImpl.class);
+
+ private PermissionsManager permissionsManager = PermissionsManagerFactory.getInstance().createInterface();
+ private AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance().createInterface();
+ private VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
+ private ConflictsManager conflictsManager = ConflictsManagerFactory.getInstance().createInterface();
+ private ActivityLogManager activityLogManager = ActivityLogManagerFactory.getInstance().createInterface();
+ private NotificationPropagationManager notifier =
+ NotificationPropagationManagerFactory.getInstance().createInterface();
+
+ @Override
+ public Response list(String itemId, String user) {
+ GenericCollectionWrapper<VersionDto> results = new GenericCollectionWrapper<>();
+ MapVersionToDto mapper = new MapVersionToDto();
+
+ versioningManager.list(itemId).forEach(version -> results.add(mapper.applyMapping(version, VersionDto.class)));
+ return Response.ok(results).build();
}
- return Response.ok().build();
- }
- private Version getVersion(String itemId, Version version) {
- Version retrievedVersion = versioningManager.get(itemId, version);
+ @Override
+ public Response create(VersionRequestDto request, String itemId, String baseVersionId, String user) {
+ Version version = new Version();
+ version.setBaseId(baseVersionId);
+ version.setDescription(request.getDescription());
+
+ version = versioningManager
+ .create(itemId, version, VersionCreationMethod.valueOf(request.getCreationMethod().name()));
- if (retrievedVersion.getState().getSynchronizationState() != SynchronizationState.Merging &&
- // looks for sdc applicative conflicts
- conflictsManager.isConflicted(itemId, retrievedVersion)) {
- retrievedVersion.getState().setSynchronizationState(SynchronizationState.Merging);
+ VersionDto versionDto = new MapVersionToDto().applyMapping(version, VersionDto.class);
+
+ activityLogManager
+ .logActivity(new ActivityLogEntity(itemId, version, ActivityType.Create_Version, user, true, "", ""));
+
+ return Response.ok(versionDto).build();
}
- return retrievedVersion;
- }
- private void sync(String itemId, Version version) {
- versioningManager.sync(itemId, version);
- conflictsManager.finalizeMerge(itemId, version);
- }
+ @Override
+ public Response get(String itemId, String versionId, String user) {
+ Version version = getVersion(itemId, new Version(versionId));
+ VersionDto versionDto = new MapVersionToDto().applyMapping(version, VersionDto.class);
+ return Response.ok(versionDto).build();
+ }
- private void commit(CommitRequestDto request, String itemId, Version version, String user) {
+ @Override
+ public Response getActivityLog(String itemId, String versionId, String user) {
+ GenericCollectionWrapper<ActivityLogDto> results = new GenericCollectionWrapper<>();
+ MapActivityLogEntityToDto mapper = new MapActivityLogEntityToDto();
- String message = request == null ? "" : request.getMessage();
+ activityLogManager.listLoggedActivities(itemId, new Version(versionId))
+ .forEach(loggedActivity -> results.add(mapper.applyMapping(loggedActivity, ActivityLogDto.class)));
- versioningManager.publish(itemId, version, message);
- notifyUsers(itemId, version, message, user, NotificationEventTypes.COMMIT);
- }
+ return Response.ok(results).build();
+ }
- private void revert(RevisionRequestDto request, String itemId, String versionId) {
- if (request.getRevisionId() == null) {
- throw new CoreException(new RevisionIdNotFoundErrorBuilder().build());
+ @Override
+ public Response listRevisions(String itemId, String versionId, String user) {
+ List<Revision> revisions = versioningManager.listRevisions(itemId, new Version(versionId));
+ filterRevisions(revisions);
+
+ GenericCollectionWrapper<RevisionDto> results = new GenericCollectionWrapper<>();
+ MapRevisionToDto mapper = new MapRevisionToDto();
+ revisions.forEach(revision -> results.add(mapper.applyMapping(revision, RevisionDto.class)));
+ return Response.ok(results).build();
}
- versioningManager.revert(itemId, new Version(versionId), request.getRevisionId());
- }
+ @Override
+ public Response actOn(VersionActionRequestDto request, String itemId, String versionId, String user) {
+ Version version = new Version(versionId);
+ switch (request.getAction()) {
+ case Sync:
+ sync(itemId, version);
+ break;
+ case Commit:
+ if (!permissionsManager.isAllowed(itemId, user, COMMIT_ITEM_ACTION)) {
+ return Response.status(Response.Status.FORBIDDEN)
+ .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
+ }
+ commit(request.getCommitRequest(), itemId, version, user);
+ break;
+ case Revert:
+ revert(request.getRevisionRequest(), itemId, versionId);
+ break;
+ case Clean:
+ versioningManager.clean(itemId, version);
+ break;
+ default:
+ throw new UnsupportedOperationException(String.format("Action %s not supported.", request.getAction()));
+ }
+ return Response.ok().build();
+ }
+
+ private Version getVersion(String itemId, Version version) {
+ Version retrievedVersion = versioningManager.get(itemId, version);
+
+ if (retrievedVersion.getState().getSynchronizationState() != SynchronizationState.Merging &&
+ // looks for sdc applicative conflicts
+ conflictsManager.isConflicted(itemId, retrievedVersion)) {
+ retrievedVersion.getState().setSynchronizationState(SynchronizationState.Merging);
+ }
+ return retrievedVersion;
+ }
+
+ private void sync(String itemId, Version version) {
+ versioningManager.sync(itemId, version);
+ conflictsManager.finalizeMerge(itemId, version);
+ }
+
+ private void commit(CommitRequestDto request, String itemId, Version version, String user) {
+
+ String message = request == null ? "" : request.getMessage();
+
+ versioningManager.publish(itemId, version, message);
+ notifyUsers(itemId, version, message, user, NotificationEventTypes.COMMIT);
+ activityLogManager
+ .logActivity(new ActivityLogEntity(itemId, version, ActivityType.Commit, user, true, "", message));
+ }
- private void filterRevisions(List<Revision> revisions) {
+ private void revert(RevisionRequestDto request, String itemId, String versionId) {
+ if (request.getRevisionId() == null) {
+ throw new CoreException(new RevisionIdNotFoundErrorBuilder().build());
+ }
+
+ versioningManager.revert(itemId, new Version(versionId), request.getRevisionId());
+ }
+
+ private void filterRevisions(List<Revision> revisions) {
/* When creating a new item an initial version is created with invalid data.
This revision is not an applicable revision. The logic of identifying this revision is:
1- only the first version of item has this issue
2- only in the first item version there are 2 revisions created
3- the second revision is in format "Initial <vlm/vsp>: <name of the vlm/vsp>"
4- only if a revision in this format exists we remove the first revision. */
- int numOfRevisions = revisions.size();
- if (numOfRevisions > 1 &&
+ int numOfRevisions = revisions.size();
+ if (numOfRevisions > 1 &&
- revisions.get(numOfRevisions - 2).getMessage().matches("Initial .*:.*")) {
- revisions.remove(numOfRevisions - 1);
- }
- }
-
- private void notifyUsers(String itemId, Version version, String message,
- String userName, NotificationEventTypes eventType) {
- Map<String, Object> eventProperties = new HashMap<>();
- eventProperties.put(ITEM_NAME, asdcItemManager.get(itemId).getName());
- eventProperties.put(ITEM_ID, itemId);
-
- Version ver = versioningManager.get(itemId, version);
- eventProperties.put(VERSION_NAME, ver.getName());
- eventProperties.put(VERSION_ID, ver.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);
+ revisions.get(numOfRevisions - 2).getMessage().matches("Initial .*:.*")) {
+ revisions.remove(numOfRevisions - 1);
+ }
}
- }
- private class SyncEvent implements Event {
- private String eventType;
- private String originatorId;
- private Map<String, Object> attributes;
+ private void notifyUsers(String itemId, Version version, String message, String userName,
+ NotificationEventTypes eventType) {
+ Map<String, Object> eventProperties = new HashMap<>();
+ eventProperties.put(ITEM_NAME, asdcItemManager.get(itemId).getName());
+ eventProperties.put(ITEM_ID, itemId);
- private String entityId;
+ Version ver = versioningManager.get(itemId, version);
+ eventProperties.put(VERSION_NAME, ver.getName());
+ eventProperties.put(VERSION_ID, ver.getId());
- public SyncEvent(String eventType, String originatorId,
- Map<String, Object> attributes, String entityId) {
- this.eventType = eventType;
- this.originatorId = originatorId;
- this.attributes = attributes;
- this.entityId = entityId;
- }
+ eventProperties.put(SUBMIT_DESCRIPTION, message);
+ eventProperties.put(PERMISSION_USER, userName);
- @Override
- public String getEventType() {
- return eventType;
+ 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);
+ }
}
- @Override
- public String getOriginatorId() {
- return originatorId;
- }
+ private class SyncEvent implements Event {
- @Override
- public Map<String, Object> getAttributes() {
- return attributes;
- }
+ private String eventType;
+ private String originatorId;
+ private Map<String, Object> attributes;
- @Override
- public String getEntityId() {
- return entityId;
- }
+ private String entityId;
+
+ public 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;
+ }
+
+ }
}