faa53862efafd9e5dd3dfcc8ad996daddba6aec0
[sdc.git] /
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.impl;
22
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.utilities.CommonMethods;
26 import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
27 import org.openecomp.core.utilities.json.JsonUtil;
28 import org.openecomp.sdc.common.errors.CoreException;
29 import org.openecomp.sdc.common.errors.ErrorCategory;
30 import org.openecomp.sdc.common.errors.ErrorCode;
31 import org.openecomp.sdc.logging.api.Logger;
32 import org.openecomp.sdc.logging.api.LoggerFactory;
33 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
40 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
41 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
42 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity;
43 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
44 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
45 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
46 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
47 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
48 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
49 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
50 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
51 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component;
52 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
53 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData;
54 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
55 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
56 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
57 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
58 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
59 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
60 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType;
61 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
62 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
63 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
64 import org.openecomp.sdc.versioning.dao.types.Version;
65
66 import java.util.ArrayList;
67 import java.util.Collection;
68 import java.util.Collections;
69 import java.util.HashMap;
70 import java.util.HashSet;
71 import java.util.List;
72 import java.util.Map;
73 import java.util.Objects;
74 import java.util.Set;
75
76 public class CompositionEntityDataManagerImpl implements CompositionEntityDataManager {
77
78   private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR =
79       "COMPOSITION_ENTITY_DATA_MANAGER_ERR";
80   private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG =
81       "Invalid input: %s may not be null";
82   private static final String MISSING_OR_INVALID_QUESTIONNAIRE_MSG =
83       "Data is missing/invalid for this %s. Please refill and resubmit.";
84
85   private static final Logger logger =
86       LoggerFactory.getLogger(CompositionEntityDataManagerImpl.class);
87   private Map<CompositionEntityId, CompositionEntityData> entities = new HashMap<>();
88   private Map<CompositionEntityType, String> nonDynamicSchemas = new HashMap<>();
89   private List<CompositionEntityValidationData> roots = new ArrayList<>();
90
91   private VendorSoftwareProductInfoDao vspInfoDao;
92   private ComponentDao componentDao;
93   private NicDao nicDao;
94   private NetworkDao networkDao;
95   private ImageDao imageDao;
96   private ComputeDao computeDao;
97   private DeploymentFlavorDao deploymentFlavorDao;
98
99   public CompositionEntityDataManagerImpl(VendorSoftwareProductInfoDao vspInfoDao,
100                                           ComponentDao componentDao,
101                                           NicDao nicDao, NetworkDao networkDao,
102                                           ImageDao imageDao, ComputeDao computeDao,
103                                           DeploymentFlavorDao deploymentFlavorDao) {
104     this.vspInfoDao = vspInfoDao;
105     this.componentDao = componentDao;
106     this.nicDao = nicDao;
107     this.networkDao = networkDao;
108     this.imageDao = imageDao;
109     this.computeDao = computeDao;
110     this.deploymentFlavorDao = deploymentFlavorDao;
111   }
112
113   /**
114    * Validate entity composition entity validation data.
115    *
116    * @param entity                the entity
117    * @param schemaTemplateContext the schema template context
118    * @param schemaTemplateInput   the schema template input
119    * @return the composition entity validation data
120    */
121   @Override
122   public CompositionEntityValidationData validateEntity(CompositionEntity entity,
123                                                         SchemaTemplateContext schemaTemplateContext,
124                                                         SchemaTemplateInput schemaTemplateInput) {
125     if (entity == null) {
126       throw new CoreException(
127           new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
128               .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
129               String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity"))
130               .build());
131     }
132     if (schemaTemplateContext == null) {
133       throw new CoreException(
134           new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
135               .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
136               String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context"))
137               .build());
138     }
139
140     CompositionEntityValidationData validationData =
141         new CompositionEntityValidationData(entity.getType(), entity.getId());
142     String json =
143         schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData()
144             : entity.getQuestionnaireData();
145     validationData.setErrors(JsonUtil.validate(
146         json == null ? JsonUtil.object2Json(new Object()) : json,
147         generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput)));
148     return validationData;
149   }
150
151   /**
152    * Add entity.
153    *
154    * @param entity              the entity
155    * @param schemaTemplateInput the schema template input
156    */
157   @Override
158   public void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) {
159     if (entity == null) {
160       throw new CoreException(
161           new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
162               .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
163               String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity"))
164               .build());
165     }
166     entities.put(entity.getCompositionEntityId(),
167         new CompositionEntityData(entity, schemaTemplateInput));
168   }
169
170   /**
171    * Validate entities questionnaire map.
172    *
173    * @return the map
174    */
175   @Override
176   public Map<CompositionEntityId, Collection<String>> validateEntitiesQuestionnaire() {
177     Map<CompositionEntityId, Collection<String>> errorsByEntityId = new HashMap<>();
178     entities.entrySet().forEach(entry -> {
179       Collection<String> errors = validateQuestionnaire(entry.getValue());
180       if (errors != null) {
181         errorsByEntityId.put(entry.getKey(), errors);
182       }
183     });
184     return errorsByEntityId;
185   }
186
187   /**
188    * Build trees.
189    */
190   @Override
191   public void buildTrees() {
192     Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData =
193         new HashMap<>();
194     entities.entrySet().forEach(
195         entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(),
196             entry.getValue().entity));
197   }
198
199   public Collection<CompositionEntityValidationData> getTrees() {
200     return roots;
201   }
202
203   @Override
204   public void saveCompositionData(String vspId, Version version, CompositionData compositionData) {
205     if (Objects.isNull(compositionData)) {
206       return;
207     }
208
209     Map<String, String> networkIdByName = saveNetworks(vspId, version, compositionData);
210     saveComponents(vspId, version, compositionData, networkIdByName);
211   }
212
213   @Override
214   public Set<CompositionEntityValidationData> getAllErrorsByVsp(String vspId) {
215     Set<CompositionEntityValidationData> entitiesWithErrors = new HashSet<>();
216     for (CompositionEntityValidationData root : roots) {
217       if (root.getEntityId().equals(vspId)) {
218         getEntityListWithErrors(root, entitiesWithErrors);
219         break;
220       }
221     }
222
223     if (CollectionUtils.isNotEmpty(entitiesWithErrors)) {
224       updateValidationCompositionEntityName(entitiesWithErrors);
225       return entitiesWithErrors;
226     }
227
228     return null;
229   }
230
231   private boolean isThereErrorsInSubTree(CompositionEntityValidationData entity) {
232     if (Objects.isNull(entity)) {
233       return false;
234     }
235
236     if (CollectionUtils.isNotEmpty(entity.getErrors())) {
237       return true;
238     }
239
240     Collection<CompositionEntityValidationData> subEntitiesValidationData =
241         entity.getSubEntitiesValidationData();
242     return !CollectionUtils.isEmpty(subEntitiesValidationData) &&
243         checkForErrorsInChildren(subEntitiesValidationData);
244
245   }
246
247   private boolean checkForErrorsInChildren(
248       Collection<CompositionEntityValidationData> subEntitiesValidationData) {
249     boolean result = false;
250     for (CompositionEntityValidationData subEntity : subEntitiesValidationData) {
251       if (CollectionUtils.isNotEmpty(subEntity.getErrors())) {
252         return true;
253       }
254
255       result = isThereErrorsInSubTree(subEntity) || result;
256       if (result) {
257         return true;
258       }
259     }
260     return false;
261   }
262
263   private void saveComponents(String vspId, Version version, CompositionData compositionData,
264                               Map<String, String> networkIdByName) {
265     if (CollectionUtils.isNotEmpty(compositionData.getComponents())) {
266       for (Component component : compositionData.getComponents()) {
267         ComponentEntity componentEntity = new ComponentEntity(vspId, version, null);
268         componentEntity.setComponentCompositionData(component.getData());
269
270         String componentId = createComponent(componentEntity).getId();
271
272         saveImagesByComponent(vspId, version, component, componentId);
273         saveComputesFlavorByComponent(vspId, version, component, componentId);
274
275         saveNicsByComponent(vspId, version, networkIdByName, component, componentId);
276       }
277     }
278   }
279
280   private void saveNicsByComponent(String vspId, Version version,
281                                    Map<String, String> networkIdByName, Component component,
282                                    String componentId) {
283     if (CollectionUtils.isNotEmpty(component.getNics())) {
284       for (Nic nic : component.getNics()) {
285         if (nic.getNetworkName() != null && MapUtils.isNotEmpty(networkIdByName)) {
286           nic.setNetworkId(networkIdByName.get(nic.getNetworkName()));
287         }
288         nic.setNetworkName(null);
289         //For heat flow set network type to be internal by default for NIC
290         nic.setNetworkType(NetworkType.Internal);
291
292         NicEntity nicEntity = new NicEntity(vspId, version, componentId, null);
293         nicEntity.setNicCompositionData(nic);
294         createNic(nicEntity);
295       }
296     }
297   }
298
299   private Map<String, String> saveNetworks(String vspId, Version version,
300                                            CompositionData compositionData) {
301     Map<String, String> networkIdByName = new HashMap<>();
302     if (CollectionUtils.isNotEmpty(compositionData.getNetworks())) {
303       for (Network network : compositionData.getNetworks()) {
304
305         NetworkEntity networkEntity = new NetworkEntity(vspId, version, null);
306         networkEntity.setNetworkCompositionData(network);
307
308         if (network.getName() != null) {
309           networkIdByName.put(network.getName(), createNetwork(networkEntity).getId());
310         }
311       }
312     }
313     return networkIdByName;
314   }
315
316   private NetworkEntity createNetwork(NetworkEntity network) {
317     //network.setId(CommonMethods.nextUuId()); will be set by the dao
318     networkDao.create(network);
319     return network;
320   }
321
322   @Override
323   public ComponentEntity createComponent(ComponentEntity component) {
324     //component.setId(CommonMethods.nextUuId()); will be set by the dao
325     component.setQuestionnaireData(
326         new JsonSchemaDataGenerator(
327             generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component,
328                 null))
329             .generateData());
330
331     componentDao.create(component);
332     return component;
333   }
334
335   @Override
336   public NicEntity createNic(NicEntity nic) {
337     //nic.setId(CommonMethods.nextUuId()); will be set by the dao
338     nic.setQuestionnaireData(
339         new JsonSchemaDataGenerator(
340             generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null))
341             .generateData());
342
343     nicDao.create(nic);
344     return nic;
345   }
346
347
348   public void addErrorsToTrees(Map<CompositionEntityId, Collection<String>> errors) {
349     roots.forEach(root -> addErrorsToTree(root, null, errors));
350   }
351
352   /* *
353    * get a flat list of all questionnaire entities that have validation errors
354    * */
355   public Set<CompositionEntityValidationData> getEntityListWithErrors() {
356     Set<CompositionEntityValidationData> treeAsList = new HashSet<>();
357
358     for (CompositionEntityValidationData entity : roots) {
359       if (CollectionUtils.isNotEmpty(entity.getErrors())) {
360         addNodeWithErrors(entity, treeAsList);
361       }
362       getEntityListWithErrors(entity, treeAsList);
363     }
364
365     updateValidationCompositionEntityName(treeAsList);
366     return treeAsList;
367   }
368
369   private void getEntityListWithErrors(CompositionEntityValidationData entity,
370                                        Set<CompositionEntityValidationData> compositionSet) {
371     if (CollectionUtils.isNotEmpty(entity.getErrors())) {
372       addNodeWithErrors(entity, compositionSet);
373     }
374
375     if (CollectionUtils.isEmpty(entity.getSubEntitiesValidationData())) {
376       return;
377     }
378
379     for (CompositionEntityValidationData child : entity.getSubEntitiesValidationData()) {
380       getEntityListWithErrors(child, compositionSet);
381     }
382   }
383
384
385   private void addNodeWithErrors(CompositionEntityValidationData node,
386                                  Set<CompositionEntityValidationData> entitiesWithErrors) {
387     CompositionEntityValidationData compositionNodeToAdd = new CompositionEntityValidationData(node
388         .getEntityType(), node.getEntityId());
389     compositionNodeToAdd.setErrors(node.getErrors());
390     compositionNodeToAdd.setSubEntitiesValidationData(null);
391
392     entitiesWithErrors.add(compositionNodeToAdd);
393   }
394
395   public void removeNodesWithoutErrors() {
396     roots.forEach(root -> removeNodesWithoutErrors(root, null));
397   }
398
399
400   private CompositionEntityData getCompositionEntityDataById(CompositionEntityValidationData
401                                                                  entity) {
402     for (Map.Entry<CompositionEntityId, CompositionEntityData> entityEntry : entities
403         .entrySet()) {
404       if (entityEntry.getKey().getId().equals(entity.getEntityId())) {
405         return entityEntry.getValue();
406       }
407     }
408     return null;
409   }
410
411
412   private void updateValidationCompositionEntityName(Set<CompositionEntityValidationData>
413                                                          compositionSet) {
414     for (CompositionEntityValidationData entity : compositionSet) {
415       String compositionData = getCompositionDataAsString(entity);
416       if (entity.getEntityType().equals(CompositionEntityType.vsp) ||
417           Objects.nonNull(compositionData)) {
418         entity.setEntityName(getEntityNameByEntityType(compositionData, entity));
419       }
420     }
421   }
422
423   private String getCompositionDataAsString(CompositionEntityValidationData entity) {
424     CompositionEntityData compositionEntityData = getCompositionEntityDataById(entity);
425     return compositionEntityData == null ? null : compositionEntityData.entity.getCompositionData();
426   }
427
428
429   private String getEntityNameByEntityType(String compositionData,
430                                            CompositionEntityValidationData entity) {
431     switch (entity.getEntityType()) {
432       case component:
433         ComponentData component = JsonUtil.json2Object(compositionData, ComponentData.class);
434         return component.getDisplayName();
435
436       case nic:
437         Nic nic = JsonUtil.json2Object(compositionData, Nic.class);
438         return nic.getName();
439
440       case network:
441         Network network = JsonUtil.json2Object(compositionData, Network.class);
442         return network.getName();
443
444       case image:
445         Image image = JsonUtil.json2Object(compositionData, Image.class);
446         return image.getFileName();
447
448       case vsp:
449         CompositionEntityData vspEntity = getCompositionEntityDataById(entity);
450         if (Objects.isNull(vspEntity)) {
451           return null;
452         }
453         VspQuestionnaireEntity vspQuestionnaireEntity = (VspQuestionnaireEntity) vspEntity.entity;
454         VspDetails vspDetails =
455             vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(),
456                 vspQuestionnaireEntity.getVersion()));
457         return vspDetails.getName();
458     }
459
460     return null;
461   }
462
463   private void removeNodesWithoutErrors(CompositionEntityValidationData node,
464                                         CompositionEntityValidationData parent) {
465
466     if (Objects.isNull(node)) {
467       return;
468     }
469
470     if (hasChildren(node)) {
471       Collection<CompositionEntityValidationData> subNodes =
472           new ArrayList<>(node.getSubEntitiesValidationData());
473       subNodes.forEach(subNode -> removeNodesWithoutErrors(subNode, node));
474       node.setSubEntitiesValidationData(subNodes);
475
476       if (canNodeGetRemovedFromValidationDataTree(node)) {
477         removeNodeFromChildren(parent, node);
478       }
479     } else if (canNodeGetRemovedFromValidationDataTree(node)) {
480       removeNodeFromChildren(parent, node);
481     }
482   }
483
484   private void removeNodeFromChildren(CompositionEntityValidationData parent,
485                                       CompositionEntityValidationData childToRemove) {
486     if (!Objects.isNull(parent)) {
487       parent.getSubEntitiesValidationData().remove(childToRemove);
488     }
489   }
490
491   private boolean hasChildren(CompositionEntityValidationData node) {
492     return !CollectionUtils.isEmpty(node.getSubEntitiesValidationData());
493   }
494
495   private boolean canNodeGetRemovedFromValidationDataTree(CompositionEntityValidationData node) {
496     return !hasChildren(node) && CollectionUtils.isEmpty(node.getErrors());
497   }
498
499
500   private void addValidationDataEntity(
501       Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData,
502       CompositionEntityId entityId, CompositionEntity entity) {
503     if (entitiesValidationData.containsKey(entityId)) {
504       return;
505     }
506
507     CompositionEntityValidationData validationData =
508         new CompositionEntityValidationData(entity.getType(), entity.getId());
509     entitiesValidationData.put(entityId, validationData);
510
511     CompositionEntityId parentEntityId = entityId.getParentId();
512     if (parentEntityId == null) {
513       roots.add(validationData);
514     } else {
515       CompositionEntityData parentEntity = entities.get(parentEntityId);
516       if (parentEntity == null) {
517         roots.add(validationData);
518       } else {
519         addValidationDataEntity(entitiesValidationData, parentEntityId, parentEntity.entity);
520         entitiesValidationData.get(parentEntityId).addSubEntityValidationData(validationData);
521       }
522     }
523   }
524
525   private void addErrorsToTree(CompositionEntityValidationData node,
526                                CompositionEntityId parentNodeId,
527                                Map<CompositionEntityId, Collection<String>> errors) {
528     if (node == null) {
529       return;
530     }
531     CompositionEntityId nodeId = new CompositionEntityId(node.getEntityId(), parentNodeId);
532     node.setErrors(errors.get(nodeId));
533
534     if (node.getSubEntitiesValidationData() != null) {
535       node.getSubEntitiesValidationData()
536           .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors));
537     }
538   }
539
540   private Collection<String> validateQuestionnaire(CompositionEntityData compositionEntityData) {
541     logger.debug(String.format("validateQuestionnaire start:  " +
542             "[entity.type]=%s, [entity.id]=%s, [entity.questionnaireString]=%s",
543         compositionEntityData.entity.getType().name(),
544         compositionEntityData.entity.getCompositionEntityId().toString(),
545         compositionEntityData.entity.getQuestionnaireData()));
546
547     if (Objects.isNull(compositionEntityData.entity.getQuestionnaireData()) ||
548         !JsonUtil.isValidJson(compositionEntityData.entity.getQuestionnaireData())) {
549       return Collections.singletonList(String
550           .format(MISSING_OR_INVALID_QUESTIONNAIRE_MSG, compositionEntityData.entity.getType()));
551     }
552
553     return JsonUtil.validate(
554         compositionEntityData.entity.getQuestionnaireData() == null
555             ? JsonUtil.object2Json(new Object())
556             : compositionEntityData.entity.getQuestionnaireData(),
557         getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire,
558             compositionEntityData.schemaTemplateInput));
559   }
560
561   private String getSchema(CompositionEntityType compositionEntityType,
562                            SchemaTemplateContext schemaTemplateContext,
563                            SchemaTemplateInput schemaTemplateInput) {
564     return schemaTemplateInput == null
565         ? nonDynamicSchemas.computeIfAbsent(compositionEntityType,
566         k -> generateSchema(schemaTemplateContext, compositionEntityType, null))
567         : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput);
568   }
569
570   private static class CompositionEntityData {
571     private CompositionEntity entity;
572     private SchemaTemplateInput schemaTemplateInput;
573
574     CompositionEntityData(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) {
575       this.entity = entity;
576       this.schemaTemplateInput = schemaTemplateInput;
577     }
578
579   }
580
581   // todo - make SchemaGenerator non static and mock it in UT instead of mocking this method (and
582   // make the method private
583   protected String generateSchema(SchemaTemplateContext schemaTemplateContext,
584                                   CompositionEntityType compositionEntityType,
585                                   SchemaTemplateInput schemaTemplateInput) {
586     return SchemaGenerator
587         .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput);
588   }
589
590   @Override
591   public DeploymentFlavorEntity createDeploymentFlavor(DeploymentFlavorEntity deploymentFlavor) {
592     deploymentFlavor.setId(CommonMethods.nextUuId());
593     deploymentFlavorDao.create(deploymentFlavor);
594     return deploymentFlavor;
595   }
596
597   @Override
598   public ImageEntity createImage(ImageEntity image) {
599     image.setId(CommonMethods.nextUuId());
600
601     image.setQuestionnaireData(
602         new JsonSchemaDataGenerator(SchemaGenerator
603             .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, null))
604             .generateData());
605
606     imageDao.create(image);
607     return image;
608   }
609
610   public void saveComputesFlavorByComponent(String vspId, Version version, Component component,
611                                             String componentId) {
612     if (CollectionUtils.isNotEmpty(component.getCompute())) {
613       for (ComputeData flavor : component.getCompute()) {
614         ComputeEntity computeEntity = new ComputeEntity(vspId, version, componentId, null);
615         computeEntity.setComputeCompositionData(flavor);
616         computeEntity.setQuestionnaireData(
617             new JsonSchemaDataGenerator(SchemaGenerator
618                 .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.compute,
619                     null)).generateData());
620
621         computeDao.create(computeEntity);
622       }
623     }
624   }
625
626   public void saveImagesByComponent(String vspId, Version version, Component component, String
627       componentId) {
628     if (CollectionUtils.isNotEmpty(component.getImages())) {
629       for (Image img : component.getImages()) {
630         ImageEntity imageEntity = new ImageEntity(vspId, version, componentId, null);
631         imageEntity.setImageCompositionData(img);
632         createImage(imageEntity);
633       }
634     }
635   }
636
637 }