1 package org.openecomp.sdc.enrichment.impl.external.artifact;
3 import org.openecomp.core.enrichment.types.ArtifactCategory;
4 import org.openecomp.core.enrichment.types.ComponentProcessInfo;
5 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
6 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
7 import org.openecomp.core.model.types.ServiceArtifact;
8 import org.openecomp.core.utilities.file.FileUtils;
9 import org.openecomp.sdc.datatypes.error.ErrorMessage;
10 import org.openecomp.sdc.enrichment.EnrichmentInfo;
11 import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface;
12 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
13 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao;
17 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory;
18 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
19 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
20 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType;
21 import org.openecomp.sdc.versioning.dao.types.Version;
24 import java.io.IOException;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.List;
30 public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterface {
32 private ComponentDao componentDao;
33 private ProcessDao processDao;
34 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
35 private EnrichedServiceModelDao enrichedServiceModelDao;
38 public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo,
39 ToscaServiceModel serviceModel) throws IOException {
40 Map<String, List<ErrorMessage>> errors = new HashMap<>();
41 String vspId = enrichmentInfo.getKey();
42 Version version = enrichmentInfo.getVersion();
44 Collection<ComponentEntity> components =
45 getComponentDao().list(new ComponentEntity(vspId, version, null));
46 components.forEach(componentEntry -> errors.putAll(enrichComponent(componentEntry,
52 Map<String, List<ErrorMessage>> enrichComponent(ComponentEntity componentEntry, String vspId,
54 mdcDataDebugMessage.debugEntryMessage("LifeCycleOperationArtifactEnricher vspId ",
57 Map<String, List<ErrorMessage>> errors = new HashMap<>();
58 enrichComponentProcessArtifact(componentEntry, vspId, version, errors);
60 mdcDataDebugMessage.debugExitMessage("LifeCycleOperationArtifactEnricher vspId ",
65 void enrichComponentProcessArtifact(ComponentEntity componentEntity,
66 String vspId, Version version,
67 Map<String, List<ErrorMessage>> errors) {
70 mdcDataDebugMessage.debugEntryMessage(null, null);
72 String componentId = componentEntity.getId();
73 ProcessEntity processEntity = new ProcessEntity(vspId, version, componentId, null);
74 final Collection<ProcessEntity> processes = getProcessDao().list(processEntity);
76 processes.forEach(entity -> {
77 ProcessEntity artifactEntity = new ProcessEntity(vspId, version,
78 componentId, entity.getId());
80 ProcessEntity artifactProcessEntity = getProcessDao().get(artifactEntity);
81 if (artifactProcessEntity != null && ProcessType.Lifecycle_Operations.equals(
82 artifactProcessEntity.getType())
83 && artifactProcessEntity.getArtifactName() != null ) {
84 String componentName = componentEntity.getComponentCompositionData().getName();
85 String path = componentName + File.separator
86 + ArtifactCategory.DEPLOYMENT.getDisplayName() + File.separator
87 + "Lifecycle Operations" + File.separator + artifactProcessEntity.getArtifactName();
89 ComponentProcessInfo componentProcessInfo = new ComponentProcessInfo();
90 componentProcessInfo.setName(path);
91 componentProcessInfo.setContent(artifactProcessEntity.getArtifact().array());
93 ServiceArtifact processServiceArtifact = new ServiceArtifact();
94 processServiceArtifact.setVspId(vspId);
95 processServiceArtifact.setVersion(version);
96 enrichServiceArtifact(componentProcessInfo, processServiceArtifact);
100 mdcDataDebugMessage.debugExitMessage(null);
103 void enrichServiceArtifact(ComponentProcessInfo componentProcessInfo,
104 ServiceArtifact processServiceArtifact) {
107 mdcDataDebugMessage.debugEntryMessage(null);
109 processServiceArtifact.setName(componentProcessInfo.getName());
110 processServiceArtifact.setContentData(FileUtils.toByteArray(componentProcessInfo.getContent()));
111 getEnrichedServiceModelDao().storeExternalArtifact(processServiceArtifact);
112 mdcDataDebugMessage.debugExitMessage(null);
115 private ComponentDao getComponentDao() {
116 if (componentDao == null) {
117 componentDao = ComponentDaoFactory.getInstance().createInterface();
122 private ProcessDao getProcessDao() {
123 if (processDao == null) {
124 processDao = ProcessDaoFactory.getInstance().createInterface();
129 private EnrichedServiceModelDao getEnrichedServiceModelDao() {
131 if (enrichedServiceModelDao == null) {
132 enrichedServiceModelDao = EnrichedServiceModelDaoFactory.getInstance().createInterface();
134 return enrichedServiceModelDao;