2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.enrichment.impl.external.artifact;
23 import org.openecomp.core.enrichment.types.ArtifactCategory;
24 import org.openecomp.core.enrichment.types.ComponentProcessInfo;
25 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
26 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
27 import org.openecomp.core.model.types.ServiceArtifact;
28 import org.openecomp.core.utilities.file.FileUtils;
29 import org.openecomp.sdc.datatypes.error.ErrorMessage;
30 import org.openecomp.sdc.enrichment.EnrichmentInfo;
31 import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface;
32 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType;
40 import org.openecomp.sdc.versioning.dao.types.Version;
43 import java.io.IOException;
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.List;
49 public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterface {
51 private ComponentDao componentDao;
52 private ProcessDao processDao;
53 private EnrichedServiceModelDao enrichedServiceModelDao;
56 public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo,
57 ToscaServiceModel serviceModel) throws IOException {
58 Map<String, List<ErrorMessage>> errors = new HashMap<>();
59 String vspId = enrichmentInfo.getKey();
60 Version version = enrichmentInfo.getVersion();
62 Collection<ComponentEntity> components =
63 getComponentDao().list(new ComponentEntity(vspId, version, null));
64 components.forEach(componentEntry -> errors.putAll(enrichComponent(componentEntry,
70 Map<String, List<ErrorMessage>> enrichComponent(ComponentEntity componentEntry, String vspId,
72 Map<String, List<ErrorMessage>> errors = new HashMap<>();
73 enrichComponentProcessArtifact(componentEntry, vspId, version, errors);
77 void enrichComponentProcessArtifact(ComponentEntity componentEntity,
78 String vspId, Version version,
79 Map<String, List<ErrorMessage>> errors) {
80 String componentId = componentEntity.getId();
81 ProcessEntity processEntity = new ProcessEntity(vspId, version, componentId, null);
82 final Collection<ProcessEntity> processes = getProcessDao().list(processEntity);
84 processes.forEach(entity -> {
85 ProcessEntity artifactEntity = new ProcessEntity(vspId, version,
86 componentId, entity.getId());
88 ProcessEntity artifactProcessEntity = getProcessDao().getArtifact(artifactEntity);
89 if (artifactProcessEntity != null && ProcessType.Lifecycle_Operations.equals(
90 artifactProcessEntity.getType())
91 && artifactProcessEntity.getArtifactName() != null ) {
92 String componentName = componentEntity.getComponentCompositionData().getName();
93 String path = componentName + File.separator
94 + ArtifactCategory.DEPLOYMENT.getDisplayName() + File.separator
95 + "Lifecycle Operations" + File.separator + artifactProcessEntity.getArtifactName();
97 ComponentProcessInfo componentProcessInfo = new ComponentProcessInfo();
98 componentProcessInfo.setName(path);
99 componentProcessInfo.setContent(artifactProcessEntity.getArtifact().array());
101 ServiceArtifact processServiceArtifact = new ServiceArtifact();
102 processServiceArtifact.setVspId(vspId);
103 processServiceArtifact.setVersion(version);
104 enrichServiceArtifact(componentProcessInfo, processServiceArtifact);
109 void enrichServiceArtifact(ComponentProcessInfo componentProcessInfo,
110 ServiceArtifact processServiceArtifact) {
111 processServiceArtifact.setName(componentProcessInfo.getName());
112 processServiceArtifact.setContentData(FileUtils.toByteArray(componentProcessInfo.getContent()));
113 getEnrichedServiceModelDao().storeExternalArtifact(processServiceArtifact);
116 private ComponentDao getComponentDao() {
117 if (componentDao == null) {
118 componentDao = ComponentDaoFactory.getInstance().createInterface();
123 private ProcessDao getProcessDao() {
124 if (processDao == null) {
125 processDao = ProcessDaoFactory.getInstance().createInterface();
130 private EnrichedServiceModelDao getEnrichedServiceModelDao() {
132 if (enrichedServiceModelDao == null) {
133 enrichedServiceModelDao = EnrichedServiceModelDaoFactory.getInstance().createInterface();
135 return enrichedServiceModelDao;