2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.healing.healers;
19 import org.openecomp.core.utilities.file.FileContentHandler;
20 import org.openecomp.core.utilities.json.JsonUtil;
21 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
22 import org.openecomp.sdc.common.utils.CommonUtil;
23 import org.openecomp.sdc.healing.interfaces.Healer;
24 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao;
26 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory;
27 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
28 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
29 import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory;
30 import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
32 import org.openecomp.sdc.versioning.dao.types.Version;
34 import java.util.HashMap;
35 import java.util.Optional;
37 public class FileDataStructureHealer implements Healer {
38 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
41 public Optional<FilesDataStructure> heal(String vspId,
42 Version version) throws Exception {
43 mdcDataDebugMessage.debugEntryMessage(null);
45 OrchestrationTemplateCandidateDao candidateDao =
46 OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface();
48 OrchestrationTemplateCandidateData candidateData = candidateDao.get(vspId, version);
50 if (candidateData == null || candidateData.getContentData() == null ||
51 candidateData.getFilesDataStructure() != null) {
52 return Optional.of(new FilesDataStructure());
55 Optional<FilesDataStructure> filesDataStructure =
56 healFilesDataStructure(vspId, version, candidateData);
59 .ifPresent(structure -> candidateDao.updateStructure(vspId, version, structure));
61 mdcDataDebugMessage.debugExitMessage(null);
62 return filesDataStructure;
65 private Optional<FilesDataStructure> healFilesDataStructure(
66 String vspId, Version version, OrchestrationTemplateCandidateData candidateData)
68 mdcDataDebugMessage.debugEntryMessage(null);
70 Optional<FilesDataStructure> healingResult;
71 byte[] byteContentData = candidateData.getContentData().array();
72 FileContentHandler fileContentHandler;
75 CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, byteContentData);
77 String filesDataStructure =
78 new CandidateEntityBuilder(CandidateServiceFactory.getInstance().createInterface())
79 .buildCandidateEntityFromZip(new VspDetails(vspId, version), byteContentData,
80 fileContentHandler, new HashMap<>()).getFilesDataStructure();
83 Optional.of(JsonUtil.json2Object(filesDataStructure, FilesDataStructure.class));
84 } catch (Exception e) {
85 healingResult = Optional.empty();
88 mdcDataDebugMessage.debugExitMessage(null);