From 298c383225d728eb6a04e4b8cb03472f4990de7e Mon Sep 17 00:00:00 2001 From: shiria Date: Wed, 21 Mar 2018 09:11:30 +0200 Subject: Handle OperationDefinition in Tosca Data Model Change-Id: Ib1a7f0c5548fc9c7a98cff1182ff02300353443d Issue-ID: SDC-1154 Signed-off-by: shiria --- .../tosca/datatypes/model/InterfaceDefinition.java | 44 +--------------------- .../model/InterfaceDefinitionTemplate.java | 39 ++++++++++++++++--- .../datatypes/model/InterfaceDefinitionType.java | 44 +++++++++++++++++++--- .../model/OperationDefinitionTemplate.java | 2 +- 4 files changed, 75 insertions(+), 54 deletions(-) (limited to 'common') 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 2f629ef54a..8d6ace2043 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,47 +15,7 @@ */ package org.openecomp.sdc.tosca.datatypes.model; -import org.apache.commons.collections4.MapUtils; +public abstract class InterfaceDefinition { + public abstract void addOperation(String operationName, OperationDefinition operationDefinition); -import java.util.HashMap; -import java.util.Map; - -public class InterfaceDefinition { - protected Map operations; - - public Map getOperations() { - return operations; - } - - public void setOperations( - Map operations) { - this.operations = operations; - } - - public void addOperation(String operationName, OperationDefinition operationDefinition) { - if (MapUtils.isEmpty(this.operations)) { - this.operations = new HashMap<>(); - } - this.operations.put(operationName, operationDefinition); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof InterfaceDefinition)) { - return false; - } - - InterfaceDefinition that = (InterfaceDefinition) o; - - return getOperations() != null ? getOperations().equals(that.getOperations()) - : that.getOperations() == null; - } - - @Override - public int hashCode() { - return getOperations() != null ? getOperations().hashCode() : 0; - } } 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 85dc0c571d..912e5a7b99 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 @@ -16,12 +16,15 @@ package org.openecomp.sdc.tosca.datatypes.model; +import org.apache.commons.collections4.MapUtils; + +import java.util.HashMap; import java.util.Map; -import java.util.Objects; public class InterfaceDefinitionTemplate extends InterfaceDefinition { private Map inputs; + private Map operations; public Map getInputs() { return inputs; @@ -32,6 +35,23 @@ public class InterfaceDefinitionTemplate extends InterfaceDefinition { this.inputs = inputs; } + public Map getOperations() { + return operations; + } + + public void setOperations( + Map operations) { + this.operations = operations; + } + + public void addOperation(String operationName, OperationDefinitionTemplate operation) { + if(MapUtils.isEmpty(this.operations)) { + this.operations = new HashMap<>(); + } + + this.operations.put(operationName, operation); + } + @Override public boolean equals(Object o) { if (this == o) { @@ -40,16 +60,25 @@ public class InterfaceDefinitionTemplate extends InterfaceDefinition { if (!(o instanceof InterfaceDefinitionTemplate)) { return false; } - if (!super.equals(o)) { + + InterfaceDefinitionTemplate that = (InterfaceDefinitionTemplate) o; + + if (getInputs() != null ? !getInputs().equals(that.getInputs()) : that.getInputs() != null) { return false; } - InterfaceDefinitionTemplate that = (InterfaceDefinitionTemplate) o; - return Objects.equals(inputs, that.inputs); + return getOperations() != null ? getOperations().equals(that.getOperations()) + : that.getOperations() == null; } @Override public int hashCode() { + int result = getInputs() != null ? getInputs().hashCode() : 0; + result = 31 * result + (getOperations() != null ? getOperations().hashCode() : 0); + return result; + } - return Objects.hash(super.hashCode(), inputs); + @Override + public void addOperation(String operationName, OperationDefinition operationDefinition) { + addOperation(operationName, (OperationDefinitionTemplate)operationDefinition); } } 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 fdd11095a2..8bd1b26332 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 @@ -16,13 +16,16 @@ package org.openecomp.sdc.tosca.datatypes.model; +import org.apache.commons.collections4.MapUtils; + +import java.util.HashMap; import java.util.Map; -import java.util.Objects; public class InterfaceDefinitionType extends InterfaceDefinition { private String type; private Map inputs; + protected Map operations; public String getType() { return type; @@ -41,6 +44,23 @@ public class InterfaceDefinitionType extends InterfaceDefinition { this.inputs = inputs; } + public Map getOperations() { + return operations; + } + + public void setOperations( + Map operations) { + this.operations = operations; + } + + public void addOperation(String operationName, OperationDefinitionType operation) { + if(MapUtils.isEmpty(this.operations)) { + this.operations = new HashMap<>(); + } + + this.operations.put(operationName, operation); + } + @Override public boolean equals(Object o) { if (this == o) { @@ -49,17 +69,29 @@ public class InterfaceDefinitionType extends InterfaceDefinition { if (!(o instanceof InterfaceDefinitionType)) { return false; } - if (!super.equals(o)) { + + InterfaceDefinitionType that = (InterfaceDefinitionType) o; + + if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) { return false; } - InterfaceDefinitionType that = (InterfaceDefinitionType) o; - return Objects.equals(type, that.type) && - Objects.equals(inputs, that.inputs); + if (getInputs() != null ? !getInputs().equals(that.getInputs()) : that.getInputs() != null) { + return false; + } + return getOperations() != null ? getOperations().equals(that.getOperations()) + : that.getOperations() == null; } @Override public int hashCode() { + int result = getType() != null ? getType().hashCode() : 0; + result = 31 * result + (getInputs() != null ? getInputs().hashCode() : 0); + result = 31 * result + (getOperations() != null ? getOperations().hashCode() : 0); + return result; + } - return Objects.hash(super.hashCode(), type, inputs); + @Override + public void addOperation(String operationName, OperationDefinition operationDefinition) { + addOperation(operationName, (OperationDefinitionType)operationDefinition); } } 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 155175a120..7b4be10236 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 @@ -3,7 +3,7 @@ package org.openecomp.sdc.tosca.datatypes.model; import java.util.Map; import java.util.Objects; -public class OperationDefinitionTemplate { +public class OperationDefinitionTemplate extends OperationDefinition{ private Implementation implementation; private Map inputs; -- cgit 1.2.3-korg