From 784eb5b7c8b85c0d24403eff2f0b1d40e024e448 Mon Sep 17 00:00:00 2001 From: brunomilitzer Date: Wed, 28 Jul 2021 16:58:45 +0100 Subject: Add Create Instance Rest Endpoint Added Camel Endpoint Will Apply Unit Tests on POLICY-3537, since focus is to get the functionalities completed. Issue-ID: POLICY-3436 Change-Id: I8305896b24c30fc0403c57b3925af983065a5ec2 Signed-off-by: brunomilitzer --- .../persistence/provider/ControlLoopProvider.java | 25 +++++++++++++++ .../instantiation/InstancePropertiesResponse.java | 37 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java (limited to 'models') diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java index 4e502c64c..71407916d 100644 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java @@ -22,12 +22,15 @@ package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provide import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.ws.rs.core.Response; import lombok.NonNull; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; +import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; @@ -38,6 +41,7 @@ import org.onap.policy.models.provider.impl.AbstractModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; import org.springframework.stereotype.Component; @@ -183,6 +187,26 @@ public class ControlLoopProvider extends AbstractModelsProvider { return jpaDeleteControlLoop.toAuthorative(); } + /** + * Saves Instance Properties to the database. + * @param serviceTemplate the service template + * @return a Map of tosca node templates + */ + public Map saveInstanceProperties(ToscaServiceTemplate serviceTemplate) { + + Map savedNodeTemplates = new HashMap<>(); + + serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, template) -> { + JpaToscaNodeTemplate jpaToscaNodeTemplate = new JpaToscaNodeTemplate(template); + + getPfDao().create(jpaToscaNodeTemplate); + + savedNodeTemplates.put(key, template); + }); + + return savedNodeTemplates; + } + /** * Get Node Templates. * @@ -220,4 +244,5 @@ public class ControlLoopProvider extends AbstractModelsProvider { private > List asEntityList(List jpaEntityList) { return jpaEntityList.stream().map(J::toAuthorative).collect(Collectors.toList()); } + } diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java new file mode 100644 index 000000000..eed339447 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Response to Instance Properties requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class InstancePropertiesResponse extends SimpleResponse { + private List affectedInstanceProperties; +} -- cgit 1.2.3-korg