use of io.adminshell.aas.v3.dataformat.Deserializer in project FAAAST-Service by FraunhoferIOSB.
the class AASEnvironmentFactory method guessDeserializerAndTryToParse.
private AssetAdministrationShellEnvironment guessDeserializerAndTryToParse(String envFilePath, String env) {
Deserializer approxDeserializer = null;
String fileEnding = envFilePath.split("\\.")[1];
if (!envFilePath.equalsIgnoreCase(Application.DEFAULT_AASENV_PATH)) {
LOGGER.debug("Looking for Deserializer for file ending '" + fileEnding + "'");
approxDeserializer = deserializer.getOrDefault(deserializer.keySet().stream().filter(x -> x.equalsIgnoreCase(fileEnding)).findFirst().orElseGet(null), null);
}
if (approxDeserializer != null) {
try {
LOGGER.debug("Try resolving with '" + approxDeserializer.getClass().getSimpleName() + "'");
AssetAdministrationShellEnvironment environment = approxDeserializer.read(env);
// but returns an empty AASEnvironment
if (!Objects.equals(environment, new DefaultAssetAdministrationShellEnvironment())) {
return environment;
}
} catch (Exception ignored) {
LOGGER.debug("Resolving with '" + approxDeserializer.getClass().getSimpleName() + "' was not successfull. Try other Deserializers.");
}
}
return null;
}
use of io.adminshell.aas.v3.dataformat.Deserializer in project FAAAST-Service by FraunhoferIOSB.
the class AASEnvironmentFactory method getAASEnvironment.
/**
* Parses the content in the given file path to an
* {@link io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment}.
* Supported formats of the file:
* <p>
* <ul>
* <li>json
* <li>aml
* <li>xml
* <li>opcua nodeset (also as .xml)
* <li>rdf
* <li>json-ld
* </ul>
* The method retrieves the right deserializer and parses the content to an
* {@link io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment}.
*
* @param envFilePath of the file which contains the Asset Administration Shell Environment
* @return the parsed Asset Administration Shell Environment object
* @throws Exception
*/
public AssetAdministrationShellEnvironment getAASEnvironment(String envFilePath) throws Exception {
initDeserializer();
String env = getFileContent(envFilePath);
LOGGER.info("Try to resolve Asset Administration Shell Environment from file '" + envFilePath + "'");
AssetAdministrationShellEnvironment parsedEnvironment = guessDeserializerAndTryToParse(envFilePath, env);
if (parsedEnvironment != null) {
return parsedEnvironment;
}
// else try every deserializer
String formats = "";
for (Map.Entry<String, Deserializer> deserializer : deserializer.entrySet()) {
try {
LOGGER.debug("Try resolving with '" + deserializer.getValue().getClass().getSimpleName() + "'");
formats += "\t" + deserializer.getKey() + "\n";
return deserializer.getValue().read(env);
} catch (DeserializationException ex) {
}
}
throw new Exception("Could not deserialize content to an Asset Administration Shell Environment. Used File: " + envFilePath + "\nSupported Formats:\n" + formats);
}
use of io.adminshell.aas.v3.dataformat.Deserializer in project FAAAST-Service by FraunhoferIOSB.
the class AASEnvironmentFactory method initDeserializer.
private void initDeserializer() {
// TODO: AASX Deserializer seems to be a little bit different since it needs an input in constructor
deserializer = new HashMap<>();
deserializer.put("JSON", new JsonDeserializer());
deserializer.put("AML", new AmlDeserializer());
deserializer.put("XML", new XmlDeserializer());
deserializer.put("I4AAS/OPC UA Nodeset", new I4AASDeserializer());
deserializer.put("RDF", new io.adminshell.aas.v3.dataformat.rdf.Serializer());
deserializer.put("JSON-LD", new io.adminshell.aas.v3.dataformat.jsonld.Serializer());
}
use of io.adminshell.aas.v3.dataformat.Deserializer in project FAAAST-Service by FraunhoferIOSB.
the class StarterTest method testAASEnvironment.
private void testAASEnvironment(String filePath, Deserializer deserializer) throws Exception, FileNotFoundException, DeserializationException {
AssetAdministrationShellEnvironment expected = deserializer.read(new File(filePath));
AssetAdministrationShellEnvironment actual = environmentFactory.getAASEnvironment(filePath);
Assert.assertEquals(expected, actual);
}
Aggregations