summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2018-03-25 13:25:43 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-04-09 12:14:23 +0000
commitad8669b1b40e199a4b39832d81203d16f720941c (patch)
treed5466f2d5b5628446b962f5dd44ebd06fbd3b3d6
parentd9d360318e1a4ae67958356d0fe3fb207f90fbf8 (diff)
Interface definition
Add handling in reading and writing operation definition Change-Id: I0fd5770b19a8cf5d5a8d2b93a549fd66a3b1e728 Issue-ID: SDC-1161 Signed-off-by: talio <tali.orenbach@amdocs.com>
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Implementation.java5
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinition.java6
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java20
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionType.java1
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java18
-rw-r--r--common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionType.java16
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java2
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java51
8 files changed, 84 insertions, 35 deletions
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Implementation.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Implementation.java
index cb79691b21..b14e49a012 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Implementation.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Implementation.java
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.openecomp.sdc.tosca.datatypes.model;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
@@ -50,12 +52,11 @@ public class Implementation {
}
Implementation that = (Implementation) o;
return Objects.equals(primary, that.primary) &&
- Objects.equals(dependencies, that.dependencies);
+ Objects.equals(new HashSet<>(dependencies), new HashSet<>(that.dependencies));
}
@Override
public int hashCode() {
-
return Objects.hash(primary, dependencies);
}
}
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinition.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinition.java
index 8d6ace2043..3a35b46907 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinition.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinition.java
@@ -15,7 +15,11 @@
*/
package org.openecomp.sdc.tosca.datatypes.model;
+import java.util.Map;
+
public abstract class InterfaceDefinition {
- public abstract void addOperation(String operationName, OperationDefinition operationDefinition);
+ protected Map<String, OperationDefinition> operations;
+
+ public abstract void addOperation(String operationName, OperationDefinition operationDefinition);
}
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java
index 912e5a7b99..efa86f0ced 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java
@@ -20,6 +20,7 @@ import org.apache.commons.collections4.MapUtils;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
public class InterfaceDefinitionTemplate extends InterfaceDefinition {
@@ -39,11 +40,6 @@ public class InterfaceDefinitionTemplate extends InterfaceDefinition {
return operations;
}
- public void setOperations(
- Map<String, OperationDefinitionTemplate> operations) {
- this.operations = operations;
- }
-
public void addOperation(String operationName, OperationDefinitionTemplate operation) {
if(MapUtils.isEmpty(this.operations)) {
this.operations = new HashMap<>();
@@ -60,21 +56,15 @@ public class InterfaceDefinitionTemplate extends InterfaceDefinition {
if (!(o instanceof InterfaceDefinitionTemplate)) {
return false;
}
-
InterfaceDefinitionTemplate that = (InterfaceDefinitionTemplate) o;
-
- if (getInputs() != null ? !getInputs().equals(that.getInputs()) : that.getInputs() != null) {
- return false;
- }
- return getOperations() != null ? getOperations().equals(that.getOperations())
- : that.getOperations() == null;
+ return Objects.equals(inputs, that.inputs) &&
+ Objects.equals(operations, that.operations);
}
@Override
public int hashCode() {
- int result = getInputs() != null ? getInputs().hashCode() : 0;
- result = 31 * result + (getOperations() != null ? getOperations().hashCode() : 0);
- return result;
+
+ return Objects.hash(inputs, operations);
}
@Override
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionType.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionType.java
index 8bd1b26332..4860b3a2ac 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionType.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/InterfaceDefinitionType.java
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+
package org.openecomp.sdc.tosca.datatypes.model;
import org.apache.commons.collections4.MapUtils;
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java
index 7b4be10236..6710e271b6 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java
@@ -1,9 +1,25 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
package org.openecomp.sdc.tosca.datatypes.model;
import java.util.Map;
import java.util.Objects;
-public class OperationDefinitionTemplate extends OperationDefinition{
+public class OperationDefinitionTemplate extends OperationDefinition {
private Implementation implementation;
private Map<String, Object> inputs;
diff --git a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionType.java b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionType.java
index 70c6a58041..7043812fc7 100644
--- a/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionType.java
+++ b/common/openecomp-tosca-datatype/src/main/java/org/openecomp/sdc/tosca/datatypes/model/OperationDefinitionType.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
package org.openecomp.sdc.tosca.datatypes.model;
import java.util.Map;
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
index 2236622222..32cfb89418 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
@@ -20,8 +20,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.converter.errors.CreateToscaObjectErrorBuilder;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.utils.CommonUtil;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
import java.util.HashSet;
import java.util.Map;
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
index c66a5ba13b..ecd182f384 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
@@ -1269,16 +1269,25 @@ public class DataModelUtil {
CommonUtil.createObjectUsingSetters(interfaceObj, interfaceClass);
interfaceDefinition.ifPresent(interfaceDefinitionType1 -> updateInterfaceDefinitionOperations(
CommonUtil.getObjectAsMap(interfaceObj),
- interfaceDefinitionType1));
+ interfaceDefinitionType1, getOperationClass(interfaceClass)));
return interfaceDefinition;
} catch (Exception ex) {
throw new CoreException(
new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(),
- interfaceId, ex.getMessage()).build());
+ interfaceId,
+ ex.getMessage()).build());
}
}
+ private static <T extends OperationDefinition, V extends InterfaceDefinition> Class<T> getOperationClass(
+ Class<V> interfaceClass) {
+ return interfaceClass.equals(InterfaceDefinitionType.class)
+ ? (Class<T>) OperationDefinitionType.class
+ :
+ (Class<T>) OperationDefinitionTemplate.class;
+ }
+
public static Optional<Object> convertInterfaceDefinitionToObj(
InterfaceDefinitionType interfaceDefinitionType) {
return converInetrfaceToToscaInterfaceObj(interfaceDefinitionType);
@@ -1351,21 +1360,35 @@ public class DataModelUtil {
return Optional.empty();
}
- private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations(
- Map<String, Object> interfaceAsMap,
- InterfaceDefinition interfaceDefinition) {
+ private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations
+ (Map<String, Object> interfaceAsMap, InterfaceDefinition interfaceDefinition,
+ Class<T> operationClass) {
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class);
- Optional<? extends OperationDefinition> operationDefinition = Optional.empty();
+ Set<String> fieldNames = CommonUtil.getClassFieldNames(interfaceDefinition.getClass());
+ Optional<? extends OperationDefinition> operationDefinition;
for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- operationDefinition = createOperation(entry.getKey(), entry.getValue(), fieldNames,
- interfaceDefinition instanceof InterfaceDefinitionType ? OperationDefinitionType.class :
- OperationDefinitionTemplate.class);
-
- operationDefinition
- .ifPresent(operation -> interfaceDefinition.addOperation(entry.getKey(), operation));
-
+ operationDefinition =
+ createOperation(entry.getKey(), entry.getValue(), fieldNames, operationClass);
+ operationDefinition.ifPresent(operation -> addOperationToInterface(interfaceDefinition,
+ entry.getKey(), operation));
+ }
+ }
+
+ private static void addOperationToInterface(InterfaceDefinition interfaceDefinition,
+ String operationName,
+ OperationDefinition operationDefinition) {
+ if (interfaceDefinition instanceof InterfaceDefinitionType) {
+ InterfaceDefinitionType interfaceDefinitionType =
+ (InterfaceDefinitionType) interfaceDefinition;
+ interfaceDefinitionType.addOperation(operationName, (OperationDefinitionType)
+ operationDefinition);
+ }
+ if (interfaceDefinition instanceof InterfaceDefinitionTemplate) {
+ InterfaceDefinitionTemplate interfaceDefinitionTemplate =
+ (InterfaceDefinitionTemplate) interfaceDefinition;
+ interfaceDefinitionTemplate.addOperation(operationName, (OperationDefinitionTemplate)
+ operationDefinition);
}
}