Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-schema-abstraction / src / main / java / org / onap / aai / schemaif / json / FromJsonEdgeSchema.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2019 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.aai.schemaif.json;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.onap.aai.schemaif.SchemaProviderException;
28 import org.onap.aai.schemaif.definitions.EdgeSchema;
29 import org.onap.aai.schemaif.definitions.PropertySchema;
30 import org.onap.aai.schemaif.json.definitions.JsonEdgeSchema;
31
32 public class FromJsonEdgeSchema extends EdgeSchema {
33     public static final String WILDCARD_CHAR = "*";
34
35     public FromJsonEdgeSchema() {
36     }
37
38     public FromJsonEdgeSchema(EdgeSchema other) {
39         // A shallow copy should suffice, as edge definitions don't change.
40         name = other.getName();
41         source = other.getSource();
42         target = other.getTarget();
43         multiplicity = other.getMultiplicity();
44         properties = other.getPropertySchemaList();
45         annotations = other.getAnnotations();
46     }
47
48     public void fromJson(JsonEdgeSchema jsonEdge) throws SchemaProviderException {
49
50         name = jsonEdge.getLabel();
51         source = jsonEdge.getFrom();
52         target = jsonEdge.getTo();
53
54         // TODO: At present, multiplicity isn't described in the JSON schema. By default, make everything
55         // many-to-many
56         multiplicity = Multiplicity.MANY_2_MANY;
57
58         // Populate annotation schema
59         annotations = new HashMap<String, String>();
60         if (jsonEdge.getAnnotations() != null) {
61             for (Map.Entry<String, String> entry : jsonEdge.getAnnotations().entrySet()) {
62                 annotations.put(entry.getKey().toLowerCase(), entry.getValue());
63             }
64         }
65
66         // Currently edge properties are not supported in the json schema
67         properties = new HashMap<String, PropertySchema>();
68     }
69
70     public void replaceWildcard(String vertexName) throws SchemaProviderException {
71         if (source.equals(WILDCARD_CHAR) && target.equals(WILDCARD_CHAR)) {
72             throw new SchemaProviderException("Edge definition with wildcard source and target: " + toString());
73         }
74
75         if (source.equals(WILDCARD_CHAR)) {
76             source = vertexName;
77         }
78
79         if (target.equals(WILDCARD_CHAR)) {
80             target = vertexName;
81         }
82     }
83 }