Get manifest location from Meta file
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / impl / VendorSoftwareProductManagerImpl.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.vendorsoftwareproduct.impl;
18
19 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_MANIFEST;
20 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
21 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
22 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.candidateDataNotProcessedOrAbortedErrorBuilder;
23 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate;
24 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder;
25 import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
26
27 import java.io.BufferedOutputStream;
28 import java.io.ByteArrayInputStream;
29 import java.io.ByteArrayOutputStream;
30 import java.io.File;
31 import java.io.FileOutputStream;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.OutputStream;
35 import java.nio.ByteBuffer;
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Objects;
44 import java.util.Optional;
45 import java.util.Set;
46 import java.util.zip.ZipInputStream;
47 import java.util.zip.ZipOutputStream;
48 import org.apache.commons.collections4.CollectionUtils;
49 import org.apache.commons.collections4.MapUtils;
50 import org.apache.commons.lang3.tuple.ImmutablePair;
51 import org.apache.commons.lang3.tuple.Pair;
52 import org.openecomp.core.dao.UniqueValueDao;
53 import org.openecomp.core.enrichment.api.EnrichmentManager;
54 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
55 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
56 import org.openecomp.core.model.dao.ServiceModelDao;
57 import org.openecomp.core.model.types.ServiceElement;
58 import org.openecomp.core.util.UniqueValueUtil;
59 import org.openecomp.core.utilities.file.FileContentHandler;
60 import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
61 import org.openecomp.core.utilities.json.JsonUtil;
62 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
63 import org.openecomp.core.validation.api.ValidationManager;
64 import org.openecomp.core.validation.util.MessageContainerUtil;
65 import org.openecomp.sdc.common.errors.CoreException;
66 import org.openecomp.sdc.common.errors.ErrorCode;
67 import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
68 import org.openecomp.sdc.common.utils.CommonUtil;
69 import org.openecomp.sdc.datatypes.error.ErrorLevel;
70 import org.openecomp.sdc.datatypes.error.ErrorMessage;
71 import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
72 import org.openecomp.sdc.tosca.csar.ToscaMetadata;
73 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
74 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
75 import org.openecomp.sdc.validation.util.ValidationManagerUtil;
76 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
77 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
78 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
79 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory;
80 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
81 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
82 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
83 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
84 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
85 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
86 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao;
87 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
88 import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao;
89 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
90 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
91 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
92 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
93 import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDao;
94 import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.VendorSoftwareProductNotFoundErrorBuilder;
95 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
96 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
97 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
98 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
99 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
100 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
101 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod;
102 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
103 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
104 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
105 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
106 import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentDependencyModelErrorBuilder;
107 import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentErrorBuilder;
108 import org.openecomp.sdc.vendorsoftwareproduct.errors.DeploymentFlavorErrorBuilder;
109 import org.openecomp.sdc.vendorsoftwareproduct.errors.FileCreationErrorBuilder;
110 import org.openecomp.sdc.vendorsoftwareproduct.errors.InformationArtifactCreationErrorBuilder;
111 import org.openecomp.sdc.vendorsoftwareproduct.errors.NicInternalNetworkErrorBuilder;
112 import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageInvalidErrorBuilder;
113 import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilder;
114 import org.openecomp.sdc.vendorsoftwareproduct.errors.TranslationFileCreationErrorBuilder;
115 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder;
116 import org.openecomp.sdc.tosca.csar.Manifest;
117 import org.openecomp.sdc.tosca.csar.OnboardingManifest;
118 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
119 import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService;
120 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
121 import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl;
122 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
123 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
124 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult;
125 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
126 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
127 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation;
128 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
129 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
130 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
131 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
132 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType;
133 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
134 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentQuestionnaireSchemaInput;
135 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
136 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
137 import org.openecomp.sdc.vendorsoftwareproduct.utils.ComponentDependencyTracker;
138 import org.openecomp.sdc.versioning.VersioningManager;
139 import org.openecomp.sdc.versioning.VersioningManagerFactory;
140 import org.openecomp.sdc.versioning.VersioningUtil;
141 import org.openecomp.sdc.versioning.dao.types.Version;
142
143 public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
144
145   private VspMergeDao vspMergeDao;
146   private OrchestrationTemplateDao orchestrationTemplateDao;
147   private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
148   private VendorSoftwareProductInfoDao vspInfoDao;
149   private VendorLicenseFacade vendorLicenseFacade;
150   private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
151   private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
152   private VendorLicenseArtifactsService licenseArtifactsService;
153   private InformationArtifactGenerator informationArtifactGenerator;
154   private PackageInfoDao packageInfoDao;
155   private DeploymentFlavorDao deploymentFlavorDao;
156   private ComponentDao componentDao;
157   private ComponentDependencyModelDao componentDependencyModelDao;
158   private NicDao nicDao;
159   private ComputeDao computeDao;
160   private ImageDao imageDao;
161   private ManualVspToscaManager manualVspToscaManager;
162   private UniqueValueUtil uniqueValueUtil;
163   private CandidateService candidateService;
164
165   @Override
166   public ValidationResponse validate(VspDetails vspDetails) throws IOException {
167     List<ErrorCode> vspErrors = new ArrayList<>(validateVspFields(vspDetails));
168     ValidationResponse validationResponse = new ValidationResponse();
169     if (Objects.nonNull(vspDetails.getOnboardingMethod())
170         && OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) {
171       validateManualOnboardingMethod(vspDetails, validationResponse, vspErrors);
172     } else {
173       validateOrchestrationTemplateCandidate(validationResponse, vspErrors, vspDetails.getId(), vspDetails.getVersion());
174       if (!validationResponse.isValid()) {
175         return validationResponse;
176       }
177       validateLicense(vspDetails, vspErrors);
178       OrchestrationTemplateEntity orchestrationTemplate =
179           orchestrationTemplateDao.get(vspDetails.getId(), vspDetails.getVersion());
180       ToscaServiceModel serviceModel =
181           serviceModelDao.getServiceModel( vspDetails.getId(), vspDetails.getVersion());
182       if (isOrchestrationTemplateMissing(orchestrationTemplate)
183           || isServiceModelMissing(serviceModel)) {
184         vspErrors.add(VendorSoftwareProductInvalidErrorBuilder
185             .vendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(),
186                 vspDetails.getVersion()));
187       }
188       validationResponse.setUploadDataErrors(validateOrchestrationTemplate(orchestrationTemplate));
189     }
190
191     QuestionnaireValidationResult questionnaireValidationResult = validateQuestionnaire
192         (vspDetails.getId(), vspDetails.getVersion(), vspDetails.getOnboardingMethod());
193
194     if (Objects.nonNull(questionnaireValidationResult)) {
195       if (validationResponse.getQuestionnaireValidationResult() == null || validationResponse
196           .getQuestionnaireValidationResult().getValidationData() == null) {
197         validationResponse.setQuestionnaireValidationResult(questionnaireValidationResult);
198       } else {
199         validationResponse.getQuestionnaireValidationResult().getValidationData().addAll
200             (questionnaireValidationResult.getValidationData());
201       }
202     }
203
204     Collection<ComponentDependencyModelEntity> componentDependencies =
205         componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspDetails.getId(), vspDetails.getVersion(), null));
206
207     if (validateComponentDependencies(componentDependencies)) {
208       vspErrors
209           .add(ComponentDependencyModelErrorBuilder.getcyclicDependencyComponentErrorBuilder());
210     }
211     validationResponse
212         .setVspErrors(vspErrors);
213     validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails));
214     return validationResponse;
215   }
216
217   private void validateLicense(VspDetails vspDetails, List<ErrorCode> vspErrors) {
218     if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
219             || vspDetails.getFeatureGroups() != null) {
220       vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
221     }
222   }
223
224   private void validateOrchestrationTemplateCandidate(ValidationResponse validationResponse,
225                                                       List<ErrorCode> vspErrors, String vspId,
226                                                       Version version) {
227     orchestrationTemplateCandidateManager.getInfo(vspId, version)
228         .ifPresent(candidateInfo -> {
229           String fileName = candidateInfo.getFileName();
230           vspErrors.add(candidateInfo.getValidationData().isEmpty()
231               ? candidateDataNotProcessedOrAbortedErrorBuilder(fileName)
232               : invalidProcessedCandidate(fileName));
233           validationResponse.setVspErrors(vspErrors);
234         });
235   }
236
237   private void validateManualOnboardingMethod(VspDetails vspDetails,
238                                               ValidationResponse validationResponse,
239                                               List<ErrorCode> vspErrors) {
240     vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
241
242     Collection<DeploymentFlavorEntity> deploymentFlavors = deploymentFlavorDao
243         .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails.getVersion(), null));
244     if (CollectionUtils.isEmpty(deploymentFlavors)) {
245       vspErrors.add(vspMissingDeploymentFlavorErrorBuilder());
246     }
247     vspErrors.addAll(validateDeploymentFlavors(deploymentFlavors));
248
249     Set<CompositionEntityValidationData> componentValidationResult =
250         componentValidation(vspDetails.getId(), vspDetails.getVersion());
251     if (!CollectionUtils.isEmpty(componentValidationResult)) {
252       if (validationResponse.getQuestionnaireValidationResult() == null
253           || validationResponse.getQuestionnaireValidationResult().getValidationData() == null) {
254         validationResponse.setQuestionnaireValidationResult(
255             new QuestionnaireValidationResult(componentValidationResult));
256       } else {
257         validationResponse.getQuestionnaireValidationResult().getValidationData()
258             .addAll(componentValidationResult);
259       }
260     }
261   }
262
263   @Override
264   public Map<String, List<ErrorMessage>> compile(String vspId, Version version) {
265     ToscaServiceModel serviceModel =
266         OnboardingMethod.Manual.name().equals(getValidatedVsp(vspId, version).getOnboardingMethod())
267             //Generate Tosca service model for Manual Onboarding flow
268             ? manualVspToscaManager
269             .generateToscaModel(manualVspToscaManager.gatherVspInformation(vspId, version))
270             : serviceModelDao.getServiceModel(vspId, version);
271
272     return compile(vspId, version, serviceModel);
273   }
274
275   private boolean validateComponentDependencies(
276       Collection<ComponentDependencyModelEntity> componentDependencies) {
277     ComponentDependencyTracker dependencyTracker = new ComponentDependencyTracker();
278
279     for (ComponentDependencyModelEntity componentDependency : componentDependencies) {
280       dependencyTracker.addDependency(componentDependency.getSourceComponentId(),
281           componentDependency.getTargetComponentId());
282     }
283     return dependencyTracker.isCyclicDependencyPresent();
284   }
285
286   private Collection<ErrorCode> validateDeploymentFlavors(
287       Collection<DeploymentFlavorEntity> deploymentFlavors) {
288
289     Collection<ErrorCode> errorCodeList = new ArrayList<>();
290     if (!CollectionUtils.isEmpty(deploymentFlavors)) {
291       deploymentFlavors.forEach(deploymentFlavor -> {
292         DeploymentFlavorEntity deployment = deploymentFlavorDao.get(deploymentFlavor);
293         DeploymentFlavor deploymentLocalFlavor = deployment.getDeploymentFlavorCompositionData();
294         if (deploymentLocalFlavor != null) {
295           if (deploymentLocalFlavor.getFeatureGroupId() == null) {
296             ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder.
297                 getFeatureGroupMandatoryErrorBuilder(deploymentLocalFlavor.getModel());
298             errorCodeList.add(deploymentFlavorErrorBuilder);
299           }
300           validateComponentComputeAssociations(errorCodeList, deploymentFlavor,
301               deployment, deploymentLocalFlavor);
302         }
303       });
304     }
305     return errorCodeList;
306   }
307
308   private void validateComponentComputeAssociations(Collection<ErrorCode> errorCodeList,
309                                                     DeploymentFlavorEntity deploymentFlavor,
310                                                     DeploymentFlavorEntity deployment,
311                                                     DeploymentFlavor deploymentlocalFlavor) {
312     List<ComponentComputeAssociation> componentComputeAssociations =
313         deploymentlocalFlavor.getComponentComputeAssociations();
314     if (CollectionUtils.isEmpty(componentComputeAssociations)) {
315         validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
316     } else {
317       componentComputeAssociations.forEach(componentComputeAssociation -> {
318         if (componentComputeAssociation == null
319             || !(componentComputeAssociation.getComponentId() != null
320             && componentComputeAssociation.getComputeFlavorId() != null)) {
321             validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
322         }
323       });
324     }
325   }
326
327   private void validateCompositionEntity(Collection<ErrorCode> errorCodeList,
328                                                                              DeploymentFlavorEntity deploymentFlavor,
329                                                                              DeploymentFlavorEntity deployment,
330                                                                              DeploymentFlavor deploymentlocalFlavor){
331     CompositionEntityValidationData compositionEntityValidationData = new
332             CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
333             .getId());
334     compositionEntityValidationData.setEntityName(deployment
335             .getDeploymentFlavorCompositionData().getModel());
336     ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
337             .getInvalidComponentComputeAssociationErrorBuilder(
338                     deploymentlocalFlavor.getModel());
339     errorCodeList.add(deploymentFlavorErrorBuilder);
340   }
341
342   private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
343     Set<CompositionEntityValidationData> validationData = new HashSet<>();
344     Collection<ComponentEntity> components =
345         componentDao.list(new ComponentEntity(vspId, version, null));
346     if (!CollectionUtils.isEmpty(components)) {
347       components.forEach(component -> {
348         validateImage(vspId, version, validationData, component);
349         validateNic(vspId, version, validationData, component);
350
351       });
352     }
353
354     return validationData;
355   }
356
357   private void validateNic(String vspId, Version version,
358                            Set<CompositionEntityValidationData> validationData,
359                            ComponentEntity component) {
360     Collection<NicEntity> nics =
361         nicDao.list(new NicEntity(vspId, version, component.getId(), null));
362     if (CollectionUtils.isNotEmpty(nics)) {
363       nics.forEach(nicEntity -> {
364         NicEntity nic = nicDao.get(new NicEntity(vspId, version, component.getId(),
365             nicEntity.getId()));
366         NetworkType networkType = nic.getNicCompositionData().getNetworkType();
367         String networkId = nic.getNicCompositionData().getNetworkId();
368         if (networkType.equals(NetworkType.Internal) && networkId == null) {
369           CompositionEntityValidationData compositionEntityValidationData = new
370               CompositionEntityValidationData(CompositionEntityType.nic, nic.getId());
371           compositionEntityValidationData.setEntityName(nic.getNicCompositionData().getName());
372           ErrorCode nicInternalNetworkErrorBuilder = NicInternalNetworkErrorBuilder
373               .getNicNullNetworkIdInternalNetworkIdErrorBuilder();
374           List<String> errors = new ArrayList<>();
375           errors.add(nicInternalNetworkErrorBuilder.message());
376           compositionEntityValidationData.setErrors(errors);
377           validationData.add(compositionEntityValidationData);
378         }
379       });
380     }
381   }
382
383   private void validateImage(String vspId, Version version,
384                              Set<CompositionEntityValidationData> validationData,
385                              ComponentEntity component) {
386     Collection<ImageEntity> images =
387         imageDao.list(new ImageEntity(vspId, version, component.getId(), null));
388     if (CollectionUtils.isEmpty(images)) {
389       CompositionEntityValidationData compositionEntityValidationData = new
390           CompositionEntityValidationData(component.getType(), component.getId());
391       compositionEntityValidationData
392           .setEntityName(component.getComponentCompositionData().getDisplayName());
393       ErrorCode vfcMissingImageErrorBuilder =
394           ComponentErrorBuilder.vfcMissingImageErrorBuilder();
395       List<String> errors = new ArrayList<>();
396       errors.add(vfcMissingImageErrorBuilder.message());
397       compositionEntityValidationData.setErrors(errors);
398       validationData.add(compositionEntityValidationData);
399     }
400   }
401
402   private List<ErrorCode> validateVspFields(VspDetails vspDetails) {
403     List<ErrorCode> errors = new ArrayList<>();
404
405     if (vspDetails.getName() == null) {
406       errors.add(createMissingMandatoryFieldError("name"));
407     }
408     if (vspDetails.getDescription() == null) {
409       errors.add(createMissingMandatoryFieldError("description"));
410     }
411     if (vspDetails.getVendorId() == null) {
412       errors.add(createMissingMandatoryFieldError("vendor Id"));
413     }
414     if (vspDetails.getCategory() == null) {
415       errors.add(createMissingMandatoryFieldError("category"));
416     }
417     if (vspDetails.getSubCategory() == null) {
418       errors.add(createMissingMandatoryFieldError("sub category"));
419     }
420     return errors;
421   }
422
423   private List<ErrorCode> validateMandatoryLicenseFields(VspDetails vspDetails) {
424     List<ErrorCode> errors = new ArrayList<>();
425     if (vspDetails.getVlmVersion() == null) {
426       errors.add(createMissingMandatoryFieldError("licensing version"));
427     }
428     if (vspDetails.getLicenseAgreement() == null) {
429       errors.add(createMissingMandatoryFieldError("license agreement"));
430     }
431     if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
432       errors.add(createMissingMandatoryFieldError("feature groups"));
433     }
434     return errors;
435   }
436
437   private static ErrorCode createMissingMandatoryFieldError(String fieldName) {
438     return new ValidationErrorBuilder("must be supplied", fieldName).build();
439   }
440
441   private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
442                                                   ToscaServiceModel serviceModel) {
443     if (isServiceModelMissing(serviceModel)) {
444       return null;
445     }
446
447     enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version);
448
449     EnrichmentManager<ToscaServiceModel> enrichmentManager =
450         EnrichmentManagerFactory.getInstance().createInterface();
451     enrichmentManager.init(vendorSoftwareProductId, version);
452     enrichmentManager.setModel(serviceModel);
453     Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich();
454
455     enrichedServiceModelDao
456         .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
457
458     return enrichErrors;
459   }
460
461   private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
462     if (vspDetails.getVendorId() != null) {
463       Optional<ErrorCode> errorCode = vendorLicenseFacade.validateVendorForUsage(vspDetails.getVendorId(),vspDetails.getVlmVersion());
464       if (errorCode.isPresent()) {
465         return Collections.singleton(errorCode.get());
466       }
467     }
468
469     if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
470         || vspDetails.getLicenseAgreement() == null
471         || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
472       return Collections.emptyList();
473     }
474     return vendorLicenseFacade
475         .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
476             vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
477   }
478
479   @Override
480   public VspDetails createVsp(VspDetails vspDetails) {
481     vspInfoDao.create(vspDetails);
482     vspInfoDao.updateQuestionnaireData(vspDetails.getId(), vspDetails.getVersion(),
483         new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData());
484     return vspDetails;
485   }
486
487   @Override
488   public void updateVsp(VspDetails vspDetails) {
489     VspDetails retrieved = vspInfoDao.get(vspDetails);
490     if (retrieved == null) {
491       throw new CoreException((new ErrorCode.ErrorCodeBuilder()
492           .withMessage(String.format("Vsp with id %s and version %s does not exist.",
493               vspDetails.getId(), vspDetails.getVersion().getId()))).build());
494     }
495     vspDetails.setOnboardingMethod(retrieved.getOnboardingMethod());
496
497     //If any existing feature group is removed from VSP which is also associated in DF then
498     //update DF to remove feature group associations.
499     updateDeploymentFlavor(vspDetails);
500
501     updateUniqueName(retrieved.getName(), vspDetails.getName());
502     vspInfoDao.update(vspDetails);
503   }
504
505   private void updateDeploymentFlavor(VspDetails vspDetails) {
506     final List<String> featureGroups = vspDetails.getFeatureGroups();
507     if (featureGroups != null) {
508       final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao
509           .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails
510               .getVersion(), null));
511       if (Objects.nonNull(deploymentFlavorEntities)) {
512         for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) {
513           updateDeploymentFlavourEntity(featureGroups, deploymentFlavorEntity);
514         }
515       }
516     }
517   }
518
519   private void updateDeploymentFlavourEntity(List<String> featureGroups,
520                                              DeploymentFlavorEntity deploymentFlavorEntity) {
521     final String featureGroupId =
522         deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId();
523     if (!featureGroups.contains(featureGroupId)) {
524       DeploymentFlavor deploymentFlavorCompositionData =
525           deploymentFlavorEntity.getDeploymentFlavorCompositionData();
526       deploymentFlavorCompositionData.setFeatureGroupId(null);
527       deploymentFlavorEntity.setDeploymentFlavorCompositionData
528           (deploymentFlavorCompositionData);
529       deploymentFlavorDao.update(deploymentFlavorEntity);
530     }
531   }
532
533
534   @Override
535   public VspDetails getVsp(String vspId, Version version) {
536     return getValidatedVsp(vspId, version);
537   }
538
539   private VspDetails getValidatedVsp(String vspId, Version version) {
540     VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version));
541     if (vsp == null) {
542       throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
543     }
544     return vsp;
545   }
546
547   @Override
548   public void deleteVsp(String vspId, Version version) {
549     vspMergeDao.deleteHint(vspId, version);
550   }
551
552   @Override
553   public List<PackageInfo> listPackages(String category, String subCategory) {
554     return packageInfoDao.listByCategory(category, subCategory);
555   }
556
557   @Override
558   public File getTranslatedFile(String vspId, Version version) {
559     PackageInfo packageInfo = packageInfoDao.get(new PackageInfo(vspId, version));
560     if (packageInfo == null) {
561       throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build());
562     }
563
564     ByteBuffer translatedFileBuffer = packageInfo.getTranslatedFile();
565     if (translatedFileBuffer == null) {
566       throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build());
567     }
568
569     File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP);
570
571     try (FileOutputStream fos = new FileOutputStream(translatedFile)) {
572       fos.write(translatedFileBuffer.array());
573     } catch (IOException exception) {
574       throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(),
575           exception);
576     }
577     return translatedFile;
578   }
579
580   @Override
581   public byte[] getOrchestrationTemplateFile(String vspId, Version version) {
582     OrchestrationTemplateEntity uploadData = orchestrationTemplateDao.get(vspId, version);
583     ByteBuffer contentData = uploadData.getContentData();
584     if (contentData == null) {
585       return new byte[0];
586     }
587
588     ByteArrayOutputStream baos = new ByteArrayOutputStream();
589
590     try (final ZipOutputStream zos = new ZipOutputStream(baos);
591          ZipInputStream ignored = new ZipInputStream(
592              new ByteArrayInputStream(contentData.array()))) {
593       zos.write(contentData.array());
594     } catch (IOException exception) {
595       throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception);
596     }
597     return baos.toByteArray();
598   }
599
600   @Override
601   public OrchestrationTemplateEntity getOrchestrationTemplateInfo(String vspId, Version version) {
602     return orchestrationTemplateDao.getInfo(vspId, version);
603   }
604
605   @Override
606   public Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId,
607                                                                         Version version) {
608     Optional<String> jsonFileDataStructure =
609         orchestrationTemplateDao.getOrchestrationTemplateStructure(vspId, version);
610
611     if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) {
612       return Optional
613           .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class));
614     } else {
615       return Optional.empty();
616     }
617   }
618
619   @Override
620   public PackageInfo createPackage(String vspId, Version version) throws IOException {
621     ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version);
622     VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
623     Version vlmVersion = vspDetails.getVlmVersion();
624     if (vlmVersion != null) {
625       populateVersionsForVlm(vspDetails.getVendorId(), vlmVersion);
626     }
627     PackageInfo packageInfo = createPackageInfo(vspDetails);
628
629     ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar =
630         new ToscaFileOutputServiceCsarImpl();
631     FileContentHandler licenseArtifacts = licenseArtifactsService
632         .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
633             vspDetails.getFeatureGroups());
634     ETSIService etsiService = new ETSIServiceImpl();
635     if(etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())){
636         FileContentHandler handler = toscaServiceModel.getArtifactFiles();
637         try(InputStream manifestInputStream = getManifest(handler)) {
638           Manifest onboardingManifest = OnboardingManifest.parse(manifestInputStream);
639           etsiService.moveNonManoFileToArtifactFolder(handler, onboardingManifest);
640         }
641     }
642     packageInfo.setTranslatedFile(ByteBuffer.wrap(
643         toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
644
645     packageInfoDao.create(packageInfo);
646     return packageInfo;
647   }
648
649   private InputStream getManifest(FileContentHandler handler) throws IOException {
650     ToscaMetadata metadata = getMetadata(handler);
651     return getManifestInputStream(handler, metadata.getMetaEntries().get(TOSCA_META_ENTRY_MANIFEST));
652   }
653
654   private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException {
655     ToscaMetadata metadata;
656     if(handler.containsFile(TOSCA_META_PATH_FILE_NAME)){
657       metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_PATH_FILE_NAME));
658
659     }else if(handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)){
660       metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME));
661     }else {
662       throw new IOException("TOSCA.meta file not found!");
663     }
664     return metadata;
665   }
666
667   private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException {
668     InputStream io;
669     if(manifestLocation == null || !handler.containsFile(manifestLocation)){
670       io = handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME);
671     }else {
672       io = handler.getFileContent(manifestLocation);
673     }
674
675     if(io == null){
676       throw new IOException("Manifest file not found!");
677     }
678     return io;
679   }
680
681   void populateVersionsForVlm(String vlmId, Version vlmVersion) {
682     VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
683     versioningManager.list(vlmId).stream()
684         .filter(version -> version.getId().equalsIgnoreCase(vlmVersion.getId()))
685         .findAny()
686         .ifPresent(version -> {
687           vlmVersion.setMinor(version.getMinor());
688           vlmVersion.setMajor(version.getMajor());
689         });
690   }
691
692   private PackageInfo createPackageInfo(VspDetails vspDetails) {
693     PackageInfo packageInfo = new PackageInfo(vspDetails.getId(), vspDetails.getVersion());
694     packageInfo.setVspName(vspDetails.getName());
695     packageInfo.setVspDescription(vspDetails.getDescription());
696     packageInfo.setCategory(vspDetails.getCategory());
697     packageInfo.setSubCategory(vspDetails.getSubCategory());
698     packageInfo.setVendorName(vspDetails.getVendorName());
699     packageInfo.setPackageType(VendorSoftwareProductConstants.CSAR);
700     packageInfo.setVendorRelease("1.0"); //todo TBD
701     return packageInfo;
702   }
703
704   @Override
705
706   public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version) {
707     VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version);
708     VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version),
709         VspDetails.ENTITY_TYPE);
710
711     String questionnaireData = retrieved.getQuestionnaireData();
712
713     QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
714     questionnaireResponse.setData(questionnaireData);
715     questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
716     return questionnaireResponse;
717   }
718
719   @Override
720   public void updateVspQuestionnaire(String vspId, Version version, String questionnaireData) {
721     vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
722   }
723
724
725   private Map<String, List<ErrorMessage>> validateOrchestrationTemplate(
726       OrchestrationTemplateEntity orchestrationTemplate) throws IOException {
727
728     if (isOrchestrationTemplateMissing(orchestrationTemplate)) {
729       return null;
730     }
731     Map<String, List<ErrorMessage>> validationErrors = new HashMap<>();
732
733     FileContentHandler fileContentMap = CommonUtil.validateAndUploadFileContent(
734         OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix()),
735         orchestrationTemplate.getContentData().array());
736
737     if (CommonUtil.isFileOriginFromZip(orchestrationTemplate.getFileSuffix())) {
738       ValidationManager validationManager =
739           ValidationManagerUtil.initValidationManager(fileContentMap);
740       validationErrors.putAll(validationManager.validate());
741     }
742
743     return
744         MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors))
745             ? null : validationErrors;
746   }
747
748   private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
749                                                               String onboardingMethod) {
750     // The apis of CompositionEntityDataManager used here are stateful!
751     // so, it must be re-created from scratch when it is used!
752     CompositionEntityDataManager compositionEntityDataManager =
753         CompositionEntityDataManagerFactory.getInstance().createInterface();
754     compositionEntityDataManager
755         .addEntity(vspInfoDao.getQuestionnaire(vspId, version), null);
756
757     Collection<NicEntity> nics = nicDao.listByVsp(vspId, version);
758
759     Map<String, List<String>> nicNamesByComponent = new HashMap<>();
760     for (NicEntity nicEntity : nics) {
761       compositionEntityDataManager.addEntity(nicEntity, null);
762
763       Nic nic = nicEntity.getNicCompositionData();
764       if (nic != null && nic.getName() != null) {
765         List<String> nicNames =
766             nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>());
767         nicNames.add(nic.getName());
768       }
769     }
770
771     Collection<ComponentEntity> components =
772         componentDao.listCompositionAndQuestionnaire(vspId, version);
773     components.forEach(component -> compositionEntityDataManager.addEntity(component,
774         new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()),
775             JsonUtil.json2Object(component.getQuestionnaireData(), Map.class), null,
776                                                      OnboardingMethod.Manual.name().equals(onboardingMethod))));
777
778     Collection<ComputeEntity> computes = computeDao.listByVsp(vspId, version);
779     computes.forEach(compute -> compositionEntityDataManager.addEntity(compute, null));
780
781     if (OnboardingMethod.Manual.name().equals(onboardingMethod)) {
782       Collection<ImageEntity> images = imageDao.listByVsp(vspId, version);
783       images.forEach(image -> compositionEntityDataManager.addEntity(image, null));
784     }
785
786     Map<CompositionEntityId, Collection<String>> errorsByEntityId =
787         compositionEntityDataManager.validateEntitiesQuestionnaire();
788     if (MapUtils.isNotEmpty(errorsByEntityId)) {
789       compositionEntityDataManager.buildTrees();
790       compositionEntityDataManager.addErrorsToTrees(errorsByEntityId);
791       return new QuestionnaireValidationResult(
792           compositionEntityDataManager.getAllErrorsByVsp(vspId));
793     }
794     return null;
795   }
796
797   @Override
798   public File getInformationArtifact(String vspId, Version version) {
799     VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
800
801     if (vspDetails == null) {
802       return null;
803     }
804
805     String vspName = vspDetails.getName();
806     ByteBuffer infoArtifactAsByteBuffer;
807     File infoArtifactFile;
808     try {
809       infoArtifactAsByteBuffer = ByteBuffer.wrap(informationArtifactGenerator.generate(vspId,
810           version).getBytes());
811
812       infoArtifactFile =
813           new File(
814               String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName));
815       try (OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile))) {
816         out.write(infoArtifactAsByteBuffer.array());
817       }
818
819     } catch (IOException ex) {
820       throw new CoreException(new InformationArtifactCreationErrorBuilder(vspId).build(), ex);
821     }
822     return infoArtifactFile;
823   }
824
825   String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
826     return SchemaGenerator
827         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
828   }
829
830   @Override
831   public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException {
832
833     OrchestrationTemplateEntity orchestrationTemplateEntity =
834         orchestrationTemplateDao.get(vspId, version);
835
836     if (isOrchestrationTemplateMissing(orchestrationTemplateEntity)) {
837       return Optional.empty();
838     }
839
840     if (CommonUtil.isFileOriginFromZip(orchestrationTemplateEntity.getFileSuffix())) {
841       return Optional.of(new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(), candidateService
842           .getZipData(orchestrationTemplateEntity.getContentData())));
843     }
844     return Optional.of(new ImmutablePair<>(orchestrationTemplateEntity.getFileSuffix(),
845         orchestrationTemplateEntity.getContentData().array()));
846   }
847
848   void updateUniqueName(String oldVspName, String newVspName) {
849     uniqueValueUtil.updateUniqueValue(
850         VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
851         oldVspName, newVspName);
852   }
853
854   @Override
855   public Collection<ComputeEntity> getComputeByVsp(String vspId, Version version) {
856     return computeDao.listByVsp(vspId, version);
857   }
858
859   private boolean isOrchestrationTemplateMissing(
860       OrchestrationTemplateEntity orchestrationTemplate) {
861     return orchestrationTemplate == null
862         || orchestrationTemplate.getContentData() == null
863         || orchestrationTemplate.getFileSuffix() == null
864         || orchestrationTemplate.getFileName() == null;
865   }
866
867   private boolean isServiceModelMissing(ToscaServiceModel serviceModel) {
868     return serviceModel == null || serviceModel.getEntryDefinitionServiceTemplate() == null;
869   }
870
871   public static class Builder{
872     private VspMergeDao vspMergeDao;
873     private OrchestrationTemplateDao orchestrationTemplateDao;
874     private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
875     private VendorSoftwareProductInfoDao vspInfoDao;
876     private VendorLicenseFacade vendorLicenseFacade;
877     private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
878     private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
879     private VendorLicenseArtifactsService licenseArtifactsService;
880     private InformationArtifactGenerator informationArtifactGenerator;
881     private PackageInfoDao packageInfoDao;
882     private DeploymentFlavorDao deploymentFlavorDao;
883     private ComponentDao componentDao;
884     private ComponentDependencyModelDao componentDependencyModelDao;
885     private NicDao nicDao;
886     private ComputeDao computeDao;
887     private ImageDao imageDao;
888     private ManualVspToscaManager manualVspToscaManager;
889     private UniqueValueDao uniqueValueDao;
890     private CandidateService candidateService;
891
892     public Builder vspMerge(VspMergeDao vspMergeDao){
893       this.vspMergeDao = vspMergeDao;
894       return this;
895     }
896
897     public Builder orchestrationTemplate(OrchestrationTemplateDao orchestrationTemplateDao) {
898       this.orchestrationTemplateDao = orchestrationTemplateDao;
899       return this;
900     }
901
902     public Builder orchestrationTemplateCandidateManager(OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager) {
903       this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
904       return this;
905     }
906
907     public Builder vspInfo(VendorSoftwareProductInfoDao vspInfoDao) {
908       this.vspInfoDao = vspInfoDao;
909       return this;
910     }
911
912     public Builder vendorLicenseFacade(VendorLicenseFacade vendorLicenseFacade) {
913       this.vendorLicenseFacade = vendorLicenseFacade;
914       return this;
915     }
916
917     public Builder serviceModel(ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao) {
918       this.serviceModelDao = serviceModelDao;
919       return this;
920     }
921
922     public Builder enrichedServiceModel(EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao) {
923       this.enrichedServiceModelDao = enrichedServiceModelDao;
924       return this;
925     }
926
927     public Builder licenseArtifactsService(VendorLicenseArtifactsService licenseArtifactsService) {
928       this.licenseArtifactsService = licenseArtifactsService;
929       return this;
930     }
931
932     public Builder informationArtifactGenerator(InformationArtifactGenerator informationArtifactGenerator) {
933       this.informationArtifactGenerator = informationArtifactGenerator;
934       return this;
935     }
936
937     public Builder packageInfo(PackageInfoDao packageInfoDao) {
938       this.packageInfoDao = packageInfoDao;
939       return this;
940     }
941
942     public Builder deploymentFlavor(DeploymentFlavorDao deploymentFlavorDao) {
943       this.deploymentFlavorDao = deploymentFlavorDao;
944       return this;
945     }
946
947     public Builder component(ComponentDao componentDao) {
948       this.componentDao = componentDao;
949       return this;
950     }
951
952     public Builder componentDependencyModel(ComponentDependencyModelDao componentDependencyModelDao) {
953       this.componentDependencyModelDao = componentDependencyModelDao;
954       return this;
955     }
956
957     public Builder nic(NicDao nicDao) {
958       this.nicDao = nicDao;
959       return this;
960     }
961
962     public Builder compute(ComputeDao computeDao) {
963       this.computeDao = computeDao;
964       return this;
965     }
966
967     public Builder image(ImageDao imageDao) {
968       this.imageDao = imageDao;
969       return this;
970     }
971
972     public Builder manualVspToscaManager(ManualVspToscaManager manualVspToscaManager) {
973       this.manualVspToscaManager = manualVspToscaManager;
974       return this;
975     }
976
977     public Builder uniqueValue(UniqueValueDao uniqueValueDao) {
978       this.uniqueValueDao = uniqueValueDao;
979       return this;
980     }
981
982     public Builder candidateService(CandidateService candidateService) {
983       this.candidateService = candidateService;
984       return this;
985     }
986
987     private void registerToVersioning() {
988       if(serviceModelDao != null) {
989         serviceModelDao.registerVersioning(
990                 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
991       }
992       if(enrichedServiceModelDao != null) {
993         enrichedServiceModelDao.registerVersioning(
994                 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
995       }
996     }
997
998     public VendorSoftwareProductManager build(){
999       VendorSoftwareProductManagerImpl vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl();
1000       vendorSoftwareProductManager.vspMergeDao = this.vspMergeDao;
1001       vendorSoftwareProductManager.orchestrationTemplateDao = this.orchestrationTemplateDao;
1002       vendorSoftwareProductManager.orchestrationTemplateCandidateManager = this.orchestrationTemplateCandidateManager;
1003       vendorSoftwareProductManager.vspInfoDao = this.vspInfoDao;
1004       vendorSoftwareProductManager.vendorLicenseFacade = this.vendorLicenseFacade;
1005       vendorSoftwareProductManager.serviceModelDao = this.serviceModelDao;
1006       vendorSoftwareProductManager.enrichedServiceModelDao = this.enrichedServiceModelDao;
1007       vendorSoftwareProductManager.licenseArtifactsService = this.licenseArtifactsService;
1008       vendorSoftwareProductManager.informationArtifactGenerator = this.informationArtifactGenerator;
1009       vendorSoftwareProductManager.packageInfoDao = this.packageInfoDao;
1010       vendorSoftwareProductManager.deploymentFlavorDao = this.deploymentFlavorDao;
1011       vendorSoftwareProductManager.componentDao = this.componentDao;
1012       vendorSoftwareProductManager.componentDependencyModelDao = this.componentDependencyModelDao;
1013       vendorSoftwareProductManager.nicDao = this.nicDao;
1014       vendorSoftwareProductManager.computeDao = this.computeDao;
1015       vendorSoftwareProductManager.imageDao = this.imageDao;
1016       vendorSoftwareProductManager.manualVspToscaManager = this.manualVspToscaManager;
1017       vendorSoftwareProductManager.uniqueValueUtil = new UniqueValueUtil(this.uniqueValueDao);
1018       vendorSoftwareProductManager.candidateService = candidateService;
1019       this.registerToVersioning();
1020       return vendorSoftwareProductManager;
1021     }
1022   }
1023
1024 }