use of org.onap.aai.schemaif.definitions.PropertySchema in project aai-aai-common by onap.
the class FromOxmVertexSchema method fromOxm.
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>();
String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType);
DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName);
if (modelObjectType == null) {
// Try to lookup by xml root element by exact match
modelObjectType = xmlElementLookup.get(vertexType);
}
if (modelObjectType == null) {
// Try to lookup by xml root element by lowercase
modelObjectType = xmlElementLookup.get(vertexType.toLowerCase());
}
if (modelObjectType == null) {
// Direct lookup as java-type name
modelObjectType = jaxbContext.getDynamicType(vertexType);
}
if (modelObjectType == null) {
// 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());
}
}
// Regular props
for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) {
if (mapping instanceof XMLAnyObjectMapping)
continue;
if (mapping instanceof XMLAnyCollectionMapping)
continue;
FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
propSchema.fromOxm(mapping, modelObjectType, false);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
// Reserved Props
final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) {
if (mapping.isAbstractDirectMapping()) {
FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
propSchema.fromOxm(mapping, reservedType, true);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
}
}
use of org.onap.aai.schemaif.definitions.PropertySchema in project aai-aai-common by onap.
the class JsonSchemaProviderTest method testJsonSchemaComplexAttribute.
@Test
public void testJsonSchemaComplexAttribute() {
try {
String testSchema = readFile("src/test/resources/json/jsonSchema.json");
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
VertexSchema vertSchema = schemaProvider.getVertexSchema("org.onap.resource.extContrailCP", schemaProvider.getLatestSchemaVersion());
System.out.println(vertSchema.toString());
System.out.println("\n\nSize: " + vertSchema.getPropertySchemaList().size());
System.out.println(vertSchema.getPropertySchemaList());
assertEquals(22, vertSchema.getPropertySchemaList().size());
// Validate property schema
PropertySchema propSchema = vertSchema.getPropertySchema("exCP_naming");
assertEquals(0, propSchema.getDataType().getType().compareTo(Type.COMPLEX));
ComplexDataType complexType = (ComplexDataType) propSchema.getDataType();
List<PropertySchema> complexProps = complexType.getSubProperties();
assertEquals(4, complexProps.size());
PropertySchema subProp = null;
for (PropertySchema p : complexProps) {
if (p.getName().equals("naming_policy")) {
subProp = p;
}
}
assertNotNull(subProp);
assertFalse(subProp.isRequired());
assertEquals(0, subProp.getDataType().getType().compareTo(Type.STRING));
} catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
System.out.println(writer);
fail();
}
}
use of org.onap.aai.schemaif.definitions.PropertySchema in project aai-aai-common by onap.
the class JsonSchemaProviderTest method testJsonSchemaMapAttribute.
@Test
public void testJsonSchemaMapAttribute() {
try {
String testSchema = readFile("src/test/resources/json/jsonSchema.json");
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
VertexSchema vertSchema = schemaProvider.getVertexSchema("onap.nodes.sdwan.ManagementDomain", schemaProvider.getLatestSchemaVersion());
System.out.println(vertSchema.toString());
// Validate schema
PropertySchema propSchema = vertSchema.getPropertySchema("analyticClusters");
assertEquals(0, propSchema.getDataType().getType().compareTo(Type.MAP));
MapDataType mapType = (MapDataType) propSchema.getDataType();
assertEquals(0, mapType.getMapType().getType().compareTo(Type.STRING));
} catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
System.out.println(writer);
fail();
}
}
use of org.onap.aai.schemaif.definitions.PropertySchema in project aai-aai-common by onap.
the class FromJsonPropertySchema method resolveComplexDataType.
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))) {
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);
}
use of org.onap.aai.schemaif.definitions.PropertySchema in project aai-aai-common by onap.
the class FromJsonVertexSchema method fromJson.
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>();
// Populate property schema
if (jsonVertex.getProperties() != null) {
for (JsonPropertySchema pSchema : jsonVertex.getProperties()) {
FromJsonPropertySchema propSchema = new FromJsonPropertySchema();
propSchema.fromJson(pSchema, false, dataTypes);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
}
// Add common properties
if (commonProps != null) {
for (JsonPropertySchema pSchema : commonProps) {
FromJsonPropertySchema propSchema = new FromJsonPropertySchema();
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
addCommonProps();
}
// Populate annotation schema
if (jsonVertex.getAnnotations() != null) {
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
// 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 (searchableVal.length() > 0) {
searchableVal.append(",");
}
searchableVal.append(pSchema.getName());
}
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());
}
if (indexedVal.length() > 0) {
annotations.put("indexedprops", indexedVal.toString());
}
}
Aggregations