2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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;
24 import org.openecomp.core.enrichment.types.ArtifactCategory;
25 import org.openecomp.core.enrichment.types.InformationArtifactFolderNames;
26 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
27 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
28 import org.openecomp.core.model.types.ServiceArtifact;
29 import org.openecomp.sdc.datatypes.error.ErrorLevel;
30 import org.openecomp.sdc.datatypes.error.ErrorMessage;
31 import org.openecomp.sdc.enrichment.EnrichmentInfo;
32 import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface;
33 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
34 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
40 import org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGeneratorFactory;
41 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
42 import org.openecomp.sdc.versioning.dao.types.Version;
45 import java.io.IOException;
46 import java.nio.ByteBuffer;
47 import java.util.ArrayList;
48 import java.util.HashMap;
49 import java.util.List;
51 import java.util.Objects;
54 * Created by Talio on 11/24/2016
56 public class VspInformationArtifactEnricher implements ExternalArtifactEnricherInterface {
57 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
58 private static InformationArtifactGenerator informationArtifactGenerator =
59 InformationArtifactGeneratorFactory.getInstance().createInterface();
60 private EnrichedServiceModelDao enrichedServiceModelDao =
61 EnrichedServiceModelDaoFactory.getInstance().createInterface();
62 private VendorSoftwareProductInfoDao vspInfoDao = VendorSoftwareProductInfoDaoFactory
63 .getInstance().createInterface();
64 private OrchestrationTemplateDao orchestrationTemplateDataDao =
65 OrchestrationTemplateDaoFactory.getInstance().createInterface();
67 public VspInformationArtifactEnricher() {
70 public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo)
73 String vspId = enrichmentInfo.getKey();
74 Version version = enrichmentInfo.getVersion();
75 Map<String, List<ErrorMessage>> errors = enrichInformationArtifact(vspId, version);
80 private Map<String, List<ErrorMessage>> enrichInformationArtifact(String vspId, Version version)
84 mdcDataDebugMessage.debugEntryMessage(null, null);
86 Map<String, List<ErrorMessage>> errors = new HashMap<>();
87 ByteBuffer infoArtifactByteBuffer = ByteBuffer.wrap(informationArtifactGenerator.generate(
88 vspId, version).getBytes());
90 if (Objects.isNull(infoArtifactByteBuffer)) {
91 List<ErrorMessage> errorList = new ArrayList<>();
92 errorList.add(new ErrorMessage(ErrorLevel.ERROR, String.format(
93 "Cannot enrich information artifact for vendor software product with id %s and version %s",
94 vspId, version.toString())));
95 //TODO: add error to map (what is the key?)
97 mdcDataDebugMessage.debugExitMessage(null, null);
101 enrichInformationArtifact(vspId, version, infoArtifactByteBuffer);
103 mdcDataDebugMessage.debugExitMessage(null, null);
107 private void enrichInformationArtifact(String vspId, Version version,
108 ByteBuffer infoArtifactByteBuffer) {
109 ServiceArtifact infoArtifactServiceArtifact = new ServiceArtifact();
111 VspDetails vspDetails = getVspDetails(vspId, version);
113 String vspName = vspDetails.getName();
116 infoArtifactServiceArtifact.setVspId(vspId);
117 infoArtifactServiceArtifact.setVersion(version);
118 infoArtifactServiceArtifact
119 .setName(ArtifactCategory.INFORMATIONAL.getDisplayName() + File.separator
120 + InformationArtifactFolderNames.Guide + File.separator + String.format(
121 VendorSoftwareProductConstants
122 .INFORMATION_ARTIFACT_NAME,
124 infoArtifactServiceArtifact.setContentData(infoArtifactByteBuffer.array());
126 enrichedServiceModelDao.storeExternalArtifact(infoArtifactServiceArtifact);
129 public VspDetails getVspDetails(String vspId,Version version){
130 VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId,version));
131 vspDetails.setValidationData(orchestrationTemplateDataDao.getValidationData(vspId,version));