diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-11-07 08:35:37 +0000 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-11-07 08:38:19 +0000 |
commit | fbb02159b84435cf37221ae8ae5e0045167be15a (patch) | |
tree | 78196f6a3e5e4d0b1e5ca6ecadec0f9e9a623303 /aai-schema-abstraction/src/main/java/org/onap | |
parent | 58f0fd2f6ef58de52e1f9a73540c1bb895c0d6e6 (diff) |
Reduce the number of problems in aai-common by removing unused imports
- run mvn spotless:apply across aai-commmon to remove unused imports
- run mvn formatter:format across aai-common
Issue-ID: AAI-3583
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I2dfeb395eafa2824ce8369bba3a18db3e1845522
Diffstat (limited to 'aai-schema-abstraction/src/main/java/org/onap')
36 files changed, 368 insertions, 377 deletions
diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java index 5aa8d688..2e93ef95 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java @@ -21,12 +21,12 @@ package org.onap.aai.schemaif; -import org.onap.aai.schemaif.definitions.EdgeSchema; -import org.onap.aai.schemaif.definitions.VertexSchema; - import java.util.Map; import java.util.Set; +import org.onap.aai.schemaif.definitions.EdgeSchema; +import org.onap.aai.schemaif.definitions.VertexSchema; + public interface SchemaProvider { /** @@ -61,7 +61,8 @@ public interface SchemaProvider { * * @return The edge schema definition */ - EdgeSchema getEdgeSchema(String edgeType, String sourceVertex, String targetVertex, String version) throws SchemaProviderException; + EdgeSchema getEdgeSchema(String edgeType, String sourceVertex, String targetVertex, String version) + throws SchemaProviderException; /** * Get the list of edge definitions which are adjacent to the given vertex @@ -82,7 +83,8 @@ public interface SchemaProvider { * * @return The list of edge schema definitions */ - Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException; + Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) + throws SchemaProviderException; /** * Get vertex map for a schema version @@ -92,4 +94,4 @@ public interface SchemaProvider { * @return The list of vertex types */ Map<String, VertexSchema> getVertexMap(String schemaVersion) throws SchemaProviderException; - } +} diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderException.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderException.java index 9a95c337..4fb99f0e 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderException.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderException.java @@ -21,13 +21,12 @@ package org.onap.aai.schemaif; - public class SchemaProviderException extends Exception { private static final long serialVersionUID = 8162385108397238865L; - - public SchemaProviderException() {} + public SchemaProviderException() { + } public SchemaProviderException(String message) { super(message); @@ -41,7 +40,8 @@ public class SchemaProviderException extends Exception { super(message, cause); } - public SchemaProviderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + public SchemaProviderException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderMsgs.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderMsgs.java index 9b2c1518..b3b32576 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderMsgs.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProviderMsgs.java @@ -21,16 +21,16 @@ * ECOMP and OpenECOMP are trademarks * and service marks of AT&T Intellectual Property. */ + package org.onap.aai.schemaif; import com.att.eelf.i18n.EELFResourceManager; + import org.onap.aai.cl.eelf.LogMessageEnum; public enum SchemaProviderMsgs implements LogMessageEnum { - SCHEMA_LOAD_ERROR, - LOADED_SCHEMA_FILE, - LOADED_DB_RULE_FILE; - + SCHEMA_LOAD_ERROR, LOADED_SCHEMA_FILE, LOADED_DB_RULE_FILE; + static { EELFResourceManager.loadMessageBundle("logging/SchemaProviderMsgs"); } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/EdgeSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/EdgeSchema.java index 5d259128..e2dbc09c 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/EdgeSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/EdgeSchema.java @@ -18,24 +18,21 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.definitions; import java.util.Map; - public class EdgeSchema { protected String name; protected String source; protected String target; protected Multiplicity multiplicity; - protected Map<String,String> annotations; - protected Map<String,PropertySchema> properties; + protected Map<String, String> annotations; + protected Map<String, PropertySchema> properties; public enum Multiplicity { - MANY_2_MANY, - MANY_2_ONE, - ONE_2_MANY, - ONE_2_ONE + MANY_2_MANY, MANY_2_ONE, ONE_2_MANY, ONE_2_ONE } public String getName() { @@ -58,7 +55,7 @@ public class EdgeSchema { return properties.get(propName.toLowerCase()); } - public Map<String,PropertySchema> getPropertySchemaList() { + public Map<String, PropertySchema> getPropertySchemaList() { return properties; } @@ -66,7 +63,7 @@ public class EdgeSchema { return annotations.get(annotation.toLowerCase()); } - public Map<String,String> getAnnotations() { + public Map<String, String> getAnnotations() { return annotations; } @@ -88,9 +85,8 @@ public class EdgeSchema { EdgeSchema other = (EdgeSchema) obj; - return (source.equals(other.getSource())) - && (target.equals(other.getTarget())) - && (name.equals(other.getName())); + return (source.equals(other.getSource())) && (target.equals(other.getTarget())) + && (name.equals(other.getName())); } public String toString() { diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/PropertySchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/PropertySchema.java index a512da0b..c1021189 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/PropertySchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/PropertySchema.java @@ -26,7 +26,6 @@ import java.util.Map; import org.onap.aai.schemaif.SchemaProviderException; import org.onap.aai.schemaif.definitions.types.DataType; - public class PropertySchema { protected String name; protected DataType dataType; @@ -34,7 +33,7 @@ public class PropertySchema { protected String defaultValue; protected Boolean unique; protected Boolean isReserved; - protected Map<String,String> annotations; + protected Map<String, String> annotations; public String getName() { return name; @@ -47,11 +46,11 @@ public class PropertySchema { public Boolean isRequired() { return required; } - + public Boolean isKey() { return (unique && required); } - + public Boolean isUnique() { return unique; } @@ -59,17 +58,17 @@ public class PropertySchema { public String getDefaultValue() { return defaultValue; } - + public Boolean isReserved() { return isReserved; } - + public String getAnnotationValue(String annotation) { return annotations.get(annotation.toLowerCase()); } - + public Map<String, String> getAnnotations() { - return annotations; + return annotations; } public Object validateValue(String value) throws SchemaProviderException { @@ -77,10 +76,10 @@ public class PropertySchema { if (obj == null) { throw new SchemaProviderException("Invalid value for porperty '" + name + "': " + value); } - - return obj; + + return obj; } - + public String toString() { StringBuilder sb = new StringBuilder(); sb.append(" property: " + getName() + "\n"); @@ -90,11 +89,11 @@ public class PropertySchema { sb.append(" reserved: " + isReserved() + "\n"); sb.append(" default: " + getDefaultValue() + "\n"); sb.append(" annotations: " + "\n"); - + for (String annotation : annotations.keySet()) { sb.append(" " + annotation + ": " + annotations.get(annotation) + "\n"); } - + return sb.toString(); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/VertexSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/VertexSchema.java index 7ad1cfc6..a31c70e2 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/VertexSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/VertexSchema.java @@ -18,15 +18,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.definitions; import java.util.Map; - public class VertexSchema { protected String name; - protected Map<String,PropertySchema> properties; - protected Map<String,String> annotations; + protected Map<String, PropertySchema> properties; + protected Map<String, String> annotations; public String getName() { return name; @@ -36,14 +36,14 @@ public class VertexSchema { return properties.get(propName.toLowerCase()); } - public Map<String,PropertySchema> getPropertySchemaList() { + public Map<String, PropertySchema> getPropertySchemaList() { return properties; } - public Map<String,String> getAnnotationSchemaList() { - return annotations; + public Map<String, String> getAnnotationSchemaList() { + return annotations; } - + public String getAnnotationValue(String annotation) { return annotations.get(annotation.toLowerCase()); } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/BooleanDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/BooleanDataType.java index 52fb4ca5..a1d35138 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/BooleanDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/BooleanDataType.java @@ -21,8 +21,7 @@ package org.onap.aai.schemaif.definitions.types; - -public class BooleanDataType extends DataType { +public class BooleanDataType extends DataType { public BooleanDataType() { super(Type.BOOL); } @@ -32,7 +31,7 @@ public class BooleanDataType extends DataType { if (value.equalsIgnoreCase("true") || (value.equalsIgnoreCase("false"))) { return Boolean.parseBoolean(value); } - + return null; } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ComplexDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ComplexDataType.java index e09c18fd..98a74d8e 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ComplexDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ComplexDataType.java @@ -25,9 +25,9 @@ import java.util.List; import org.onap.aai.schemaif.definitions.PropertySchema; -public class ComplexDataType extends DataType { +public class ComplexDataType extends DataType { private List<PropertySchema> subProperties; - + public ComplexDataType(List<PropertySchema> subProperties) { super(Type.COMPLEX); this.subProperties = subProperties; @@ -36,23 +36,23 @@ public class ComplexDataType extends DataType { public List<PropertySchema> getSubProperties() { return subProperties; } - + @Override public Object validateValue(String value) { // TODO: Validate the complex type against the subProperties return value; } - + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("COMPLEX[ "); - + for (PropertySchema prop : getSubProperties()) { sb.append(prop.getDataType().toString() + " "); } - + sb.append("]"); - + return sb.toString(); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java index 2e2884b4..a51d70f9 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java @@ -23,14 +23,7 @@ package org.onap.aai.schemaif.definitions.types; public abstract class DataType { public enum Type { - STRING, - BOOL, - INT, - LONG, - FLOAT, - LIST, - MAP, - COMPLEX + STRING, BOOL, INT, LONG, FLOAT, LIST, MAP, COMPLEX } private final Type type; diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/FloatDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/FloatDataType.java index 17fb9485..d40a9845 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/FloatDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/FloatDataType.java @@ -21,23 +21,22 @@ package org.onap.aai.schemaif.definitions.types; -public class FloatDataType extends DataType { +public class FloatDataType extends DataType { public FloatDataType() { super(Type.FLOAT); } @Override public Object validateValue(String value) { - // TODO: In Tosca, you can impose constraints such as min/max value. + // TODO: In Tosca, you can impose constraints such as min/max value. // In future we can add this type of validation Float floatValue; try { floatValue = Float.parseFloat(value); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { return null; } - + return floatValue; } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/IntDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/IntDataType.java index 59eb788f..0911c8a5 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/IntDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/IntDataType.java @@ -23,28 +23,26 @@ package org.onap.aai.schemaif.definitions.types; import java.text.DecimalFormat; -public class IntDataType extends DataType { +public class IntDataType extends DataType { public IntDataType() { super(Type.INT); } @Override public Object validateValue(String value) { - // TODO: In Tosca, you can impose constraints such as min/max value. + // TODO: In Tosca, you can impose constraints such as min/max value. // In future we can add this type of validation Integer intValue; try { intValue = Integer.parseInt(value); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { // There is an edge case where an int value is stored as "x.0" in champ. // In that case, we just want to drop the ".0" and treat it as a proper // integer try { DecimalFormat decimalFormat = new DecimalFormat("0.#"); intValue = Integer.parseInt(decimalFormat.format(Double.valueOf(value))); - } - catch (Exception ex) { + } catch (Exception ex) { return null; } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ListDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ListDataType.java index 84adefec..4169ba1b 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ListDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/ListDataType.java @@ -23,7 +23,7 @@ package org.onap.aai.schemaif.definitions.types; public class ListDataType extends DataType { private DataType listType; - + public ListDataType(DataType listType) { super(Type.LIST); this.listType = listType; @@ -32,7 +32,7 @@ public class ListDataType extends DataType { public DataType getListType() { return listType; } - + @Override public Object validateValue(String value) { // TODO: Break the string into a list and validate each element against the listType diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/LongDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/LongDataType.java index 38195f9c..1c30054d 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/LongDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/LongDataType.java @@ -21,23 +21,22 @@ package org.onap.aai.schemaif.definitions.types; -public class LongDataType extends DataType { +public class LongDataType extends DataType { public LongDataType() { super(Type.LONG); } @Override public Object validateValue(String value) { - // TODO: In Tosca, you can impose constraints such as min/max value. + // TODO: In Tosca, you can impose constraints such as min/max value. // In future we can add this type of validation Long longInt; try { longInt = Long.parseLong(value); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { return null; } - + return longInt; } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/MapDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/MapDataType.java index 443f460e..b08cdb5f 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/MapDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/MapDataType.java @@ -23,7 +23,7 @@ package org.onap.aai.schemaif.definitions.types; public class MapDataType extends DataType { private DataType mapType; - + public MapDataType(DataType mapType) { super(Type.MAP); this.mapType = mapType; @@ -32,7 +32,7 @@ public class MapDataType extends DataType { public DataType getMapType() { return mapType; } - + @Override public Object validateValue(String value) { // TODO: Break the string into a map and validate each element against the mapType diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/StringDataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/StringDataType.java index 39487ea2..787ccda9 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/StringDataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/StringDataType.java @@ -21,15 +21,15 @@ package org.onap.aai.schemaif.definitions.types; -public class StringDataType extends DataType { +public class StringDataType extends DataType { public StringDataType() { super(Type.STRING); } @Override public Object validateValue(String value) { - // TODO: In Tosca, you can impose constraints such as string length, regex matches, valid values, - // string length maximums, etc. In future we can add this type of validation + // TODO: In Tosca, you can impose constraints such as string length, regex matches, valid values, + // string length maximums, etc. In future we can add this type of validation return value; } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonEdgeSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonEdgeSchema.java index e3bc450b..89a9eb83 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonEdgeSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonEdgeSchema.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json; import java.util.HashMap; @@ -30,10 +31,10 @@ import org.onap.aai.schemaif.json.definitions.JsonEdgeSchema; public class FromJsonEdgeSchema extends EdgeSchema { public static final String WILDCARD_CHAR = "*"; - + public FromJsonEdgeSchema() { } - + public FromJsonEdgeSchema(EdgeSchema other) { // A shallow copy should suffice, as edge definitions don't change. name = other.getName(); @@ -43,38 +44,38 @@ public class FromJsonEdgeSchema extends EdgeSchema { properties = other.getPropertySchemaList(); annotations = other.getAnnotations(); } - + public void fromJson(JsonEdgeSchema jsonEdge) throws SchemaProviderException { name = jsonEdge.getLabel(); source = jsonEdge.getFrom(); target = jsonEdge.getTo(); - - // TODO: At present, multiplicity isn't described in the JSON schema. By default, make everything + + // TODO: At present, multiplicity isn't described in the JSON schema. By default, make everything // many-to-many multiplicity = Multiplicity.MANY_2_MANY; - + // Populate annotation schema - annotations = new HashMap<String,String>(); + annotations = new HashMap<String, String>(); if (jsonEdge.getAnnotations() != null) { - for (Map.Entry<String,String> entry : jsonEdge.getAnnotations().entrySet()) { + for (Map.Entry<String, String> entry : jsonEdge.getAnnotations().entrySet()) { annotations.put(entry.getKey().toLowerCase(), entry.getValue()); } } - + // Currently edge properties are not supported in the json schema - properties = new HashMap<String,PropertySchema>(); + properties = new HashMap<String, PropertySchema>(); } public void replaceWildcard(String vertexName) throws SchemaProviderException { if (source.equals(WILDCARD_CHAR) && target.equals(WILDCARD_CHAR)) { throw new SchemaProviderException("Edge definition with wildcard source and target: " + toString()); } - + if (source.equals(WILDCARD_CHAR)) { source = vertexName; } - + if (target.equals(WILDCARD_CHAR)) { target = vertexName; } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonPropertySchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonPropertySchema.java index ea522191..ad1cec27 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonPropertySchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonPropertySchema.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json; import java.util.ArrayList; @@ -40,7 +41,8 @@ import org.onap.aai.schemaif.json.definitions.JsonPropertySchema; public class FromJsonPropertySchema extends PropertySchema { - public void fromJson(JsonPropertySchema pSchema, boolean reserved, List<DataTypeDefinition> dataTypes) throws SchemaProviderException { + public void fromJson(JsonPropertySchema pSchema, boolean reserved, List<DataTypeDefinition> dataTypes) + throws SchemaProviderException { name = pSchema.getName(); defaultValue = pSchema.getDefaultValue() == null ? "" : pSchema.getDefaultValue(); required = pSchema.getRequired() == null ? false : pSchema.getRequired(); @@ -49,68 +51,70 @@ public class FromJsonPropertySchema extends PropertySchema { dataType = resolveDataType(pSchema.getDataType(), dataTypes); // Populate annotations - annotations = new HashMap<String,String>(); + annotations = new HashMap<String, String>(); if (pSchema.getAnnotations() != null) { - for (Map.Entry<String,String> entry : pSchema.getAnnotations().entrySet()) { + for (Map.Entry<String, String> entry : pSchema.getAnnotations().entrySet()) { annotations.put(entry.getKey().toLowerCase(), entry.getValue()); } } } - - private DataType resolveDataType(String typeString, List<DataTypeDefinition> dataTypes) throws SchemaProviderException { - if (typeString.equalsIgnoreCase("string")) { + + private DataType resolveDataType(String typeString, List<DataTypeDefinition> dataTypes) + throws SchemaProviderException { + if (typeString.equalsIgnoreCase("string")) { return new StringDataType(); } - + if (typeString.equalsIgnoreCase("integer")) { return new IntDataType(); } if (typeString.equalsIgnoreCase("long")) { - return new LongDataType(); + return new LongDataType(); } - + if (typeString.equalsIgnoreCase("boolean")) { return new BooleanDataType(); } - + if (typeString.startsWith("list:")) { String segments[] = typeString.split(":"); DataType subType = resolveDataType(segments[1], dataTypes); return new ListDataType(subType); } - + if (typeString.startsWith("map:")) { String segments[] = typeString.split(":"); DataType subType = resolveDataType(segments[1], dataTypes); return new MapDataType(subType); } - + // Must be a complex type return resolveComplexDataType(typeString, dataTypes); } - - private DataType resolveComplexDataType(String typeString, List<DataTypeDefinition> dataTypes) throws SchemaProviderException { + + private DataType resolveComplexDataType(String typeString, List<DataTypeDefinition> dataTypes) + throws SchemaProviderException { // It must be a custom/complex type. DataTypeDefinition dType = null; for (DataTypeDefinition d : dataTypes) { - if ( (d.getName().equals(typeString)) ) { + if ((d.getName().equals(typeString))) { dType = d; break; } } - + if (dType == null) { throw new SchemaProviderException("Invalid data type: " + typeString); } - + List<PropertySchema> propList = new ArrayList<PropertySchema>(); for (JsonPropertySchema p : dType.getProperties()) { FromJsonPropertySchema pSchema = new FromJsonPropertySchema(); pSchema.fromJson(p, false, dataTypes); propList.add(pSchema); } - + return new ComplexDataType(propList); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonVertexSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonVertexSchema.java index 7a3251f1..5ce4b469 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonVertexSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/FromJsonVertexSchema.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json; import java.util.HashMap; @@ -31,12 +32,12 @@ import org.onap.aai.schemaif.json.definitions.DataTypeDefinition; import org.onap.aai.schemaif.json.definitions.JsonPropertySchema; import org.onap.aai.schemaif.json.definitions.JsonVertexSchema; - public class FromJsonVertexSchema extends VertexSchema { - public void fromJson(JsonVertexSchema jsonVertex, List<DataTypeDefinition> dataTypes, List<JsonPropertySchema> commonProps) throws SchemaProviderException { + public void fromJson(JsonVertexSchema jsonVertex, List<DataTypeDefinition> dataTypes, + List<JsonPropertySchema> commonProps) throws SchemaProviderException { name = jsonVertex.getName(); - properties = new HashMap<String,PropertySchema>(); - annotations = new HashMap<String,String>(); + properties = new HashMap<String, PropertySchema>(); + annotations = new HashMap<String, String>(); // Populate property schema if (jsonVertex.getProperties() != null) { @@ -46,7 +47,7 @@ public class FromJsonVertexSchema extends VertexSchema { properties.put(propSchema.getName().toLowerCase(), propSchema); } } - + // Add common properties if (commonProps != null) { for (JsonPropertySchema pSchema : commonProps) { @@ -54,40 +55,39 @@ public class FromJsonVertexSchema extends VertexSchema { propSchema.fromJson(pSchema, true, dataTypes); properties.put(propSchema.getName().toLowerCase(), propSchema); } - } - else { - // TODO: This is a hack until the schema-service return the list of common props + } else { + // TODO: This is a hack until the schema-service return the list of common props addCommonProps(); } - + // Populate annotation schema if (jsonVertex.getAnnotations() != null) { - for (Map.Entry<String,String> entry : jsonVertex.getAnnotations().entrySet()) { + for (Map.Entry<String, String> entry : jsonVertex.getAnnotations().entrySet()) { annotations.put(entry.getKey().toLowerCase(), entry.getValue()); } } - - // The searchable and indexed annotations, need to grab these from the property annotations + + // The searchable and indexed annotations, need to grab these from the property annotations // and store them at the vertex level as well (backwards compatibility with OXM) StringBuilder searchableVal = new StringBuilder(); StringBuilder indexedVal = new StringBuilder(); for (PropertySchema pSchema : properties.values()) { - if ( (pSchema.getAnnotationValue("searchable") != null) - && (pSchema.getAnnotationValue("searchable").equalsIgnoreCase("true")) ) { + if ((pSchema.getAnnotationValue("searchable") != null) + && (pSchema.getAnnotationValue("searchable").equalsIgnoreCase("true"))) { if (searchableVal.length() > 0) { searchableVal.append(","); } searchableVal.append(pSchema.getName()); } - if ( (pSchema.getAnnotationValue("indexed") != null) - && (pSchema.getAnnotationValue("indexed").equalsIgnoreCase("true")) ) { + if ((pSchema.getAnnotationValue("indexed") != null) + && (pSchema.getAnnotationValue("indexed").equalsIgnoreCase("true"))) { if (indexedVal.length() > 0) { indexedVal.append(","); } indexedVal.append(pSchema.getName()); } } - + if (searchableVal.length() > 0) { annotations.put("searchable", searchableVal.toString()); } @@ -105,10 +105,11 @@ public class FromJsonVertexSchema extends VertexSchema { addCommonProperty("aai-last-mod-ts", false, false, "string", "false"); addCommonProperty("source-of-truth", false, false, "string", "false"); addCommonProperty("aai-uri", false, false, "string", "false"); - + } - - private void addCommonProperty(String name, boolean req, boolean unique, String type, String indexed) throws SchemaProviderException { + + private void addCommonProperty(String name, boolean req, boolean unique, String type, String indexed) + throws SchemaProviderException { JsonPropertySchema pSchema = new JsonPropertySchema(); pSchema.setName(name); pSchema.setRequired(req); @@ -116,14 +117,14 @@ public class FromJsonVertexSchema extends VertexSchema { pSchema.setDataType(type); pSchema.setDescription(""); pSchema.setDefaultValue(""); - - Map<String,String> propAnnotations = new HashMap<String,String>(); + + Map<String, String> propAnnotations = new HashMap<String, String>(); propAnnotations.put("indexed", indexed); propAnnotations.put("searchable", "false"); propAnnotations.put("source_of_truth_type", "AAI"); pSchema.setAnnotations(propAnnotations); - + FromJsonPropertySchema propSchema = new FromJsonPropertySchema(); propSchema.fromJson(pSchema, true, null); diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java index 78ae6a6d..637bbfe4 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json; import java.io.BufferedOutputStream; @@ -50,13 +51,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; - public class JsonSchemaProvider implements SchemaProvider { // Logger logger = LoggerFactory.getInstance().getLogger(JsonSchemaProvider.class.getName()); Logger logger = LoggerFactory.getInstance().getLogger(SchemaProvider.class); private JsonSchemaProviderConfig config; - private Map<String,SchemaInstance> schemaCache = new ConcurrentHashMap<>(); + private Map<String, SchemaInstance> schemaCache = new ConcurrentHashMap<>(); private RestTemplate restTemplate = null; public JsonSchemaProvider(JsonSchemaProviderConfig config) { @@ -140,7 +140,6 @@ public class JsonSchemaProvider implements SchemaProvider { return; } - String url = config.getSchemaServiceBaseUrl() + "/" + version; HttpHeaders headers = new HttpHeaders(); @@ -148,30 +147,28 @@ public class JsonSchemaProvider implements SchemaProvider { headers.put("X-TransactionId", Arrays.asList(java.util.UUID.randomUUID().toString())); headers.setAccept(Arrays.asList(org.springframework.http.MediaType.APPLICATION_OCTET_STREAM)); - HttpEntity <String> entity = new HttpEntity<>(headers); + HttpEntity<String> entity = new HttpEntity<>(headers); ResponseEntity<byte[]> response = restTemplate.exchange(url, HttpMethod.GET, entity, byte[].class); - if (response.getStatusCodeValue() == HttpStatus.NOT_FOUND.value()) { logger.warn(SchemaProviderMsgs.SCHEMA_LOAD_ERROR, "version " + version + " not found"); throw new SchemaProviderException("Schema version " + version + " not found"); - } - else if (response.getStatusCodeValue() != HttpStatus.OK.value()) { - logger.error(SchemaProviderMsgs.SCHEMA_LOAD_ERROR, "failed to load version " + version + ": " + response.getBody()); + } else if (response.getStatusCodeValue() != HttpStatus.OK.value()) { + logger.error(SchemaProviderMsgs.SCHEMA_LOAD_ERROR, + "failed to load version " + version + ": " + response.getBody()); throw new SchemaProviderException("Error getting schema version " + version + ":" + response.getBody()); } try { SchemaServiceResponse resp = SchemaServiceResponse.fromJson(unzipAndGetJSONString(response.getBody())); loadSchema(resp.getData().toJson(), version); - } - catch (Exception ex) { + } catch (Exception ex) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); ex.printStackTrace(printWriter); - logger.error(SchemaProviderMsgs.SCHEMA_LOAD_ERROR, "failed to load version " + version + ": " - + response.getBody() + "\n" + writer.toString()); + logger.error(SchemaProviderMsgs.SCHEMA_LOAD_ERROR, + "failed to load version " + version + ": " + response.getBody() + "\n" + writer.toString()); throw new SchemaProviderException("Error loading schema version " + version + ":" + ex.getMessage()); } @@ -181,14 +178,15 @@ public class JsonSchemaProvider implements SchemaProvider { static final int BUFFER = 512; static final long TOOBIG = 0x6400000; // Max size of unzipped data, 100MB - static final int TOOMANY = 1024; // Max number of files + static final int TOOMANY = 1024; // Max number of files protected String unzipAndGetJSONString(byte[] inputData) throws java.io.IOException { ZipEntry entry; String result = ""; int entries = 0; long total = 0; - try (ByteArrayInputStream bis = new ByteArrayInputStream(inputData); ZipInputStream zis = new ZipInputStream(bis)) { + try (ByteArrayInputStream bis = new ByteArrayInputStream(inputData); + ZipInputStream zis = new ZipInputStream(bis)) { while ((entry = zis.getNextEntry()) != null) { int count; byte[] data = new byte[BUFFER]; @@ -218,7 +216,7 @@ public class JsonSchemaProvider implements SchemaProvider { } private SchemaInstance getSchemaVersion(String version) throws SchemaProviderException { - // TODO: For now, we are only supporting a single version of the schema. Load that + // TODO: For now, we are only supporting a single version of the schema. Load that // version regardless of what the client asks for. String versionToLoad = getLatestSchemaVersion(); SchemaInstance inst = schemaCache.get(versionToLoad); @@ -236,7 +234,7 @@ public class JsonSchemaProvider implements SchemaProvider { @Override public Map<String, VertexSchema> getVertexMap(String schemaVersion) throws SchemaProviderException { - return getSchemaVersion(schemaVersion).getVertexMap(); + return getSchemaVersion(schemaVersion).getVertexMap(); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProviderConfig.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProviderConfig.java index 3a235f63..b5d85d82 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProviderConfig.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProviderConfig.java @@ -18,40 +18,44 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaif.json; +package org.onap.aai.schemaif.json; public class JsonSchemaProviderConfig { - + private String schemaServiceBaseUrl; private String schemaServiceCertFile; private String schemaServiceCertPwd; private String serviceName; - + public String getSchemaServiceBaseUrl() { return schemaServiceBaseUrl; } + public void setSchemaServiceBaseUrl(String schemaServiceBaseUrl) { this.schemaServiceBaseUrl = schemaServiceBaseUrl; } - + public String getSchemaServiceCertFile() { return schemaServiceCertFile; } + public void setSchemaServiceCertFile(String schemaServiceCertFile) { this.schemaServiceCertFile = schemaServiceCertFile; } - + public String getSchemaServiceCertPwd() { return schemaServiceCertPwd; } + public void setSchemaServiceCertPwd(String schemaServiceCertPwd) { this.schemaServiceCertPwd = schemaServiceCertPwd; } - + public String getServiceName() { return serviceName; } + public void setServiceName(String serviceName) { this.serviceName = serviceName; } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaInstance.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaInstance.java index 77a1c56b..cfd93862 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaInstance.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaInstance.java @@ -33,49 +33,48 @@ import org.onap.aai.schemaif.definitions.VertexSchema; public class SchemaInstance { // vertex-name -> vertex-schema private Map<String, VertexSchema> vertexMap = new HashMap<>(); - + // source:target:type -> edge-schema private Map<String, EdgeSchema> edgeKeyMap = new HashMap<>(); - + // source:target -> edge-schema private Map<String, Set<EdgeSchema>> edgeSourceTargetMap = new HashMap<>(); - + // vertex-name -> edge-schema private Map<String, Set<EdgeSchema>> vertexEdgeMap = new HashMap<>(); - + public VertexSchema getVertexSchema(String vertexName) { return vertexMap.get(vertexName.toLowerCase()); } - + public EdgeSchema getEdgeSchema(String source, String target, String type) { return edgeKeyMap.get(generateEdgeKey(source, target, type)); } - + public Set<EdgeSchema> getEdgeSchemas(String source, String target) { return edgeSourceTargetMap.get(source.toLowerCase() + ":" + target.toLowerCase()); } - + public Set<EdgeSchema> getEdgeSchema(String vertexName) { return vertexEdgeMap.get(vertexName.toLowerCase()); } - + public void addVertex(VertexSchema v) { vertexMap.put(v.getName().toLowerCase(), v); } - + public void addEdge(EdgeSchema e) throws SchemaProviderException { - if (e.getSource().equals(FromJsonEdgeSchema.WILDCARD_CHAR) || - e.getTarget().equals(FromJsonEdgeSchema.WILDCARD_CHAR)) { + if (e.getSource().equals(FromJsonEdgeSchema.WILDCARD_CHAR) + || e.getTarget().equals(FromJsonEdgeSchema.WILDCARD_CHAR)) { // Handle wildcard edges for (VertexSchema vertex : vertexMap.values()) { addWildcardEdge(e, vertex); } - } - else { + } else { addEdgeInternal(e); } } - + private void addWildcardEdge(EdgeSchema e, VertexSchema vertex) throws SchemaProviderException { FromJsonEdgeSchema newEdge = new FromJsonEdgeSchema(e); newEdge.replaceWildcard(vertex.getName()); @@ -84,38 +83,38 @@ public class SchemaInstance { private void addEdgeInternal(EdgeSchema e) { edgeKeyMap.put(generateEdgeKey(e.getSource(), e.getTarget(), e.getName()), e); - + Set<EdgeSchema> edgeListSource = vertexEdgeMap.get(e.getSource().toLowerCase()); Set<EdgeSchema> edgeListTarget = vertexEdgeMap.get(e.getTarget().toLowerCase()); - + if (edgeListSource == null) { edgeListSource = new HashSet<EdgeSchema>(); } if (edgeListTarget == null) { edgeListTarget = new HashSet<EdgeSchema>(); } - + edgeListSource.add(e); edgeListTarget.add(e); vertexEdgeMap.put(e.getSource().toLowerCase(), edgeListSource); vertexEdgeMap.put(e.getTarget().toLowerCase(), edgeListTarget); - + String sourceTargetKey = e.getSource().toLowerCase() + ":" + e.getTarget().toLowerCase(); Set<EdgeSchema> edgeList = edgeSourceTargetMap.get(sourceTargetKey); if (edgeList == null) { edgeList = new HashSet<EdgeSchema>(); } - + edgeList.add(e); edgeSourceTargetMap.put(sourceTargetKey, edgeList); } - + private String generateEdgeKey(String source, String target, String type) { String key = source + ":" + target + ":" + type; return key.toLowerCase(); } public Map<String, VertexSchema> getVertexMap() { - return vertexMap; + return vertexMap; } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java index 0bc1760b..c5baf00a 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java @@ -18,11 +18,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.SerializedName; + import org.onap.aai.schemaif.SchemaProviderException; import org.onap.aai.schemaif.json.definitions.JsonSchema; diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SecureClientHttpRequestFactory.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SecureClientHttpRequestFactory.java index 5be74c39..3f17c9be 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SecureClientHttpRequestFactory.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SecureClientHttpRequestFactory.java @@ -21,7 +21,6 @@ package org.onap.aai.schemaif.json; - import java.io.FileInputStream; import java.io.IOException; import java.net.HttpURLConnection; @@ -38,7 +37,6 @@ import javax.net.ssl.X509TrustManager; import org.springframework.http.client.SimpleClientHttpRequestFactory; - public class SecureClientHttpRequestFactory extends SimpleClientHttpRequestFactory { private static final String SSL_PROTOCOL = "TLS"; @@ -46,18 +44,15 @@ public class SecureClientHttpRequestFactory extends SimpleClientHttpRequestFacto private static final String KEYSTORE_TYPE = "PKCS12"; private JsonSchemaProviderConfig config; - - public SecureClientHttpRequestFactory(JsonSchemaProviderConfig config) { + public SecureClientHttpRequestFactory(JsonSchemaProviderConfig config) { super(); this.config = config; } @Override - protected void prepareConnection(final HttpURLConnection connection, final String httpMethod) - throws IOException { + protected void prepareConnection(final HttpURLConnection connection, final String httpMethod) throws IOException { if (connection instanceof HttpsURLConnection) { - ((HttpsURLConnection) connection) - .setSSLSocketFactory(getSSLContext().getSocketFactory()); + ((HttpsURLConnection) connection).setSSLSocketFactory(getSSLContext().getSocketFactory()); ((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String str, SSLSession sslSession) { @@ -95,7 +90,7 @@ public class SecureClientHttpRequestFactory extends SimpleClientHttpRequestFacto KeyStore ks = KeyStore.getInstance(KEYSTORE_TYPE); char[] pwd = null; - if (config.getSchemaServiceCertPwd()!= null) { + if (config.getSchemaServiceCertPwd() != null) { pwd = config.getSchemaServiceCertPwd().toCharArray(); } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/DataTypeDefinition.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/DataTypeDefinition.java index 93c67bdc..59680538 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/DataTypeDefinition.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/DataTypeDefinition.java @@ -18,22 +18,23 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json.definitions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + import java.util.List; import org.onap.aai.schemaif.SchemaProviderException; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - public class DataTypeDefinition { private static final Gson gson = new GsonBuilder().create(); - + private String name; private String description; private List<JsonPropertySchema> properties; - + public String getName() { return name; } @@ -57,9 +58,9 @@ public class DataTypeDefinition { public void setProperties(List<JsonPropertySchema> properties) { this.properties = properties; } - + public void validate() throws SchemaProviderException { - if ( (getName() == null) || (getName().isEmpty()) ) { + if ((getName() == null) || (getName().isEmpty())) { throw new SchemaProviderException("Type definition missing a name"); } @@ -69,19 +70,18 @@ public class DataTypeDefinition { } } } - + public String toJson() { return gson.toJson(this); } - + public static DataTypeDefinition fromJson(String json) { return gson.fromJson(json, DataTypeDefinition.class); } @Override public String toString() { - return "DataTypeDefinition [name=" + name + ", description=" + description + ", properties=" - + properties + "]"; + return "DataTypeDefinition [name=" + name + ", description=" + description + ", properties=" + properties + "]"; } @Override @@ -120,6 +120,5 @@ public class DataTypeDefinition { return false; return true; } - - + } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonEdgeSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonEdgeSchema.java index ffbc54de..b75f32d5 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonEdgeSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonEdgeSchema.java @@ -18,78 +18,84 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json.definitions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import java.util.Map; import org.onap.aai.schemaif.SchemaProviderException; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - public class JsonEdgeSchema { private static final Gson gson = new GsonBuilder().create(); - + private String from; private String to; private String label; - private Map<String,String> annotations; - + private Map<String, String> annotations; + public String getFrom() { return from; } + public void setFrom(String from) { this.from = from; } - + public String getTo() { return to; } + public void setTo(String to) { this.to = to; } - + public String getLabel() { return label; } + public void setLabel(String label) { this.label = label; } - - public Map<String,String> getAnnotations() { + + public Map<String, String> getAnnotations() { return annotations; } - public void setAnnotations(Map<String,String> annotations) { + + public void setAnnotations(Map<String, String> annotations) { this.annotations = annotations; } - + public void validate() throws SchemaProviderException { - if ( (getTo() == null) || (getTo().isEmpty()) ) { + if ((getTo() == null) || (getTo().isEmpty())) { throw new SchemaProviderException("Edge definition missing 'to'"); } - - if ( (getFrom() == null) || (getFrom().isEmpty()) ) { + + if ((getFrom() == null) || (getFrom().isEmpty())) { throw new SchemaProviderException("Edge definition missing 'from'"); } - - if ( (getLabel() == null) || (getLabel().isEmpty()) ) { + + if ((getLabel() == null) || (getLabel().isEmpty())) { throw new SchemaProviderException("Edge definition missing 'label'"); } } - + public String toJson() { return gson.toJson(this); } - + public static JsonEdgeSchema fromJson(String json) { return gson.fromJson(json, JsonEdgeSchema.class); } + @Override public String toString() { - return "JsonEdgeSchema [from=" + from + ", to=" + to + ", label=" + label + ", annotations=" - + annotations + "]"; + return "JsonEdgeSchema [from=" + from + ", to=" + to + ", label=" + label + ", annotations=" + annotations + + "]"; } + @Override public int hashCode() { final int prime = 31; @@ -100,6 +106,7 @@ public class JsonEdgeSchema { result = prime * result + ((to == null) ? 0 : to.hashCode()); return result; } + @Override public boolean equals(Object obj) { if (this == obj) @@ -131,5 +138,5 @@ public class JsonEdgeSchema { return false; return true; } - + } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonPropertySchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonPropertySchema.java index b6934eb8..25cd0a84 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonPropertySchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonPropertySchema.java @@ -18,33 +18,34 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaif.json.definitions; - -import java.util.Map; -import org.onap.aai.schemaif.SchemaProviderException; +package org.onap.aai.schemaif.json.definitions; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.SerializedName; +import java.util.Map; + +import org.onap.aai.schemaif.SchemaProviderException; + public class JsonPropertySchema { private static final Gson gson = new GsonBuilder().create(); - + private String name; private Boolean required; private Boolean unique; - + @SerializedName("type") private String dataType; - + private String description; - + @SerializedName("default") private String defaultValue; - - private Map<String,String> annotations; - + + private Map<String, String> annotations; + public String getName() { return name; } @@ -76,7 +77,7 @@ public class JsonPropertySchema { public void setDataType(String dataType) { this.dataType = dataType; } - + public String getDefaultValue() { return defaultValue; } @@ -92,39 +93,38 @@ public class JsonPropertySchema { public void setDescription(String description) { this.description = description; } - - public Map<String,String> getAnnotations() { + + public Map<String, String> getAnnotations() { return annotations; } - public void setAnnotations(Map<String,String> annotations) { + public void setAnnotations(Map<String, String> annotations) { this.annotations = annotations; } public void validate() throws SchemaProviderException { - if ( (getName() == null) || (getName().isEmpty()) ) { + if ((getName() == null) || (getName().isEmpty())) { throw new SchemaProviderException(getName() + " property has no name"); } - if ( (getDataType() == null) || (getDataType().isEmpty()) ) { + if ((getDataType() == null) || (getDataType().isEmpty())) { throw new SchemaProviderException(getName() + " property has no type"); } } - public String toJson() { return gson.toJson(this); } - + public static JsonVertexSchema fromJson(String json) { return gson.fromJson(json, JsonVertexSchema.class); } @Override public String toString() { - return "JsonPropertySchema [name=" + name + ", required=" + required + ", unique=" + unique - + ", dataType=" + dataType + ", description=" + description + ", defaultValue=" - + defaultValue + ", annotations=" + annotations + "]"; + return "JsonPropertySchema [name=" + name + ", required=" + required + ", unique=" + unique + ", dataType=" + + dataType + ", description=" + description + ", defaultValue=" + defaultValue + ", annotations=" + + annotations + "]"; } @Override @@ -187,6 +187,5 @@ public class JsonPropertySchema { return false; return true; } - - + } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonSchema.java index b9cacb87..5d292bd9 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonSchema.java @@ -18,56 +18,56 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaif.json.definitions; - -import java.util.List; -import org.onap.aai.schemaif.SchemaProviderException; +package org.onap.aai.schemaif.json.definitions; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.SerializedName; +import java.util.List; + +import org.onap.aai.schemaif.SchemaProviderException; + public class JsonSchema { private static final Gson gson = new GsonBuilder().create(); @SerializedName("relationship_types") private List<JsonEdgeSchema> relationshipTypes; - + @SerializedName("node_types") private List<JsonVertexSchema> nodeTypes; - + @SerializedName("data_types") private List<DataTypeDefinition> dataTypes; - + @SerializedName("common_node_properties") private List<JsonPropertySchema> commonNodeProps; - public void setRelationshipTypes(List<JsonEdgeSchema> relationshipTypes) { - this.relationshipTypes = relationshipTypes; - } + this.relationshipTypes = relationshipTypes; + } - public void setNodeTypes(List<JsonVertexSchema> nodeTypes) { - this.nodeTypes = nodeTypes; - } + public void setNodeTypes(List<JsonVertexSchema> nodeTypes) { + this.nodeTypes = nodeTypes; + } - public void setDataTypes(List<DataTypeDefinition> dataTypes) { - this.dataTypes = dataTypes; - } + public void setDataTypes(List<DataTypeDefinition> dataTypes) { + this.dataTypes = dataTypes; + } - public List<JsonEdgeSchema> getRelationshipTypes() { + public List<JsonEdgeSchema> getRelationshipTypes() { return relationshipTypes; } - + public List<JsonVertexSchema> getNodeTypes() { return nodeTypes; } - + public List<DataTypeDefinition> getDataTypes() { return dataTypes; } - + public List<JsonPropertySchema> getCommonProperties() { return commonNodeProps; } @@ -75,21 +75,21 @@ public class JsonSchema { public void setCommonProperties(List<JsonPropertySchema> properties) { this.commonNodeProps = properties; } - + public void validate() throws SchemaProviderException { if (getNodeTypes() != null) { for (JsonVertexSchema vertexSchema : getNodeTypes()) { vertexSchema.validate(); } } - + // Validate edges if (getRelationshipTypes() != null) { for (JsonEdgeSchema edgeSchema : getRelationshipTypes()) { edgeSchema.validate(); } } - + // Validate data types if (getDataTypes() != null) { for (DataTypeDefinition typeSchema : getDataTypes()) { @@ -97,7 +97,7 @@ public class JsonSchema { } } } - + public String toJson() { return gson.toJson(this); } @@ -107,7 +107,7 @@ public class JsonSchema { if (json == null || json.isEmpty()) { throw new SchemaProviderException("Empty schema definition"); } - + return gson.fromJson(json, JsonSchema.class); } catch (Exception ex) { throw new SchemaProviderException("Invalid json: " + ex.getMessage()); @@ -116,8 +116,8 @@ public class JsonSchema { @Override public String toString() { - return "JsonSchema [relationshipTypes=" + relationshipTypes + ", nodeTypes=" + nodeTypes - + ", dataTypes=" + dataTypes + ", commonNodeProps=" + commonNodeProps + "]"; + return "JsonSchema [relationshipTypes=" + relationshipTypes + ", nodeTypes=" + nodeTypes + ", dataTypes=" + + dataTypes + ", commonNodeProps=" + commonNodeProps + "]"; } @Override @@ -163,5 +163,4 @@ public class JsonSchema { return true; } - } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonVertexSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonVertexSchema.java index 87a1eac7..2fc2c802 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonVertexSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/definitions/JsonVertexSchema.java @@ -18,24 +18,25 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.json.definitions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + import java.util.List; import java.util.Map; import org.onap.aai.schemaif.SchemaProviderException; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - public class JsonVertexSchema { private static final Gson gson = new GsonBuilder().create(); - + private String name; private String description; private List<JsonPropertySchema> properties; - private Map<String,String> annotations; - + private Map<String, String> annotations; + public String getName() { return name; } @@ -59,17 +60,17 @@ public class JsonVertexSchema { public void setProperties(List<JsonPropertySchema> properties) { this.properties = properties; } - - public Map<String,String> getAnnotations() { + + public Map<String, String> getAnnotations() { return annotations; } - public void setAnnotations(Map<String,String> annotations) { + public void setAnnotations(Map<String, String> annotations) { this.annotations = annotations; } public void validate() throws SchemaProviderException { - if ( (getName() == null) || (getName().isEmpty()) ) { + if ((getName() == null) || (getName().isEmpty())) { throw new SchemaProviderException("Node definition missing a name"); } @@ -79,19 +80,19 @@ public class JsonVertexSchema { } } } - + public String toJson() { return gson.toJson(this); } - + public static JsonVertexSchema fromJson(String json) { return gson.fromJson(json, JsonVertexSchema.class); } @Override public String toString() { - return "JsonVertexSchema [name=" + name + ", description=" + description + ", properties=" - + properties + ", annotations=" + annotations + "]"; + return "JsonVertexSchema [name=" + name + ", description=" + description + ", properties=" + properties + + ", annotations=" + annotations + "]"; } @Override @@ -136,6 +137,5 @@ public class JsonVertexSchema { return false; return true; } - - + } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/EdgePropsConfiguration.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/EdgePropsConfiguration.java index bd30e77e..abe0c5cd 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/EdgePropsConfiguration.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/EdgePropsConfiguration.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; import org.springframework.beans.factory.annotation.Value; diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmEdgeSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmEdgeSchema.java index 336b6d9e..3958a620 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmEdgeSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmEdgeSchema.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; import java.util.HashMap; @@ -29,14 +30,13 @@ import org.onap.aai.schemaif.definitions.EdgeSchema; import org.onap.aai.schemaif.definitions.PropertySchema; import org.onap.aai.schemaif.definitions.types.DataType; - public class FromOxmEdgeSchema extends EdgeSchema { public void fromEdgeRule(EdgeRule edgeRule) throws SchemaProviderException { name = edgeRule.getLabel(); source = edgeRule.getFrom(); target = edgeRule.getTo(); - + switch (edgeRule.getMultiplicityRule()) { case MANY2MANY: multiplicity = Multiplicity.MANY_2_MANY; @@ -52,22 +52,22 @@ public class FromOxmEdgeSchema extends EdgeSchema { break; } - annotations = new HashMap<String,String>(); - properties = new HashMap<String,PropertySchema>(); - - // TODO: For now these are hard-coded ... should read them from a config file or something + annotations = new HashMap<String, String>(); + properties = new HashMap<String, PropertySchema>(); + + // TODO: For now these are hard-coded ... should read them from a config file or something annotations.put(EdgeProperty.CONTAINS.toString().toLowerCase(), edgeRule.getContains()); annotations.put(EdgeProperty.DELETE_OTHER_V.toString().toLowerCase(), edgeRule.getDeleteOtherV()); annotations.put(EdgeProperty.PREVENT_DELETE.toString().toLowerCase(), edgeRule.getPreventDelete()); - + FromOxmPropertySchema pSchema = new FromOxmPropertySchema(); pSchema.fromRelationship(EdgeProperty.CONTAINS.toString(), DataType.Type.STRING); properties.put(EdgeProperty.CONTAINS.toString().toLowerCase(), pSchema); - + pSchema = new FromOxmPropertySchema(); pSchema.fromRelationship(EdgeProperty.DELETE_OTHER_V.toString(), DataType.Type.STRING); properties.put(EdgeProperty.DELETE_OTHER_V.toString().toLowerCase(), pSchema); - + pSchema = new FromOxmPropertySchema(); pSchema.fromRelationship(EdgeProperty.PREVENT_DELETE.toString(), DataType.Type.STRING); properties.put(EdgeProperty.PREVENT_DELETE.toString().toLowerCase(), pSchema); diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmPropertySchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmPropertySchema.java index 2174bce2..bb9f3d8c 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmPropertySchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmPropertySchema.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; import java.util.HashMap; @@ -37,7 +38,6 @@ import org.onap.aai.schemaif.definitions.types.IntDataType; import org.onap.aai.schemaif.definitions.types.LongDataType; import org.onap.aai.schemaif.definitions.types.StringDataType; - public class FromOxmPropertySchema extends PropertySchema { // Handle vertex properties from OXM @@ -55,8 +55,7 @@ public class FromOxmPropertySchema extends PropertySchema { if (isPrimaryKeyOxm(name, dynType)) { unique = true; required = true; - } - else { + } else { required = ((XMLField) field).isRequired(); unique = false; } @@ -82,13 +81,13 @@ public class FromOxmPropertySchema extends PropertySchema { throw new SchemaProviderException("Invalid OXM property type: " + oxmType); } } - + // Check annotations - annotations = new HashMap<String,String>(); + annotations = new HashMap<String, String>(); Map<String, Object> oxmProps = mapping.getProperties(); for (Map.Entry<String, Object> entry : oxmProps.entrySet()) { if (entry.getValue() instanceof String) { - annotations.put(entry.getKey().toLowerCase(), (String)entry.getValue()); + annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue()); } } } @@ -99,8 +98,8 @@ public class FromOxmPropertySchema extends PropertySchema { required = false; defaultValue = ""; unique = false; - annotations = new HashMap<String,String>(); - + annotations = new HashMap<String, String>(); + switch (propDataType) { case STRING: dataType = new StringDataType(); @@ -118,13 +117,13 @@ public class FromOxmPropertySchema extends PropertySchema { dataType = new BooleanDataType(); break; default: - throw new SchemaProviderException("Invalid EdgeRule property type: " + propDataType); + throw new SchemaProviderException("Invalid EdgeRule property type: " + propDataType); } } - + private boolean isPrimaryKeyOxm(String propName, DynamicType dynType) { List<String> primaryKeyList = dynType.getDescriptor().getPrimaryKeyFieldNames(); - if ( (primaryKeyList == null) || (primaryKeyList.size() == 0) ) { + if ((primaryKeyList == null) || (primaryKeyList.size() == 0)) { return false; } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmVertexSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmVertexSchema.java index 6083429b..95ed2f50 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmVertexSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/FromOxmVertexSchema.java @@ -18,8 +18,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; +import com.google.common.base.CaseFormat; + import java.util.HashMap; import java.util.Map; @@ -32,13 +35,12 @@ import org.onap.aai.schemaif.SchemaProviderException; import org.onap.aai.schemaif.definitions.PropertySchema; import org.onap.aai.schemaif.definitions.VertexSchema; -import com.google.common.base.CaseFormat; - public class FromOxmVertexSchema extends VertexSchema { - public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext, HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException { + public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext, + HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException { name = vertexType; - properties = new HashMap<String,PropertySchema>(); - annotations = new HashMap<String,String>(); + properties = new HashMap<String, PropertySchema>(); + annotations = new HashMap<String, String>(); String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType); DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName); @@ -62,21 +64,21 @@ public class FromOxmVertexSchema extends VertexSchema { // Vertex isn't found in the OXM throw new SchemaProviderException("Vertex " + vertexType + " not found in OXM"); } - + // Check annotations Map<String, Object> oxmProps = modelObjectType.getDescriptor().getProperties(); for (Map.Entry<String, Object> entry : oxmProps.entrySet()) { if (entry.getValue() instanceof String) { - annotations.put(entry.getKey().toLowerCase(), (String)entry.getValue()); + annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue()); } } // Regular props for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) { if (mapping instanceof XMLAnyObjectMapping) - continue; - if(mapping instanceof XMLAnyCollectionMapping) - continue; + continue; + if (mapping instanceof XMLAnyCollectionMapping) + continue; FromOxmPropertySchema propSchema = new FromOxmPropertySchema(); propSchema.fromOxm(mapping, modelObjectType, false); properties.put(propSchema.getName().toLowerCase(), propSchema); @@ -90,6 +92,6 @@ public class FromOxmVertexSchema extends VertexSchema { propSchema.fromOxm(mapping, reservedType, true); properties.put(propSchema.getName().toLowerCase(), propSchema); } - } + } } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmEdgeRulesLoader.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmEdgeRulesLoader.java index 93508fc5..b404ccfe 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmEdgeRulesLoader.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmEdgeRulesLoader.java @@ -18,8 +18,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; +import com.google.common.collect.Multimap; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -45,8 +48,6 @@ import org.onap.aai.setup.Translator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.google.common.collect.Multimap; - @Component public class OxmEdgeRulesLoader { @@ -63,10 +64,10 @@ public class OxmEdgeRulesLoader { final static Pattern propsFilePattern = Pattern.compile(propsPrefix + "(.*)" + propsSuffix); final static Pattern propsVersionPattern = Pattern.compile("(?i)v\\d*"); - private static Logger logger = - LoggerFactory.getInstance().getLogger(OxmEdgeRulesLoader.class.getName()); + private static Logger logger = LoggerFactory.getInstance().getLogger(OxmEdgeRulesLoader.class.getName()); - private OxmEdgeRulesLoader() {} + private OxmEdgeRulesLoader() { + } /** * This constructor presents an awkward marrying of Spring bean creation and static method use. This @@ -88,7 +89,7 @@ public class OxmEdgeRulesLoader { * Finds all DB Edge Rules and Edge Properties files for all OXM models. * * @throws SchemaProviderException - * @throws SchemaProviderException + * @throws SchemaProviderException */ public static synchronized void loadModels() throws SchemaProviderException { Map<String, File> propFiles = edgePropertyFiles(edgePropsConfiguration); diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaLoader.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaLoader.java index b3708b12..84bde101 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaLoader.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaLoader.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; import java.io.IOException; @@ -61,7 +62,8 @@ public class OxmSchemaLoader { private static org.onap.aai.cl.api.Logger logger = LoggerFactory.getInstance().getLogger(OxmSchemaLoader.class.getName()); - private OxmSchemaLoader() {} + private OxmSchemaLoader() { + } /** * This constructor presents an awkward marrying of Spring bean creation and static method use. This @@ -172,24 +174,24 @@ public class OxmSchemaLoader { } xmlElementLookup.put(version, types); } - + private static void loadVertexLookupMap(String version, DynamicJAXBContext jaxbContext) { - @SuppressWarnings("rawtypes") - List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors(); - HashMap<String, VertexSchema> vertexMap = new HashMap<String, VertexSchema>(); - - for (@SuppressWarnings("rawtypes") - Descriptor desc : descriptorsList) { - try { - FromOxmVertexSchema vs = new FromOxmVertexSchema(); - vs.fromOxm(desc.getDefaultRootElement(), jaxbContext, getXmlLookupMap(version)); - vertexMap.put(vs.getName(), vs); - } catch (SchemaProviderException e) { - continue; + @SuppressWarnings("rawtypes") + List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors(); + HashMap<String, VertexSchema> vertexMap = new HashMap<String, VertexSchema>(); + + for (@SuppressWarnings("rawtypes") + Descriptor desc : descriptorsList) { + try { + FromOxmVertexSchema vs = new FromOxmVertexSchema(); + vs.fromOxm(desc.getDefaultRootElement(), jaxbContext, getXmlLookupMap(version)); + vertexMap.put(vs.getName(), vs); + } catch (SchemaProviderException e) { + continue; + } } - } - vertexLookup.put(version, vertexMap); + vertexLookup.put(version, vertexMap); } /** @@ -223,14 +225,15 @@ public class OxmSchemaLoader { return xmlElementLookup.get(version); } - public static HashMap<String, VertexSchema> getVertexLookupForVersion(String version) throws SchemaProviderException { - // If we haven't already loaded in the available OXM models, then do so now. - if (vertexLookup == null || vertexLookup.isEmpty()) { - loadModels(); - } else if (!vertexLookup.containsKey(version)) { - throw new SchemaProviderException("Error loading oxm model: " + version); - } - return vertexLookup.get(version); + public static HashMap<String, VertexSchema> getVertexLookupForVersion(String version) + throws SchemaProviderException { + // If we haven't already loaded in the available OXM models, then do so now. + if (vertexLookup == null || vertexLookup.isEmpty()) { + loadModels(); + } else if (!vertexLookup.containsKey(version)) { + throw new SchemaProviderException("Error loading oxm model: " + version); + } + return vertexLookup.get(version); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java index bced602c..c8e6bea0 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaif.oxm; import java.util.HashSet; @@ -32,7 +33,6 @@ import org.onap.aai.schemaif.SchemaProviderException; import org.onap.aai.schemaif.definitions.EdgeSchema; import org.onap.aai.schemaif.definitions.VertexSchema; - public class OxmSchemaProvider implements SchemaProvider { @Override @@ -53,9 +53,8 @@ public class OxmSchemaProvider implements SchemaProvider { try { vs.fromOxm(vertexName, jaxbContext, OxmSchemaLoader.getXmlLookupMap(schemaVersion)); - } - catch (SchemaProviderException ex) { - // Node doesn't exist in schema. Return null. + } catch (SchemaProviderException ex) { + // Node doesn't exist in schema. Return null. return null; } @@ -95,7 +94,8 @@ public class OxmSchemaProvider implements SchemaProvider { } @Override - public Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException { + public Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) + throws SchemaProviderException { RelationshipSchema relSchema = OxmEdgeRulesLoader.getSchemaForVersion(version); Set<EdgeSchema> edges = new HashSet<>(); Set<String> relTypes = relSchema.getValidRelationTypes(sourceType, targetType); @@ -112,6 +112,6 @@ public class OxmSchemaProvider implements SchemaProvider { @Override public Map<String, VertexSchema> getVertexMap(String schemaVersion) throws SchemaProviderException { - return OxmSchemaLoader.getVertexLookupForVersion(schemaVersion); + return OxmSchemaLoader.getVertexLookupForVersion(schemaVersion); } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/RelationshipSchema.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/RelationshipSchema.java index fa4fe45d..921cff33 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/RelationshipSchema.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/RelationshipSchema.java @@ -20,8 +20,11 @@ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.schemaif.oxm; +import com.google.common.collect.Multimap; + import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -38,12 +41,8 @@ import org.onap.aai.edges.EdgeRule; import org.onap.aai.schemaif.SchemaProviderException; import org.onap.aai.schemaif.SchemaProviderMsgs; -import com.google.common.collect.Multimap; - - public class RelationshipSchema { - public static final String SCHEMA_SOURCE_NODE_TYPE = "from"; public static final String SCHEMA_TARGET_NODE_TYPE = "to"; public static final String SCHEMA_RELATIONSHIP_TYPE = "label"; @@ -62,19 +61,18 @@ public class RelationshipSchema { // A map storing the list of valid edge types for a source/target pair private Map<String, Set<String>> edgeTypesForNodePair = new HashMap<>(); - - public RelationshipSchema(Multimap<String, EdgeRule> rules, String props) throws SchemaProviderException, IOException { + public RelationshipSchema(Multimap<String, EdgeRule> rules, String props) + throws SchemaProviderException, IOException { HashMap<String, String> properties = new ObjectMapper().readValue(props, HashMap.class); - // hold the true values of the edge rules by key + // hold the true values of the edge rules by key for (EdgeRule rule : rules.values()) { String nodePairKey = buildNodePairKey(rule.getFrom(), rule.getTo()); if (edgeTypesForNodePair.get(nodePairKey) == null) { Set<String> typeSet = new HashSet<String>(); typeSet.add(rule.getLabel()); edgeTypesForNodePair.put(nodePairKey, typeSet); - } - else { + } else { edgeTypesForNodePair.get(nodePairKey).add(rule.getLabel()); } @@ -138,8 +136,6 @@ public class RelationshipSchema { }); } - - public Map<String, Class<?>> lookupRelation(String key) { return this.relations.get(key); } @@ -152,7 +148,6 @@ public class RelationshipSchema { return relationTypes.containsKey(type); } - private String buildRelation(String source, String target, String relation) { return source + ":" + target + ":" + relation; } @@ -171,7 +166,6 @@ public class RelationshipSchema { return source + ":" + target; } - private Class<?> resolveClass(String type) throws SchemaProviderException, ClassNotFoundException { Class<?> clazz = Class.forName(type); validateClassTypes(clazz); @@ -185,5 +179,3 @@ public class RelationshipSchema { } } } - - |