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=========================================================
22 package org.onap.aai.schemaif.oxm;
24 import java.util.HashMap;
25 import java.util.List;
28 import org.eclipse.persistence.dynamic.DynamicType;
29 import org.eclipse.persistence.internal.helper.DatabaseField;
30 import org.eclipse.persistence.mappings.DatabaseMapping;
31 import org.eclipse.persistence.oxm.XMLField;
32 import org.onap.aai.schemaif.SchemaProviderException;
33 import org.onap.aai.schemaif.definitions.PropertySchema;
34 import org.onap.aai.schemaif.definitions.types.BooleanDataType;
35 import org.onap.aai.schemaif.definitions.types.DataType;
36 import org.onap.aai.schemaif.definitions.types.FloatDataType;
37 import org.onap.aai.schemaif.definitions.types.IntDataType;
38 import org.onap.aai.schemaif.definitions.types.LongDataType;
39 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)) {
59 required = ((XMLField) field).isRequired();
63 isReserved = reserved;
65 String oxmType = ((XMLField) field).getTypeName() != null ? ((XMLField) field).getTypeName() : "";
66 if (!mapping.isAbstractDirectMapping()) {
67 // treat complex types as string blobs in oxm
68 dataType = new StringDataType();
70 if (oxmType.equalsIgnoreCase("java.lang.String")) {
71 dataType = new StringDataType();
72 } else if (oxmType.equalsIgnoreCase("java.lang.Long")) {
73 dataType = new LongDataType();
74 } else if (oxmType.equalsIgnoreCase("java.lang.Boolean")) {
75 dataType = new BooleanDataType();
76 } else if (oxmType.equalsIgnoreCase("java.lang.Integer")) {
77 dataType = new IntDataType();
78 } else if (oxmType.equalsIgnoreCase("java.lang.Float")) {
79 dataType = new FloatDataType();
81 throw new SchemaProviderException("Invalid OXM property type: " + oxmType);
86 annotations = new HashMap<String, String>();
87 Map<String, Object> oxmProps = mapping.getProperties();
88 for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
89 if (entry.getValue() instanceof String) {
90 annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue());
95 // Handle edge properties from DBEdgeRules
96 public void fromRelationship(String propName, DataType.Type propDataType) throws SchemaProviderException {
101 annotations = new HashMap<String, String>();
103 switch (propDataType) {
105 dataType = new StringDataType();
108 dataType = new IntDataType();
111 dataType = new FloatDataType();
114 dataType = new LongDataType();
117 dataType = new BooleanDataType();
120 throw new SchemaProviderException("Invalid EdgeRule property type: " + propDataType);
124 private boolean isPrimaryKeyOxm(String propName, DynamicType dynType) {
125 List<String> primaryKeyList = dynType.getDescriptor().getPrimaryKeyFieldNames();
126 if ((primaryKeyList == null) || (primaryKeyList.size() == 0)) {
130 for (String key : primaryKeyList) {
131 String keyName = key.substring(0, key.indexOf('/'));
132 if (keyName.equals(propName)) {