2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.schemaif.oxm;
23 import java.util.HashMap;
24 import java.util.List;
27 import org.eclipse.persistence.dynamic.DynamicType;
28 import org.eclipse.persistence.internal.helper.DatabaseField;
29 import org.eclipse.persistence.mappings.DatabaseMapping;
30 import org.eclipse.persistence.oxm.XMLField;
31 import org.onap.aai.schemaif.SchemaProviderException;
32 import org.onap.aai.schemaif.definitions.PropertySchema;
33 import org.onap.aai.schemaif.definitions.types.BooleanDataType;
34 import org.onap.aai.schemaif.definitions.types.DataType;
35 import org.onap.aai.schemaif.definitions.types.FloatDataType;
36 import org.onap.aai.schemaif.definitions.types.IntDataType;
37 import org.onap.aai.schemaif.definitions.types.LongDataType;
38 import org.onap.aai.schemaif.definitions.types.StringDataType;
41 public class FromOxmPropertySchema extends PropertySchema {
43 // Handle vertex properties from OXM
44 public void fromOxm(DatabaseMapping mapping, DynamicType dynType, boolean reserved) throws SchemaProviderException {
45 DatabaseField field = mapping.getField();
46 if (field.getName().contains("/")) {
47 name = field.getName().substring(0, field.getName().indexOf("/"));
49 name = field.getName();
52 defaultValue = mapping.getProperties().get("defaultValue") == null ? ""
53 : mapping.getProperties().get("defaultValue").toString();
55 if (isPrimaryKeyOxm(name, dynType)) {
60 required = ((XMLField) field).isRequired();
64 isReserved = reserved;
66 String oxmType = ((XMLField) field).getTypeName() != null ? ((XMLField) field).getTypeName() : "";
67 if (!mapping.isAbstractDirectMapping()) {
68 // treat complex types as string blobs in oxm
69 dataType = new StringDataType();
71 if (oxmType.equalsIgnoreCase("java.lang.String")) {
72 dataType = new StringDataType();
73 } else if (oxmType.equalsIgnoreCase("java.lang.Long")) {
74 dataType = new LongDataType();
75 } else if (oxmType.equalsIgnoreCase("java.lang.Boolean")) {
76 dataType = new BooleanDataType();
77 } else if (oxmType.equalsIgnoreCase("java.lang.Integer")) {
78 dataType = new IntDataType();
79 } else if (oxmType.equalsIgnoreCase("java.lang.Float")) {
80 dataType = new FloatDataType();
82 throw new SchemaProviderException("Invalid OXM property type: " + oxmType);
87 annotations = new HashMap<String,String>();
88 Map<String, Object> oxmProps = mapping.getProperties();
89 for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
90 if (entry.getValue() instanceof String) {
91 annotations.put(entry.getKey().toLowerCase(), (String)entry.getValue());
96 // Handle edge properties from DBEdgeRules
97 public void fromRelationship(String propName, DataType.Type propDataType) throws SchemaProviderException {
102 annotations = new HashMap<String,String>();
104 switch (propDataType) {
106 dataType = new StringDataType();
109 dataType = new IntDataType();
112 dataType = new FloatDataType();
115 dataType = new LongDataType();
118 dataType = new BooleanDataType();
121 throw new SchemaProviderException("Invalid EdgeRule property type: " + propDataType);
125 private boolean isPrimaryKeyOxm(String propName, DynamicType dynType) {
126 List<String> primaryKeyList = dynType.getDescriptor().getPrimaryKeyFieldNames();
127 if ( (primaryKeyList == null) || (primaryKeyList.size() == 0) ) {
131 for (String key : primaryKeyList) {
132 String keyName = key.substring(0, key.indexOf('/'));
133 if (keyName.equals(propName)) {