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 org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
26 import org.openecomp.sdc.common.errors.Messages;
27 import org.openecomp.sdc.common.utils.SdcCommon;
28 import org.openecomp.sdc.datatypes.error.ErrorLevel;
29 import org.openecomp.sdc.datatypes.error.ErrorMessage;
30 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
31 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
32 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
33 import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
34 import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
35 import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
36 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
38 public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler
39 implements OrchestrationTemplateFileHandler {
42 public UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo) {
43 final UploadFileResponse uploadFileResponse = new UploadFileResponse();
44 final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage();
46 .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, onboardPackage.getFileContent().array());
47 return uploadFileResponse;
51 protected UploadFileResponse updateCandidateData(final VspDetails vspDetails,
52 final OnboardPackageInfo onboardPackageInfo,
53 final CandidateService candidateService) {
54 final UploadFileResponse uploadFileResponse = new UploadFileResponse();
56 final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage();
57 final OrchestrationTemplateCandidateData candidateData =
58 new CandidateEntityBuilder(candidateService)
59 .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), zipPackage.getFileContentHandler(),
60 uploadFileResponse.getErrors());
61 candidateData.setFileName(zipPackage.getFilename());
62 candidateData.setFileSuffix(zipPackage.getFileExtension());
64 .updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData);
65 } catch (final 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()));
71 return uploadFileResponse;
75 protected OnboardingTypesEnum getHandlerType() {
76 return OnboardingTypesEnum.ZIP;