2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.toscaparser.api.elements;
23 import java.util.LinkedHashMap;
27 public class ArtifactTypeDef extends StatefulEntityType {
30 private LinkedHashMap<String, Object> customDef;
31 private LinkedHashMap<String, Object> properties;
32 private LinkedHashMap<String, Object> parentArtifacts;
34 public ArtifactTypeDef(String type, LinkedHashMap<String, Object> customDef) {
35 super(type, ARTIFACT_PREFIX, customDef);
38 this.customDef = customDef;
39 properties = defs != null ? (LinkedHashMap<String, Object>) defs.get(PROPERTIES) : null;
40 parentArtifacts = getParentArtifacts();
43 private LinkedHashMap<String, Object> getParentArtifacts() {
44 LinkedHashMap<String, Object> artifacts = new LinkedHashMap<>();
45 String parentArtif = null;
46 if (getParentType() != null) {
47 parentArtif = getParentType().getType();
49 if (parentArtif != null && !parentArtif.isEmpty()) {
50 while (!parentArtif.equals("tosca.artifacts.Root")) {
51 Object ob = TOSCA_DEF.get(parentArtif);
52 artifacts.put(parentArtif, ob);
54 (String) ((LinkedHashMap<String, Object>) ob).get("derived_from");
60 public ArtifactTypeDef getParentType() {
61 // Return a artifact entity from which this entity is derived
65 String partifactEntity = derivedFrom(defs);
66 if (partifactEntity != null) {
67 return new ArtifactTypeDef(partifactEntity, customDef);
72 public Object getArtifact(String name) {
73 // Return the definition of an artifact field by name
75 return defs.get(name);