Add collaboration feature
[sdc.git] / openecomp-be / lib / openecomp-sdc-model-lib / openecomp-sdc-model-impl / src / main / java / org / openecomp / sdc / model / impl / zusammen / EnrichedServiceModelDaoZusammenImpl.java
1 package org.openecomp.sdc.model.impl.zusammen;
2
3 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
4 import com.amdocs.zusammen.datatypes.SessionContext;
5 import com.amdocs.zusammen.datatypes.item.Action;
6 import com.amdocs.zusammen.datatypes.item.ElementContext;
7 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
8 import org.openecomp.core.model.types.ServiceArtifact;
9 import org.openecomp.core.model.types.ServiceElement;
10 import org.openecomp.core.utilities.file.FileUtils;
11 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
12 import org.openecomp.core.zusammen.api.ZusammenUtil;
13 import org.openecomp.sdc.datatypes.model.ElementType;
14 import org.openecomp.sdc.logging.api.Logger;
15 import org.openecomp.sdc.logging.api.LoggerFactory;
16 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
17
18 import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
19
20 public class EnrichedServiceModelDaoZusammenImpl extends ServiceModelDaoZusammenImpl implements
21     EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> {
22
23   private static final Logger logger =
24       LoggerFactory.getLogger(EnrichedServiceModelDaoZusammenImpl.class);
25
26   public EnrichedServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
27     super(zusammenAdaptor);
28     this.elementType = ElementType.EnrichedServiceModel;
29   }
30
31   @Override
32   public void storeExternalArtifact(ServiceArtifact serviceArtifact) {
33     ZusammenElement artifact = buildArtifactElement(serviceArtifact.getName(),
34         FileUtils.toByteArray(serviceArtifact.getContent()), Action.CREATE);
35
36     ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.IGNORE);
37     artifacts.addSubElement(artifact);
38
39     ZusammenElement enrichedServiceModel = buildStructuralElement(elementType, Action.IGNORE);
40     enrichedServiceModel.addSubElement(artifacts);
41
42     ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE);
43     vspModel.addSubElement(enrichedServiceModel);
44
45     SessionContext context = ZusammenUtil.createSessionContext();
46     ElementContext elementContext =
47         new ElementContext(serviceArtifact.getVspId(), serviceArtifact.getVersion().getId());
48     zusammenAdaptor
49         .saveElement(context, elementContext, vspModel, "add service external artifact.");
50
51     logger.info(
52         "Finished adding artifact to enriched service model for VendorSoftwareProduct id -> {}",
53         elementContext.getItemId().getValue());
54   }
55 }