diff options
Diffstat (limited to 'models-tosca/src/main/java')
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java) | 5 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java | 89 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java | 56 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java | 56 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogical.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKey.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalString.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataType.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilter.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaModel.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java) | 39 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyType.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplates.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeInterval.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTrigger.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java) | 2 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java | 49 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java) | 6 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java) | 4 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java) | 6 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java) | 10 | ||||
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java) | 6 |
31 files changed, 191 insertions, 175 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java index 30e62eb93..2454b51be 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.legacy; +package org.onap.policy.models.tosca.legacy.concepts; import java.util.List; import java.util.Map; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java index 358d70247..60a1e454d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java @@ -19,7 +19,9 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.legacy; +package org.onap.policy.models.tosca.legacy.concepts; + +import com.google.gson.annotations.SerializedName; import lombok.Data; @@ -31,6 +33,7 @@ import lombok.Data; @Data public class LegacyOperationalPolicy { + @SerializedName("policy-id") private String policyId; private String policyVersion; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java new file mode 100644 index 000000000..781602a7e --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.legacy.mapping; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.mapping.ToscaServiceTemplateMapper; + +/** + * This class maps a legacy operational policy to and from a TOSCA service template. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class LegacyOperationalPolicyMapper + implements ToscaServiceTemplateMapper<LegacyOperationalPolicy, LegacyOperationalPolicy> { + + // TODO: Do this correctly with an atomic integer + private static int nextVersion = 1; + + @Override + public ToscaServiceTemplate toToscaServiceTemplate(LegacyOperationalPolicy legacyOperationalPolicy) { + PfConceptKey policyKey = + new PfConceptKey(legacyOperationalPolicy.getPolicyId(), getNextVersion()); + + ToscaPolicy toscaPolicy = new ToscaPolicy(policyKey); + + // TODO: Find out how to parse the PolicyType from the content + // TODO: Check if this is the correct way to set the policy type version + toscaPolicy.setType(new PfConceptKey("SomeDerivedPolicyType", "1.0.0")); + + Map<String, Object> propertyMap = new HashMap<>(); + toscaPolicy.setProperties(propertyMap); + toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent()); + + PfConceptKey serviceTemplateKey = new PfConceptKey("ServiceTemplate", "1.0.0"); + ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(serviceTemplateKey); + serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0"); + + PfReferenceKey topologyTemplateKey = new PfReferenceKey(serviceTemplateKey, "TopolocyTemplate"); + serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate(topologyTemplateKey)); + + PfConceptKey policiesKey = new PfConceptKey("Policies", "1.0.0"); + serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies(policiesKey)); + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy); + + return serviceTemplate; + } + + @Override + public LegacyOperationalPolicy fromToscaServiceTemplate(ToscaServiceTemplate serviceTemplate) { + // TODO Auto-generated method stub + return null; + } + + /** + * Get the next policy version. + * + * @return the next version + */ + private static String getNextVersion() { + return "1.0." + nextVersion++; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java deleted file mode 100644 index b343c9e66..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.serialization.legacy; - -import com.google.gson.GsonBuilder; - -import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provider used to serialize and deserialize TOSCA objects using GSON. - */ -public class LegacyGuardMessageBodyHandler extends GsonMessageBodyHandler { - - public static final Logger logger = LoggerFactory.getLogger(LegacyGuardMessageBodyHandler.class); - - /** - * Constructs the object. - */ - public LegacyGuardMessageBodyHandler() { - this(new GsonBuilder()); - - logger.info("Using GSON with TOSCA for REST calls"); - } - - /** - * Constructs the object. - * - * @param builder builder to use to create the gson object - */ - public LegacyGuardMessageBodyHandler(final GsonBuilder builder) { - // @formatter:off - super(builder - .create() - ); - // @formatter:on - } - -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java deleted file mode 100644 index f51a427f0..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.serialization.legacy; - -import com.google.gson.GsonBuilder; - -import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provider used to serialize and deserialize TOSCA objects using GSON. - */ -public class LegacyOperationalMessageBodyHandler extends GsonMessageBodyHandler { - - public static final Logger logger = LoggerFactory.getLogger(LegacyOperationalMessageBodyHandler.class); - - /** - * Constructs the object. - */ - public LegacyOperationalMessageBodyHandler() { - this(new GsonBuilder()); - - logger.info("Using GSON with TOSCA for REST calls"); - } - - /** - * Constructs the object. - * - * @param builder builder to use to create the gson object - */ - public LegacyOperationalMessageBodyHandler(final GsonBuilder builder) { - // @formatter:off - super(builder - .create() - ); - // @formatter:on - } - -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java index dadad6fd6..ee153a295 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogical.java index f186d8525..25a03c9e1 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogical.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import javax.persistence.Column; import javax.ws.rs.core.Response; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKey.java index 1a63f30c8..0fe50dd71 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKey.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalString.java index c786d626b..fbf036004 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalString.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataType.java index 5af24d6ed..e7d91ea40 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataType.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.ArrayList; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java index 61c3500cb..cbf0e3844 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.Map; import java.util.TreeMap; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java index b0dc58d93..8b6dd40d6 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java index 72bedbd9e..2dca1ef55 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.ArrayList; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilter.java index 4e2d73763..e2e5488e0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilter.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaModel.java index 9169e6778..a7852976d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaModel.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java index 7209fd081..9dd12ec88 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.Map; import java.util.TreeMap; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java index 3e1fddd31..af94af08d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java @@ -21,10 +21,12 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -38,6 +40,7 @@ import lombok.EqualsAndHashCode; import lombok.NonNull; import org.onap.policy.common.utils.validation.Assertions; +import org.onap.policy.common.utils.validation.ParameterValidationUtils; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; @@ -64,7 +67,7 @@ public class ToscaPolicy extends ToscaEntityType { private PfConceptKey type; @ElementCollection - private List<ToscaProperty> properties; + private Map<String, Object> properties; @ElementCollection private List<PfConceptKey> targets; @@ -112,12 +115,6 @@ public class ToscaPolicy extends ToscaEntityType { keyList.addAll(type.getKeys()); - if (properties != null) { - for (ToscaProperty property : properties) { - keyList.addAll(property.getKeys()); - } - } - if (targets != null) { keyList.addAll(targets); } @@ -131,12 +128,6 @@ public class ToscaPolicy extends ToscaEntityType { type.clean(); - if (properties != null) { - for (ToscaProperty property : properties) { - property.clean(); - } - } - if (targets != null) { for (PfConceptKey target : targets) { target.clean(); @@ -151,8 +142,7 @@ public class ToscaPolicy extends ToscaEntityType { if (type == null || type.isNullKey()) { result.addValidationMessage(new PfValidationMessage(type, this.getClass(), ValidationResult.INVALID, "type is null or a null key")); - } - else { + } else { result = type.validate(result); } @@ -176,12 +166,13 @@ public class ToscaPolicy extends ToscaEntityType { private PfValidationResult validateProperties(@NonNull final PfValidationResult resultIn) { PfValidationResult result = resultIn; - for (ToscaProperty property : properties) { - if (property == null) { + for (Entry<String, Object> propertyEntry : properties.entrySet()) { + if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy property may not be null ")); - } else { - result = property.validate(result); + "policy property key may not be null ")); + } else if (propertyEntry.getValue() == null) { + result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, + "policy property value may not be null ")); } } return result; @@ -251,11 +242,7 @@ public class ToscaPolicy extends ToscaEntityType { if (properties == null) { copy.setProperties(null); } else { - final List<ToscaProperty> newProperties = new ArrayList<>(); - for (final ToscaProperty property : properties) { - newProperties.add(new ToscaProperty(property)); - } - copy.setProperties(newProperties); + copy.setProperties(properties); } if (targets == null) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyType.java index dbd011468..b155192cb 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyType.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.ArrayList; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java index e33e6c0c9..23159ccfa 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.Map; import java.util.TreeMap; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java index ab72ff60e..da13877c6 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java index acf231a3e..fd8b134ce 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplates.java index bd1620747..33d774889 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplates.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.Map; import java.util.TreeMap; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeInterval.java index 10ee6cc7d..69c7c6c97 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeInterval.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.java index aed181f94..9d156c3df 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import java.util.List; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTrigger.java index 5f3b6392f..d772d554e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTrigger.java @@ -21,7 +21,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.concepts; +package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java new file mode 100644 index 000000000..6dcbfe694 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.simple.mapping; + +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; + +/** + * This interface is used to map legacy and proprietary policies into and out of TOSCA service templates. + * + * @author Liam Fallon (liam.fallon@est.tech) + * @param <I> the type for the incoming policy definition + * @param <O> the type for the outgoing policy definition + */ +public interface ToscaServiceTemplateMapper<I, O> { + + /** + * Translate from the other format to a TOSCA service template. + * + * @param otherPolicyType the other policy type + * @return the TOSCA service template + */ + public ToscaServiceTemplate toToscaServiceTemplate(final I otherPolicyType); + + /** + * Translate to the other format from a TOSCA service template. + * + * @param serviceTemplate the TOSCA service template + * @return the policy in the other format + */ + public O fromToscaServiceTemplate(final ToscaServiceTemplate serviceTemplate); +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java index a12ba8be9..2b61b6861 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.simple; +package org.onap.policy.models.tosca.simple.serialization; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; @@ -33,8 +33,8 @@ import java.util.Iterator; import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.concepts.ToscaPolicies; -import org.onap.policy.models.tosca.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; /** * GSON type adapter for TOSCA policies. diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java index ae5e596ba..075445d01 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.simple; +package org.onap.policy.models.tosca.simple.serialization; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; @@ -35,7 +35,7 @@ import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java index b08a33d64..286bb7492 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.simple; +package org.onap.policy.models.tosca.simple.serialization; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; @@ -32,8 +32,8 @@ import java.lang.reflect.Type; import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; /** * GSON type adapter for TOSCA policies. diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java index 9abbf1c72..a386a9cc5 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java @@ -16,15 +16,15 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.simple; +package org.onap.policy.models.tosca.simple.serialization; import com.google.gson.GsonBuilder; import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.onap.policy.models.tosca.concepts.ToscaPolicies; -import org.onap.policy.models.tosca.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java index 4f2f590b7..c76b9b027 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.serialization.simple; +package org.onap.policy.models.tosca.simple.serialization; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; @@ -33,8 +33,8 @@ import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.tosca.concepts.ToscaPolicies; -import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; /** * GSON type adapter for TOSCA policies. |