[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-software-product-lib / openecomp-sdc-vendor-software-product-core / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / dao / impl / VendorSoftwareProductDaoImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.dao.impl;
22
23 import org.openecomp.core.model.dao.EnrichedServiceArtifactDao;
24 import org.openecomp.core.model.dao.EnrichedServiceArtifactDaoFactory;
25 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
26 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
27 import org.openecomp.core.model.dao.ServiceArtifactDaoFactory;
28 import org.openecomp.core.model.dao.ServiceArtifactDaoInter;
29 import org.openecomp.core.model.dao.ServiceModelDao;
30 import org.openecomp.core.model.dao.ServiceModelDaoFactory;
31 import org.openecomp.core.model.dao.ServiceTemplateDaoFactory;
32 import org.openecomp.core.model.dao.ServiceTemplateDaoInter;
33 import org.openecomp.core.utilities.CommonMethods;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory;
40 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
41 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory;
42 import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao;
43 import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory;
44 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
45 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory;
46 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
47 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
48 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao;
49 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory;
50 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
51 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory;
52 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao;
53 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory;
54 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
55 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
56 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
57 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
58 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
59 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
60 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
61 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
62 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
63 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
64 import org.openecomp.sdc.versioning.dao.types.Version;
65
66 import java.nio.ByteBuffer;
67 import java.util.Collection;
68 import java.util.List;
69
70 public class VendorSoftwareProductDaoImpl implements VendorSoftwareProductDao {
71
72   private static final VendorSoftwareProductInfoDao vspInfoDao = VendorSoftwareProductInfoDaoFactory
73       .getInstance().createInterface();
74   private static final PackageInfoDao packageInfoDao =
75       PackageInfoDaoFactory.getInstance().createInterface();
76   private static final OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao =
77       OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface();
78   private static final NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface();
79   private static final ComponentDao componentDao =
80       ComponentDaoFactory.getInstance().createInterface();
81   private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface();
82   private static final ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface();
83   private static final ServiceArtifactDaoInter
84       artifactDao = ServiceArtifactDaoFactory.getInstance().createInterface();
85   public static final ServiceTemplateDaoInter
86       templateDao = ServiceTemplateDaoFactory.getInstance().createInterface();
87   private static final EnrichedServiceArtifactDao enrichArtifactDao =
88       EnrichedServiceArtifactDaoFactory.getInstance().createInterface();
89   private static final EnrichedServiceModelDao enrichedServiceModelDao =
90       EnrichedServiceModelDaoFactory.getInstance().createInterface();
91   private static final ServiceModelDao serviceModelDao =
92       ServiceModelDaoFactory.getInstance().createInterface();
93   private static final ComponentDependencyModelDao componentDependencyModelDao =
94       ComponentDependencyModelDaoFactory.getInstance().createInterface();
95   private static final DeploymentFlavorDao
96       deploymentFlavorDao = DeploymentFlavorDaoFactory.getInstance().createInterface();
97   private static final ImageDao imageDao = ImageDaoFactory.getInstance().createInterface();
98   private static final ComputeDao computeDao = ComputeDaoFactory.getInstance().createInterface();
99
100
101   @Override
102   public void registerVersioning(String versionableEntityType) {
103     vspInfoDao.registerVersioning(versionableEntityType);
104     networkDao.registerVersioning(versionableEntityType);
105     componentDao.registerVersioning(versionableEntityType);
106     nicDao.registerVersioning(versionableEntityType);
107     processDao.registerVersioning(versionableEntityType);
108     orchestrationTemplateCandidateDataDao.registerVersioning(versionableEntityType);
109     componentDependencyModelDao.registerVersioning(versionableEntityType);
110     computeDao.registerVersioning(versionableEntityType);
111     deploymentFlavorDao.registerVersioning(versionableEntityType);
112     imageDao.registerVersioning(versionableEntityType);
113   }
114
115   @Override
116   public Collection<ComponentEntity> listComponents(String vspId, Version version) {
117     return componentDao.list(new ComponentEntity(vspId, version, null));
118   }
119
120   @Override
121   public Collection<ComponentEntity> listComponentsQuestionnaire(String vspId, Version version) {
122     return componentDao.listQuestionnaires(vspId, version);
123   }
124
125   @Override
126   public Collection<ComponentEntity> listComponentsCompositionAndQuestionnaire(String vspId,
127                                                                                Version version) {
128     return componentDao.listCompositionAndQuestionnaire(vspId, version);
129   }
130
131   @Override
132   public Collection<ProcessEntity> listProcesses(String vspId, Version version,
133                                                  String componentId) {
134     return processDao.list(new ProcessEntity(vspId, version, componentId, null));
135   }
136
137   @Override
138   public void deleteProcesses(String vspId, Version version, String componentId) {
139     processDao.delete(new ProcessEntity(vspId, version, componentId, null));
140   }
141
142   @Override
143   public ProcessEntity getProcess(String vspId, Version version, String componentId,
144                                   String processId) {
145     return processDao.get(new ProcessEntity(vspId, version, componentId, processId));
146   }
147
148   @Override
149   public void createProcess(ProcessEntity processEntity) {
150     processDao.create(processEntity);
151   }
152
153   @Override
154   public void updateProcess(ProcessEntity processEntity) {
155     ProcessEntity process = processDao.get(new ProcessEntity(processEntity.getVspId(), processEntity.getVersion(),
156             processEntity.getComponentId(), processEntity.getId()));
157     processEntity.setArtifact(process.getArtifact());
158     processEntity.setArtifactName(process.getArtifactName());
159     processDao.update(processEntity);
160   }
161
162   @Override
163   public void deleteProcess(String vspId, Version version, String componentId, String processId) {
164     processDao.delete(new ProcessEntity(vspId, version, componentId, processId));
165   }
166
167   @Override
168   public void uploadProcessArtifact(String vspId, Version version, String componentId,
169                                     String processId, byte[] artifact, String artifactName) {
170     ProcessEntity
171         processArtifact = new ProcessEntity(vspId, version, componentId, processId);
172     processArtifact = processDao.get(processArtifact);
173     processArtifact.setArtifact(ByteBuffer.wrap(artifact));
174     processArtifact.setArtifactName(artifactName);
175     processDao.update(processArtifact);
176   }
177
178   @Override
179   public ProcessEntity getProcessArtifact(String vspId, Version version, String componentId,
180                                           String processId) {
181     return processDao
182         .get(new ProcessEntity(vspId, version, componentId, processId));
183   }
184
185   @Override
186   public void deleteProcessArtifact(String vspId, Version version, String componentId,
187                                     String processId) {
188     processDao.delete(new ProcessEntity(vspId, version, componentId, processId));
189   }
190
191   @Override
192   public Collection<NicEntity> listNicsByVsp(String vspId, Version version) {
193     return nicDao.listByVsp(vspId, version);
194   }
195
196   @Override
197   public void deleteUploadData(String vspId, Version version) {
198
199     networkDao.deleteAll(vspId, version);
200     //nicDao.deleteByVspId(vspId, version);
201     //artifactDao.delete(vspId, version);
202     //templateDao.deleteAll(vspId, version);
203     enrichedServiceModelDao.deleteAll(vspId, version);
204     serviceModelDao.deleteAll(vspId, version);
205     //processDao.deleteVspAll(vspId,version);
206     componentDao.deleteAll(vspId, version);
207     vspInfoDao.deleteAll(vspId, version);
208
209 //    uploadDataDao.deleteContentDataAndValidationData(vspId, version);
210
211 //    enrichArtifactDao.deleteAll(vspId, version);
212 //    artifactDao.deleteAll(vspId, version);
213   }
214
215   /* @Override
216    public void updateVspLatestModificationTime(String vspId, Version version) {
217    *//*  if (Objects.isNull(vspId) || Objects.isNull(version)) {
218       return;
219     }
220
221     VspDetails retrieved = getVendorSoftwareProductInfo(new VspDetails(vspId, version));
222     updateVendorSoftwareProductInfo(retrieved);*//*
223   }
224 */
225   @Override
226   public void createComponentDependencyModel(List<ComponentDependencyModelEntity>
227                                                  componentDependencyModel, String vspId,
228                                              Version version) {
229     componentDependencyModelDao.deleteAll(vspId, version);
230     for (ComponentDependencyModelEntity entity : componentDependencyModel) {
231       entity.setId(CommonMethods.nextUuId());
232       componentDependencyModelDao.create(entity);
233     }
234   }
235
236   @Override
237   public Collection<ComponentDependencyModelEntity> listComponentDependencies(String vspId,
238                                                                               Version version) {
239     return componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version,
240         null));
241   }
242
243   @Override
244   public void createDeploymentFlavor(DeploymentFlavorEntity deploymentFlavor) {
245     deploymentFlavorDao.create(deploymentFlavor);
246   }
247
248   @Override
249   public Collection<DeploymentFlavorEntity> listDeploymentFlavors(String vspId, Version version) {
250     return deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null));
251   }
252
253   @Override
254   public DeploymentFlavorEntity getDeploymentFlavor(String vspId, Version version,
255                                                     String deploymentFlavorId) {
256     return deploymentFlavorDao.get(new DeploymentFlavorEntity(vspId, version, deploymentFlavorId));
257   }
258
259   @Override
260   public void deleteDeploymentFlavor(String vspId, Version version, String deploymentFlavorId) {
261     deploymentFlavorDao.delete(new DeploymentFlavorEntity(vspId,version,
262         deploymentFlavorId));
263   }
264
265   @Override
266   public void createImage(ImageEntity imageEntity) {
267     imageDao.create(imageEntity);
268   }
269
270   @Override
271   public Collection<ImageEntity> listImages(String vspId, Version version, String componentId) {
272     return imageDao.list(new ImageEntity(vspId, version, componentId, null));
273   }
274
275   @Override
276   public ImageEntity getImage(String vspId, Version version, String componentId, String imageId) {
277     return imageDao.get(new ImageEntity(vspId, version, componentId, imageId));
278   }
279
280   @Override
281   public Collection<ImageEntity> listImagesByVsp(String vspId, Version version) {
282     return imageDao.listByVsp(vspId, version);
283   }
284
285   @Override
286   public void createCompute(ComputeEntity computeEntity) {
287     computeDao.create(computeEntity);
288   }
289
290   @Override
291   public Collection<ComputeEntity> listComputes(String vspId, Version version, String componentId) {
292     return computeDao.list(new ComputeEntity(vspId, version, componentId, null));
293   }
294
295   @Override
296   public Collection<ComputeEntity> listComputesByVsp(String vspId, Version version) {
297     return computeDao.listByVsp(vspId, version);
298   }
299
300   @Override
301   public ComputeEntity getCompute(String vspId, Version version, String componentId,
302                                   String computeFlavorId) {
303     return computeDao.get(new ComputeEntity(vspId, version, componentId, computeFlavorId));
304   }
305
306   @Override
307   public void deleteImage(String vspId, Version version, String componentId, String imageId) {
308     ImageEntity imageEntity = new ImageEntity(vspId, version, componentId, imageId);
309     imageDao.delete(imageEntity);
310   }
311
312   @Override
313   public void updateDeploymentFlavor(DeploymentFlavorEntity deploymentFlavorEntity) {
314     deploymentFlavorDao.update(deploymentFlavorEntity);
315   }
316
317   @Override
318   public void updateImage(ImageEntity imageEntity) {
319     imageDao.update(imageEntity);
320   }
321
322   @Override
323   public void updateImageQuestionnaire(String vspId, Version version, String componentId,
324                                        String imageId, String questionnaireData) {
325     imageDao.updateQuestionnaireData(vspId, version, componentId, imageId, questionnaireData);
326   }
327
328   @Override
329   public void updateComputeQuestionnaire(String vspId, Version version, String componentId,
330                                          String computeId, String questionnaireData) {
331     computeDao.updateQuestionnaireData(vspId, version, componentId, computeId, questionnaireData);
332   }
333
334   @Override
335   public void updateCompute(ComputeEntity compute) {
336     computeDao.update(compute);
337   }
338
339   @Override
340   public void deleteCompute(String vspId, Version version, String componentId, String
341       computeFlavorId) {
342     computeDao.delete(new ComputeEntity(vspId, version, componentId, computeFlavorId));
343   }
344 }