use of org.onap.aai.schemaif.SchemaProviderException 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.SchemaProviderException in project aai-aai-common by onap.
the class OxmEdgeRulesLoader method loadModels.
/**
* Finds all DB Edge Rules and Edge Properties files for all OXM models.
*
* @throws SchemaProviderException
* @throws SchemaProviderException
*/
public static synchronized void loadModels() throws SchemaProviderException {
Map<String, File> propFiles = edgePropertyFiles(edgePropsConfiguration);
if (logger.isDebugEnabled()) {
logger.debug("Loading DB Edge Rules");
}
for (String version : OxmSchemaLoader.getLoadedOXMVersions()) {
try {
SchemaVersion schemaVersion = translator.getSchemaVersions().getVersions().stream().filter(s -> s.toString().equalsIgnoreCase(version)).findAny().orElse(null);
loadModel(schemaVersion, edgeIngestor, propFiles);
} catch (IOException | EdgeRuleNotFoundException e) {
throw new SchemaProviderException(e.getMessage(), e);
}
}
}
use of org.onap.aai.schemaif.SchemaProviderException in project aai-aai-common by onap.
the class OxmEdgeRulesLoader method loadModels.
/**
* Loads DB Edge Rules and Edge Properties for a given version.
*
* @throws SchemaProviderException
*/
public static synchronized void loadModels(String v) throws SchemaProviderException {
Map<String, File> propFiles = edgePropertyFiles(edgePropsConfiguration);
if (logger.isDebugEnabled()) {
logger.debug("Loading DB Edge Rules ");
}
try {
SchemaVersion schemaVersion = translator.getSchemaVersions().getVersions().stream().filter(s -> s.toString().equalsIgnoreCase(v)).findAny().orElse(null);
loadModel(schemaVersion, edgeIngestor, propFiles);
} catch (IOException | EdgeRuleNotFoundException e) {
throw new SchemaProviderException(e.getMessage());
}
}
use of org.onap.aai.schemaif.SchemaProviderException in project aai-aai-common by onap.
the class OxmSchemaLoader method getLatestVersion.
public static String getLatestVersion() throws SchemaProviderException {
// If we haven't already loaded in the available OXM models, then do so now.
if (versionContextMap == null || versionContextMap.isEmpty()) {
loadModels();
}
// If there are still no models available, then there's not much we can do...
if (versionContextMap.isEmpty()) {
throw new SchemaProviderException("No available OXM schemas to get latest version for.");
}
// Iterate over the available model versions to determine which is the most
// recent.
Integer latestVersion = null;
String latestVersionStr = null;
for (String versionKey : versionContextMap.keySet()) {
Matcher matcher = versionPattern.matcher(versionKey);
if (matcher.find()) {
int currentVersion = Integer.valueOf(matcher.group(1));
if ((latestVersion == null) || (currentVersion > latestVersion)) {
latestVersion = currentVersion;
latestVersionStr = versionKey;
}
}
}
return latestVersionStr;
}
use of org.onap.aai.schemaif.SchemaProviderException in project aai-aai-common by onap.
the class OxmSchemaProviderTest method testInvalidVertexOrEdge.
@Test
public void testInvalidVertexOrEdge() throws SchemaProviderException {
try {
OxmSchemaProvider schemaProvider = new OxmSchemaProvider();
schemaProvider.loadSchema();
VertexSchema vertSchema = schemaProvider.getVertexSchema("bad-node", schemaProvider.getLatestSchemaVersion());
assertTrue(vertSchema == null);
EdgeSchema edgeSchema = schemaProvider.getEdgeSchema("org.onap.relationships.inventory.LocatedIn", "cloud-region", "bad-node", schemaProvider.getLatestSchemaVersion());
assertTrue(edgeSchema == null);
Set<EdgeSchema> edgeSchemaList = schemaProvider.getAdjacentEdgeSchema("org.onap.nodes.bad-node", schemaProvider.getLatestSchemaVersion());
assertTrue(edgeSchemaList.isEmpty());
} catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
System.out.println(writer.toString());
assertTrue(false);
}
}
Aggregations