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=========================================================
20 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
22 import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
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.OnboardPackage;
34 import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
35 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
37 public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler {
40 public UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo) {
41 final UploadFileResponse uploadFileResponse = new UploadFileResponse();
42 final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage();
43 OrchestrationUtil.getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, onboardPackage.getFileContent().array());
44 return uploadFileResponse;
48 protected UploadFileResponse updateCandidateData(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo,
49 final CandidateService candidateService) {
50 final UploadFileResponse uploadFileResponse = new UploadFileResponse();
52 final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage();
53 final OrchestrationTemplateCandidateData candidateData = new CandidateEntityBuilder(candidateService)
54 .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), zipPackage.getFileContentHandler(),
55 uploadFileResponse.getErrors());
56 candidateData.setFileName(zipPackage.getFilename());
57 candidateData.setFileSuffix(zipPackage.getFileExtension());
58 candidateService.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData);
59 } catch (final Exception exception) {
60 logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(), getHandlerType().toString()), exception);
61 uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, exception.getMessage()));
63 return uploadFileResponse;
67 protected OnboardingTypesEnum getHandlerType() {
68 return OnboardingTypesEnum.ZIP;