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.vendorsoftwareproduct.impl.orchestration;
23 import org.openecomp.core.utilities.file.FileContentHandler;
24 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
25 import org.openecomp.sdc.common.errors.Messages;
26 import org.openecomp.sdc.common.utils.SdcCommon;
27 import org.openecomp.sdc.datatypes.error.ErrorLevel;
28 import org.openecomp.sdc.datatypes.error.ErrorMessage;
29 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
30 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
31 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
32 import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
33 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
35 import java.util.Optional;
37 import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
39 public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler
40 implements OrchestrationTemplateFileHandler {
43 public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse,
44 byte[] uploadedFileData) {
45 return OrchestrationUtil
46 .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, uploadedFileData);
50 protected boolean updateCandidateData(VspDetails vspDetails, byte[] uploadedFileData,
51 FileContentHandler contentMap,
52 String fileSuffix, String networkPackageName,
53 CandidateService candidateService,
54 UploadFileResponse uploadFileResponse) {
56 OrchestrationTemplateCandidateData candidateData =
57 new CandidateEntityBuilder(candidateService)
58 .buildCandidateEntityFromZip(vspDetails, uploadedFileData, contentMap,
59 uploadFileResponse.getErrors());
60 candidateData.setFileSuffix(fileSuffix);
61 candidateData.setFileName(networkPackageName);
64 .updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData);
65 } catch (Exception exception) {
66 logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
67 getHandlerType().toString()), exception);
68 uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE,
69 new ErrorMessage(ErrorLevel.ERROR, exception.getMessage()));
76 protected OnboardingTypesEnum getHandlerType() {
77 return OnboardingTypesEnum.ZIP;