use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class BulkUploadHelper method parseZipFile.
private ZipParseResult parseZipFile(byte[] content) {
if (content == null) {
throw new FatalModelRepositoryException("Contents of zip file are invalid", null);
}
ZipParseResult parsingResult = new ZipParseResult();
parsingResult.invalidModels = new HashSet<>();
parsingResult.validModels = new HashSet<>();
Collection<FileContent> fileContents = getFileContentsFromZip(content);
LocalModelWorkspace workspace = new LocalModelWorkspace(modelRepoFactory, fileContents);
fileContents.forEach(fileContent -> {
try {
IModelParser parser = ModelParserFactory.instance().getParser(fileContent.getFileName());
parser.setWorkspace(workspace);
parser.enableValidation();
parsingResult.validModels.add(parser.parse(new ByteArrayInputStream(fileContent.getContent())));
} catch (ValidationException grammarProblem) {
parsingResult.invalidModels.add(ValidationReport.invalid(trytoCreateModelFromCorruptFile(fileContent.getFileName()), grammarProblem));
} catch (Exception e) {
parsingResult.invalidModels.add(ValidationReport.invalid(trytoCreateModelFromCorruptFile(fileContent.getFileName()), "File cannot be processed to a Vorto model."));
}
});
return parsingResult;
}
use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class ModelSequencerOld method execute.
@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
ModelInfo modelResource = null;
try {
IModelParser parser = ModelParserFactory.instance().getParser(outputNode.getPath());
modelResource = parser.parse(binaryValue.getStream());
outputNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
outputNode.setProperty("vorto:type", modelResource.getType().name());
outputNode.setProperty("vorto:displayname", modelResource.getDisplayName());
outputNode.setProperty("vorto:version", modelResource.getId().getVersion());
outputNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
outputNode.setProperty("vorto:name", modelResource.getId().getName());
if (outputNode.hasProperty("vorto:references")) {
// first remove any previous references of the node.
outputNode.getProperty("vorto:references").remove();
outputNode.getSession().save();
}
ModelReferencesHelper referencesHelper = new ModelReferencesHelper(modelResource.getReferences());
if (referencesHelper.hasReferences()) {
List<Value> references = new ArrayList<Value>();
for (ModelId modelId : referencesHelper.getReferences()) {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node referencedFolder = outputNode.getSession().getNode(modelIdHelper.getFullPath());
Node reference = referencedFolder.getNodes().nextNode();
references.add(context.valueFactory().createValue(reference));
}
outputNode.setProperty("vorto:references", references.toArray(new Value[references.size()]));
}
} catch (Throwable couldNotParse) {
outputNode.setProperty("vorto:description", "Erronous Model !!!!");
outputNode.setProperty("vorto:type", ModelType.create(outputNode.getPath()).name());
outputNode.setProperty("vorto:displayname", "");
outputNode.setProperty("vorto:version", "1.0.0");
outputNode.setProperty("vorto:namespace", "erronous");
outputNode.setProperty("vorto:name", outputNode.getName());
}
return true;
}
use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class ModelParserTest method testModelParsingWithDependencyPassedIn.
@Test
public void testModelParsingWithDependencyPassedIn() {
try {
FileContent file1 = new FileContent("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color.type").getInputStream()));
FileContent file2 = new FileContent("Colorlight.fbmodel", IOUtils.toByteArray(new ClassPathResource("sample_models/Colorlight.fbmodel").getInputStream()));
IModelParser parser = modelParserFactory.getParser("ColorLightIM.infomodel");
parser.setWorkspace(new LocalModelWorkspace(repositoryFactory, Arrays.asList(file1, file2)));
parser.enableValidation();
ModelInfo modelInfo = parser.parse(new ClassPathResource("sample_models/ColorLightIM.infomodel").getInputStream());
assertTrue(modelInfo != null);
assertEquals("com.mycompany", modelInfo.getId().getNamespace());
assertEquals("ColorLightIM", modelInfo.getId().getName());
assertEquals("1.0.0", modelInfo.getId().getVersion());
} catch (ValidationException e) {
fail("There should be no exception");
} catch (IOException e) {
fail("Not able to load test file");
}
}
use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class ModelParserTest method testModelWithInvalidReference.
@Test(expected = ValidationException.class)
public void testModelWithInvalidReference() throws IOException {
IModelParser parser = modelParserFactory.getParser("InfoModelWithoutNamespace.infomodel");
parser.enableValidation();
parser.parse(new ClassPathResource("sample_models/InfoModelWithoutNamespace.infomodel").getInputStream());
}
Aggregations