diff options
author | amitjai <amitjai@amdocs.com> | 2018-04-27 13:28:57 +0530 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-04-30 06:05:27 +0000 |
commit | 42c920baf4dbb9fe8775843a6d4c9f70fa29f064 (patch) | |
tree | ac2aff977e2b129e61d2166c4832842676e4f5c3 /common/onap-tosca-datatype/src/main/java | |
parent | f487427a32f410ab5c97a4092865d32beb88ee27 (diff) |
Rename packages from openecomp to onap.
This task is all about package name space change also make changes to pom for common module
Change-Id: Ie9bda0f958a9a05826c0374830cc9cb7d6d196b6
Issue-ID: SDC-1272
Signed-off-by: amitjai <amitjai@amdocs.com>
Diffstat (limited to 'common/onap-tosca-datatype/src/main/java')
57 files changed, 4498 insertions, 0 deletions
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ActivityDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ActivityDefinition.java new file mode 100644 index 0000000000..538ed37409 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ActivityDefinition.java @@ -0,0 +1,41 @@ +package org.onap.sdc.tosca.datatypes.model; + +public class ActivityDefinition { + + private String delegate; + private String set_state; + private String call_operation; + private String inline; + + public String getDelegate() { + return delegate; + } + + public void setDelegate(String delegate) { + this.delegate = delegate; + } + + public String getSet_state() { + return set_state; + } + + public void setSet_state(String set_state) { + this.set_state = set_state; + } + + public String getCall_operation() { + return call_operation; + } + + public void setCall_operation(String call_operation) { + this.call_operation = call_operation; + } + + public String getInline() { + return inline; + } + + public void setInline(String inline) { + this.inline = inline; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ArtifactDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ArtifactDefinition.java new file mode 100644 index 0000000000..b3aae7e75e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ArtifactDefinition.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + + +public class ArtifactDefinition { + private String type; + private String file; + private String repository; + private String description; + private String deploy_path; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getFile() { + return file; + } + + public void setFile(String file) { + this.file = file; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDeploy_path() { + return deploy_path; + } + + public void setDeploy_path(String deploy_path) { + this.deploy_path = deploy_path; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ArtifactType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ArtifactType.java new file mode 100644 index 0000000000..1dff6b9e8d --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ArtifactType.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + + + +public class ArtifactType { + + private String derived_from; + private String version; + private Map<String, String> metadata; + private String description; + private String mime_type; + private List<String> file_ext; + private Map<String, PropertyDefinition> properties; + + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getMime_type() { + return mime_type; + } + + public void setMime_type(String mime_type) { + this.mime_type = mime_type; + } + + public List<String> getFile_ext() { + return file_ext; + } + + public void setFile_ext(List<String> file_ext) { + this.file_ext = file_ext; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/AttributeDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/AttributeDefinition.java new file mode 100644 index 0000000000..aefe987402 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/AttributeDefinition.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.Objects; + +public class AttributeDefinition { + + private String type; + private String description; + private Object _default; + private Status status; + private EntrySchema entry_schema; + + public AttributeDefinition() { + status = Status.SUPPORTED; + } + + public EntrySchema getEntry_schema() { + return entry_schema; + } + + public void setEntry_schema(EntrySchema entry_schema) { + this.entry_schema = entry_schema; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public Object get_default() { + return _default; + } + + public void set_default(Object _default) { + this._default = _default; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public AttributeDefinition clone() { + AttributeDefinition attributeDefinition = new AttributeDefinition(); + attributeDefinition.setType(this.getType()); + attributeDefinition.setDescription(this.getDescription()); + attributeDefinition.set_default(this.get_default()); + attributeDefinition.setStatus(this.getStatus()); + attributeDefinition.setEntry_schema( + Objects.isNull(this.getEntry_schema()) ? null : this.getEntry_schema().clone()); + return attributeDefinition; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityAssignment.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityAssignment.java new file mode 100644 index 0000000000..bed4e8c6b0 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityAssignment.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.Map; + + + +public class CapabilityAssignment { + + private Map<String, Object> properties; + private Map<String, Object> attributes; + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + public Map<String, Object> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, Object> attributes) { + this.attributes = attributes; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityDefinition.java new file mode 100644 index 0000000000..0eb205b3fd --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityDefinition.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import org.onap.sdc.tosca.services.DataModelCloneUtil; + +import java.util.List; +import java.util.Map; + +public class CapabilityDefinition { + + private String type; + private String description; + private Map<String, PropertyDefinition> properties; + private Map<String, AttributeDefinition> attributes; + private List<String> valid_source_types; + private Object[] occurrences; + + + /** + * Constructor. + */ + public CapabilityDefinition() { + occurrences = new Object[2]; + occurrences[0] = 1; + occurrences[1] = "UNBOUNDED"; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + public Map<String, AttributeDefinition> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, AttributeDefinition> attributes) { + this.attributes = attributes; + } + + public List<String> getValid_source_types() { + return valid_source_types; + } + + public void setValid_source_types(List<String> valid_source_types) { + this.valid_source_types = valid_source_types; + } + + public Object[] getOccurrences() { + return occurrences; + } + + public void setOccurrences(Object[] occurrences) { + this.occurrences = occurrences; + } + + @Override + public CapabilityDefinition clone() { + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition + .setOccurrences(new Object[]{this.getOccurrences()[0], this.getOccurrences()[1]}); + capabilityDefinition + .setProperties(DataModelCloneUtil.clonePropertyDefinitions(this.getProperties())); + capabilityDefinition.setType(this.getType()); + capabilityDefinition + .setAttributes(DataModelCloneUtil.cloneAttributeDefinitions(this.getAttributes())); + capabilityDefinition.setDescription(this.getDescription()); + capabilityDefinition + .setValid_source_types(DataModelCloneUtil.cloneValidSourceTypes(this.getValid_source_types())); + return capabilityDefinition; + + } + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityFilterDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityFilterDefinition.java new file mode 100644 index 0000000000..83f9d2576b --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityFilterDefinition.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; + + + +public class CapabilityFilterDefinition { + List<Constraint> properties; + + public List<Constraint> getProperties() { + return properties; + } + + public void setProperties(List<Constraint> properties) { + this.properties = properties; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityType.java new file mode 100644 index 0000000000..a6368f8a6f --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/CapabilityType.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + + + +public class CapabilityType { + + private String derived_from; + private String version; + private String description; + private Map<String, PropertyDefinition> properties; + private Map<String, AttributeDefinition> attributes; + private List<String> valid_source_types; + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + public Map<String, AttributeDefinition> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, AttributeDefinition> attributes) { + this.attributes = attributes; + } + + public List<String> getValid_source_types() { + return valid_source_types; + } + + public void setValid_source_types(List<String> valid_source_types) { + this.valid_source_types = valid_source_types; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Constraint.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Constraint.java new file mode 100644 index 0000000000..a21e31b387 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Constraint.java @@ -0,0 +1,179 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.ArrayList; +import java.util.List; + +public class Constraint { + private Object equal; + private Object greater_or_equal; + private Object greater_than; + private Object less_than; + private Object less_or_equal; + private Object[] in_range; + private List<Object> valid_values; + private Integer length; + private Integer min_length; + private Integer max_length; + private Object pattern; + + public Constraint() { + } + + public Object getGreater_or_equal() { + return greater_or_equal; + } + + public void setGreater_or_equal(Object greater_or_equal) { + this.greater_or_equal = greater_or_equal; + } + + public Object getEqual() { + return equal; + } + + public void setEqual(Object equal) { + this.equal = equal; + } + + public Object getGreater_than() { + return greater_than; + } + + public void setGreater_than(Object greater_than) { + this.greater_than = greater_than; + } + + public Object getLess_than() { + return less_than; + } + + public void setLess_than(Object less_than) { + this.less_than = less_than; + } + + public Object getLess_or_equal() { + return less_or_equal; + } + + public void setLess_or_equal(Object less_or_equal) { + this.less_or_equal = less_or_equal; + } + + public Object[] getIn_range() { + return in_range; + } + + /** + * Sets in_range attribute. + * @param in_range. + */ + public void setIn_range(Object[] in_range) { + this.in_range = new Object[2]; + this.in_range[0] = in_range[0]; + this.in_range[1] = in_range[1]; + } + + public List<Object> getValid_values() { + return valid_values; + } + + public void setValid_values(List<Object> valid_values) { + this.valid_values = valid_values; + } + + /** + * Add Valid value + * @param validValue object. + */ + public void addValidValue(Object validValue) { + if (this.valid_values == null) { + this.valid_values = new ArrayList<>(); + } + valid_values.add(validValue); + } + + public Integer getLength() { + return length; + } + + public void setLength(Integer length) { + this.length = length; + } + + public Integer getMin_length() { + return min_length; + } + + public void setMin_length(Integer min_length) { + this.min_length = min_length; + } + + public Integer getMax_length() { + return max_length; + } + + public void setMax_length(Integer max_length) { + this.max_length = max_length; + } + + public Object getPattern() { + return pattern; + } + + public void setPattern(Object pattern) { + this.pattern = pattern; + } + + @Override + public Constraint clone() { + Constraint constraint = new Constraint(); + constraint.setEqual(this.getEqual()); + constraint.setGreater_or_equal(this.getGreater_or_equal()); + constraint.setGreater_than(this.getGreater_than()); + cloneInRange(constraint); + constraint.setLength(this.getLength()); + constraint.setLess_or_equal(this.getLess_or_equal()); + constraint.setLess_than(this.getLess_than()); + constraint.setMax_length(this.getMax_length()); + constraint.setMin_length(this.getMin_length()); + constraint.setPattern(this.getPattern()); + cloneValidValues(constraint); + + return constraint; + } + + private void cloneInRange(Constraint constraint) { + if (this.getIn_range() != null) { + constraint.setIn_range(new Object[]{this.getIn_range()[0], this.getIn_range()[1]}); + } + } + + private void cloneValidValues(Constraint constraint) { + if (this.getValid_values() != null) { + constraint.setValid_values(new ArrayList<>()); + for (Object entry : this.getValid_values()) { + constraint.getValid_values().add(entry); + } + } + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Credential.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Credential.java new file mode 100644 index 0000000000..fdfbcbe280 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Credential.java @@ -0,0 +1,55 @@ +package org.onap.sdc.tosca.datatypes.model; + +import java.util.Map; + +public class Credential { + private String protocol; + private String token_type; + private String token; + private Map<String, String> keys; + private String user; + + public Credential(){ + this.token_type = "password"; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getToken_type() { + return token_type; + } + + public void setToken_type(String token_type) { + this.token_type = token_type; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public Map<String, String> getKeys() { + return keys; + } + + public void setKeys(Map<String, String> keys) { + this.keys = keys; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/DataType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/DataType.java new file mode 100644 index 0000000000..bf318a7d3e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/DataType.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + +public class DataType { + + private String derived_from; + private String version; + Map<String, String> metadata; + private String description; + private List<Constraint> constraints; + private Map<String, PropertyDefinition> properties; + + /** + * Gets derived from. + * + * @return the derived from + */ + public String getDerived_from() { + return derived_from; + } + + /** + * Sets derived from. + * + * @param derived_from the derived from + */ + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + /** + * Gets version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Sets version. + * + * @param version the version + */ + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + /** + * Gets description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Sets description. + * + * @param description the description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Gets constraints. + * + * @return the constraints + */ + public List<Constraint> getConstraints() { + return constraints; + } + + /** + * Sets constraints. + * + * @param constraints the constraints + */ + public void setConstraints(List<Constraint> constraints) { + this.constraints = constraints; + } + + /** + * Gets properties. + * + * @return the properties + */ + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + /** + * Sets properties. + * + * @param properties the properties + */ + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/DefinitionOfDataType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/DefinitionOfDataType.java new file mode 100644 index 0000000000..e249cd5335 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/DefinitionOfDataType.java @@ -0,0 +1,96 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import java.util.List; + +public class DefinitionOfDataType { + + protected String type; + protected String description; + protected Object value; + protected Boolean required; + protected Object _default; + protected Status status; + protected List<Constraint> constraints; + protected EntrySchema entry_schema; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public Boolean getRequired() { + return required; + } + + public void setRequired(Boolean required) { + this.required = required; + } + + public Object get_default() { + return _default; + } + + public void set_default(Object _default) { + this._default = _default; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public List<Constraint> getConstraints() { + return constraints; + } + + public void setConstraints(List<Constraint> constraints) { + this.constraints = constraints; + } + + public EntrySchema getEntry_schema() { + return entry_schema; + } + + public void setEntry_schema(EntrySchema entry_schema) { + this.entry_schema = entry_schema; + } + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Directive.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Directive.java new file mode 100644 index 0000000000..749044bf8e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Directive.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + + +public enum Directive { + + + SELECTABLE("selectable"), + SUBSTITUTABLE("substitutable"); + + private String displayName; + + Directive(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } + + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/EntrySchema.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/EntrySchema.java new file mode 100644 index 0000000000..0b826e22cd --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/EntrySchema.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import org.onap.sdc.tosca.services.DataModelCloneUtil; + +import java.util.List; + +public class EntrySchema { + + private String description; + private String type; + private List<Constraint> constraints; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List<Constraint> getConstraints() { + return constraints; + } + + public void setConstraints(List<Constraint> constraints) { + this.constraints = constraints; + } + + @Override + public EntrySchema clone() { + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setDescription(this.getDescription()); + entrySchema.setType(this.getType()); + entrySchema.setConstraints(DataModelCloneUtil.cloneConstraints(this.getConstraints())); + return entrySchema; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/EventFilter.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/EventFilter.java new file mode 100644 index 0000000000..273a64f5af --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/EventFilter.java @@ -0,0 +1,32 @@ +package org.onap.sdc.tosca.datatypes.model; + +public class EventFilter { + + private String node; + private String requirement; + private String capability; + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public String getRequirement() { + return requirement; + } + + public void setRequirement(String requirement) { + this.requirement = requirement; + } + + public String getCapability() { + return capability; + } + + public void setCapability(String capability) { + this.capability = capability; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/GroupDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/GroupDefinition.java new file mode 100644 index 0000000000..e2002bf22e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/GroupDefinition.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + + + +public class GroupDefinition { + + private String type; + private String description; + private Map<String, String> metadata; + private Map<String, Object> properties; + private List<String> members; + private Map<String, Object> interfaces; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + public List<String> getMembers() { + return members; + } + + public void setMembers(List<String> members) { + this.members = members; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public Map<String, Object> getInterfaces() { + return interfaces; + } + + public void setInterfaces( + Map<String, Object> interfaces) { + this.interfaces = interfaces; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/GroupType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/GroupType.java new file mode 100644 index 0000000000..611b1bf447 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/GroupType.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + + + +public class GroupType { + + private String derived_from; + private String version; + private Map<String, String> metadata; + private String description; + private Map<String, PropertyDefinition> properties; + private List<String> members; + private List<Map<String, RequirementDefinition>> requirements; + private Map<String, CapabilityDefinition> capabilities; + private Map<String, Object> interfaces; + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public List<Map<String, RequirementDefinition>> getRequirements() { + return requirements; + } + + public void setRequirements( + List<Map<String, RequirementDefinition>> requirements) { + this.requirements = requirements; + } + + public Map<String, CapabilityDefinition> getCapabilities() { + return capabilities; + } + + public void setCapabilities( + Map<String, CapabilityDefinition> capabilities) { + this.capabilities = capabilities; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + public List<String> getMembers() { + return members; + } + + public void setMembers(List<String> members) { + this.members = members; + } + + public Map<String, Object> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, Object> interfaces) { + this.interfaces = interfaces; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Implementation.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Implementation.java new file mode 100644 index 0000000000..00c0833956 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Implementation.java @@ -0,0 +1,62 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import java.util.HashSet; +import java.util.List; +import java.util.Objects; + + +public class Implementation { + + private String primary; + private List<String> dependencies; + + public String getPrimary() { + return primary; + } + + public void setPrimary(String primary) { + this.primary = primary; + } + + public List<String> getDependencies() { + return dependencies; + } + + public void setDependencies(List<String> dependencies) { + this.dependencies = dependencies; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Implementation)) { + return false; + } + Implementation that = (Implementation) o; + return Objects.equals(primary, that.primary) && + Objects.equals(new HashSet<>(dependencies), new HashSet<>(that.dependencies)); + } + + @Override + public int hashCode() { + return Objects.hash(primary, dependencies); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Import.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Import.java new file mode 100644 index 0000000000..604607c11e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Import.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + + +public class Import { + + private String file; + private String repository; + private String namespace_uri; + private String namespace_prefix; + + public String getFile() { + return file; + } + + public void setFile(String file) { + this.file = file; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + + public String getNamespace_uri() { + return namespace_uri; + } + + public void setNamespace_uri(String namespace_uri) { + this.namespace_uri = namespace_uri; + } + + public String getNamespace_prefix() { + return namespace_prefix; + } + + public void setNamespace_prefix(String namespace_prefix) { + this.namespace_prefix = namespace_prefix; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinition.java new file mode 100644 index 0000000000..28e871a454 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinition.java @@ -0,0 +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.onap.sdc.tosca.datatypes.model; + +import java.util.Map; + +public abstract class InterfaceDefinition { + + protected Map<String, OperationDefinition> operations; + + public abstract void addOperation(String operationName, OperationDefinition operationDefinition); +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java new file mode 100644 index 0000000000..a39221fe39 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinitionTemplate.java @@ -0,0 +1,74 @@ +/* + * 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.onap.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<String, Object> inputs; + private Map<String, OperationDefinitionTemplate> operations; + + public Map<String, Object> getInputs() { + return inputs; + } + + public void setInputs( + Map<String, Object> inputs) { + this.inputs = inputs; + } + + public Map<String, OperationDefinitionTemplate> getOperations() { + return 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) { + return true; + } + if (!(o instanceof InterfaceDefinitionTemplate)) { + return false; + } + InterfaceDefinitionTemplate that = (InterfaceDefinitionTemplate) o; + return Objects.equals(inputs, that.inputs) && + Objects.equals(operations, that.operations); + } + + @Override + public int hashCode() { + + return Objects.hash(inputs, operations); + } + + @Override + public void addOperation(String operationName, OperationDefinition operationDefinition) { + addOperation(operationName, (OperationDefinitionTemplate)operationDefinition); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinitionType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinitionType.java new file mode 100644 index 0000000000..800786c1af --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceDefinitionType.java @@ -0,0 +1,98 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import org.apache.commons.collections4.MapUtils; + +import java.util.HashMap; +import java.util.Map; + +public class InterfaceDefinitionType extends InterfaceDefinition { + + private String type; + private Map<String, PropertyDefinition> inputs; + protected Map<String, OperationDefinitionType> operations; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map<String, PropertyDefinition> getInputs() { + return inputs; + } + + public void setInputs( + Map<String, PropertyDefinition> inputs) { + this.inputs = inputs; + } + + public Map<String, OperationDefinitionType> getOperations() { + return operations; + } + + public void setOperations( + Map<String, OperationDefinitionType> 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) { + return true; + } + if (!(o instanceof InterfaceDefinitionType)) { + return false; + } + + InterfaceDefinitionType that = (InterfaceDefinitionType) o; + + if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) { + return false; + } + 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; + } + + @Override + public void addOperation(String operationName, OperationDefinition operationDefinition) { + addOperation(operationName, (OperationDefinitionType)operationDefinition); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceType.java new file mode 100644 index 0000000000..d89aa9fd82 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/InterfaceType.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import org.apache.commons.collections4.MapUtils; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class InterfaceType { + private String derived_from; + private String version; + private Map<String, String> metadata; + private String description; + private Map<String, PropertyDefinition> inputs; + private Map<String, OperationDefinition> operations; + + public Map<String, PropertyDefinition> getInputs() { + return inputs; + } + + public void setInputs( + Map<String, PropertyDefinition> inputs) { + this.inputs = inputs; + } + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, OperationDefinition> getOperations() { + return operations; + } + + public void setOperations( + Map<String, OperationDefinition> 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 InterfaceType)) { + return false; + } + InterfaceType that = (InterfaceType) o; + return Objects.equals(derived_from, that.derived_from) && + Objects.equals(version, that.version) && + Objects.equals(metadata, that.metadata) && + Objects.equals(description, that.description) && + Objects.equals(inputs, that.inputs) && + Objects.equals(operations, that.operations); + } + + @Override + public int hashCode() { + + return Objects.hash(derived_from, version, metadata, description, inputs, operations); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java new file mode 100644 index 0000000000..692d7e47ee --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + + + +public class NodeFilter { + + Map<String, List<Constraint>> properties; + Map<String, CapabilityFilterDefinition> capabilities; + + public Map<String, List<Constraint>> getProperties() { + + return properties; + } + + public void setProperties(Map<String, List<Constraint>> properties) { + this.properties = properties; + } + + public Map<String, CapabilityFilterDefinition> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, CapabilityFilterDefinition> capabilities) { + this.capabilities = capabilities; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java new file mode 100644 index 0000000000..258a7ec2cd --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import org.onap.sdc.tosca.services.YamlUtil; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + + +public class NodeTemplate implements Template { + + private String type; + private String description; + private Map<String, String> metadata; + private List<String> directives; + private Map<String, Object> properties; + private Map<String, Object> attributes; + private List<Map<String, RequirementAssignment>> requirements; + private Map<String, CapabilityAssignment> capabilities; + private Map<String, Object> interfaces; + private Map<String, ArtifactDefinition> artifacts; + private NodeFilter node_filter; + private String copy; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public List<String> getDirectives() { + return directives; + } + + public void setDirectives(List<String> directives) { + this.directives = directives; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + public Map<String, Object> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, Object> attributes) { + this.attributes = attributes; + } + + public List<Map<String, RequirementAssignment>> getRequirements() { + return requirements; + } + + public void setRequirements(List<Map<String, RequirementAssignment>> requirements) { + this.requirements = requirements; + } + + public Map<String, CapabilityAssignment> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, CapabilityAssignment> capabilities) { + this.capabilities = capabilities; + } + + public Map<String, Object> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, Object> interfaces) { + this.interfaces = interfaces; + } + + public Map<String, ArtifactDefinition> getArtifacts() { + return artifacts; + } + + public void setArtifacts(Map<String, ArtifactDefinition> artifacts) { + this.artifacts = artifacts; + } + + public NodeFilter getNode_filter() { + return node_filter; + } + + public void setNode_filter(NodeFilter node_filter) { + this.node_filter = node_filter; + } + + public String getCopy() { + return copy; + } + + public void setCopy(String copy) { + this.copy = copy; + } + + @Override + public NodeTemplate clone() { + YamlUtil yamlUtil = new YamlUtil(); + return yamlUtil.yamlToObject(yamlUtil.objectToYaml(this), NodeTemplate.class); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof NodeTemplate)) { + return false; + } + NodeTemplate that = (NodeTemplate) o; + return Objects.equals(type, that.type) && + Objects.equals(description, that.description) && + Objects.equals(metadata, that.metadata) && + Objects.equals(directives, that.directives) && + Objects.equals(properties, that.properties) && + Objects.equals(attributes, that.attributes) && + Objects.equals(requirements, that.requirements) && + Objects.equals(capabilities, that.capabilities) && + Objects.equals(interfaces, that.interfaces) && + Objects.equals(artifacts, that.artifacts) && + Objects.equals(node_filter, that.node_filter) && + Objects.equals(copy, that.copy); + } + + @Override + public int hashCode() { + + return Objects + .hash(type, description, metadata, directives, properties, attributes, requirements, + capabilities, interfaces, artifacts, node_filter, copy); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeType.java new file mode 100644 index 0000000000..767e8a6668 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeType.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + +public class NodeType { + + private String derived_from; + private String version; + private Map<String, String> metadata; + private String description; + private Map<String, PropertyDefinition> properties; + private Map<String, AttributeDefinition> attributes; + private List<Map<String, RequirementDefinition>> requirements; + private Map<String, CapabilityDefinition> capabilities; + private Map<String, Object> interfaces; + private Map<String, ArtifactDefinition> artifacts; + + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + public Map<String, AttributeDefinition> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, AttributeDefinition> attributes) { + this.attributes = attributes; + } + + public List<Map<String, RequirementDefinition>> getRequirements() { + return requirements; + } + + public void setRequirements(List<Map<String, RequirementDefinition>> requirements) { + this.requirements = requirements; + } + + public Map<String, CapabilityDefinition> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, CapabilityDefinition> capabilities) { + this.capabilities = capabilities; + } + + public Map<String, Object> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, Object> interfaces) { + this.interfaces = interfaces; + } + + public Map<String, ArtifactDefinition> getArtifacts() { + return artifacts; + } + + public void setArtifacts(Map<String, ArtifactDefinition> artifacts) { + this.artifacts = artifacts; + } + + @Override + public NodeType clone() { + NodeType clone = new NodeType(); + clone.setCapabilities(this.getCapabilities()); + clone.setDerived_from(this.getDerived_from()); + clone.setProperties(this.getProperties()); + clone.setRequirements(this.getRequirements()); + clone.setDescription(this.getDescription()); + clone.setAttributes(this.getAttributes()); + clone.setInterfaces(this.getInterfaces()); + clone.setVersion(this.getVersion()); + clone.setArtifacts(this.getArtifacts()); + return clone; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinition.java new file mode 100644 index 0000000000..c166588985 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinition.java @@ -0,0 +1,34 @@ +package org.onap.sdc.tosca.datatypes.model; + +import java.util.Objects; + +public class OperationDefinition { + + protected String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof OperationDefinition)) { + return false; + } + OperationDefinition that = (OperationDefinition) o; + return Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + + return Objects.hash(description); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java new file mode 100644 index 0000000000..16e45393cf --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinitionTemplate.java @@ -0,0 +1,61 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import java.util.Map; +import java.util.Objects; + +public class OperationDefinitionTemplate extends OperationDefinition { + + private Implementation implementation; + private Map<String, Object> inputs; + + public Implementation getImplementation() { + return implementation; + } + + public void setImplementation(Implementation implementation) { + this.implementation = implementation; + } + + public Map<String, Object> getInputs() { + return inputs; + } + + public void setInputs(Map<String, Object> inputs) { + this.inputs = inputs; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof OperationDefinitionTemplate)) { + return false; + } + OperationDefinitionTemplate that = (OperationDefinitionTemplate) o; + return Objects.equals(implementation, that.implementation) && + Objects.equals(inputs, that.inputs); + } + + @Override + public int hashCode() { + + return Objects.hash(implementation, inputs); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinitionType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinitionType.java new file mode 100644 index 0000000000..5b87d49055 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/OperationDefinitionType.java @@ -0,0 +1,62 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import java.util.Map; +import java.util.Objects; + +public class OperationDefinitionType extends OperationDefinition { + + private String implementation; + private Map<String, PropertyDefinition> inputs; + + public String getImplementation() { + return implementation; + } + + public void setImplementation(String implementation) { + this.implementation = implementation; + } + + public Map<String, PropertyDefinition> getInputs() { + return inputs; + } + + public void setInputs( + Map<String, PropertyDefinition> inputs) { + this.inputs = inputs; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof OperationDefinitionType)) { + return false; + } + OperationDefinitionType that = (OperationDefinitionType) o; + return Objects.equals(implementation, that.implementation) && + Objects.equals(inputs, that.inputs); + } + + @Override + public int hashCode() { + + return Objects.hash(implementation, inputs); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ParameterDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ParameterDefinition.java new file mode 100644 index 0000000000..7426c33010 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ParameterDefinition.java @@ -0,0 +1,22 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + + +public class ParameterDefinition extends DefinitionOfDataType { + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java new file mode 100644 index 0000000000..e1c2fb468c --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + +public class PolicyDefinition implements Template { + private String type; + private String description; + private Map<String, String> metadata; + private Map<String, Object> properties; + private List<String> targets; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + public List<String> getTargets() { + return targets; + } + + public void setTargets(List<String> targets) { + this.targets = targets; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java new file mode 100644 index 0000000000..54d52cceec --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + + + +public class PolicyType { + + private String derived_from; + private String version; + private Map<String, String> metadata; + private String description; + private Map<String, PropertyDefinition> properties; + private List<String> targets; + private List<Trigger> triggers; + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + public List<String> getTargets() { + return targets; + } + + public void setTargets(List<String> targets) { + this.targets = targets; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public List<Trigger> getTriggers() { + return triggers; + } + + public void setTriggers( + List<Trigger> triggers) { + this.triggers = triggers; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PreconditionDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PreconditionDefinition.java new file mode 100644 index 0000000000..8bd5c540b0 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PreconditionDefinition.java @@ -0,0 +1,32 @@ +package org.onap.sdc.tosca.datatypes.model; + +public class PreconditionDefinition { + + private String target; + private String target_relationship; + private Constraint condition; + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getTarget_relationship() { + return target_relationship; + } + + public void setTarget_relationship(String target_relationship) { + this.target_relationship = target_relationship; + } + + public Constraint getCondition() { + return condition; + } + + public void setCondition(Constraint condition) { + this.condition = condition; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinition.java new file mode 100644 index 0000000000..58c4a75347 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinition.java @@ -0,0 +1,45 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import org.onap.sdc.tosca.services.DataModelCloneUtil; + +import java.util.Objects; + +public class PropertyDefinition extends DefinitionOfDataType { + + public PropertyDefinition() { + this.status = Status.SUPPORTED; + this.required = true; + } + + @Override + public PropertyDefinition clone() { + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(this.getType()); + propertyDefinition.setDescription(this.getDescription()); + propertyDefinition.setRequired(this.getRequired()); + propertyDefinition.set_default(this.get_default()); + propertyDefinition.setStatus(this.getStatus()); + propertyDefinition.setEntry_schema( + Objects.isNull(this.getEntry_schema()) ? null : this.getEntry_schema().clone()); + propertyDefinition.setConstraints(DataModelCloneUtil.cloneConstraints(this.getConstraints())); + return propertyDefinition; + } + + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PropertyType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PropertyType.java new file mode 100644 index 0000000000..d08a1271e3 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PropertyType.java @@ -0,0 +1,94 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public enum PropertyType { + + STRING("string"), + INTEGER("integer"), + FLOAT("float"), + BOOLEAN("boolean"), + TIMESTAMP("timestamp"), + NULL("null"), + MAP("map"), + LIST("list"), + SCALAR_UNIT_SIZE("scalar-unit.size"), + SCALAR_UNIT_FREQUENCY("scalar-unit.frequency"); + + private static final Map<String, PropertyType> mMap = + Collections.unmodifiableMap(initializeMapping()); + private static final Set<String> simplePropertyTypes = + Collections.unmodifiableSet(initializeSimplePropertyTypes()); + private String displayName; + + PropertyType(String displayName) { + + this.displayName = displayName; + } + + /** + * Initilize property type display name mapping. + * @return Map + */ + public static Map<String, PropertyType> initializeMapping() { + Map<String, PropertyType> typeMap = new HashMap<>(); + for (PropertyType v : PropertyType.values()) { + typeMap.put(v.displayName, v); + } + return typeMap; + } + + /** + * Get Property type by display name. + * @param displayName + * @return PropertyType + */ + public static PropertyType getPropertyTypeByDisplayName(String displayName) { + if (mMap == null) { + initializeMapping(); + } + if (mMap.containsKey(displayName)) { + return mMap.get(displayName); + } + return null; + } + + private static Set<String> initializeSimplePropertyTypes() { + Set<String> simplePropertyTypes = new HashSet<>(4); + simplePropertyTypes.add(STRING.getDisplayName().toLowerCase()); + simplePropertyTypes.add(INTEGER.getDisplayName().toLowerCase()); + simplePropertyTypes.add(FLOAT.getDisplayName().toLowerCase()); + simplePropertyTypes.add(BOOLEAN.getDisplayName().toLowerCase()); + return simplePropertyTypes; + } + + public static Set<String> getSimplePropertyTypes() { + return simplePropertyTypes; + } + + public String getDisplayName() { + return displayName; + } + + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RelationshipTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RelationshipTemplate.java new file mode 100644 index 0000000000..d9a81137f0 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RelationshipTemplate.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.Map; + + + +public class RelationshipTemplate implements Template { + + private String type; + private String description; + private Map<String, String> metadata; + private Map<String, Object> properties; + private Map<String, Object> attributes; + private Map<String, RequirementAssignment> requirements; + private Map<String, CapabilityAssignment> capabilities; + private Map<String, Object> interfaces; + private String copy; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + public Map<String, Object> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, Object> attributes) { + this.attributes = attributes; + } + + public Map<String, RequirementAssignment> getRequirements() { + return requirements; + } + + public void setRequirements(Map<String, RequirementAssignment> requirements) { + this.requirements = requirements; + } + + public Map<String, CapabilityAssignment> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, CapabilityAssignment> capabilities) { + this.capabilities = capabilities; + } + + public Map<String, Object> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, Object> interfaces) { + this.interfaces = interfaces; + } + + public String getCopy() { + return copy; + } + + public void setCopy(String copy) { + this.copy = copy; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RelationshipType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RelationshipType.java new file mode 100644 index 0000000000..dacd5bcddf --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RelationshipType.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + +public class RelationshipType { + + private String derived_from; + private String version; + private Map<String, String> metadata; + private String description; + private Map<String, PropertyDefinition> properties; + private Map<String, AttributeDefinition> attributes; + private Map<String, Object> interfaces; + private List<String> valid_target_types; + //An optional list of one or more names of Capability Types that are valid targets + // for this relationship + + public String getDerived_from() { + return derived_from; + } + + public void setDerived_from(String derived_from) { + this.derived_from = derived_from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + public Map<String, AttributeDefinition> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, AttributeDefinition> attributes) { + this.attributes = attributes; + } + + public Map<String, Object> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, Object> interfaces) { + this.interfaces = interfaces; + } + + public List<String> getValid_target_types() { + return valid_target_types; + } + + public void setValid_target_types(List<String> valid_target_types) { + this.valid_target_types = valid_target_types; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Repository.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Repository.java new file mode 100644 index 0000000000..a9328234d1 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Repository.java @@ -0,0 +1,32 @@ +package org.onap.sdc.tosca.datatypes.model; + +public class Repository { + + private String description; + private String url; + private Credential credential; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Credential getCredential() { + return credential; + } + + public void setCredential(Credential credential) { + this.credential = credential; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RequirementAssignment.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RequirementAssignment.java new file mode 100644 index 0000000000..0cd15e5549 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RequirementAssignment.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + +public class RequirementAssignment { + + private String capability; + private String node; + private String relationship; + private NodeFilter node_filter; + private Object[] occurrences; + + public String getCapability() { + return capability; + } + + public void setCapability(String capability) { + this.capability = capability; + } + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; + } + + public NodeFilter getNode_filter() { + return node_filter; + } + + public void setNode_filter(NodeFilter node_filter) { + this.node_filter = node_filter; + } + + public Object[] getOccurrences() { + return occurrences; + } + + public void setOccurrences(Object[] occurrences) { + this.occurrences = occurrences; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinition.java new file mode 100644 index 0000000000..cc8b6f6166 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinition.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + +public class RequirementDefinition { + + private String capability; + private String node; + private String relationship; + private Object[] occurrences; + + /** + * Instantiates a new Requirement definition. + */ + public RequirementDefinition() { + occurrences = new Object[2]; + occurrences[0] = 1; + occurrences[1] = 1; + } + + public String getCapability() { + return capability; + } + + public void setCapability(String capability) { + this.capability = capability; + } + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; + } + + public Object[] getOccurrences() { + return occurrences; + } + + public void setOccurrences(Object[] occurrences) { + this.occurrences = occurrences; + } + + @Override + public RequirementDefinition clone() { + RequirementDefinition requirementDefinition = new RequirementDefinition(); + requirementDefinition.setNode(this.getNode()); + requirementDefinition.setRelationship(this.getRelationship()); + requirementDefinition.setCapability(this.getCapability()); + requirementDefinition + .setOccurrences(new Object[]{this.getOccurrences()[0], this.getOccurrences()[1]}); + return requirementDefinition; + } + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Scalar.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Scalar.java new file mode 100644 index 0000000000..302ba4808c --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Scalar.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + + +public class Scalar { + + private Float value; + + public Float getValue() { + return value; + } + + public void setValue(Float value) { + this.value = value; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java new file mode 100644 index 0000000000..8ffc1f601e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java @@ -0,0 +1,184 @@ +/* + * 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.onap.sdc.tosca.datatypes.model; + +import org.apache.commons.collections4.MapUtils; +import org.onap.sdc.tosca.datatypes.model.heatextend.AnnotationType; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class ServiceTemplate implements Template { + + private String tosca_definitions_version; + private Map<String, String> metadata; + private Object dsl_definitions; + private Map<String, Repository> repositories; + private String description; + private List<Map<String, Import>> imports; + private Map<String, ArtifactType> artifact_types; + private Map<String, DataType> data_types; + private Map<String, CapabilityType> capability_types; + private Map<String, Object> interface_types; + private Map<String, RelationshipType> relationship_types; + private Map<String, NodeType> node_types; + private Map<String, GroupType> group_types; + private Map<String, PolicyType> policy_types; + private Map<String, AnnotationType> annotation_types; + private TopologyTemplate topology_template; + + public String getTosca_definitions_version() { + return tosca_definitions_version; + } + + public void setTosca_definitions_version(String tosca_definitions_version) { + this.tosca_definitions_version = tosca_definitions_version; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public Object getDsl_definitions() { + return dsl_definitions; + } + + public void setDsl_definitions(Object dsl_definitions) { + this.dsl_definitions = dsl_definitions; + } + + public Map<String, Repository> getRepositories() { + return repositories; + } + + public void setRepositories( + Map<String, Repository> repositories) { + this.repositories = repositories; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List<Map<String, Import>> getImports() { + return imports; + } + + public void setImports( + List<Map<String, Import>> imports) { + this.imports = imports; + } + + public Map<String, ArtifactType> getArtifact_types() { + return artifact_types; + } + + public void setArtifact_types(Map<String, ArtifactType> artifact_types) { + this.artifact_types = artifact_types; + } + + public Map<String, DataType> getData_types() { + return data_types; + } + + public void setData_types(Map<String, DataType> data_types) { + this.data_types = data_types; + } + + public Map<String, CapabilityType> getCapability_types() { + return capability_types; + } + + public void setCapability_types(Map<String, CapabilityType> capability_types) { + this.capability_types = capability_types; + } + + public Map<String, RelationshipType> getRelationship_types() { + return relationship_types; + } + + public void setRelationship_types(Map<String, RelationshipType> relationship_types) { + this.relationship_types = relationship_types; + } + + public Map<String, NodeType> getNode_types() { + return node_types; + } + + public void setNode_types(Map<String, NodeType> node_types) { + this.node_types = node_types; + } + + public Map<String, GroupType> getGroup_types() { + return group_types; + } + + public void setGroup_types(Map<String, GroupType> group_types) { + this.group_types = group_types; + } + + public Map<String, Object> getInterface_types() { + return interface_types; + } + + public void setInterface_types(Map<String, Object> interface_types) { + this.interface_types = interface_types; + } + + public void addInterfaceType(String interfaceKey, InterfaceType interfaceType) { + if (MapUtils.isEmpty(this.interface_types)) { + this.interface_types = new HashMap<>(); + } + + this.interface_types.put(interfaceKey, interfaceType); + } + + public Map<String, PolicyType> getPolicy_types() { + return policy_types; + } + + public void setPolicy_types(Map<String, PolicyType> policy_types) { + this.policy_types = policy_types; + } + + public TopologyTemplate getTopology_template() { + return topology_template; + } + + public void setTopology_template(TopologyTemplate topology_template) { + this.topology_template = topology_template; + } + + public Map<String, AnnotationType> getAnnotation_types() { + return annotation_types; + } + + public void setAnnotation_types(Map<String, AnnotationType> annotation_types) { + this.annotation_types = annotation_types; + } + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Status.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Status.java new file mode 100644 index 0000000000..c0f6d874d7 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Status.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + + + +public enum Status { + + SUPPORTED("supported"), + UNSUPPORTED("unsupported"), + EXPERIMENTAL("experimental"), + DEPRECATED("deprecated"),; + private String displayName; + + Status(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } + + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/StepDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/StepDefinition.java new file mode 100644 index 0000000000..660b31c5e4 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/StepDefinition.java @@ -0,0 +1,71 @@ +package org.onap.sdc.tosca.datatypes.model; + +import java.util.List; + +public class StepDefinition { + + private String target; + private String target_relationship; + private String operation_host; + private List<Constraint> filter; + private List<ActivityDefinition> activities; + private String on_success; + private String on_failure; + + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getTarget_relationship() { + return target_relationship; + } + + public void setTarget_relationship(String target_relationship) { + this.target_relationship = target_relationship; + } + + public String getOperation_host() { + return operation_host; + } + + public void setOperation_host(String operation_host) { + this.operation_host = operation_host; + } + + public List<Constraint> getFilter() { + return filter; + } + + public void setFilter(List<Constraint> filter) { + this.filter = filter; + } + + public List<ActivityDefinition> getActivities() { + return activities; + } + + public void setActivities(List<ActivityDefinition> activities) { + this.activities = activities; + } + + public String getOn_success() { + return on_success; + } + + public void setOn_success(String on_success) { + this.on_success = on_success; + } + + public String getOn_failure() { + return on_failure; + } + + public void setOn_failure(String on_failure) { + this.on_failure = on_failure; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java new file mode 100644 index 0000000000..3669ae1df4 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + +public class SubstitutionMapping { + private String node_type; + private Map<String, List<String>> capabilities; + private Map<String, List<String>> requirements; + + public String getNode_type() { + return node_type; + } + + public void setNode_type(String node_type) { + this.node_type = node_type; + } + + public Map<String, List<String>> getRequirements() { + return requirements; + } + + public void setRequirements(Map<String, List<String>> requirements) { + this.requirements = requirements; + } + + public Map<String, List<String>> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, List<String>> capabilities) { + this.capabilities = capabilities; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Template.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Template.java new file mode 100644 index 0000000000..490881688e --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Template.java @@ -0,0 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +public interface Template { +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/TimeInterval.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/TimeInterval.java new file mode 100644 index 0000000000..6e39ec67e3 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/TimeInterval.java @@ -0,0 +1,24 @@ +package org.onap.sdc.tosca.datatypes.model; + +import java.sql.Timestamp; + +public class TimeInterval { + private Timestamp start_time; + private Timestamp end_time; + + public Timestamp getStart_time() { + return start_time; + } + + public void setStart_time(Timestamp start_time) { + this.start_time = start_time; + } + + public Timestamp getEnd_time() { + return end_time; + } + + public void setEnd_time(Timestamp end_time) { + this.end_time = end_time; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/TopologyTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/TopologyTemplate.java new file mode 100644 index 0000000000..fde5f41bd2 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/TopologyTemplate.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class TopologyTemplate { + + private String description; + private Map<String, ParameterDefinition> inputs; + private Map<String, NodeTemplate> node_templates; + private Map<String, RelationshipTemplate> relationship_templates; + private Map<String, GroupDefinition> groups; + private Map<String, ParameterDefinition> outputs; + private SubstitutionMapping substitution_mappings; + private Map<String, PolicyDefinition> policies; + private List<WorkflowDefinition> workflows; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, ParameterDefinition> getInputs() { + return inputs; + } + + public void setInputs(Map<String, ParameterDefinition> inputs) { + this.inputs = inputs; + } + + public Map<String, NodeTemplate> getNode_templates() { + return node_templates; + } + + public void setNode_templates(Map<String, NodeTemplate> node_templates) { + this.node_templates = node_templates; + } + + public Map<String, RelationshipTemplate> getRelationship_templates() { + return relationship_templates; + } + + public void setRelationship_templates(Map<String, RelationshipTemplate> relationship_templates) { + this.relationship_templates = relationship_templates; + } + + public Map<String, GroupDefinition> getGroups() { + return groups; + } + + public void setGroups(Map<String, GroupDefinition> groups) { + this.groups = groups; + } + + /** + * Add group. + * + * @param groupKey the group key + * @param groupDefinition the group definition + */ + public void addGroup(String groupKey, GroupDefinition groupDefinition) { + if (Objects.isNull(this.groups)) { + this.groups = new HashMap<>(); + } + this.groups.put(groupKey, groupDefinition); + } + + public Map<String, ParameterDefinition> getOutputs() { + return outputs; + } + + public void setOutputs(Map<String, ParameterDefinition> outputs) { + this.outputs = outputs; + } + + public SubstitutionMapping getSubstitution_mappings() { + return substitution_mappings; + } + + public void setSubstitution_mappings(SubstitutionMapping substitution_mappings) { + this.substitution_mappings = substitution_mappings; + } + + public Map<String, PolicyDefinition> getPolicies() { + return policies; + } + + public void setPolicies(Map<String, PolicyDefinition> policies) { + this.policies = policies; + } + + public List<WorkflowDefinition> getWorkflows() { + return workflows; + } + + public void setWorkflows(List<WorkflowDefinition> workflows) { + this.workflows = workflows; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java new file mode 100644 index 0000000000..92f3b30183 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java @@ -0,0 +1,97 @@ +package org.onap.sdc.tosca.datatypes.model; + +public class Trigger { + + private String description; + private String event_type; + private TimeInterval schedule; + private EventFilter target_filter; + private Constraint condition; + private Constraint constraint; + private String period; + private int evaluations; + private String method; + //action - String or operation? + private Object action; + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getEvent_type() { + return event_type; + } + + public void setEvent_type(String event_type) { + this.event_type = event_type; + } + + public TimeInterval getSchedule() { + return schedule; + } + + public void setSchedule(TimeInterval schedule) { + this.schedule = schedule; + } + + public EventFilter getTarget_filter() { + return target_filter; + } + + public void setTarget_filter(EventFilter target_filter) { + this.target_filter = target_filter; + } + + public Constraint getCondition() { + return condition; + } + + public void setCondition(Constraint condition) { + this.condition = condition; + } + + public Constraint getConstraint() { + return constraint; + } + + public void setConstraint(Constraint constraint) { + this.constraint = constraint; + } + + public String getPeriod() { + return period; + } + + public void setPeriod(String period) { + this.period = period; + } + + public int getEvaluations() { + return evaluations; + } + + public void setEvaluations(int evaluations) { + this.evaluations = evaluations; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public Object getAction() { + return action; + } + + public void setAction(Object action) { + this.action = action; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/WorkflowDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/WorkflowDefinition.java new file mode 100644 index 0000000000..deacc77767 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/WorkflowDefinition.java @@ -0,0 +1,55 @@ +package org.onap.sdc.tosca.datatypes.model; + +import java.util.List; +import java.util.Map; + +public class WorkflowDefinition { + private String description; + private Map<String, String> metadata; + private Map<String, PropertyDefinition> inputs; + private List<PreconditionDefinition> preconditions; + private Map<String, StepDefinition> steps; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, String> getMetadata() { + return metadata; + } + + public void setMetadata(Map<String, String> metadata) { + this.metadata = metadata; + } + + public Map<String, PropertyDefinition> getInputs() { + return inputs; + } + + public void setInputs( + Map<String, PropertyDefinition> inputs) { + this.inputs = inputs; + } + + public List<PreconditionDefinition> getPreconditions() { + return preconditions; + } + + public void setPreconditions( + List<PreconditionDefinition> preconditions) { + this.preconditions = preconditions; + } + + public Map<String, StepDefinition> getSteps() { + return steps; + } + + public void setSteps( + Map<String, StepDefinition> steps) { + this.steps = steps; + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/AnnotationDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/AnnotationDefinition.java new file mode 100644 index 0000000000..8734dbcf07 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/AnnotationDefinition.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2016-2017 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.onap.sdc.tosca.datatypes.model.heatextend; + +import java.util.Map; + +public class AnnotationDefinition { + + private String type; + private Map<String, Object> properties; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/AnnotationType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/AnnotationType.java new file mode 100644 index 0000000000..f2d124ac18 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/AnnotationType.java @@ -0,0 +1,53 @@ +/* + * Copyright © 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.onap.sdc.tosca.datatypes.model.heatextend; + + import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; + + import java.util.Map; + + public class AnnotationType { + + private String version; + private String description; + private Map<String, PropertyDefinition> properties; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map<String, PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(Map<String, PropertyDefinition> properties) { + this.properties = properties; + } + + }
\ No newline at end of file diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/ParameterDefinitionExt.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/ParameterDefinitionExt.java new file mode 100644 index 0000000000..dccb200148 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/ParameterDefinitionExt.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2016-2017 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.onap.sdc.tosca.datatypes.model.heatextend; + +import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; +import java.util.Map; + +public class ParameterDefinitionExt extends ParameterDefinition { + + private String label; + private Boolean hidden; + private Boolean immutable; + private Map<String, AnnotationDefinition> annotations; + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Boolean getHidden() { + return hidden; + } + + public void setHidden(Boolean hidden) { + this.hidden = hidden; + } + + public Boolean getImmutable() { + return immutable; + } + + public void setImmutable(Boolean immutable) { + this.immutable = immutable; + } + + public Map<String, AnnotationDefinition> getAnnotations() { + return annotations; + } + + public void setAnnotations(Map<String, AnnotationDefinition> annotations) { + this.annotations = annotations; + } + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/PropertyTypeExt.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/PropertyTypeExt.java new file mode 100644 index 0000000000..34d91cbb51 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/heatextend/PropertyTypeExt.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.datatypes.model.heatextend; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * The enum Property type ext. + */ +public enum PropertyTypeExt { + + /** + * Json property type ext. + */ + JSON("json"); + + private static final Map<String, PropertyTypeExt> mMap = + Collections.unmodifiableMap(initializeMapping()); + private String displayName; + + PropertyTypeExt(String displayName) { + + this.displayName = displayName; + } + + /** + * Initialize mapping map. + * + * @return the map + */ + public static Map<String, PropertyTypeExt> initializeMapping() { + Map<String, PropertyTypeExt> typeMap = new HashMap<String, PropertyTypeExt>(); + for (PropertyTypeExt v : PropertyTypeExt.values()) { + typeMap.put(v.displayName, v); + } + return typeMap; + } + + /** + * Gets property type by display name. + * + * @param displayName the display name + * @return the property type by display name + */ + public static PropertyTypeExt getPropertyTypeByDisplayName(String displayName) { + if (mMap == null) { + initializeMapping(); + } + if (mMap.containsKey(displayName)) { + return mMap.get(displayName); + } + return null; + } + + /** + * Gets display name. + * + * @return the display name + */ + public String getDisplayName() { + return displayName; + } + + +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelCloneUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelCloneUtil.java new file mode 100644 index 0000000000..f2868449c7 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelCloneUtil.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.tosca.services; + + +import org.onap.sdc.tosca.datatypes.model.AttributeDefinition; +import org.onap.sdc.tosca.datatypes.model.Constraint; +import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class DataModelCloneUtil { + + /** + * Clone constraints list. + * + * @param constraints the constraints + * @return the list + */ + public static List<Constraint> cloneConstraints(List<Constraint> constraints) { + + if (constraints == null) { + return null; + } + return constraints.stream().map(Constraint::clone).collect(Collectors.toList()); + } + + /** + * Clone property definitions map. + * + * @param propertyDefinitions the property definitions + * @return the map + */ + public static Map<String, PropertyDefinition> clonePropertyDefinitions( + Map<String, PropertyDefinition> propertyDefinitions) { + + if (propertyDefinitions == null) { + return null; + } + Map<String, PropertyDefinition> clonedProperties = new HashMap<>(); + for (String propertyKey : propertyDefinitions.keySet()) { + clonedProperties.put(propertyKey, propertyDefinitions.get(propertyKey).clone()); + } + + return clonedProperties; + } + + /** + * Clone attribute definitions map. + * + * @param attributeDefinitions the attribute definitions + * @return the map + */ + public static Map<String, AttributeDefinition> cloneAttributeDefinitions( + Map<String, AttributeDefinition> attributeDefinitions) { + + if (attributeDefinitions == null) { + return null; + } + Map<String, AttributeDefinition> clonedAttributeDefinitions = new HashMap<>(); + for (String attributeKey : attributeDefinitions.keySet()) { + clonedAttributeDefinitions.put(attributeKey, attributeDefinitions.get(attributeKey).clone()); + } + + return clonedAttributeDefinitions; + } + + /** + * Clone valid source types list. + * + * @param validSourceTypes the valid source types + * @return the list + */ + public static List<String> cloneValidSourceTypes(List<String> validSourceTypes) { + + if (validSourceTypes == null) { + return null; + } + + return validSourceTypes.stream().collect(Collectors.toList()); + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java new file mode 100644 index 0000000000..efd4982541 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java @@ -0,0 +1,86 @@ +/* + * Copyright © 2016-2017 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.onap.sdc.tosca.services; + +import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.introspector.Property; +import org.yaml.snakeyaml.introspector.PropertyUtils; +import org.yaml.snakeyaml.nodes.MappingNode; +import org.yaml.snakeyaml.nodes.NodeId; + +import java.beans.IntrospectionException; + + +public class ToscaExtensionYamlUtil extends YamlUtil { + + @Override + public <T> Constructor getConstructor(Class<T> typClass) { + return new ToscaWithHeatExtensionConstructor(typClass); + } + + @Override + protected PropertyUtils getPropertyUtils() { + return new ToscaPropertyUtilsWithHeatExtension(); + } + + public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils { + @Override + public Property getProperty(Class<? extends Object> type, String name) + throws IntrospectionException { + Class<? extends Object> classType = type; + try { + if (type + .equals(Class.forName("org.onap.sdc.tosca.datatypes.model.ParameterDefinition"))) { + classType = Class + .forName("org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt"); + } + } catch (ClassNotFoundException ex) { + throw new RuntimeException(ex); + } + return super.getProperty(classType, name); + } + } + + protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor { + public ToscaWithHeatExtensionConstructor(Class<?> theRoot) { + super(theRoot); + yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct()); + } + + class MyPersistentObjectConstruct extends Constructor.ConstructMapping { + @Override + protected Object constructJavaBean2ndStep(MappingNode node, Object object) { + Class type = node.getType(); + try { + if (type.equals( + Class.forName("org.onap.sdc.tosca.datatypes.model.ParameterDefinition"))) { + Class extendHeatClass = Class.forName( + "org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt"); + Object extendHeatObject = extendHeatClass.newInstance(); + // create JavaBean + return super.constructJavaBean2ndStep(node, extendHeatObject); + } else { + // create JavaBean + return super.constructJavaBean2ndStep(node, object); + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + } + } +} diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java new file mode 100644 index 0000000000..4030d3acd1 --- /dev/null +++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java @@ -0,0 +1,272 @@ +/* + * Copyright © 2016-2017 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.onap.sdc.tosca.services; + +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.TypeDescription; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.introspector.BeanAccess; +import org.yaml.snakeyaml.introspector.Property; +import org.yaml.snakeyaml.introspector.PropertyUtils; +import org.yaml.snakeyaml.nodes.MappingNode; +import org.yaml.snakeyaml.nodes.NodeTuple; +import org.yaml.snakeyaml.nodes.Tag; +import org.yaml.snakeyaml.parser.ParserException; +import org.yaml.snakeyaml.representer.Representer; + +import java.beans.IntrospectionException; +import java.io.IOException; +import java.io.InputStream; +import java.util.AbstractMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * The type Yaml util. + */ +@SuppressWarnings("unchecked") +public class YamlUtil { + + private static final String DEFAULT = "default"; + private static final String DEFAULT_STR = "_default"; + + /** + * Yaml to object t. + * + * @param <T> the type parameter + * @param yamlContent the yaml content + * @param typClass the t class + * @return the t + */ + public <T> T yamlToObject(String yamlContent, Class<T> typClass) { + Constructor constructor = getConstructor(typClass); + constructor.setPropertyUtils(getPropertyUtils()); + TypeDescription yamlFileDescription = new TypeDescription(typClass); + constructor.addTypeDescription(yamlFileDescription); + Yaml yaml = new Yaml(constructor); + T yamlObj = (T) yaml.load(yamlContent); + //noinspection ResultOfMethodCallIgnored + yamlObj.toString(); + return yamlObj; + } + + public InputStream loadYamlFileIs(String yamlFullFileName) { + return YamlUtil.class.getResourceAsStream(yamlFullFileName); + } + + /** + * Yaml to object t. + * + * @param <T> the type parameter + * @param yamlContent the yaml content + * @param typClass the t class + * @return the t + */ + public <T> T yamlToObject(InputStream yamlContent, Class<T> typClass) { + try { + Constructor constructor = getConstructor(typClass); + constructor.setPropertyUtils(getPropertyUtils()); + TypeDescription yamlFileDescription = new TypeDescription(typClass); + constructor.addTypeDescription(yamlFileDescription); + Yaml yaml = new Yaml(constructor); + T yamlObj = (T) yaml.load(yamlContent); + if (yamlObj != null) { + //noinspection ResultOfMethodCallIgnored + yamlObj.toString(); + return yamlObj; + } else { + throw new RuntimeException(); + } + } catch (Exception exception) { + throw new RuntimeException(exception); + } finally { + try { + if (yamlContent != null) { + yamlContent.close(); + } + } catch (IOException ignore) { + //do nothing + } + } + } + + + /** + * Gets constructor. + * + * @param <T> the type parameter + * @param typClass the t class + * @return the constructor + */ + public <T> Constructor getConstructor(Class<T> typClass) { + return new StrictMapAppenderConstructor(typClass); + } + + /** + * Gets property utils. + * + * @return the property utils + */ + protected PropertyUtils getPropertyUtils() { + return new MyPropertyUtils(); + } + + + /** + * Yaml to map map. + * + * @param yamlContent the yaml content + * @return the map + */ + public Map<String, LinkedHashMap<String, Object>> yamlToMap(InputStream yamlContent) { + Yaml yaml = new Yaml(); + return (Map<String, LinkedHashMap<String, Object>>) yaml.load(yamlContent); + } + + /** + * Object to yaml string. + * @param obj the obj + * @return the string + */ + public String objectToYaml(Object obj) { + DumperOptions options = new DumperOptions(); + options.setPrettyFlow(true); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + Representer representer = new CustomRepresenter(); + representer.addClassTag(obj.getClass(), Tag.MAP); + representer.setPropertyUtils(new MyPropertyUtils()); + + Yaml yaml = new Yaml(representer, options); + return yaml.dump(obj); + } + + /** + * Is yaml file content valid boolean. + * + * @param yamlFullFileName the yaml full file name + * @return the boolean + */ + public boolean isYamlFileContentValid(String yamlFullFileName) { + Yaml yaml = new Yaml(); + try { + Object loadResult = yaml.load(yamlFullFileName); + return loadResult != null; + } catch (Exception exception) { + return false; + } + } + + + private class CustomRepresenter extends Representer { + @Override + protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) { + //remove the bean type from the output yaml (!! ...) + if (!classTags.containsKey(javaBean.getClass())) { + addClassTag(javaBean.getClass(), Tag.MAP); + } + + return super.representJavaBean(properties, javaBean); + } + + @Override + protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, + Object propertyValue, Tag customTag) { + if (propertyValue == null) { + return null; + } else { + NodeTuple defaultNode = + super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); + + return DEFAULT_STR.equals(property.getName()) + ? new NodeTuple(representData(DEFAULT), defaultNode.getValueNode()) + : defaultNode; + } + } + } + + + /** + * The type My property utils. + */ + public class MyPropertyUtils extends PropertyUtils { + //Unsorted properties + @Override + protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bnAccess) + throws IntrospectionException { + return new LinkedHashSet<>(getPropertiesMap(type, + BeanAccess.FIELD).values()); + } + + @Override + public Property getProperty(Class<?> type, String name) throws IntrospectionException { + String updatedName = name; + if (DEFAULT.equals(updatedName)) { + updatedName = DEFAULT_STR; + } + return super.getProperty(type, updatedName); + } + + } + + /** + * The type Strict map appender constructor. + */ + protected class StrictMapAppenderConstructor extends Constructor { + + /** + * Instantiates a new Strict map appender constructor. + * + * @param theRoot the the root + */ + public StrictMapAppenderConstructor(Class<?> theRoot) { + super(theRoot); + } + + @Override + protected Map<Object, Object> createDefaultMap() { + final Map<Object, Object> delegate = super.createDefaultMap(); + return new AbstractMap<Object, Object>() { + @Override + public Object put(Object key, Object value) { + if (delegate.containsKey(key)) { + throw new IllegalStateException("duplicate key: " + key); + } + return delegate.put(key, value); + } + + @Override + public Set<Entry<Object, Object>> entrySet() { + return delegate.entrySet(); + } + }; + } + + @Override + protected Map<Object, Object> constructMapping(MappingNode node) { + try { + return super.constructMapping(node); + } catch (IllegalStateException exception) { + throw new ParserException("while parsing MappingNode", + node.getStartMark(), exception.getMessage(), + node.getEndMark()); + } + } + } +} |