diff options
author | talig <talig@amdocs.com> | 2018-01-01 13:07:47 +0200 |
---|---|---|
committer | talig <talig@amdocs.com> | 2018-01-01 13:07:47 +0200 |
commit | 664c11581c7ea5d36e36af1fe7b26e14271e77fe (patch) | |
tree | e0e519697d5105c8ef57406c548f1444e9bf476c /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest | |
parent | 16f5d02fee065f1bbafe056e22627d996dcf2e6a (diff) |
Fix sonar issues + tests in versioning lib
Change-Id: Ib49288fe49be1e848b9615e548689cdbe0df4fee
Issue-ID: SDC-779
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest')
-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.java | 62 |
1 files changed, 34 insertions, 28 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/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<RevisionDto> results = new GenericCollectionWrapper<>(); - MapRevisionToDto mapper = new MapRevisionToDto(); - List<Revision> 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 <vlm/vsp>: <name of the vlm/vsp>" - 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<RevisionDto> 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<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 && + + 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<>(); @@ -236,10 +251,10 @@ public class VersionsImpl implements Versions { } private class SyncEvent implements Event { - private String eventType; private String originatorId; private Map<String, Object> 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; } } |