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 static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
25 import java.util.Optional;
26 import org.openecomp.core.utilities.file.FileContentHandler;
27 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
28 import org.openecomp.sdc.common.errors.Messages;
29 import org.openecomp.sdc.common.utils.SdcCommon;
30 import org.openecomp.sdc.datatypes.error.ErrorLevel;
31 import org.openecomp.sdc.datatypes.error.ErrorMessage;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
34 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
35 import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
36 import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
37 import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
38 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
40 public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler
41 implements OrchestrationTemplateFileHandler {
44 public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse,
45 byte[] uploadedFileData) {
46 return OrchestrationUtil
47 .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, uploadedFileData);
51 protected boolean updateCandidateData(final VspDetails vspDetails,
52 final OnboardPackageInfo onboardPackageInfo,
53 final CandidateService candidateService,
54 final UploadFileResponse uploadFileResponse,
55 final FileContentHandler contentMap) {
57 final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage();
58 final OrchestrationTemplateCandidateData candidateData =
59 new CandidateEntityBuilder(candidateService)
60 .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), contentMap,
61 uploadFileResponse.getErrors());
62 candidateData.setFileName(zipPackage.getFilename());
63 candidateData.setFileSuffix(zipPackage.getFileExtension());
65 .updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData);
66 } catch (final Exception exception) {
67 logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
68 getHandlerType().toString()), exception);
69 uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE,
70 new ErrorMessage(ErrorLevel.ERROR, exception.getMessage()));
77 protected OnboardingTypesEnum getHandlerType() {
78 return OnboardingTypesEnum.ZIP;