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.tosca.datatypes.ToscaServiceModel;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory;
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 ComponentDao componentDao;
32 private ProcessDao processDao;
33 private EnrichedServiceModelDao enrichedServiceModelDao;
36 public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo,
37 ToscaServiceModel serviceModel) throws IOException {
38 Map<String, List<ErrorMessage>> errors = new HashMap<>();
39 String vspId = enrichmentInfo.getKey();
40 Version version = enrichmentInfo.getVersion();
42 Collection<ComponentEntity> components =
43 getComponentDao().list(new ComponentEntity(vspId, version, null));
44 components.forEach(componentEntry -> errors.putAll(enrichComponent(componentEntry,
50 Map<String, List<ErrorMessage>> enrichComponent(ComponentEntity componentEntry, String vspId,
52 Map<String, List<ErrorMessage>> errors = new HashMap<>();
53 enrichComponentProcessArtifact(componentEntry, vspId, version, errors);
57 void enrichComponentProcessArtifact(ComponentEntity componentEntity,
58 String vspId, Version version,
59 Map<String, List<ErrorMessage>> errors) {
60 String componentId = componentEntity.getId();
61 ProcessEntity processEntity = new ProcessEntity(vspId, version, componentId, null);
62 final Collection<ProcessEntity> processes = getProcessDao().list(processEntity);
64 processes.forEach(entity -> {
65 ProcessEntity artifactEntity = new ProcessEntity(vspId, version,
66 componentId, entity.getId());
68 ProcessEntity artifactProcessEntity = getProcessDao().getArtifact(artifactEntity);
69 if (artifactProcessEntity != null && ProcessType.Lifecycle_Operations.equals(
70 artifactProcessEntity.getType())
71 && artifactProcessEntity.getArtifactName() != null ) {
72 String componentName = componentEntity.getComponentCompositionData().getName();
73 String path = componentName + File.separator
74 + ArtifactCategory.DEPLOYMENT.getDisplayName() + File.separator
75 + "Lifecycle Operations" + File.separator + artifactProcessEntity.getArtifactName();
77 ComponentProcessInfo componentProcessInfo = new ComponentProcessInfo();
78 componentProcessInfo.setName(path);
79 componentProcessInfo.setContent(artifactProcessEntity.getArtifact().array());
81 ServiceArtifact processServiceArtifact = new ServiceArtifact();
82 processServiceArtifact.setVspId(vspId);
83 processServiceArtifact.setVersion(version);
84 enrichServiceArtifact(componentProcessInfo, processServiceArtifact);
89 void enrichServiceArtifact(ComponentProcessInfo componentProcessInfo,
90 ServiceArtifact processServiceArtifact) {
91 processServiceArtifact.setName(componentProcessInfo.getName());
92 processServiceArtifact.setContentData(FileUtils.toByteArray(componentProcessInfo.getContent()));
93 getEnrichedServiceModelDao().storeExternalArtifact(processServiceArtifact);
96 private ComponentDao getComponentDao() {
97 if (componentDao == null) {
98 componentDao = ComponentDaoFactory.getInstance().createInterface();
103 private ProcessDao getProcessDao() {
104 if (processDao == null) {
105 processDao = ProcessDaoFactory.getInstance().createInterface();
110 private EnrichedServiceModelDao getEnrichedServiceModelDao() {
112 if (enrichedServiceModelDao == null) {
113 enrichedServiceModelDao = EnrichedServiceModelDaoFactory.getInstance().createInterface();
115 return enrichedServiceModelDao;