use of org.eclipse.vorto.repository.core.impl.parser.IModelParser 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.IModelParser in project vorto by eclipse.
the class ModelSequencer method execute.
@Override
public boolean execute(Property inputProperty, Node fileNode, Context context) throws Exception {
final Node folderNode = fileNode.getParent();
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
IModelParser parser = ModelParserFactory.instance().getParser(fileNode.getPath());
ModelInfo modelResource = parser.parse(binaryValue.getStream());
fileNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
fileNode.setProperty("vorto:type", modelResource.getType().name());
fileNode.setProperty("vorto:displayname", modelResource.getDisplayName());
fileNode.setProperty("vorto:version", modelResource.getId().getVersion());
fileNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
fileNode.setProperty("vorto:name", modelResource.getId().getName());
if (modelResource.getType() == ModelType.Mapping) {
MappingModel mappingModel = (MappingModel) ((ModelResource) modelResource).getModel();
fileNode.setProperty("vorto:targetplatform", mappingModel.getTargetPlatform());
}
folderNode.addMixin("mix:referenceable");
folderNode.addMixin("vorto:meta");
folderNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
folderNode.setProperty("vorto:type", modelResource.getType().name());
folderNode.setProperty("vorto:name", modelResource.getId().getName());
if (folderNode.hasProperty("vorto:references")) {
// first remove any previous references of the node.
folderNode.getProperty("vorto:references").remove();
folderNode.getSession().save();
}
Optional<Value[]> referencesAsValues = getReferencesAsValues(folderNode, modelResource.getReferences());
if (referencesAsValues.isPresent()) {
folderNode.setProperty("vorto:references", referencesAsValues.get());
}
return true;
}
use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class ModelRepository method getEMFResource.
@Override
public ModelResource getEMFResource(ModelId modelId) {
return doInSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
if (!folderNode.getNodes(FILE_NODES).hasNext()) {
LOGGER.warn("Folder Node :" + folderNode + " does not have any files as children. Cannot load EMF Model.");
return null;
}
Node fileNode = (Node) folderNode.getNodes(FILE_NODES).next();
Node fileItem = (Node) fileNode.getPrimaryItem();
InputStream is = fileItem.getProperty(JCR_DATA).getBinary().getStream();
IModelParser parser = modelParserFactory.getParser(fileNode.getName());
return (ModelResource) parser.parse(is);
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
});
}
use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class ModelRepository method save.
@Override
public ModelInfo save(ModelId modelId, byte[] content, String fileName, IUserContext userContext, boolean validate) {
Objects.requireNonNull(content);
Objects.requireNonNull(modelId);
IModelParser parser = modelParserFactory.getParser("model" + ModelType.fromFileName(fileName).getExtension());
if (validate) {
parser.enableValidation();
}
ModelResource modelInfo = (ModelResource) parser.parse(new ByteArrayInputStream(content));
save(modelInfo, userContext);
return modelInfo;
}
use of org.eclipse.vorto.repository.core.impl.parser.IModelParser in project vorto by eclipse.
the class ModelRepository method getModelContent.
@Override
public ModelFileContent getModelContent(ModelId modelId, boolean validate) {
return doInSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node fileNode = (Node) folderNode.getNodes(FILE_NODES).next();
Node fileItem = (Node) fileNode.getPrimaryItem();
InputStream is = fileItem.getProperty(JCR_DATA).getBinary().getStream();
final String fileContent = IOUtils.toString(is);
IModelParser parser = modelParserFactory.getParser(fileNode.getName());
ModelResource resource = (ModelResource) parser.parse(IOUtils.toInputStream(fileContent));
return new ModelFileContent(resource.getModel(), fileNode.getName(), fileContent.getBytes());
} catch (IOException e) {
throw new FatalModelRepositoryException("Something went wrong accessing the repository", e);
}
});
}
Aggregations