diff options
author | 2017-12-20 14:30:43 +0200 | |
---|---|---|
committer | 2017-12-21 11:12:33 +0000 | |
commit | 8e9c0653dd6c6862123c9609ae34e1206d86456e (patch) | |
tree | 5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl | |
parent | 785ebcc95de3e064e843bec04ba7a209d854fc7c (diff) |
Add collaboration feature
Issue-ID: SDC-767
Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl')
3 files changed, 265 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java new file mode 100644 index 0000000000..7cb3598b9d --- /dev/null +++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java @@ -0,0 +1,17 @@ +package org.openecomp.conflicts.dao.impl.zusammen; + + +import org.openecomp.conflicts.dao.ConflictsDao; +import org.openecomp.conflicts.dao.ConflictsDaoFactory; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; + +public class ConflictsDaoFactoryImpl extends ConflictsDaoFactory { + + private static final ConflictsDao INSTANCE = new + ConflictsDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public ConflictsDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java new file mode 100644 index 0000000000..eac1be3b8e --- /dev/null +++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java @@ -0,0 +1,175 @@ +package org.openecomp.conflicts.dao.impl.zusammen; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.Resolution; +import org.openecomp.conflicts.dao.ConflictsDao; +import org.openecomp.conflicts.types.Conflict; +import org.openecomp.conflicts.types.ConflictResolution; +import org.openecomp.conflicts.types.ItemVersionConflict; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.datatypes.model.ElementType; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToEntitlementPoolConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToFeatureGroupConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLicenseAgreementConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLicenseKeyGroupConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLimitConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToVLMGeneralConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToComponentConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToComponentDependencyModelConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToCompositionEntityConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToComputeConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToImageConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToMonitoringUploadMapConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToNetworkConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToNicConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToOrchestrationTemplateCandidateMapConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToServiceModelMapConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToVSPGeneralConvertor; +import org.openecomp.sdc.versioning.dao.types.Version; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + +public class ConflictsDaoImpl implements ConflictsDao { + private final ZusammenAdaptor zusammenAdaptor; + + public ConflictsDaoImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public boolean isConflicted(String itemId, Version version) { + com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict itemVersionConflict = + zusammenAdaptor + .getVersionConflict(createSessionContext(), new Id(itemId), new Id(version.getId())); + return !(itemVersionConflict == null + || (itemVersionConflict.getVersionDataConflict() == null + && itemVersionConflict.getElementConflictInfos().isEmpty())); + } + + @Override + public ItemVersionConflict getConflict(String itemId, Version version) { + return new ItemVersionConflictConvertorFromZusammen().convert(itemId, version, + zusammenAdaptor + .getVersionConflict(createSessionContext(), new Id(itemId), new Id(version.getId()))); + } + + @Override + public Conflict getConflict(String itemId, Version version, String conflictId) { + return zusammenAdaptor.getElementConflict(createSessionContext(), + new ElementContext(new Id(itemId), new Id(version.getId())), new Id(conflictId)) + .map(elementConflict -> convertElementConflict(conflictId, elementConflict)) + .orElse(null); + } + + @Override + public void resolveConflict(String itemId, Version version, String conflictId, + ConflictResolution conflictResolution) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(new Id(itemId), new Id(version.getId())); + + // TODO: 7/31/2017 when 'OTHER' resolution will be supported - populate zusammen element with it + zusammenAdaptor.resolveElementConflict(context, elementContext, + buildElement(new Id(conflictId), null), + Resolution.valueOf(conflictResolution.getResolution().name())); + } + + private Conflict convertElementConflict(String conflictId, ElementConflict elementConflict) { + Element element = elementConflict.getLocalElement() == null + ? elementConflict.getRemoteElement() + : elementConflict.getLocalElement(); + ElementType elementType = ElementConvertor.getElementType(element); + + Conflict conflict = + new Conflict(conflictId, elementType, ElementConvertor.getElementName(element)); + ElementConvertor convertor = getConvertor(elementType); + if (elementConflict.getLocalElement() != null) { + conflict.setYours(convertor.convert(elementConflict.getLocalElement())); + } + if (elementConflict.getRemoteElement() != null) { + conflict.setTheirs(convertor.convert(elementConflict.getRemoteElement())); + } + return conflict; + } + + private ElementConvertor getConvertor(ElementType type) { + switch (type) { + case VendorSoftwareProduct: + return new ElementToVSPGeneralConvertor(); + case Process: + return new ElementToProcessConvertor(); + case Nic: + return new ElementToNicConvertor(); + case Network: + return new ElementToNetworkConvertor(); + case SNMP_POLL: + case SNMP_TRAP: + case VES_EVENTS: + return new ElementToMonitoringUploadMapConvertor(); + case Image: + return new ElementToImageConvertor(); + case Compute: + return new ElementToComputeConvertor(); + case Component: + return new ElementToComponentConvertor(); + case ComponentDependencies: + return new ElementToComponentDependencyModelConvertor(); + case VendorLicenseModel: + return new ElementToVLMGeneralConvertor(); + case LicenseAgreement: + return new ElementToLicenseAgreementConvertor(); + case FeatureGroup: + return new ElementToFeatureGroupConvertor(); + case LicenseKeyGroup: + return new ElementToLicenseKeyGroupConvertor(); + case EntitlementPool: + return new ElementToEntitlementPoolConvertor(); + case Limit: + return new ElementToLimitConvertor(); + case OrchestrationTemplateCandidate: + return new ElementToOrchestrationTemplateCandidateMapConvertor(); + case ServiceModel: + return new ElementToServiceModelMapConvertor(); + case VSPQuestionnaire: + case ImageQuestionnaire: + case ComponentQuestionnaire: + case ComputeQuestionnaire: + case NicQuestionnaire: + return new ElementToCompositionEntityConvertor(); + default: + return new EchoConvertor(); + } + } + + public static class EchoConvertor extends ElementConvertor { + + @Override + public Object convert(Element element) { + return element; + } + + @Override + public Object convert(Item item) { + return item; + } + + @Override + public Object convert(ElementInfo elementInfo) { + return elementInfo; + } + + @Override + public Object convert(ItemVersion itemVersion) { + return null; + } + } +} diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ItemVersionConflictConvertorFromZusammen.java b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ItemVersionConflictConvertorFromZusammen.java new file mode 100644 index 0000000000..4dffaf8231 --- /dev/null +++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ItemVersionConflictConvertorFromZusammen.java @@ -0,0 +1,73 @@ +package org.openecomp.conflicts.dao.impl.zusammen; + + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflictInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.ItemVersionData; +import com.amdocs.zusammen.datatypes.item.ItemVersionDataConflict; +import org.openecomp.conflicts.types.Conflict; +import org.openecomp.conflicts.types.ConflictInfo; +import org.openecomp.sdc.datatypes.model.ElementType; +import org.openecomp.sdc.versioning.dao.impl.zusammen.convertor.ItemVersionToVersionConvertor; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.types.ElementPropertyName; + +import java.util.stream.Collectors; + +public class ItemVersionConflictConvertorFromZusammen { + public org.openecomp.conflicts.types.ItemVersionConflict convert(String itemId, Version version, + ItemVersionConflict source) { + org.openecomp.conflicts.types.ItemVersionConflict target = + new org.openecomp.conflicts.types.ItemVersionConflict(); + + target.setVersionConflict( + convertVersionDataConflict(itemId, version, source.getVersionDataConflict())); + target.setElementConflicts(source.getElementConflictInfos().stream() + .map(this::convertElementConflictInfo) + .collect(Collectors.toList())); + + return target; + } + + + private Conflict<Version> convertVersionDataConflict(String itemId, Version version, + ItemVersionDataConflict versionDataConflict) { + if (versionDataConflict == null) { + return null; + } + + Conflict<Version> conflict = + new Conflict<>(version.getId(), ElementType.itemVersion, null); + + ItemVersionToVersionConvertor convertor = new ItemVersionToVersionConvertor(); + conflict.setYours(convertor.convert( + getItemVersion(version.getId(), versionDataConflict.getLocalData()))); + conflict.setTheirs(convertor.convert( + getItemVersion(version.getId(), versionDataConflict.getRemoteData()))); + return conflict; + } + + private ItemVersion getItemVersion(String versionId, ItemVersionData versionData) { + if (versionData == null) { + return null; + } + ItemVersion itemVersion = new ItemVersion(); + itemVersion.setId(new Id(versionId)); + itemVersion.setData(versionData); + return itemVersion; + } + + private ConflictInfo convertElementConflictInfo(ElementConflictInfo elementConflictInfo) { + ElementInfo elementInfo = elementConflictInfo.getLocalElementInfo() == null + ? elementConflictInfo.getRemoteElementInfo() + : elementConflictInfo.getLocalElementInfo(); + + return new ConflictInfo(elementInfo.getId().getValue(), + ElementType + .valueOf(elementInfo.getInfo().getProperty(ElementPropertyName.elementType.name())), + elementInfo.getInfo().getName()); + } +} |