aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorSébastien Determe <sebastien.determe@intl.att.com>2020-01-16 13:38:31 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-16 13:38:31 +0000
commit5dfa4b58906921dea2aab38d20d761f460f49964 (patch)
tree693e297621d9b114f2d648ef13b8fdfa599f6e90 /src/main/java/org/onap
parent8c2ce6065ddd8405ef3faa99969453e080b63f55 (diff)
parent825612628f130b394f9ee1aa1ad2cca41b67bc7f (diff)
Merge "Add template and tosca model entities and repositories"
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/clds/Application.java8
-rw-r--r--src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java46
-rw-r--r--src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/CldsDictionary.java159
-rw-r--r--src/main/java/org/onap/clamp/clds/model/CldsDictionaryItem.java214
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java57
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java25
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopService.java26
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopsRepository.java5
-rw-r--r--src/main/java/org/onap/clamp/loop/common/AuditEntity.java108
-rw-r--r--src/main/java/org/onap/clamp/loop/log/LoopLog.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/log/LoopLogRepository.java4
-rw-r--r--src/main/java/org/onap/clamp/loop/service/Service.java18
-rw-r--r--src/main/java/org/onap/clamp/loop/service/ServicesRepository.java31
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplate.java268
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplatesRepository.java37
-rw-r--r--src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java217
-rw-r--r--src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java31
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModel.java239
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelId.java93
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsRepository.java38
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java59
-rw-r--r--src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java194
-rw-r--r--src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java102
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java64
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyRepository.java4
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java (renamed from src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java)4
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java35
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepository.java4
-rw-r--r--src/main/java/org/onap/clamp/tosca/Dictionary.java174
-rw-r--r--src/main/java/org/onap/clamp/tosca/DictionaryElement.java249
-rw-r--r--src/main/java/org/onap/clamp/tosca/DictionaryElementsRepository.java32
-rw-r--r--src/main/java/org/onap/clamp/tosca/DictionaryRepository.java38
-rw-r--r--src/main/java/org/onap/clamp/util/SemanticVersioning.java76
34 files changed, 2190 insertions, 473 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java
index e41140f5..63320d2f 100644
--- a/src/main/java/org/onap/clamp/clds/Application.java
+++ b/src/main/java/org/onap/clamp/clds/Application.java
@@ -58,6 +58,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -65,13 +66,14 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@ComponentScan(basePackages = { "org.onap.clamp" })
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class,
- UserDetailsServiceAutoConfiguration.class })
+ UserDetailsServiceAutoConfiguration.class })
@EnableJpaRepositories(basePackages = { "org.onap.clamp" })
@EntityScan(basePackages = { "org.onap.clamp" })
@EnableTransactionManagement
@EnableConfigurationProperties
@EnableAsync
@EnableScheduling
+@EnableJpaAuditing
public class Application extends SpringBootServletInitializer {
protected static final EELFLogger eelfLogger = EELFManager.getInstance().getLogger(Application.class);
@@ -137,8 +139,6 @@ public class Application extends SpringBootServletInitializer {
return tomcat;
}
-
-
private Connector createRedirectConnector(int redirectSecuredPort) {
if (redirectSecuredPort <= 0) {
eelfLogger.warn("HTTP port redirection to HTTPS is disabled because the HTTPS port is 0 (random port) or -1"
@@ -159,7 +159,7 @@ public class Application extends SpringBootServletInitializer {
if (env.getProperty("server.ssl.key-store") != null) {
KeyStore keystore = KeyStore.getInstance(env.getProperty("server.ssl.key-store-type"));
- String password = PassDecoder.decode(env.getProperty("server.ssl.key-store-password"),
+ String password = PassDecoder.decode(env.getProperty("server.ssl.key-store-password"),
env.getProperty("clamp.config.keyFile"));
String keyStore = env.getProperty("server.ssl.key-store");
InputStream is = ResourceFileUtil.getResourceAsStream(keyStore.replaceAll("classpath:", ""));
diff --git a/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java b/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java
new file mode 100644
index 00000000..d18e7ebf
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds;
+
+import java.util.Optional;
+
+import org.springframework.data.domain.AuditorAware;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ClampInUserAuditorAware implements AuditorAware<String> {
+
+ @Override
+ public Optional<String> getCurrentAuditor() {
+ if (SecurityContextHolder.getContext().getAuthentication() != null
+ && SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
+ return Optional.of(((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
+ .getUsername());
+ }
+ return Optional.of("");
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java b/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java
index 9e04bd08..3bbb8a0b 100644
--- a/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java
+++ b/src/main/java/org/onap/clamp/clds/filter/ClampCadiFilter.java
@@ -153,7 +153,7 @@ public class ClampCadiFilter extends CadiFilter {
URLDecoder.decode(certHeader, StandardCharsets.UTF_8.toString()).getBytes()));
X509Certificate caCert = (X509Certificate) certificateFactory
.generateCertificate(new ByteArrayInputStream(
- ResourceFileUtil.getResourceAsString("clds/aaf/ssl/ca-certs.pem").getBytes()));
+ ResourceFileUtil.getResourceAsString("clds/aaf/ssl/ca-certs.pem").getBytes()));
X509Certificate[] certifArray = ((X509Certificate[]) request
.getAttribute("javax.servlet.request.X509Certificate"));
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsDictionary.java b/src/main/java/org/onap/clamp/clds/model/CldsDictionary.java
deleted file mode 100644
index 35fbcec4..00000000
--- a/src/main/java/org/onap/clamp/clds/model/CldsDictionary.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END============================================
- * ===================================================================
- *
- */
-
-package org.onap.clamp.clds.model;
-
-import com.google.gson.annotations.Expose;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents a CLDS Dictionary.
- */
-
-public class CldsDictionary {
-
- @Expose
- private String dictionaryId;
- @Expose
- private String dictionaryName;
-
- @Expose
- private String createdBy;
- @Expose
- private String updatedBy;
- @Expose
- private String lastUpdatedDate;
- @Expose
- private List<CldsDictionaryItem> cldsDictionaryItems = new ArrayList<>();
-
- /**
- * Get the dictionary ID.
- *
- * @return the dictionaryId
- */
- public String getDictionaryId() {
- return dictionaryId;
- }
-
- /**
- * Set the dictionary Id.
- *
- * @param dictionaryId the dictionaryId to set
- */
- public void setDictionaryId(String dictionaryId) {
- this.dictionaryId = dictionaryId;
- }
-
- /**
- * Get the dictionary name.
- *
- * @return the dictionaryName
- */
- public String getDictionaryName() {
- return dictionaryName;
- }
-
- /**
- * Set the dictionary name.
- *
- * @param dictionaryName the dictionaryName to set
- */
- public void setDictionaryName(String dictionaryName) {
- this.dictionaryName = dictionaryName;
- }
-
- /**
- * Get the createdBy info.
- *
- * @return the createdBy
- */
- public String getCreatedBy() {
- return createdBy;
- }
-
- /**
- * Set the createdBy info.
- *
- * @param createdBy the createdBy to set
- */
- public void setCreatedBy(String createdBy) {
- this.createdBy = createdBy;
- }
-
- /**
- * Get the updatedBy info.
- *
- * @return the updatedBy
- */
- public String getUpdatedBy() {
- return updatedBy;
- }
-
- /**
- * Set the updatedBy info.
- *
- * @param updatedby the updatedBy to set
- */
- public void setUpdatedBy(String updatedby) {
- updatedBy = updatedby;
- }
-
- /**
- * Get the last updated date.
- *
- * @return the lastUpdatedDate
- */
- public String getLastUpdatedDate() {
- return lastUpdatedDate;
- }
-
- /**
- * Set the last updated date.
- *
- * @param lastUpdatedDate the lastUpdatedDate to set
- */
- public void setLastUpdatedDate(String lastUpdatedDate) {
- this.lastUpdatedDate = lastUpdatedDate;
- }
-
- /**
- * Get all the dictionary items.
- *
- * @return the cldsDictionaryItems
- */
- public List<CldsDictionaryItem> getCldsDictionaryItems() {
- return cldsDictionaryItems;
- }
-
- /**
- * Set the whole dictionary items.
- *
- * @param cldsDictionaryItems the cldsDictionaryItems to set
- */
- public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
- this.cldsDictionaryItems = cldsDictionaryItems;
- }
-
-}
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsDictionaryItem.java b/src/main/java/org/onap/clamp/clds/model/CldsDictionaryItem.java
deleted file mode 100644
index 1b79bdfa..00000000
--- a/src/main/java/org/onap/clamp/clds/model/CldsDictionaryItem.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END============================================
- * ===================================================================
- *
- */
-
-package org.onap.clamp.clds.model;
-
-import com.google.gson.annotations.Expose;
-
-/**
- * Represents a CLDS Dictionary Item.
- */
-public class CldsDictionaryItem {
-
- @Expose
- private String dictElementId;
- @Expose
- private String dictionaryId;
- @Expose
- private String dictElementName;
- @Expose
- private String dictElementShortName;
- @Expose
- private String dictElementDesc;
- @Expose
- private String dictElementType;
- @Expose
- private String createdBy;
- @Expose
- private String updatedBy;
- @Expose
- private String lastUpdatedDate;
-
- /**
- * Get the dictionary element id.
- *
- * @return the dictElementId
- */
- public String getDictElementId() {
- return dictElementId;
- }
-
- /**
- * Set the dictionary element id.
- *
- * @param dictElementId the dictElementId to set
- */
- public void setDictElementId(String dictElementId) {
- this.dictElementId = dictElementId;
- }
-
- /**
- * Get the dictionary id.
- *
- * @return the dictionaryId
- */
- public String getDictionaryId() {
- return dictionaryId;
- }
-
- /**
- * Set the dictionary id.
- *
- * @param dictionaryId the dictionaryId to set
- */
- public void setDictionaryId(String dictionaryId) {
- this.dictionaryId = dictionaryId;
- }
-
- /**
- * Get the dictionary name.
- *
- * @return the dictElementName
- */
- public String getDictElementName() {
- return dictElementName;
- }
-
- /**
- * Set the dictionary name.
- *
- * @param dictElementName the dictElementName to set
- */
- public void setDictElementName(String dictElementName) {
- this.dictElementName = dictElementName;
- }
-
- /**
- * Get the dictionary element short name.
- *
- * @return the dictElementShortName
- */
- public String getDictElementShortName() {
- return dictElementShortName;
- }
-
- /**
- * Set the dictionary element short name.
- *
- * @param dictElementShortName the dictElementShortName to set
- */
- public void setDictElementShortName(String dictElementShortName) {
- this.dictElementShortName = dictElementShortName;
- }
-
- /**
- * Get the dictionary element description.
- *
- * @return the dictElementDesc
- */
- public String getDictElementDesc() {
- return dictElementDesc;
- }
-
- /**
- * Set the dictionary element description.
- *
- * @param dictElementDesc the dictElementDesc to set
- */
- public void setDictElementDesc(String dictElementDesc) {
- this.dictElementDesc = dictElementDesc;
- }
-
- /**
- * Get the dictionary element type.
- *
- * @return the dictElementType
- */
- public String getDictElementType() {
- return dictElementType;
- }
-
- /**
- * Set the dictionary element type.
- *
- * @param dictElementType the dictElementType to set
- */
- public void setDictElementType(String dictElementType) {
- this.dictElementType = dictElementType;
- }
-
- /**
- * Get the createdBy info.
- *
- * @return the createdBy
- */
- public String getCreatedBy() {
- return createdBy;
- }
-
- /**
- * Set the createdBy info.
- *
- * @param createdBy the createdBy to set
- */
- public void setCreatedBy(String createdBy) {
- this.createdBy = createdBy;
- }
-
- /**
- * Get the updatedBy info.
- *
- * @return the updatedBy
- */
- public String getUpdatedBy() {
- return updatedBy;
- }
-
- /**
- * Set the updatedBy info.
- *
- * @param updatedby the updatedBy to set
- */
- public void setUpdatedBy(String updatedby) {
- updatedBy = updatedby;
- }
-
- /**
- * Get the last updated date.
- *
- * @return the lastUpdatedDate
- */
- public String getLastUpdatedDate() {
- return lastUpdatedDate;
- }
-
- /**
- * Set the last updated date.
- *
- * @param lastUpdatedDate the lastUpdatedDate to set
- */
- public void setLastUpdatedDate(String lastUpdatedDate) {
- this.lastUpdatedDate = lastUpdatedDate;
- }
-
-}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
index 43dd5f45..2e025ba7 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
@@ -481,63 +481,6 @@ public class ToscaYamlToJsonConvertor {
private void processDictionaryElements(JSONObject childObject, String dictionaryReference) {
- /*
- * if (dictionaryReference.contains("#")) { String[] dictionaryKeyArray =
- * dictionaryReference
- * .substring(dictionaryReference.indexOf(ToscaSchemaConstants.DICTIONARY) + 11,
- * dictionaryReference.length()) .split("#"); // We support only one # as of
- * now. List<CldsDictionaryItem> cldsDictionaryElements = null;
- * List<CldsDictionaryItem> subDictionaryElements = null; if (dictionaryKeyArray
- * != null && dictionaryKeyArray.length == 2) { cldsDictionaryElements =
- * getCldsDao().getDictionaryElements(dictionaryKeyArray[0], null, null);
- * subDictionaryElements =
- * getCldsDao().getDictionaryElements(dictionaryKeyArray[1], null, null);
- *
- * if (cldsDictionaryElements != null) { List<String> subCldsDictionaryNames =
- * subDictionaryElements.stream()
- * .map(CldsDictionaryItem::getDictElementShortName).collect(Collectors.toList()
- * ); JSONArray jsonArray = new JSONArray();
- *
- * Optional.ofNullable(cldsDictionaryElements).get().stream().forEach(c -> {
- * JSONObject jsonObject = new JSONObject();
- * jsonObject.put(JsonEditorSchemaConstants.TYPE,
- * getJsonType(c.getDictElementType())); if (c.getDictElementType() != null &&
- * c.getDictElementType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) {
- * jsonObject.put(JsonEditorSchemaConstants.MIN_LENGTH, 1); }
- * jsonObject.put(JsonEditorSchemaConstants.ID, c.getDictElementName());
- * jsonObject.put(JsonEditorSchemaConstants.LABEL, c.getDictElementShortName());
- * jsonObject.put(JsonEditorSchemaConstants.OPERATORS, subCldsDictionaryNames);
- * jsonArray.put(jsonObject); }); ; JSONObject filterObject = new JSONObject();
- * filterObject.put(JsonEditorSchemaConstants.FILTERS, jsonArray);
- *
- * childObject.put(JsonEditorSchemaConstants.TYPE,
- * JsonEditorSchemaConstants.TYPE_QBLDR); // TO invoke validation on such
- * parameters childObject.put(JsonEditorSchemaConstants.MIN_LENGTH, 1);
- * childObject.put(JsonEditorSchemaConstants.QSSCHEMA, filterObject);
- *
- * } } } else { String dictionaryKey = dictionaryReference.substring(
- * dictionaryReference.indexOf(ToscaSchemaConstants.DICTIONARY) + 11,
- * dictionaryReference.length()); if (dictionaryKey != null) {
- * List<CldsDictionaryItem> cldsDictionaryElements =
- * getCldsDao().getDictionaryElements(dictionaryKey, null, null); if
- * (cldsDictionaryElements != null) { List<String> cldsDictionaryNames = new
- * ArrayList<>(); List<String> cldsDictionaryFullNames = new ArrayList<>();
- * cldsDictionaryElements.stream().forEach(c -> { // Json type will be
- * translated before Policy creation if (c.getDictElementType() != null &&
- * !c.getDictElementType().equalsIgnoreCase("json")) {
- * cldsDictionaryFullNames.add(c.getDictElementName()); }
- * cldsDictionaryNames.add(c.getDictElementShortName()); });
- *
- * if (cldsDictionaryFullNames.size() > 0) {
- * childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryFullNames); //
- * Add Enum titles for generated translated values during JSON instance //
- * generation JSONObject enumTitles = new JSONObject();
- * enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, cldsDictionaryNames);
- * childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles); } else {
- * childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames); }
- *
- * } } }
- */
}
private String getJsonType(String toscaType) {
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 531587a7..66046f02 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -56,18 +56,20 @@ import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
+import org.onap.clamp.loop.common.AuditEntity;
import org.onap.clamp.loop.components.external.DcaeComponent;
import org.onap.clamp.loop.components.external.ExternalComponent;
import org.onap.clamp.loop.components.external.PolicyComponent;
import org.onap.clamp.loop.log.LoopLog;
import org.onap.clamp.loop.service.Service;
+import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
@Entity
@Table(name = "loops")
@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
-public class Loop implements Serializable {
+public class Loop extends AuditEntity implements Serializable {
/**
* The serial version id.
@@ -103,7 +105,7 @@ public class Loop implements Serializable {
private JsonObject globalPropertiesJson;
@Expose
- @ManyToOne(fetch = FetchType.EAGER)
+ @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@JoinColumn(name = "service_uuid")
private Service modelService;
@@ -120,19 +122,24 @@ public class Loop implements Serializable {
private final Map<String, ExternalComponent> components = new HashMap<>();
@Expose
- @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop", orphanRemoval = true)
private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
@Expose
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
@JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
@Expose
- @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop", orphanRemoval = true)
@SortNatural
private SortedSet<LoopLog> loopLogs = new TreeSet<>();
+ @Expose
+ @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
+ @JoinColumn(name = "loop_template_name")
+ private LoopTemplate loopTemplate;
+
private void initializeExternalComponents() {
this.addComponent(new PolicyComponent());
this.addComponent(new DcaeComponent());
@@ -280,6 +287,14 @@ public class Loop implements Serializable {
this.components.put(component.getComponentName(), component);
}
+ public LoopTemplate getLoopTemplate() {
+ return loopTemplate;
+ }
+
+ public void setLoopTemplate(LoopTemplate loopTemplate) {
+ this.loopTemplate = loopTemplate;
+ }
+
/**
* Generate the loop name.
*
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index b18c3849..e5202966 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -31,29 +31,23 @@ import java.util.Set;
import javax.persistence.EntityNotFoundException;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
-import org.onap.clamp.policy.microservice.MicroservicePolicyService;
+import org.onap.clamp.policy.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
import org.onap.clamp.policy.operational.OperationalPolicyService;
-import org.springframework.stereotype.Component;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
-@Component
public class LoopService {
- private final LoopsRepository loopsRepository;
- private final MicroservicePolicyService microservicePolicyService;
- private final OperationalPolicyService operationalPolicyService;
+ @Autowired
+ private LoopsRepository loopsRepository;
- /**
- * Constructor.
- */
- public LoopService(LoopsRepository loopsRepository, MicroservicePolicyService microservicePolicyService,
- OperationalPolicyService operationalPolicyService) {
- this.loopsRepository = loopsRepository;
- this.microservicePolicyService = microservicePolicyService;
- this.operationalPolicyService = operationalPolicyService;
- }
+ @Autowired
+ private MicroServicePolicyService microservicePolicyService;
+
+ @Autowired
+ private OperationalPolicyService operationalPolicyService;
Loop saveOrUpdateLoop(Loop loop) {
return loopsRepository.save(loop);
@@ -109,7 +103,7 @@ public class LoopService {
private Loop findClosedLoopByName(String loopName) {
return loopsRepository.findById(loopName)
- .orElseThrow(() -> new EntityNotFoundException("Couldn't find closed loop named: " + loopName));
+ .orElseThrow(() -> new EntityNotFoundException("Couldn't find closed loop named: " + loopName));
}
/**
diff --git a/src/main/java/org/onap/clamp/loop/LoopsRepository.java b/src/main/java/org/onap/clamp/loop/LoopsRepository.java
index 37c47622..aaa49116 100644
--- a/src/main/java/org/onap/clamp/loop/LoopsRepository.java
+++ b/src/main/java/org/onap/clamp/loop/LoopsRepository.java
@@ -24,12 +24,13 @@
package org.onap.clamp.loop;
import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface LoopsRepository extends CrudRepository<Loop, String> {
+public interface LoopsRepository extends JpaRepository<Loop, String> {
@Query("SELECT loop.name FROM Loop as loop")
List<String> getAllLoopNames();
diff --git a/src/main/java/org/onap/clamp/loop/common/AuditEntity.java b/src/main/java/org/onap/clamp/loop/common/AuditEntity.java
new file mode 100644
index 00000000..445f5b9e
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/common/AuditEntity.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.common;
+
+import com.google.gson.annotations.Expose;
+
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+
+import javax.persistence.Column;
+import javax.persistence.EntityListeners;
+import javax.persistence.MappedSuperclass;
+
+import org.springframework.data.annotation.CreatedBy;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedBy;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+@MappedSuperclass
+@EntityListeners(AuditingEntityListener.class)
+public class AuditEntity {
+
+ @Expose
+ @CreatedDate
+ @Column(name = "created_timestamp", nullable = false, updatable = false)
+ private Instant createdDate;
+
+ @Expose
+ @LastModifiedDate
+ @Column(name = "updated_timestamp", nullable = false)
+ private Instant updatedDate;
+
+ @Expose
+ @LastModifiedBy
+ @Column(name = "updated_by")
+ private String updatedBy;
+
+ @Expose
+ @CreatedBy
+ @Column(name = "created_by")
+ private String createdBy;
+
+ public Instant getCreatedDate() {
+ return createdDate;
+ }
+
+ public void setCreatedDate(Instant createdDate) {
+ if (createdDate != null) {
+ this.createdDate = createdDate.truncatedTo(ChronoUnit.SECONDS);
+ } else {
+ this.createdDate = null;
+ }
+ }
+
+ public Instant getUpdatedDate() {
+ return updatedDate;
+ }
+
+ public void setUpdatedDate(Instant updatedDate) {
+ if (updatedDate != null) {
+ this.updatedDate = updatedDate.truncatedTo(ChronoUnit.SECONDS);
+ } else {
+ this.updatedDate = null;
+ }
+ }
+
+ public String getUpdatedBy() {
+ return updatedBy;
+ }
+
+ public void setUpdatedBy(String updatedBy) {
+ this.updatedBy = updatedBy;
+ }
+
+ public String getCreatedBy() {
+ return createdBy;
+ }
+
+ public void setCreatedBy(String createdBy) {
+ this.createdBy = createdBy;
+ }
+
+ public AuditEntity() {
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/loop/log/LoopLog.java b/src/main/java/org/onap/clamp/loop/log/LoopLog.java
index 0e1153a3..e4959887 100644
--- a/src/main/java/org/onap/clamp/loop/log/LoopLog.java
+++ b/src/main/java/org/onap/clamp/loop/log/LoopLog.java
@@ -190,9 +190,7 @@ public class LoopLog implements Serializable, Comparable<LoopLog> {
if (arg0.getId() == null) {
return -1;
}
-
return arg0.getId().compareTo(this.getId());
-
}
}
diff --git a/src/main/java/org/onap/clamp/loop/log/LoopLogRepository.java b/src/main/java/org/onap/clamp/loop/log/LoopLogRepository.java
index 103341fa..0b3c34ec 100644
--- a/src/main/java/org/onap/clamp/loop/log/LoopLogRepository.java
+++ b/src/main/java/org/onap/clamp/loop/log/LoopLogRepository.java
@@ -23,10 +23,10 @@
package org.onap.clamp.loop.log;
-import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface LoopLogRepository extends CrudRepository<LoopLog, Long> {
+public interface LoopLogRepository extends JpaRepository<LoopLog, Long> {
}
diff --git a/src/main/java/org/onap/clamp/loop/service/Service.java b/src/main/java/org/onap/clamp/loop/service/Service.java
index 115f9f76..b74ee0b0 100644
--- a/src/main/java/org/onap/clamp/loop/service/Service.java
+++ b/src/main/java/org/onap/clamp/loop/service/Service.java
@@ -39,9 +39,9 @@ import javax.persistence.Transient;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
+import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
-
@Entity
@Table(name = "services")
@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
@@ -76,13 +76,25 @@ public class Service implements Serializable {
private JsonObject resourceDetails;
/**
- * Public constructor.
+ * Default constructor for serialization.
*/
public Service() {
}
/**
- * Constructor.
+ * Constructor with string.
+ */
+ public Service(String serviceDetails, String resourceDetails) {
+ JsonObject serviceDetailsJson = JsonUtils.GSON.fromJson(serviceDetails, JsonObject.class);
+ JsonObject resourceDetailsJson = JsonUtils.GSON.fromJson(resourceDetails, JsonObject.class);
+ this.name = serviceDetailsJson.get("name").getAsString();
+ this.serviceUuid = serviceDetailsJson.get("UUID").getAsString();
+ this.serviceDetails = serviceDetailsJson;
+ this.resourceDetails = resourceDetailsJson;
+ }
+
+ /**
+ * Constructor with Json Object.
*/
public Service(JsonObject serviceDetails, JsonObject resourceDetails, String version) {
this.name = serviceDetails.get("name").getAsString();
diff --git a/src/main/java/org/onap/clamp/loop/service/ServicesRepository.java b/src/main/java/org/onap/clamp/loop/service/ServicesRepository.java
new file mode 100644
index 00000000..fe5ba8ed
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/service/ServicesRepository.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.service;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ServicesRepository extends JpaRepository<Service, String> {
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
new file mode 100644
index 00000000..10367e77
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java
@@ -0,0 +1,268 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.SortNatural;
+import org.onap.clamp.loop.common.AuditEntity;
+import org.onap.clamp.loop.service.Service;
+
+@Entity
+@Table(name = "loop_templates")
+public class LoopTemplate extends AuditEntity implements Serializable {
+
+ /**
+ * The serial version id.
+ */
+ private static final long serialVersionUID = -286522707701388642L;
+
+ @Id
+ @Expose
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ /**
+ * This field is used when we have a blueprint defining all microservices. The
+ * other option would be to have independent blueprint for each microservices.
+ * In that case they are stored in each MicroServiceModel
+ */
+ @Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml")
+ private String blueprint;
+
+ @Expose
+ @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
+ private String svgRepresentation;
+
+ @Expose
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loopTemplate", orphanRemoval = true)
+ @SortNatural
+ private SortedSet<TemplateMicroServiceModel> microServiceModelUsed = new TreeSet<>();
+
+ @Expose
+ @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
+ @JoinColumn(name = "service_uuid")
+ private Service modelService;
+
+ @Expose
+ @Column(name = "maximum_instances_allowed")
+ private Integer maximumInstancesAllowed;
+
+ /**
+ * name getter.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * blueprint getter.
+ *
+ * @return the blueprint
+ */
+ public String getBlueprint() {
+ return blueprint;
+ }
+
+ /**
+ * blueprint setter.
+ *
+ * @param blueprint the blueprint to set
+ */
+ public void setBlueprint(String blueprint) {
+ this.blueprint = blueprint;
+ }
+
+ /**
+ * svgRepresentation getter.
+ *
+ * @return the svgRepresentation
+ */
+ public String getSvgRepresentation() {
+ return svgRepresentation;
+ }
+
+ /**
+ * svgRepresentation setter.
+ *
+ * @param svgRepresentation the svgRepresentation to set
+ */
+ public void setSvgRepresentation(String svgRepresentation) {
+ this.svgRepresentation = svgRepresentation;
+ }
+
+ /**
+ * microServiceModelUsed getter.
+ *
+ * @return the microServiceModelUsed
+ */
+ public SortedSet<TemplateMicroServiceModel> getMicroServiceModelUsed() {
+ return microServiceModelUsed;
+ }
+
+ /**
+ * maximumInstancesAllowed getter.
+ *
+ * @return the maximumInstancesAllowed
+ */
+ public Integer getMaximumInstancesAllowed() {
+ return maximumInstancesAllowed;
+ }
+
+ /**
+ * maximumInstancesAllowed setter.
+ *
+ * @param maximumInstancesAllowed the maximumInstancesAllowed to set
+ */
+ public void setMaximumInstancesAllowed(Integer maximumInstancesAllowed) {
+ this.maximumInstancesAllowed = maximumInstancesAllowed;
+ }
+
+ /**
+ * Add a microService model to the current template, the microservice is added
+ * at the end of the list so the flowOrder is computed automatically.
+ *
+ * @param microServiceModel The microserviceModel to add
+ */
+ public void addMicroServiceModel(MicroServiceModel microServiceModel) {
+ TemplateMicroServiceModel jointEntry = new TemplateMicroServiceModel(this, microServiceModel,
+ this.microServiceModelUsed.size());
+ this.microServiceModelUsed.add(jointEntry);
+ microServiceModel.getUsedByLoopTemplates().add(jointEntry);
+ }
+
+ /**
+ * Add a microService model to the current template, the flow order must be
+ * specified manually.
+ *
+ * @param microServiceModel The microserviceModel to add
+ * @param listPosition The position in the flow
+ */
+ public void addMicroServiceModel(MicroServiceModel microServiceModel, Integer listPosition) {
+ TemplateMicroServiceModel jointEntry = new TemplateMicroServiceModel(this, microServiceModel, listPosition);
+ this.microServiceModelUsed.add(jointEntry);
+ microServiceModel.getUsedByLoopTemplates().add(jointEntry);
+ }
+
+ /**
+ * modelService getter.
+ *
+ * @return the modelService
+ */
+ public Service getModelService() {
+ return modelService;
+ }
+
+ /**
+ * modelService setter.
+ *
+ * @param modelService the modelService to set
+ */
+ public void setModelService(Service modelService) {
+ this.modelService = modelService;
+ }
+
+ /**
+ * Default constructor for serialization.
+ */
+ public LoopTemplate() {
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name The loop template name id
+ * @param blueprint The blueprint containing all microservices (legacy
+ * case)
+ * @param svgRepresentation The svg representation of that loop template
+ * @param maxInstancesAllowed The maximum number of instances that can be
+ * created from that template
+ * @param service The service associated to that loop template
+ */
+ public LoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed,
+ Service service) {
+ this.name = name;
+ this.blueprint = blueprint;
+ this.svgRepresentation = svgRepresentation;
+
+ this.maximumInstancesAllowed = maxInstancesAllowed;
+ this.modelService = service;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ LoopTemplate other = (LoopTemplate) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplatesRepository.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplatesRepository.java
new file mode 100644
index 00000000..07f304de
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplatesRepository.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface LoopTemplatesRepository extends JpaRepository<LoopTemplate, String> {
+
+ @Query("SELECT looptemplate.name FROM LoopTemplate as looptemplate")
+ List<String> getAllLoopTemplateNames();
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java b/src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java
new file mode 100644
index 00000000..1e2b140e
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/MicroServiceModel.java
@@ -0,0 +1,217 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.onap.clamp.loop.common.AuditEntity;
+
+/**
+ * This class represents a micro service model for a loop template.
+ */
+
+@Entity
+@Table(name = "micro_service_models")
+public class MicroServiceModel extends AuditEntity implements Serializable {
+
+ /**
+ * The serial version id.
+ */
+ private static final long serialVersionUID = -286522707701376645L;
+
+ @Id
+ @Expose
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ /**
+ * This variable is used to store the type mentioned in the micro-service
+ * blueprint.
+ */
+ @Expose
+ @Column(nullable = false, name = "policy_type")
+ private String policyType;
+
+ @Column(nullable = false, name = "blueprint_yaml")
+ private String blueprint;
+
+ @Expose
+ @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
+ @JoinColumns({ @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
+ @JoinColumn(name = "policy_model_version", referencedColumnName = "version") })
+ private PolicyModel policyModel;
+
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "microServiceModel", orphanRemoval = true)
+ private Set<TemplateMicroServiceModel> usedByLoopTemplates = new HashSet<>();
+
+ /**
+ * policyModel getter.
+ *
+ * @return the policyModel
+ */
+ public PolicyModel getPolicyModel() {
+ return policyModel;
+ }
+
+ /**
+ * policyModel setter.
+ *
+ * @param policyModel the policyModel to set
+ */
+ public void setPolicyModel(PolicyModel policyModel) {
+ this.policyModel = policyModel;
+ }
+
+ /**
+ * name getter.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * policyType getter.
+ *
+ * @return the policyType
+ */
+ public String getPolicyType() {
+ return policyType;
+ }
+
+ /**
+ * policyType setter.
+ *
+ * @param policyType the policyType to set
+ */
+ public void setPolicyType(String policyType) {
+ this.policyType = policyType;
+ }
+
+ /**
+ * blueprint getter.
+ *
+ * @return the blueprint
+ */
+ public String getBlueprint() {
+ return blueprint;
+ }
+
+ /**
+ * blueprint setter.
+ *
+ * @param blueprint the blueprint to set
+ */
+ public void setBlueprint(String blueprint) {
+ this.blueprint = blueprint;
+ }
+
+ /**
+ * usedByLoopTemplates getter.
+ *
+ * @return the usedByLoopTemplates
+ */
+ public Set<TemplateMicroServiceModel> getUsedByLoopTemplates() {
+ return usedByLoopTemplates;
+ }
+
+ /**
+ * Default constructor for serialization.
+ */
+ public MicroServiceModel() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name The name id
+ * @param policyType The policy model type like
+ * onap.policies.controlloop.operational.common.Apex
+ * @param blueprint The blueprint defined for dcae that contains the policy
+ * type to use
+ * @param policyModel The policy model for the policy type mentioned here
+ */
+ public MicroServiceModel(String name, String policyType, String blueprint, PolicyModel policyModel) {
+ this.name = name;
+ this.policyType = policyType;
+ this.blueprint = blueprint;
+ this.policyModel = policyModel;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MicroServiceModel other = (MicroServiceModel) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java b/src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java
new file mode 100644
index 00000000..2b187048
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/MicroServiceModelsRepository.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MicroServiceModelsRepository extends JpaRepository<MicroServiceModel, String> {
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
new file mode 100644
index 00000000..e6580bee
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
@@ -0,0 +1,239 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+
+import org.onap.clamp.loop.common.AuditEntity;
+import org.onap.clamp.util.SemanticVersioning;
+
+/**
+ * This class represents the policy model tosca revision that we can have to a
+ * specific microservice.
+ */
+@Entity
+@Table(name = "policy_models")
+@IdClass(PolicyModelId.class)
+public class PolicyModel extends AuditEntity implements Serializable, Comparable<PolicyModel> {
+
+ /**
+ * The serial version id.
+ */
+ private static final long serialVersionUID = -286522705701376645L;
+
+ /**
+ * This variable is used to store the type mentioned in the micro-service
+ * blueprint.
+ */
+ @Id
+ @Expose
+ @Column(nullable = false, name = "policy_model_type")
+ private String policyModelType;
+
+ /**
+ * Semantic versioning on policy side.
+ */
+ @Id
+ @Expose
+ @Column(name = "version")
+ private String version;
+
+ @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca")
+ private String policyModelTosca;
+
+ @Expose
+ @Column(name = "policy_acronym")
+ private String policyAcronym;
+
+ @Expose
+ @Column(name = "policy_variant")
+ private String policyVariant;
+
+ /**
+ * policyModelTosca getter.
+ *
+ * @return the policyModelTosca
+ */
+ public String getPolicyModelTosca() {
+ return policyModelTosca;
+ }
+
+ /**
+ * policyModelTosca setter.
+ *
+ * @param policyModelTosca the policyModelTosca to set
+ */
+ public void setPolicyModelTosca(String policyModelTosca) {
+ this.policyModelTosca = policyModelTosca;
+ }
+
+ /**
+ * policyModelType getter.
+ *
+ * @return the modelType
+ */
+ public String getPolicyModelType() {
+ return policyModelType;
+ }
+
+ /**
+ * policyModelType setter.
+ *
+ * @param modelType the modelType to set
+ */
+ public void setPolicyModelType(String modelType) {
+ this.policyModelType = modelType;
+ }
+
+ /**
+ * version getter.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * version setter.
+ *
+ * @param version the version to set
+ */
+ public void setVersion(String version) {
+ // Try to convert it before
+ this.version = version;
+ }
+
+ /**
+ * policyAcronym getter.
+ *
+ * @return the policyAcronym value
+ */
+ public String getPolicyAcronym() {
+ return policyAcronym;
+ }
+
+ /**
+ * policyAcronym setter.
+ *
+ * @param policyAcronym The policyAcronym to set
+ */
+ public void setPolicyAcronym(String policyAcronym) {
+ this.policyAcronym = policyAcronym;
+ }
+
+ /**
+ * policyVariant getter.
+ *
+ * @return the policyVariant value
+ */
+ public String getPolicyVariant() {
+ return policyVariant;
+ }
+
+ /**
+ * policyVariant setter.
+ *
+ * @param policyVariant The policyVariant to set
+ */
+ public void setPolicyVariant(String policyVariant) {
+ this.policyVariant = policyVariant;
+ }
+
+ /**
+ * Default constructor for serialization.
+ */
+ public PolicyModel() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param policyType The policyType (referenced in the blueprint)
+ * @param policyModelTosca The policy tosca model in yaml
+ * @param version the version like 1.0.0
+ * @param policyAcronym Short policy name if it exists
+ * @param policyVariant Subtype for policy if it exists (could be used by UI)
+ */
+ public PolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
+ String policyVariant) {
+ this.policyModelType = policyType;
+ this.policyModelTosca = policyModelTosca;
+ this.version = version;
+ this.policyAcronym = policyAcronym;
+ this.policyVariant = policyVariant;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((policyModelType == null) ? 0 : policyModelType.hashCode());
+ result = prime * result + ((version == null) ? 0 : version.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ PolicyModel other = (PolicyModel) obj;
+ if (policyModelType == null) {
+ if (other.policyModelType != null) {
+ return false;
+ }
+ } else if (!policyModelType.equals(other.policyModelType)) {
+ return false;
+ }
+ if (version == null) {
+ if (other.version != null) {
+ return false;
+ }
+ } else if (!version.equals(other.version)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int compareTo(PolicyModel arg0) {
+ // Reverse it, so that by default we have the latest
+ return SemanticVersioning.compare(arg0.getVersion(), this.version);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelId.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelId.java
new file mode 100644
index 00000000..c4dd1933
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelId.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+
+public class PolicyModelId implements Serializable {
+
+ /**
+ * Serial Id.
+ */
+ private static final long serialVersionUID = -2846526482064334745L;
+
+ @Expose
+ private String policyModelType;
+
+ @Expose
+ private String version;
+
+ /**
+ * Default constructor for serialization.
+ */
+ public PolicyModelId() {
+
+ }
+
+ /**
+ * Constructor.
+ */
+ public PolicyModelId(String policyModelType, String version) {
+ this.policyModelType = policyModelType;
+ this.version = version;
+ }
+
+ /**
+ * policyModelType getter.
+ *
+ * @return the policyModelType
+ */
+ public String getPolicyModelType() {
+ return policyModelType;
+ }
+
+ /**
+ * policyModelType setter.
+ *
+ * @param policyModelType the policyModelType to set
+ */
+ public void setPolicyModelType(String policyModelType) {
+ this.policyModelType = policyModelType;
+ }
+
+ /**
+ * version getter.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * version setter.
+ *
+ * @param version the version to set
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelsRepository.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelsRepository.java
new file mode 100644
index 00000000..a76e386b
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsRepository.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface PolicyModelsRepository extends JpaRepository<PolicyModel, PolicyModelId> {
+ @Query("SELECT policymodel.policyModelType FROM PolicyModel as policymodel")
+ List<String> getAllPolicyModelType();
+
+ List<PolicyModel> findByPolicyModelType(String policyModelType);
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
new file mode 100644
index 00000000..8e22852a
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PolicyModelsService {
+ private final PolicyModelsRepository policyModelsRepository;
+
+ @Autowired
+ public PolicyModelsService(PolicyModelsRepository policyModelrepo) {
+ policyModelsRepository = policyModelrepo;
+ }
+
+ public PolicyModel saveOrUpdatePolicyModel(PolicyModel policyModel) {
+ return policyModelsRepository.save(policyModel);
+ }
+
+ public List<String> getAllPolicyModelTypes() {
+ return policyModelsRepository.getAllPolicyModelType();
+ }
+
+ public Iterable<PolicyModel> getAllPolicyModels() {
+ return policyModelsRepository.findAll();
+ }
+
+ public PolicyModel getPolicyModel(String type, String version) {
+ return policyModelsRepository.findById(new PolicyModelId(type, version)).orElse(null);
+ }
+
+ public Iterable<PolicyModel> getAllPolicyModelsByType(String type) {
+ return policyModelsRepository.findByPolicyModelType(type);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java b/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java
new file mode 100644
index 00000000..7547c1f7
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModel.java
@@ -0,0 +1,194 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MapsId;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "templates_microservicemodels")
+public class TemplateMicroServiceModel implements Serializable, Comparable<TemplateMicroServiceModel> {
+
+ /**
+ * Serial ID.
+ */
+ private static final long serialVersionUID = 5924989899078094245L;
+
+ @EmbeddedId
+ private TemplateMicroServiceModelId templateMicroServiceModelId;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @MapsId("loopTemplateName")
+ @JoinColumn(name = "loop_template_name")
+ private LoopTemplate loopTemplate;
+
+ @Expose
+ @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
+ @MapsId("microServiceModelName")
+ @JoinColumn(name = "micro_service_model_name")
+ private MicroServiceModel microServiceModel;
+
+ @Expose
+ @Column(nullable = false, name = "flow_order")
+ private Integer flowOrder;
+
+ /**
+ * Default constructor for serialization.
+ */
+ public TemplateMicroServiceModel() {
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param loopTemplate The loop template object
+ * @param microServiceModel The microServiceModel object
+ * @param flowOrder The position of the micro service in the flow
+ */
+ public TemplateMicroServiceModel(LoopTemplate loopTemplate, MicroServiceModel microServiceModel,
+ Integer flowOrder) {
+ this.loopTemplate = loopTemplate;
+ this.microServiceModel = microServiceModel;
+ this.flowOrder = flowOrder;
+ this.templateMicroServiceModelId = new TemplateMicroServiceModelId(loopTemplate.getName(),
+ microServiceModel.getName());
+ }
+
+ /**
+ * loopTemplate getter.
+ *
+ * @return the loopTemplate
+ */
+ public LoopTemplate getLoopTemplate() {
+ return loopTemplate;
+ }
+
+ /**
+ * loopTemplate setter.
+ *
+ * @param loopTemplate the loopTemplate to set
+ */
+ public void setLoopTemplate(LoopTemplate loopTemplate) {
+ this.loopTemplate = loopTemplate;
+ }
+
+ /**
+ * microServiceModel getter.
+ *
+ * @return the microServiceModel
+ */
+ public MicroServiceModel getMicroServiceModel() {
+ return microServiceModel;
+ }
+
+ /**
+ * microServiceModel setter.
+ *
+ * @param microServiceModel the microServiceModel to set
+ */
+ public void setMicroServiceModel(MicroServiceModel microServiceModel) {
+ this.microServiceModel = microServiceModel;
+ }
+
+ /**
+ * flowOrder getter.
+ *
+ * @return the flowOrder
+ */
+ public Integer getFlowOrder() {
+ return flowOrder;
+ }
+
+ /**
+ * flowOrder setter.
+ *
+ * @param flowOrder the flowOrder to set
+ */
+ public void setFlowOrder(Integer flowOrder) {
+ this.flowOrder = flowOrder;
+ }
+
+ @Override
+ public int compareTo(TemplateMicroServiceModel arg0) {
+ // Reverse it, so that by default we have the latest
+ if (getFlowOrder() == null) {
+ return 1;
+ }
+ if (arg0.getFlowOrder() == null) {
+ return -1;
+ }
+ return arg0.getFlowOrder().compareTo(this.getFlowOrder());
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((loopTemplate == null) ? 0 : loopTemplate.hashCode());
+ result = prime * result + ((microServiceModel == null) ? 0 : microServiceModel.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TemplateMicroServiceModel other = (TemplateMicroServiceModel) obj;
+ if (loopTemplate == null) {
+ if (other.loopTemplate != null) {
+ return false;
+ }
+ } else if (!loopTemplate.equals(other.loopTemplate)) {
+ return false;
+ }
+ if (microServiceModel == null) {
+ if (other.microServiceModel != null) {
+ return false;
+ }
+ } else if (!microServiceModel.equals(other.microServiceModel)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java b/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java
new file mode 100644
index 00000000..74c76897
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/template/TemplateMicroServiceModelId.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.template;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class TemplateMicroServiceModelId implements Serializable {
+
+ /**
+ * Serial ID.
+ */
+ private static final long serialVersionUID = 4089888115504914773L;
+
+ @Expose
+ @Column(name = "loop_template_name")
+ private String loopTemplateName;
+
+ @Expose
+ @Column(name = "micro_service_model_name")
+ private String microServiceModelName;
+
+ /**
+ * Default constructor for serialization.
+ */
+ public TemplateMicroServiceModelId() {
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param loopTemplateName The loop template name id
+ * @param microServiceModelName THe micro Service name id
+ */
+ public TemplateMicroServiceModelId(String loopTemplateName, String microServiceModelName) {
+ this.loopTemplateName = loopTemplateName;
+ this.microServiceModelName = microServiceModelName;
+ }
+
+ /**
+ * loopTemplateName getter.
+ *
+ * @return the loopTemplateName
+ */
+ public String getLoopTemplateName() {
+ return loopTemplateName;
+ }
+
+ /**
+ * loopTemplateName setter.
+ *
+ * @param loopTemplateName the loopTemplateName to set
+ */
+ public void setLoopTemplateName(String loopTemplateName) {
+ this.loopTemplateName = loopTemplateName;
+ }
+
+ /**
+ * microServiceModelName getter.
+ *
+ * @return the microServiceModelName
+ */
+ public String getMicroServiceModelName() {
+ return microServiceModelName;
+ }
+
+ /**
+ * microServiceModelName setter.
+ *
+ * @param microServiceModelName the microServiceModelName to set
+ */
+ public void setMicroServiceModelName(String microServiceModelName) {
+ this.microServiceModelName = microServiceModelName;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
index 2943c39a..98742d22 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
@@ -40,7 +40,9 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
+import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -52,13 +54,15 @@ import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.common.AuditEntity;
+import org.onap.clamp.loop.template.MicroServiceModel;
import org.onap.clamp.policy.Policy;
import org.yaml.snakeyaml.Yaml;
@Entity
@Table(name = "micro_service_policies")
@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
-public class MicroServicePolicy implements Serializable, Policy {
+public class MicroServicePolicy extends AuditEntity implements Serializable, Policy {
/**
* The serial version ID.
*/
@@ -73,10 +77,18 @@ public class MicroServicePolicy implements Serializable, Policy {
private String name;
@Expose
- @Column(nullable = false, name = "model_type")
+ @Column(nullable = false, name = "policy_model_type")
private String modelType;
@Expose
+ @Column(name = "context")
+ private String context;
+
+ @Expose
+ @Column(name = "device_type_scope")
+ private String deviceTypeScope;
+
+ @Expose
@Type(type = "json")
@Column(columnDefinition = "json", name = "properties")
private JsonObject properties;
@@ -96,6 +108,11 @@ public class MicroServicePolicy implements Serializable, Policy {
@ManyToMany(mappedBy = "microServicePolicies", fetch = FetchType.EAGER)
private Set<Loop> usedByLoops = new HashSet<>();
+ @Expose
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "micro_service_model_id")
+ private MicroServiceModel microServiceModel;
+
public MicroServicePolicy() {
// serialization
}
@@ -203,6 +220,49 @@ public class MicroServicePolicy implements Serializable, Policy {
this.usedByLoops = usedBy;
}
+ public String getContext() {
+ return context;
+ }
+
+ public void setContext(String context) {
+ this.context = context;
+ }
+
+ public String getDeviceTypeScope() {
+ return deviceTypeScope;
+ }
+
+ public void setDeviceTypeScope(String deviceTypeScope) {
+ this.deviceTypeScope = deviceTypeScope;
+ }
+
+ /**
+ * microServiceModel getter.
+ *
+ * @return the microServiceModel
+ */
+ public MicroServiceModel getMicroServiceModel() {
+ return microServiceModel;
+ }
+
+ /**
+ * microServiceModel setter.
+ *
+ * @param microServiceModel the microServiceModel to set
+ */
+ public void setMicroServiceModel(MicroServiceModel microServiceModel) {
+ this.microServiceModel = microServiceModel;
+ }
+
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyRepository.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyRepository.java
index f658aacc..38b310ce 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyRepository.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyRepository.java
@@ -23,10 +23,10 @@
package org.onap.clamp.policy.microservice;
-import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-interface MicroServicePolicyRepository extends CrudRepository<MicroServicePolicy, String> {
+public interface MicroServicePolicyRepository extends JpaRepository<MicroServicePolicy, String> {
}
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
index 59ddaa00..346cdf62 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
@@ -35,12 +35,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
-public class MicroservicePolicyService implements PolicyService<MicroServicePolicy> {
+public class MicroServicePolicyService implements PolicyService<MicroServicePolicy> {
private final MicroServicePolicyRepository repository;
@Autowired
- public MicroservicePolicyService(MicroServicePolicyRepository repository) {
+ public MicroServicePolicyService(MicroServicePolicyRepository repository) {
this.repository = repository;
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index df7e27bf..d9e8a57d 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -46,6 +46,7 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -55,6 +56,7 @@ import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.policy.Policy;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@@ -90,6 +92,12 @@ public class OperationalPolicy implements Serializable, Policy {
@JoinColumn(name = "loop_id", nullable = false)
private Loop loop;
+ @Expose
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumns({ @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
+ @JoinColumn(name = "policy_model_version", referencedColumnName = "version") })
+ private PolicyModel policyModel;
+
public OperationalPolicy() {
// Serialization
}
@@ -137,6 +145,33 @@ public class OperationalPolicy implements Serializable, Policy {
this.configurationsJson = configurationsJson;
}
+ /**
+ * policyModel getter.
+ *
+ * @return the policyModel
+ */
+ public PolicyModel getPolicyModel() {
+ return policyModel;
+ }
+
+ /**
+ * policyModel setter.
+ *
+ * @param policyModel the policyModel to set
+ */
+ public void setPolicyModel(PolicyModel policyModel) {
+ this.policyModel = policyModel;
+ }
+
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
@Override
public JsonObject getJsonRepresentation() {
return jsonRepresentation;
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepository.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepository.java
index 97b183f7..c0a6e12c 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepository.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepository.java
@@ -23,10 +23,10 @@
package org.onap.clamp.policy.operational;
-import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-interface OperationalPolicyRepository extends CrudRepository<OperationalPolicy, String> {
+public interface OperationalPolicyRepository extends JpaRepository<OperationalPolicy, String> {
void deleteByName(String policyName);
}
diff --git a/src/main/java/org/onap/clamp/tosca/Dictionary.java b/src/main/java/org/onap/clamp/tosca/Dictionary.java
new file mode 100644
index 00000000..7b4e513a
--- /dev/null
+++ b/src/main/java/org/onap/clamp/tosca/Dictionary.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.tosca;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.onap.clamp.loop.common.AuditEntity;
+
+/**
+ * Represents Dictionary.
+ */
+
+@Entity
+@Table(name = "dictionary")
+public class Dictionary extends AuditEntity implements Serializable {
+
+ /**
+ * The serial version id.
+ */
+ private static final long serialVersionUID = -286522707701388645L;
+
+ @Id
+ @Expose
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ @Expose
+ @Column(name = "dictionary_second_level")
+ private int secondLevelDictionary;
+
+ @Expose
+ @Column(name = "dictionary_type")
+ private String subDictionaryType;
+
+ @Expose
+ @OneToMany(mappedBy = "dictionary", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ private List<DictionaryElement> dictionaryElements = new ArrayList<>();
+
+ /**
+ * name getter.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * secondLevelDictionary getter.
+ *
+ * @return the secondLevelDictionary
+ */
+ public int getSecondLevelDictionary() {
+ return secondLevelDictionary;
+ }
+
+ /**
+ * secondLevelDictionary setter.
+ *
+ * @param secondLevelDictionary the secondLevelDictionary to set
+ */
+ public void setSecondLevelDictionary(int secondLevelDictionary) {
+ this.secondLevelDictionary = secondLevelDictionary;
+ }
+
+ /**
+ * subDictionaryType getter.
+ *
+ * @return the subDictionaryType
+ */
+ public String getSubDictionaryType() {
+ return subDictionaryType;
+ }
+
+ /**
+ * subDictionaryType setter.
+ *
+ * @param subDictionaryType the subDictionaryType to set
+ */
+ public void setSubDictionaryType(String subDictionaryType) {
+ this.subDictionaryType = subDictionaryType;
+ }
+
+ /**
+ * dictionaryElements getter.
+ *
+ * @return the dictionaryElements
+ */
+ public List<DictionaryElement> getDictionaryElements() {
+ return dictionaryElements;
+ }
+
+ /**
+ * dictionaryElements setter.
+ *
+ * @param dictionaryElements the dictionaryElements to set
+ */
+ public void setDictionaryElements(List<DictionaryElement> dictionaryElements) {
+ this.dictionaryElements = dictionaryElements;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Dictionary other = (Dictionary) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/tosca/DictionaryElement.java b/src/main/java/org/onap/clamp/tosca/DictionaryElement.java
new file mode 100644
index 00000000..e81885f3
--- /dev/null
+++ b/src/main/java/org/onap/clamp/tosca/DictionaryElement.java
@@ -0,0 +1,249 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.tosca;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.onap.clamp.loop.common.AuditEntity;
+
+/**
+ * Represents a Dictionary Item.
+ */
+@Entity
+@Table(name = "dictionary_elements")
+public class DictionaryElement extends AuditEntity implements Serializable {
+
+ /**
+ * The serial version id.
+ */
+ private static final long serialVersionUID = -286522707701388644L;
+
+ @Id
+ @Expose
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ @Expose
+ @Column(nullable = false, name = "short_name", unique = true)
+ private String shortName;
+
+ @Expose
+ @Column(name = "description")
+ private String description;
+
+ @Expose
+ @Column(nullable = false, name = "type")
+ private String type;
+
+ @Column(name = "subdictionary_id", nullable = false)
+ @Expose
+ private String subDictionary;
+
+ @ManyToOne(cascade = CascadeType.ALL)
+ @JoinColumn(name = "dictionary_id")
+ private Dictionary dictionary;
+
+ /**
+ * name getter.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * name setter.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * shortName getter.
+ *
+ * @return the shortName
+ */
+ public String getShortName() {
+ return shortName;
+ }
+
+ /**
+ * shortName setter.
+ *
+ * @param shortName the shortName to set
+ */
+ public void setShortName(String shortName) {
+ this.shortName = shortName;
+ }
+
+ /**
+ * description getter.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * description setter.
+ *
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * type getter.
+ *
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * type setter.
+ *
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * subDictionary getter.
+ *
+ * @return the subDictionary
+ */
+ public String getSubDictionary() {
+ return subDictionary;
+ }
+
+ /**
+ * subDictionary setter.
+ *
+ * @param subDictionary the subDictionary to set
+ */
+ public void setSubDictionary(String subDictionary) {
+ this.subDictionary = subDictionary;
+ }
+
+ /**
+ * dictionary getter.
+ *
+ * @return the dictionary
+ */
+ public Dictionary getDictionary() {
+ return dictionary;
+ }
+
+ /**
+ * dictionary setter.
+ *
+ * @param dictionary the dictionary to set
+ */
+ public void setDictionary(Dictionary dictionary) {
+ this.dictionary = dictionary;
+ }
+
+ /**
+ * Default Constructor.
+ */
+ public DictionaryElement() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name The Dictionary element name
+ * @param shortName The short name
+ * @param description The description
+ * @param type The type of element
+ * @param subDictionary The sub type
+ * @param dictionary The parent dictionary
+ */
+ public DictionaryElement(String name, String shortName, String description, String type, String subDictionary,
+ Dictionary dictionary) {
+ this.name = name;
+ this.shortName = shortName;
+ this.description = description;
+ this.type = type;
+ this.subDictionary = subDictionary;
+ this.dictionary = dictionary;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((dictionary == null) ? 0 : dictionary.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DictionaryElement other = (DictionaryElement) obj;
+ if (dictionary == null) {
+ if (other.dictionary != null) {
+ return false;
+ }
+ } else if (!dictionary.equals(other.dictionary)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/tosca/DictionaryElementsRepository.java b/src/main/java/org/onap/clamp/tosca/DictionaryElementsRepository.java
new file mode 100644
index 00000000..96cb2e35
--- /dev/null
+++ b/src/main/java/org/onap/clamp/tosca/DictionaryElementsRepository.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.tosca;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface DictionaryElementsRepository extends JpaRepository<DictionaryElement, String> {
+
+}
diff --git a/src/main/java/org/onap/clamp/tosca/DictionaryRepository.java b/src/main/java/org/onap/clamp/tosca/DictionaryRepository.java
new file mode 100644
index 00000000..2a087b6d
--- /dev/null
+++ b/src/main/java/org/onap/clamp/tosca/DictionaryRepository.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.tosca;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface DictionaryRepository extends JpaRepository<Dictionary, String> {
+
+ @Query("SELECT dict.name FROM Dictionary as dict")
+ List<String> getAllDictionaryNames();
+
+}
diff --git a/src/main/java/org/onap/clamp/util/SemanticVersioning.java b/src/main/java/org/onap/clamp/util/SemanticVersioning.java
new file mode 100644
index 00000000..bf1529c2
--- /dev/null
+++ b/src/main/java/org/onap/clamp/util/SemanticVersioning.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.util;
+
+/**
+ * This class is the base class for object that requires semantic versioning.
+ * ... This class supports also a.b.c.d... etc ... as a version.
+ *
+ *
+ */
+public class SemanticVersioning {
+ public static final int BEFORE = -1;
+ public static final int EQUAL = 0;
+ public static final int AFTER = 1;
+
+ /**
+ * The compare method that compare arg0 to arg1.
+ *
+ * @param arg0 A version in string for semantice versioning (a.b.c.d...)
+ * @param arg1 A version in string for semantice versioning (a.b.c.d...)
+ * @return objects (arg0, arg1) given as parameters. It returns the value: 0: if
+ * (arg0==arg1) -1: if (arg0 < arg1) 1: if (arg0 > arg1)
+ */
+ public static int compare(String arg0, String arg1) {
+
+ if (arg0 == null && arg1 == null) {
+ return EQUAL;
+ }
+ if (arg0 == null) {
+ return BEFORE;
+ }
+ if (arg1 == null) {
+ return AFTER;
+ }
+ String[] arg0Array = arg0.split("\\.");
+ String[] arg1Array = arg1.split("\\.");
+
+ int smalestStringLength = Math.min(arg0Array.length, arg1Array.length);
+
+ for (int currentVersionIndex = 0; currentVersionIndex < smalestStringLength; ++currentVersionIndex) {
+ if (Integer.parseInt(arg0Array[currentVersionIndex]) < Integer.parseInt(arg1Array[currentVersionIndex])) {
+ return BEFORE;
+ } else if (Integer.parseInt(arg0Array[currentVersionIndex]) > Integer
+ .parseInt(arg1Array[currentVersionIndex])) {
+ return AFTER;
+ }
+ // equals, so do not return anything, continue
+ }
+ if (arg0Array.length == arg1Array.length) {
+ return EQUAL;
+ } else {
+ return Integer.compare(arg0Array.length, arg1Array.length);
+ }
+ }
+} \ No newline at end of file