summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-03-15 15:59:25 +0200
committerayalaben <ayala.benzvi@amdocs.com>2018-03-19 10:45:48 +0200
commit705fc2b672d5802696074be94b446a89d228b94d (patch)
tree135b0d30b36eaf0180314d68531186648ac29882 /openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src
parent3c24190cca30ee77c8c81d1738d7d5cbf454d647 (diff)
Archive Item
Change-Id: Idd5eedc3b0ca9e3cc72f7de9fd432cdbbf77631d Issue-ID: SDC-1086 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java96
4 files changed, 140 insertions, 5 deletions
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;
+ }
+}