From 664c11581c7ea5d36e36af1fe7b26e14271e77fe Mon Sep 17 00:00:00 2001 From: talig Date: Mon, 1 Jan 2018 13:07:47 +0200 Subject: Fix sonar issues + tests in versioning lib Change-Id: Ib49288fe49be1e848b9615e548689cdbe0df4fee Issue-ID: SDC-779 Signed-off-by: talig --- .../sdcrests/item/rest/services/VersionsImpl.java | 62 ++++++++++++---------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src') 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 c2f6c4708d..23ffc2549b 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 @@ -145,21 +145,11 @@ public class VersionsImpl implements Versions { @Override public Response listRevisions(String itemId, String versionId, String user) { - GenericCollectionWrapper results = new GenericCollectionWrapper<>(); - MapRevisionToDto mapper = new MapRevisionToDto(); - List revisions = versioningManager.listRevisions(itemId, new Version(versionId)); - /* 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 : " - 4- only if a revision in this format exists we remove the first revision. */ - if (revisions.size() > 1 && - revisions.get(revisions.size() - 2).getMessage().matches("Initial .*:.*")) { - revisions.remove(revisions.size() - 1); - } + filterRevisions(revisions); + GenericCollectionWrapper results = new GenericCollectionWrapper<>(); + MapRevisionToDto mapper = new MapRevisionToDto(); revisions.forEach(revision -> results.add(mapper.applyMapping(revision, RevisionDto.class))); return Response.ok(results).build(); } @@ -189,13 +179,15 @@ public class VersionsImpl implements Versions { return Response.ok().build(); } + private Version getVersion(String itemId, Version version) { + Version retrievedVersion = versioningManager.get(itemId, version); - private void revert(RevisionRequestDto request, String itemId, String versionId) { - if (request.getRevisionId() == null) { - throw new CoreException(new RevisionIdNotFoundErrorBuilder().build()); + if (retrievedVersion.getState().getSynchronizationState() != SynchronizationState.Merging && + // looks for sdc applicative conflicts + conflictsManager.isConflicted(itemId, retrievedVersion)) { + retrievedVersion.getState().setSynchronizationState(SynchronizationState.Merging); } - - versioningManager.revert(itemId, new Version(versionId), request.getRevisionId()); + return retrievedVersion; } private void sync(String itemId, Version version) { @@ -214,6 +206,29 @@ public class VersionsImpl implements Versions { ActivityType.Commit, user, true, "", message)); } + 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 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 : " + 4- only if a revision in this format exists we remove the first revision. */ + 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 eventProperties = new HashMap<>(); @@ -236,10 +251,10 @@ public class VersionsImpl implements Versions { } private class SyncEvent implements Event { - private String eventType; private String originatorId; private Map attributes; + private String entityId; public SyncEvent(String eventType, String originatorId, @@ -269,15 +284,6 @@ public class VersionsImpl implements Versions { public String getEntityId() { return entityId; } - } - private Version getVersion(String itemId, Version version) { - version = versioningManager.get(itemId, version); - - if (version.getState().getSynchronizationState() != SynchronizationState.Merging && - conflictsManager.isConflicted(itemId, version)) { // looks for sdc applicative conflicts - version.getState().setSynchronizationState(SynchronizationState.Merging); - } - return version; } } -- cgit 1.2.3-korg