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.vendorsoftwareproduct.dao.ProcessDao;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
17 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
18 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
19 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType;
20 import org.openecomp.sdc.versioning.dao.types.Version;
23 import java.io.IOException;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
29 public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterface {
31 private VendorSoftwareProductDao vendorSoftwareProductDao;
32 //private ProcessArtifactDao processArtifactDao;
33 private ProcessDao processDao;
34 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
35 private EnrichedServiceModelDao enrichedServiceModelDao;
38 public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo) throws IOException {
39 Map<String, List<ErrorMessage>> errors = new HashMap<>();
40 String vspId = enrichmentInfo.getKey();
41 Version version = enrichmentInfo.getVersion();
43 Collection<ComponentEntity> components =
44 getVendorSoftwareProductDao().listComponents(vspId, version);
46 .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);
77 .filter(entity -> entity.getType().equals(ProcessType.Lifecycle_Operations))
79 ProcessArtifactEntity artifactEntity = new ProcessArtifactEntity(vspId, version,
80 componentId, entity.getId());*/
83 .filter(entity -> entity.getType().equals(ProcessType.Lifecycle_Operations))
85 ProcessEntity artifactEntity = new ProcessEntity(vspId, version,
86 componentId, entity.getId());
88 ProcessEntity artifactProcessEntity = getProcessDao().get(artifactEntity);
89 //ProcessArtifactEntity artifact = getProcessArtifactDao().get(artifactEntity);
90 if (artifactProcessEntity != null) {
91 String componentName = componentEntity.getComponentCompositionData().getName();
92 String path = componentName + File.separator
93 + ArtifactCategory.DEPLOYMENT.getDisplayName() + File.separator
94 + "Lifecycle Operations" + File.separator + artifactProcessEntity.getArtifactName();
96 ComponentProcessInfo componentProcessInfo = new ComponentProcessInfo();
97 componentProcessInfo.setName(path);
98 componentProcessInfo.setContent(artifactProcessEntity.getArtifact().array());
100 ServiceArtifact processServiceArtifact = new ServiceArtifact();
101 processServiceArtifact.setVspId(vspId);
102 processServiceArtifact.setVersion(version);
103 enrichServiceArtifact(componentProcessInfo, processServiceArtifact, errors);
107 mdcDataDebugMessage.debugExitMessage(null, null);
110 void enrichServiceArtifact(ComponentProcessInfo componentProcessInfo,
111 ServiceArtifact processServiceArtifact,
112 Map<String, List<ErrorMessage>> errors) {
115 mdcDataDebugMessage.debugEntryMessage(null, null);
117 processServiceArtifact.setName(componentProcessInfo.getName());
118 processServiceArtifact.setContentData(FileUtils.toByteArray(componentProcessInfo.getContent()));
119 getEnrichedServiceModelDao().storeExternalArtifact(processServiceArtifact);
120 mdcDataDebugMessage.debugExitMessage(null, null);
123 private VendorSoftwareProductDao getVendorSoftwareProductDao() {
124 if (vendorSoftwareProductDao == null) {
125 vendorSoftwareProductDao = VendorSoftwareProductDaoFactory.getInstance().createInterface();
127 return vendorSoftwareProductDao;
130 private ProcessDao getProcessDao() {
131 if (processDao == null) {
132 processDao = ProcessDaoFactory.getInstance().createInterface();
137 private EnrichedServiceModelDao getEnrichedServiceModelDao() {
139 if (enrichedServiceModelDao == null) {
140 enrichedServiceModelDao = EnrichedServiceModelDaoFactory.getInstance().createInterface();
142 return enrichedServiceModelDao;