diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main')
3 files changed, 73 insertions, 1 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java index 348a8addbd..3bf61e5b39 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java @@ -45,4 +45,11 @@ public class EnrichedServiceModelDaoImpl extends AbstractServiceModelDao templateDao.deleteAll(vspId, version); artifactDao.deleteAll(vspId, version); } + + @Override + public void overrideServiceModel(String vspId, Version version, ToscaServiceModel serviceModel) { + storeServiceModel(vspId, version, serviceModel); + } + + } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java index 4ad8d7c98a..b9a703e96d 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java @@ -39,4 +39,10 @@ public class ServiceModelDaoImpl extends AbstractServiceModelDao public void deleteAll(String vspId, Version version) { } + + @Override + public void overrideServiceModel(String vspId, Version version, + ToscaServiceModel serviceModel) { + storeServiceModel(vspId, version, serviceModel); + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java index 4ae9353f42..c73a304c97 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java @@ -162,6 +162,65 @@ public class ServiceModelDaoZusammenImpl elementType.name(), vspId, version.getId()); } + @Override + public void overrideServiceModel(String vspId, + Version version, + ToscaServiceModel serviceModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + + ZusammenElement serviceModelElement = buildStructuralElement(elementType, Action.UPDATE); + + Optional<ElementInfo> origServiceModel = getServiceModelElementInfo(context, elementContext); + if (!origServiceModel.isPresent()) { + return; + } + + Id serviceModelElementId = origServiceModel.get().getId(); + overrideServiceTemplates(serviceModelElementId, serviceModel, context, elementContext, + serviceModelElement); + serviceModelElement.getInfo() + .addProperty(BASE_PROPERTY, serviceModel.getEntryDefinitionServiceTemplate()); + + zusammenAdaptor + .saveElement(context, elementContext, serviceModelElement, "Override service model"); + } + + + private void overrideServiceTemplates(Id serviceModelElementId, + ToscaServiceModel serviceModel, + SessionContext context, + ElementContext elementContext, + ZusammenElement serviceModelElement) { + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfoByName( + context, elementContext, serviceModelElementId, ElementType.ServiceTemplate.name()); + if (!elementInfo.isPresent()) { + return; + } + ZusammenElement zusammenElement = + buildStructuralElement(ElementType.ServiceTemplate, Action.UPDATE); + Collection<Element> elements = zusammenAdaptor.listElementData(context, elementContext, + elementInfo.get().getId()); + + elements + .forEach(element -> zusammenElement + .addSubElement(overrideServiceTemplateInElement(element, serviceModel))); + + serviceModelElement.addSubElement(zusammenElement); + } + + private ZusammenElement overrideServiceTemplateInElement(Element element, + ToscaServiceModel serviceModel) { + ZusammenElement serviceTemplateElement = (ZusammenElement) element; + String templateName = element.getInfo().getName(); + Optional<ServiceTemplate> serviceTemplate = serviceModel.getServiceTemplate(templateName); + serviceTemplate.ifPresent(serviceTemplateFile -> { + String yaml = new ToscaExtensionYamlUtil().objectToYaml(serviceTemplateFile); + serviceTemplateElement.setData(new ByteArrayInputStream(yaml.getBytes())); + }); + return serviceTemplateElement; + } + private Optional<ElementInfo> getServiceModelElementInfo(SessionContext context, ElementContext elementContext) { Collection<ElementInfo> vspModelSubs = zusammenAdaptor @@ -240,7 +299,7 @@ public class ServiceModelDaoZusammenImpl String yamlContent = IOUtils.toString(element.getData()); return new ToscaExtensionYamlUtil(). yamlToObject(yamlContent, ServiceTemplate.class); - }catch (Exception e){ + } catch (Exception e) { throw new CoreException( new RetrieveServiceTemplateFromDbErrorBuilder( element.getInfo().getName(), e.getMessage()).build()); |