push addional code
[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.ServiceArtifactDaoFactory;
26 import org.openecomp.core.model.dao.ServiceArtifactDaoInter;
27 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao;
28 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory;
29 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
30 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
31 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDaoFactory;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao;
40 import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory;
41 import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDao;
42 import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDaoFactory;
43 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
44 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
45 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
46 import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao;
47 import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDaoFactory;
48 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity;
49 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
50 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
51 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
52 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
53 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity;
54 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
55 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
56 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
57 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
58 import org.openecomp.sdc.versioning.dao.types.Version;
59
60 import java.nio.ByteBuffer;
61 import java.util.Collection;
62 import java.util.List;
63 import java.util.Objects;
64
65 public class VendorSoftwareProductDaoImpl implements VendorSoftwareProductDao {
66
67   private static final VendorSoftwareProductInfoDao vspInfoDao =
68       VendorSoftwareProductInfoDaoFactory.getInstance().createInterface();
69   private static final PackageInfoDao packageInfoDao =
70       PackageInfoDaoFactory.getInstance().createInterface();
71   private static final UploadDataDao uploadDataDao =
72       UploadDataDaoFactory.getInstance().createInterface();
73   private static final VspQuestionnaireDao vspQuestionnaireDao =
74       VspQuestionnaireDaoFactory.getInstance().createInterface();
75   private static final NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface();
76   private static final ComponentDao componentDao =
77       ComponentDaoFactory.getInstance().createInterface();
78   private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface();
79   private static final ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface();
80   private static final ProcessArtifactDao processArtifactDao =
81       ProcessArtifactDaoFactory.getInstance().createInterface();
82   private static final ComponentArtifactDao componentArtifactDao =
83       ComponentArtifactDaoFactory.getInstance().createInterface();
84   private static final ServiceArtifactDaoInter artifactDao =
85       ServiceArtifactDaoFactory.getInstance().createInterface();
86   private static final EnrichedServiceArtifactDao enrichArtifactDao =
87       EnrichedServiceArtifactDaoFactory.getInstance().createInterface();
88
89   @Override
90   public void registerVersioning(String versionableEntityType) {
91     vspInfoDao.registerVersioning(versionableEntityType);
92     vspQuestionnaireDao.registerVersioning(versionableEntityType);
93     networkDao.registerVersioning(versionableEntityType);
94     componentDao.registerVersioning(versionableEntityType);
95     nicDao.registerVersioning(versionableEntityType);
96     processDao.registerVersioning(versionableEntityType);
97   }
98
99   @Override
100   public void createVendorSoftwareProductInfo(VspDetails vspDetails) {
101     vspInfoDao.create(vspDetails);
102   }
103
104   @Override
105   public Collection<VspDetails> listVendorSoftwareProductsInfo() {
106     return vspInfoDao.list(new VspDetails());
107   }
108
109   public VspDetails getVendorSoftwareProductInfo(VspDetails vspDetails) {
110     return vspInfoDao.get(vspDetails);
111   }
112
113
114   @Override
115   public void updateVendorSoftwareProductInfo(VspDetails vspDetails) {
116     vspInfoDao.update(vspDetails);
117   }
118
119   @Override
120   public void deleteVendorSoftwareProductInfo(VspDetails vspDetails) {
121     vspInfoDao.delete(vspDetails);
122   }
123
124   @Override
125   public void updateUploadData(UploadDataEntity uploadData) {
126     uploadDataDao.update(uploadData);
127   }
128
129   @Override
130   public UploadDataEntity getUploadData(UploadDataEntity uploadData) {
131     return uploadDataDao.get(uploadData);
132   }
133
134   @Override
135   public ByteBuffer getContentData(UploadDataEntity uploadDataEntity) {
136     return uploadDataDao.getContentData(uploadDataEntity.getId(), uploadDataEntity.getVersion());
137   }
138
139   @Override
140   public void insertPackageDetails(PackageInfo packageInfo) {
141     packageInfoDao.update(packageInfo);
142   }
143
144   @Override
145   public PackageInfo getPackageInfo(PackageInfo packageInfo) {
146     return packageInfoDao.get(packageInfo);
147   }
148
149   @Override
150   public void deletePackageInfo(PackageInfo packageInfo) {
151     packageInfoDao.delete(packageInfo);
152   }
153
154   @Override
155   public Collection<NetworkEntity> listNetworks(String vspId, Version version) {
156     return networkDao.list(new NetworkEntity(vspId, version, null));
157   }
158
159   @Override
160   public void createNetwork(NetworkEntity network) {
161     networkDao.create(network);
162   }
163
164   @Override
165   public void updateNetwork(NetworkEntity networkEntity) {
166     networkDao.update(networkEntity);
167   }
168
169   @Override
170   public NetworkEntity getNetwork(String vspId, Version version, String networkId) {
171     return networkDao.get(new NetworkEntity(vspId, version, networkId));
172   }
173
174   @Override
175   public void deleteNetwork(String vspId, Version version) {
176     NetworkEntity networkEntity = new NetworkEntity(vspId, version, null);
177     networkDao.delete(networkEntity);
178   }
179
180   @Override
181   public List<PackageInfo> listPackages(String category, String subCategory) {
182     return packageInfoDao.listByCategory(category, subCategory);
183   }
184
185
186   @Override
187   public Collection<ComponentEntity> listComponents(String vspId, Version version) {
188     return componentDao.list(new ComponentEntity(vspId, version, null));
189   }
190
191   @Override
192   public void createComponent(ComponentEntity component) {
193     componentDao.create(component);
194   }
195
196   @Override
197   public void updateComponent(ComponentEntity component) {
198     componentDao.update(component);
199   }
200
201   @Override
202   public ComponentEntity getComponent(String vspId, Version version, String componentId) {
203     return componentDao.get(new ComponentEntity(vspId, version, componentId));
204   }
205
206   @Override
207   public Collection<ComponentEntity> listComponentsQuestionnaire(String vspId, Version version) {
208     return componentDao.listQuestionnaires(vspId, version);
209   }
210
211   @Override
212   public void updateComponentQuestionnaire(String vspId, Version version, String componentId,
213                                            String questionnaireData) {
214     componentDao.updateQuestionnaireData(vspId, version, componentId, questionnaireData);
215   }
216
217   @Override
218   public void deleteComponent(String vspId, Version version) {
219     ComponentEntity componentEntity = new ComponentEntity(vspId, version, null);
220     componentDao.delete(componentEntity);
221   }
222
223   @Override
224   public Collection<ProcessEntity> listProcesses(String vspId, Version version,
225                                                  String componentId) {
226     return processDao.list(new ProcessEntity(vspId, version, componentId, null));
227   }
228
229   @Override
230   public void deleteProcesses(String vspId, Version version, String componentId) {
231     processDao.delete(new ProcessEntity(vspId, version, componentId, null));
232   }
233
234   @Override
235   public ProcessEntity getProcess(String vspId, Version version, String componentId,
236                                   String processId) {
237     return processDao.get(new ProcessEntity(vspId, version, componentId, processId));
238   }
239
240   @Override
241   public void createProcess(ProcessEntity processEntity) {
242     processDao.create(processEntity);
243   }
244
245   @Override
246   public void updateProcess(ProcessEntity processEntity) {
247     processDao.update(processEntity);
248   }
249
250   @Override
251   public void deleteProcess(String vspId, Version version, String componentId, String processId) {
252     processDao.delete(new ProcessEntity(vspId, version, componentId, processId));
253   }
254
255   @Override
256   public void uploadProcessArtifact(String vspId, Version version, String componentId,
257                                     String processId, byte[] artifact, String artifactName) {
258     ProcessArtifactEntity processArtifact =
259         new ProcessArtifactEntity(vspId, version, componentId, processId);
260     processArtifact.setArtifact(ByteBuffer.wrap(artifact));
261     processArtifact.setArtifactName(artifactName);
262     processArtifactDao.update(processArtifact);
263   }
264
265   @Override
266   public ProcessArtifactEntity getProcessArtifact(String vspId, Version version, String componentId,
267                                                   String processId) {
268     return processArtifactDao
269         .get(new ProcessArtifactEntity(vspId, version, componentId, processId));
270   }
271
272   @Override
273   public void deleteProcessArtifact(String vspId, Version version, String componentId,
274                                     String processId) {
275     processArtifactDao.delete(new ProcessArtifactEntity(vspId, version, componentId, processId));
276   }
277
278   @Override
279   public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) {
280     return vspQuestionnaireDao.get(new VspQuestionnaireEntity(vspId, version));
281   }
282
283   @Override
284   public void updateQuestionnaire(String vspId, Version version, String questionnaireData) {
285     vspQuestionnaireDao.updateQuestionnaireData(vspId, version, questionnaireData);
286   }
287
288   @Override
289   public Collection<NicEntity> listNics(String vspId, Version version, String componentId) {
290     return nicDao.list(new NicEntity(vspId, version, componentId, null));
291   }
292
293   @Override
294   public void createNic(NicEntity nic) {
295     nicDao.create(nic);
296   }
297
298   @Override
299   public NicEntity getNic(String vspId, Version version, String componentId, String nicId) {
300     return nicDao.get(new NicEntity(vspId, version, componentId, nicId));
301   }
302
303   @Override
304   public void updateNic(NicEntity nicEntity) {
305     nicDao.update(nicEntity);
306   }
307
308   @Override
309   public void updateNicQuestionnaire(String vspId, Version version, String componentId,
310                                      String nicId, String questionnaireData) {
311     nicDao.updateQuestionnaireData(vspId, version, componentId, nicId, questionnaireData);
312   }
313
314   @Override
315   public Collection<NicEntity> listNicsByVsp(String vspId, Version version) {
316     return nicDao.listByVsp(vspId, version);
317   }
318
319   @Override
320   public void deleteNic(String vspId, Version version, String componentId) {
321     NicEntity nicEntity = new NicEntity(vspId, version, componentId, null);
322     nicDao.delete(nicEntity);
323   }
324
325   @Override
326   public void deleteUploadData(String vspId, Version version) {
327     networkDao.deleteAll(vspId, version);
328     nicDao.deleteByVspId(vspId, version);
329     artifactDao.delete(vspId, version);
330     enrichArtifactDao.delete(vspId, version);
331     ComponentArtifactEntity componentArtifactEntity =
332         new ComponentArtifactEntity(vspId, version, null, null);
333     ProcessEntity processEntity = new ProcessEntity(vspId, version, null, null);
334     componentArtifactDao.deleteAll(componentArtifactEntity);
335     processDao.deleteAll(processEntity);
336     componentDao.deleteAll(vspId, version);
337     uploadDataDao.deleteContentDataAndValidationData(vspId, version);
338   }
339
340   @Override
341   public void updateVspLatestModificationTime(String vspId, Version version) {
342     if (Objects.isNull(vspId) || Objects.isNull(version)) {
343       return;
344     }
345
346     VspDetails retrieved = getVendorSoftwareProductInfo(new VspDetails(vspId, version));
347     updateVendorSoftwareProductInfo(retrieved);
348   }
349 }