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.healing.healers;
23 import org.openecomp.core.utilities.file.FileContentHandler;
24 import org.openecomp.core.utilities.json.JsonUtil;
25 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
26 import org.openecomp.sdc.common.utils.CommonUtil;
27 import org.openecomp.sdc.healing.interfaces.Healer;
28 import org.openecomp.sdc.logging.api.Logger;
29 import org.openecomp.sdc.logging.api.LoggerFactory;
30 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
31 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
35 import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory;
36 import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
37 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
38 import org.openecomp.sdc.versioning.dao.types.Version;
40 import java.util.HashMap;
41 import java.util.Optional;
43 public class FileDataStructureHealer implements Healer {
44 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
46 private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName());
48 public FileDataStructureHealer() {
52 public Optional<FilesDataStructure> heal(String vspId,
53 Version version) throws Exception {
54 mdcDataDebugMessage.debugEntryMessage(null);
56 OrchestrationTemplateCandidateDao candidateDao =
57 OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface();
59 OrchestrationTemplateCandidateData candidateData = candidateDao.get(vspId, version);
61 if (candidateData == null || candidateData.getContentData() == null ||
62 candidateData.getFilesDataStructure() != null) {
63 return Optional.of(new FilesDataStructure());
66 Optional<FilesDataStructure> filesDataStructure =
67 healFilesDataStructure(vspId, version, candidateData);
70 .ifPresent(structure -> candidateDao.updateStructure(vspId, version, structure));
72 mdcDataDebugMessage.debugExitMessage(null);
73 return filesDataStructure;
76 private Optional<FilesDataStructure> healFilesDataStructure(
77 String vspId, Version version, OrchestrationTemplateCandidateData candidateData)
79 mdcDataDebugMessage.debugEntryMessage(null);
81 Optional<FilesDataStructure> healingResult;
82 byte[] byteContentData = candidateData.getContentData().array();
83 FileContentHandler fileContentHandler;
86 CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, byteContentData);
88 String filesDataStructure =
89 new CandidateEntityBuilder(CandidateServiceFactory.getInstance().createInterface())
90 .buildCandidateEntityFromZip(new VspDetails(vspId, version), byteContentData,
91 fileContentHandler, new HashMap<>()).getFilesDataStructure();
94 Optional.of(JsonUtil.json2Object(filesDataStructure, FilesDataStructure.class));
95 } catch (Exception e) {
97 healingResult = Optional.empty();
100 mdcDataDebugMessage.debugExitMessage(null);
101 return healingResult;