summaryrefslogtreecommitdiffstats
path: root/models/src/main
diff options
context:
space:
mode:
authorbrunomilitzer <bruno.militzer@est.tech>2021-07-28 16:58:45 +0100
committerBruno Militzer <bruno.militzer@est.tech>2021-08-23 13:00:57 +0000
commit784eb5b7c8b85c0d24403eff2f0b1d40e024e448 (patch)
tree97c309a2811510e11c689be976489f5b2d467530 /models/src/main
parent172f990bd92e1441eca6dd161458efddb674b2fc (diff)
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 <bruno.militzer@est.tech>
Diffstat (limited to 'models/src/main')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java25
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java37
2 files changed, 62 insertions, 0 deletions
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;
@@ -184,6 +188,26 @@ public class ControlLoopProvider extends AbstractModelsProvider {
}
/**
+ * Saves Instance Properties to the database.
+ * @param serviceTemplate the service template
+ * @return a Map of tosca node templates
+ */
+ public Map<String, ToscaNodeTemplate> saveInstanceProperties(ToscaServiceTemplate serviceTemplate) {
+
+ Map<String, ToscaNodeTemplate> 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.
*
* @param name the name of the node template to get, null to get all node templates
@@ -220,4 +244,5 @@ public class ControlLoopProvider extends AbstractModelsProvider {
private <T extends ToscaEntity, J extends PfAuthorative<T>> List<T> asEntityList(List<J> 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<ToscaConceptIdentifier> affectedInstanceProperties;
+}