Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-schema-abstraction / src / main / java / org / onap / aai / schemaif / oxm / FromOxmEdgeSchema.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.oxm;
23
24 import java.util.HashMap;
25
26 import org.onap.aai.edges.EdgeRule;
27 import org.onap.aai.edges.enums.EdgeProperty;
28 import org.onap.aai.schemaif.SchemaProviderException;
29 import org.onap.aai.schemaif.definitions.EdgeSchema;
30 import org.onap.aai.schemaif.definitions.PropertySchema;
31 import org.onap.aai.schemaif.definitions.types.DataType;
32
33 public class FromOxmEdgeSchema extends EdgeSchema {
34
35     public void fromEdgeRule(EdgeRule edgeRule) throws SchemaProviderException {
36         name = edgeRule.getLabel();
37         source = edgeRule.getFrom();
38         target = edgeRule.getTo();
39
40         switch (edgeRule.getMultiplicityRule()) {
41             case MANY2MANY:
42                 multiplicity = Multiplicity.MANY_2_MANY;
43                 break;
44             case MANY2ONE:
45                 multiplicity = Multiplicity.MANY_2_ONE;
46                 break;
47             case ONE2MANY:
48                 multiplicity = Multiplicity.ONE_2_MANY;
49                 break;
50             case ONE2ONE:
51                 multiplicity = Multiplicity.ONE_2_ONE;
52                 break;
53         }
54
55         annotations = new HashMap<String, String>();
56         properties = new HashMap<String, PropertySchema>();
57
58         // TODO: For now these are hard-coded ... should read them from a config file or something
59         annotations.put(EdgeProperty.CONTAINS.toString().toLowerCase(), edgeRule.getContains());
60         annotations.put(EdgeProperty.DELETE_OTHER_V.toString().toLowerCase(), edgeRule.getDeleteOtherV());
61         annotations.put(EdgeProperty.PREVENT_DELETE.toString().toLowerCase(), edgeRule.getPreventDelete());
62
63         FromOxmPropertySchema pSchema = new FromOxmPropertySchema();
64         pSchema.fromRelationship(EdgeProperty.CONTAINS.toString(), DataType.Type.STRING);
65         properties.put(EdgeProperty.CONTAINS.toString().toLowerCase(), pSchema);
66
67         pSchema = new FromOxmPropertySchema();
68         pSchema.fromRelationship(EdgeProperty.DELETE_OTHER_V.toString(), DataType.Type.STRING);
69         properties.put(EdgeProperty.DELETE_OTHER_V.toString().toLowerCase(), pSchema);
70
71         pSchema = new FromOxmPropertySchema();
72         pSchema.fromRelationship(EdgeProperty.PREVENT_DELETE.toString(), DataType.Type.STRING);
73         properties.put(EdgeProperty.PREVENT_DELETE.toString().toLowerCase(), pSchema);
74     }
75 }