use of org.eclipse.vorto.repository.core.impl.parser.LocalModelWorkspace in project vorto by eclipse.
the class AbstractModelImporter method parseDSL.
protected ModelResource parseDSL(String fileName, byte[] content, Collection<FileContent> fileReferences) {
IModelParser modelParser = modelParserFactory.getParser(fileName);
modelParser.setWorkspace(new LocalModelWorkspace(modelRepoFactory, fileReferences));
modelParser.enableValidation();
return (ModelResource) modelParser.parse(new ByteArrayInputStream(content));
}
use of org.eclipse.vorto.repository.core.impl.parser.LocalModelWorkspace 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.LocalModelWorkspace 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");
}
}
Aggregations