diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib')
10 files changed, 164 insertions, 28 deletions
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<Item> list(Predicate<Item> 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<other.major){ diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java index d572373d44..161c22c389 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java @@ -12,6 +12,7 @@ public class Item { private String type; private String name; private String owner; + private ItemStatus status; private String description; private Map<String, Object> properties = new HashMap<>(); private Map<VersionStatus, Integer> 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<String, Number> statusCounter : ((Map<String, Number>) 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,17 +76,34 @@ 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; + } +} |