aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-10-23 09:23:14 +0300
committertalig <talig@amdocs.com>2017-10-23 09:23:14 +0300
commitf4398a841ce8c4c185ab75abdf5e5a1c2d8ff784 (patch)
tree05a536d22c52a0b3a8ca5135ea9a17d3be833a24 /openecomp-be
parent6c416937323340a10095cfc2eb70229759fc4b92 (diff)
Fix onboarding undo checkout impl
Fix reset in zusammen collaboration plugin, Throw explicit exception in case of zusammen db illegal state. Change-Id: Ic9463517b72c7a89a2de78b86da5679ac57371a6 Issue-ID: SDC-490 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/activity-log-rest/activity-log-rest-types/src/main/java/org/openecomp/sdcrests/activitylog/types/ActivityType.java29
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java15
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java10
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java37
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/ElementCollaborationStore.java42
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStore.java81
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/dao/impl/CassandraElementRepository.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java3
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh2
9 files changed, 155 insertions, 94 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/activity-log-rest/activity-log-rest-types/src/main/java/org/openecomp/sdcrests/activitylog/types/ActivityType.java b/openecomp-be/api/openecomp-sdc-rest-webapp/activity-log-rest/activity-log-rest-types/src/main/java/org/openecomp/sdcrests/activitylog/types/ActivityType.java
index 6bfd50b401..80160bc202 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/activity-log-rest/activity-log-rest-types/src/main/java/org/openecomp/sdcrests/activitylog/types/ActivityType.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/activity-log-rest/activity-log-rest-types/src/main/java/org/openecomp/sdcrests/activitylog/types/ActivityType.java
@@ -24,14 +24,15 @@ import java.io.Serializable;
public enum ActivityType implements Serializable {
- CREATE_NEW("Create New"),
- CHECKOUT("Check Out"),
- CHECKIN("Check In"),
- UPLOAD_HEAT("Upload Heat"),
+ CREATE_NEW("Create New"),
+ CHECKOUT("Check Out"),
+ UNDO_CHECKOUT("Undo Check Out"),
+ CHECKIN("Check In"),
+ UPLOAD_HEAT("Upload Heat"),
UPLOAD_MONITORING_FILE("Upload Monitoring File"),
- SUBMIT("Submit");
+ SUBMIT("Submit");
- // after collaboration will be added - this will be added:
+ // after collaboration will be added - this will be added:
/*
CREATE_NEW,
COMMIT,
@@ -39,14 +40,14 @@ public enum ActivityType implements Serializable {
REMOVE_PERMISSION,
*/
- private String name;
+ private String name;
- ActivityType(String name) {
- this.name = name;
- }
+ ActivityType(String name) {
+ this.name = name;
+ }
- @Override
- public String toString() {
- return name;
- }
+ @Override
+ public String toString() {
+ return name;
+ }
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java
index edbf165ec1..e07a13c2e8 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java
@@ -24,7 +24,6 @@ import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICE
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.sdc.activityLog.ActivityLogManager;
-import org.openecomp.sdc.activityLog.ActivityLogManagerFactory;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCode;
@@ -41,17 +40,11 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
-import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
-import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
-import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
-import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.LimitDao;
-import org.openecomp.sdc.vendorlicense.dao.LimitDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
-import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
@@ -64,10 +57,8 @@ import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
import org.openecomp.sdc.vendorlicense.errors.InvalidDateErrorBuilder;
import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
-import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.VersioningManagerFactory;
import org.openecomp.sdc.versioning.VersioningUtil;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
@@ -151,6 +142,12 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager {
Version newVersion = versioningManager
.undoCheckout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user);
+
+ ActivityLogEntity activityLogEntity =
+ new ActivityLogEntity(vendorLicenseModelId, String.valueOf(newVersion.getMajor() + 1),
+ ActivityType.UNDO_CHECKOUT.toString(), user, true, "", "");
+ activityLogManager.addActionLog(activityLogEntity, user);
+
vendorLicenseFacade.updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
mdcDataDebugMessage.debugExitMessage("VLM id", vendorLicenseModelId);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
index 1891cddfd5..be1aaf08e5 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -256,6 +256,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
Version version =
getVersionInfo(vendorSoftwareProductId, VersionableEntityAction.Read, user)
.getActiveVersion();
+
+ ActivityLogEntity activityLogEntity =
+ new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(version.getMajor() + 1),
+ ActivityType.UNDO_CHECKOUT.toString(), user, true, "", "");
+ activityLogManager.addActionLog(activityLogEntity, user);
+
String preVspName = vspInfoDao
.get(new VspDetails(vendorSoftwareProductId, version)).getName();
@@ -407,8 +413,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
getFeatureGroupMandatoryErrorBuilder(deploymentlocalFlavor.getModel());
errorCodeList.add(deploymentFlavorErrorBuilder);
}
- List<ComponentComputeAssociation> componetComputeAssociations = new ArrayList<>();
- componetComputeAssociations = deploymentlocalFlavor.getComponentComputeAssociations();
+ List<ComponentComputeAssociation> componetComputeAssociations =
+ deploymentlocalFlavor.getComponentComputeAssociations();
if (CollectionUtils.isEmpty(componetComputeAssociations)) {
CompositionEntityValidationData compositionEntityValidationData = new
CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
index fa08ba49a8..deb5ffde35 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
@@ -60,13 +60,12 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
@Override
public Collection<Item> listItems(SessionContext context) {
- Response<Collection<Item>> response =
- itemAdaptorFactory.createInterface(context).list(context);
- if (response.isSuccessful()) {
- return response.getValue();
- } else {
- return null;
+ Response<Collection<Item>> response = itemAdaptorFactory.createInterface(context).list(context);
+ if (!response.isSuccessful()) {
+ throw new RuntimeException(
+ "Failed to list Items. message:" + response.getReturnCode().toString());
}
+ return response.getValue();
}
@Override
@@ -76,7 +75,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
return response.getValue();
} else {
throw new RuntimeException(
- "failed to create Item. message:" + response.getReturnCode().getMessage());
+ "failed to create Item. message:" + response.getReturnCode().toString());
}
}
@@ -87,7 +86,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
if (!response.isSuccessful()) {
throw new RuntimeException("failed to update Item . ItemId:" + itemId + "" +
- " message:" + response.getReturnCode().getMessage());
+ " message:" + response.getReturnCode().toString());
}
}
@@ -98,7 +97,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
if (!versions.isSuccessful()) {
logErrorMessageToMdc(ItemElementLoggerTargetServiceName.ITEM_VERSION_RETRIEVAL, versions
.getReturnCode());
- throw new RuntimeException(versions.getReturnCode().getMessage()); // TODO: 3/26/2017
+ throw new RuntimeException(versions.getReturnCode().toString()); // TODO: 3/26/2017
}
return versions.getValue();
}
@@ -114,7 +113,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
throw new RuntimeException("failed to create Item Version. ItemId:" + itemId + " based " +
"on:" + baseVersionId +
" message:" + response
- .getReturnCode().getMessage());
+ .getReturnCode().toString());
}
}
@@ -126,7 +125,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
if (!response.isSuccessful()) {
throw new RuntimeException(
String.format("failed to create Item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().getMessage()));
+ itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
}
}
@@ -151,7 +150,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
throw new RuntimeException(String.format(
"failed to reset Item Version back to %s. ItemId: %s, versionId: %s, message: %s",
changeRef, itemId.getValue(), versionId.getValue(),
- response.getReturnCode().getMessage()));
+ response.getReturnCode().toString()));
}
}
@@ -166,7 +165,7 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
} else {
logErrorMessageToMdc(ItemElementLoggerTargetServiceName.ELEMENT_GET_BY_PROPERTY,
elementInfosResponse.getReturnCode());
- throw new RuntimeException(elementInfosResponse.getReturnCode().getMessage());
+ throw new RuntimeException(elementInfosResponse.getReturnCode().toString());
}
}
@@ -187,11 +186,15 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
@Override
public Optional<Element> saveElement(SessionContext context, ElementContext elementContext,
ZusammenElement element, String message) {
- Response<Element> saveResponse = elementAdaptorFactory.createInterface(context)
+ Response<Element> response = elementAdaptorFactory.createInterface(context)
.save(context, elementContext, element, message);
- return saveResponse.isSuccessful()
- ? Optional.of(saveResponse.getValue())
- : Optional.empty(); // TODO: 3/21/2017 error?
+ if (!response.isSuccessful()) {
+ throw new RuntimeException(String
+ .format("Failed to save element %s. ItemId: %s, versionId: %s, message: %s",
+ element.getElementId().getValue(), elementContext.getItemId().getValue(),
+ elementContext.getVersionId().getValue(), response.getReturnCode().toString()));
+ }
+ return Optional.of(response.getValue());
}
private void logErrorMessageToMdc(ItemElementLoggerTargetServiceName
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/ElementCollaborationStore.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/ElementCollaborationStore.java
index 76b0a900c1..ac103c0fbf 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/ElementCollaborationStore.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/ElementCollaborationStore.java
@@ -11,17 +11,20 @@ import org.openecomp.core.zusammen.plugin.dao.ElementRepository;
import org.openecomp.core.zusammen.plugin.dao.ElementRepositoryFactory;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.Objects;
import java.util.Optional;
-import java.util.stream.Collectors;
+import static org.openecomp.core.zusammen.plugin.ZusammenPluginUtil.getCollaborationElement;
import static org.openecomp.core.zusammen.plugin.ZusammenPluginUtil.getSpaceName;
public class ElementCollaborationStore {
+ private static final String SUB_ELEMENT_NOT_EXIST_ERROR_MSG =
+ "List sub elements error: item %s, version %s - " +
+ "element %s, which appears as sub element of element %s, does not exist";
+
public Collection<CollaborationElement> listElements(SessionContext context,
ElementContext elementContext,
Id elementId) {
@@ -33,14 +36,26 @@ public class ElementCollaborationStore {
}
ElementRepository elementRepository = getElementRepository(context);
- return elementRepository.get(context, elementEntityContext, new ElementEntity(elementId))
- .map(ElementEntity::getSubElementIds).orElse(new HashSet<>()).stream()
- .map(subElementId -> elementRepository
- .get(context, elementEntityContext, new ElementEntity(subElementId)).get())
- .filter(Objects::nonNull)
- .map(subElement -> ZusammenPluginUtil
- .getCollaborationElement(elementEntityContext, subElement))
- .collect(Collectors.toList());
+ String elementIdValue = elementId.getValue();
+ String versionIdValue = elementContext.getChangeRef() == null
+ ? elementContext.getVersionId().getValue()
+ : elementContext.getChangeRef();
+ Collection<CollaborationElement> subElements = new ArrayList<>();
+
+ Optional<ElementEntity> element =
+ elementRepository.get(context, elementEntityContext, new ElementEntity(elementId));
+ if (element.isPresent() && element.get().getSubElementIds() != null) {
+ for (Id subElementId : element.get().getSubElementIds()) {
+ ElementEntity subElement =
+ elementRepository.get(context, elementEntityContext, new ElementEntity(subElementId))
+ .orElseThrow(
+ () -> new IllegalStateException(String.format(SUB_ELEMENT_NOT_EXIST_ERROR_MSG,
+ elementContext.getItemId().getValue(), versionIdValue,
+ subElementId.getValue(), elementIdValue)));
+ subElements.add(getCollaborationElement(elementEntityContext, subElement));
+ }
+ }
+ return subElements;
}
public CollaborationElement getElement(SessionContext context, ElementContext elementContext,
@@ -49,8 +64,7 @@ public class ElementCollaborationStore {
new ElementEntityContext(ZusammenPluginUtil.getPrivateSpaceName(context), elementContext);
return getElementRepository(context)
.get(context, elementEntityContext, new ElementEntity(elementId))
- .map(elementEntity -> ZusammenPluginUtil
- .getCollaborationElement(elementEntityContext, elementEntity))
+ .map(elementEntity -> getCollaborationElement(elementEntityContext, elementEntity))
.orElse(null);
}
@@ -78,7 +92,7 @@ public class ElementCollaborationStore {
ZusammenPluginUtil.getElementEntity(element));
}
- public boolean checkHealth(SessionContext sessionContext){
+ public boolean checkHealth(SessionContext sessionContext) {
return getElementRepository(sessionContext).checkHealth(sessionContext);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStore.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStore.java
index ae23b6e8a9..db3066c313 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStore.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStore.java
@@ -14,7 +14,10 @@ import org.openecomp.core.zusammen.plugin.dao.ElementRepositoryFactory;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+import static org.openecomp.core.zusammen.plugin.ZusammenPluginConstants.ROOT_ELEMENTS_PARENT_ID;
import static org.openecomp.core.zusammen.plugin.ZusammenPluginUtil.getSpaceName;
public class VersionCollaborationStore {
@@ -25,46 +28,74 @@ public class VersionCollaborationStore {
throw new UnsupportedOperationException(
"In this plugin implementation tag is supported only on versionId");
}
- copyElements(context, getSpaceName(context, Space.PRIVATE), itemId, versionId, tag.getName());
+ String space = getSpaceName(context, Space.PRIVATE);
+ ElementEntityContext targetContext = new ElementEntityContext(space, itemId, versionId);
+ targetContext.setChangeRef(tag.getName());
+ copyElements(context, new ElementEntityContext(space, itemId, versionId), targetContext,
+ getElementRepository(context));
}
public CollaborationMergeChange resetItemVersionHistory(SessionContext context, Id itemId,
Id versionId, String changeRef) {
ElementRepository elementRepository = getElementRepository(context);
- ElementEntityContext elementContext =
- new ElementEntityContext(getSpaceName(context, Space.PRIVATE), itemId, versionId);
- CollaborationMergeChange resetChange = new CollaborationMergeChange();
+ String spaceName = getSpaceName(context, Space.PRIVATE);
+ ElementEntityContext versionContext = new ElementEntityContext(spaceName, itemId, versionId);
- Collection<ElementEntity> versionElements = elementRepository.list(context, elementContext);
- versionElements.stream()
- .map(elementEntity ->
- convertElementEntityToElementChange(elementEntity, elementContext, Action.DELETE))
- .forEach(resetChange.getChangedElements()::add);
+ Collection<ElementEntity> deletedElements =
+ deleteElements(context, versionContext, elementRepository);
- elementContext.setChangeRef(changeRef);
- Collection<ElementEntity> changeRefElements = elementRepository.list(context, elementContext);
- changeRefElements.stream()
- .map(elementEntity ->
- convertElementEntityToElementChange(elementEntity, elementContext, Action.CREATE))
- .forEach(resetChange.getChangedElements()::add);
+ ElementEntityContext changeRefContext = new ElementEntityContext(spaceName, itemId, versionId);
+ changeRefContext.setChangeRef(changeRef);
- return resetChange; // TODO: 4/19/2017 version change...
+ Collection<ElementEntity> createdElements =
+ copyElements(context, changeRefContext, versionContext, elementRepository);
+
+ // TODO: 4/19/2017 version change...
+ return createCollaborationMergeChange(versionContext, deletedElements, createdElements);
}
- private void copyElements(SessionContext context, String space, Id itemId, Id sourceVersionId,
- String targetTag) {
- ElementRepository elementRepository = getElementRepository(context);
- ElementEntityContext elementContext = new ElementEntityContext(space, itemId, sourceVersionId);
+ private Collection<ElementEntity> deleteElements(SessionContext context,
+ ElementEntityContext elementContext,
+ ElementRepository elementRepository) {
+ Collection<ElementEntity> elements = elementRepository.list(context, elementContext);
+ elements.forEach(element -> elementRepository
+ .delete(context, elementContext, new ElementEntity(element.getId())));
+ elementRepository.delete(context, elementContext, new ElementEntity(ROOT_ELEMENTS_PARENT_ID));
+ return elements;
+ }
- Collection<ElementEntity> versionElements = elementRepository.list(context, elementContext);
+ private Collection<ElementEntity> copyElements(SessionContext context,
+ ElementEntityContext sourceElementContext,
+ ElementEntityContext targetElementContext,
+ ElementRepository elementRepository) {
+ Collection<ElementEntity> elements = elementRepository.list(context, sourceElementContext);
+ elements.forEach(elementEntity ->
+ elementRepository.create(context, targetElementContext, elementEntity));
+ return elements;
+ }
+
+ private CollaborationMergeChange createCollaborationMergeChange(
+ ElementEntityContext versionContext,
+ Collection<ElementEntity> deletedElements,
+ Collection<ElementEntity> createdElements) {
+ CollaborationMergeChange mergeChange = new CollaborationMergeChange();
+ mergeChange.getChangedElements().addAll(
+ convertToCollaborationElementChanges(versionContext, deletedElements, Action.DELETE));
+ mergeChange.getChangedElements().addAll(
+ convertToCollaborationElementChanges(versionContext, createdElements, Action.CREATE));
+ return mergeChange;
+ }
- elementContext.setChangeRef(targetTag);
- versionElements
- .forEach(elementEntity -> elementRepository.create(context, elementContext, elementEntity));
+ private List<CollaborationElementChange> convertToCollaborationElementChanges(
+ ElementEntityContext elementContext, Collection<ElementEntity> changedElements,
+ Action action) {
+ return changedElements.stream()
+ .map(element -> convertToCollaborationElementChange(element, elementContext, action))
+ .collect(Collectors.toList());
}
- private CollaborationElementChange convertElementEntityToElementChange(
+ private CollaborationElementChange convertToCollaborationElementChange(
ElementEntity elementEntity, ElementEntityContext elementContext, Action action) {
CollaborationElementChange elementChange = new CollaborationElementChange();
elementChange
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/dao/impl/CassandraElementRepository.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/dao/impl/CassandraElementRepository.java
index c19e8799d1..6cc1350444 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/dao/impl/CassandraElementRepository.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/main/java/org/openecomp/core/zusammen/plugin/dao/impl/CassandraElementRepository.java
@@ -16,12 +16,6 @@
package org.openecomp.core.zusammen.plugin.dao.impl;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.mapping.annotations.Accessor;
-import com.datastax.driver.mapping.annotations.Param;
-import com.datastax.driver.mapping.annotations.Query;
-import com.google.gson.reflect.TypeToken;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.Namespace;
import com.amdocs.zusammen.datatypes.SessionContext;
@@ -29,6 +23,12 @@ import com.amdocs.zusammen.datatypes.item.Info;
import com.amdocs.zusammen.datatypes.item.Relation;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
import com.amdocs.zusammen.utils.fileutils.json.JsonUtil;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Param;
+import com.datastax.driver.mapping.annotations.Query;
+import com.google.gson.reflect.TypeToken;
import org.openecomp.core.zusammen.plugin.dao.ElementRepository;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
@@ -38,22 +38,30 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class CassandraElementRepository implements ElementRepository {
+ private static final String VERSION_ELEMENT_NOT_EXIST_ERROR_MSG =
+ "List version elements error: " +
+ "element %s, which appears as an element of item %s version %s, does not exist";
+
@Override
public Collection<ElementEntity> list(SessionContext context,
ElementEntityContext elementContext) {
Set<String> elementIds = getVersionElementIds(context, elementContext);
- return elementIds.stream()
- .map(elementId -> get(context, elementContext, new ElementEntity(new Id(elementId))).get())
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
+ Collection<ElementEntity> elements = new ArrayList<>();
+ for (String elementId : elementIds) {
+ elements.add(get(context, elementContext, new ElementEntity(new Id(elementId)))
+ .orElseThrow(
+ () -> new IllegalStateException(String.format(VERSION_ELEMENT_NOT_EXIST_ERROR_MSG,
+ elementId, elementContext.getItemId().getValue(),
+ getVersionId(elementContext)))));
+ }
+ return elements;
}
@Override
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 0bbe3f81e7..4a49d5391f 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -492,11 +492,12 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoEntity.setActiveVersion(userCandidateVersion.getVersion());
versionInfoEntity.getViewableVersions().add(versionInfoEntity.getActiveVersion());
versionInfoEntity.setStatus(VersionStatus.Available);
- versionInfoDao.update(versionInfoEntity);
closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
versionInfoEntity.getActiveVersion());
+ versionInfoDao.update(versionInfoEntity);
+
return versionInfoEntity.getActiveVersion();
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
index 42c347f4e8..78af19b0f9 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
+++ b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
@@ -22,5 +22,5 @@ else
fi
echo "Configuration file location: ${CONF_FILE_LOCATION}"
-java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=${CONF_FILE_LOCATION} -jar openecomp-zusammen-tools-1.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 $5 $6
+java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=${CONF_FILE_LOCATION} -jar openecomp-zusammen-tools-1.2.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 $5 $6
STATUS="${?}" echo "${STATUS}"