056f1a4478fcc18326b8d534a3d75a40152b4805
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
22
23 import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
24
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;
37
38 public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler
39     implements OrchestrationTemplateFileHandler {
40
41     @Override
42     public UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo) {
43         final UploadFileResponse uploadFileResponse = new UploadFileResponse();
44         final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage();
45         OrchestrationUtil
46             .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, onboardPackage.getFileContent().array());
47         return uploadFileResponse;
48     }
49
50   @Override
51   protected UploadFileResponse updateCandidateData(final VspDetails vspDetails,
52                                         final OnboardPackageInfo onboardPackageInfo,
53                                         final CandidateService candidateService) {
54     final UploadFileResponse uploadFileResponse = new UploadFileResponse();
55     try {
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());
63       candidateService
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()));
70     }
71     return uploadFileResponse;
72   }
73
74   @Override
75   protected OnboardingTypesEnum getHandlerType() {
76     return OnboardingTypesEnum.ZIP;
77   }
78 }