65ce2f53976f5fdbf1591d2927876ad41f8e6fa4
[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 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
21
22 import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
23
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;
36
37 public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler {
38
39     @Override
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;
45     }
46
47     @Override
48     protected UploadFileResponse updateCandidateData(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo,
49                                                      final CandidateService candidateService) {
50         final UploadFileResponse uploadFileResponse = new UploadFileResponse();
51         try {
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()));
62         }
63         return uploadFileResponse;
64     }
65
66     @Override
67     protected OnboardingTypesEnum getHandlerType() {
68         return OnboardingTypesEnum.ZIP;
69     }
70 }