use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method getModelImage.
@Override
public byte[] getModelImage(ModelId modelId) {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
if (folderNode.hasNode("img.png")) {
Node imageNode = folderNode.getNode("img.png");
Node fileItem = (Node) imageNode.getPrimaryItem();
InputStream is = fileItem.getProperty("jcr:data").getBinary().getStream();
return IOUtils.toByteArray(is);
}
} catch (PathNotFoundException e) {
throw new ModelNotFoundException("Problem when trying to retrieve image for model", e);
} catch (RepositoryException e) {
throw new FatalModelRepositoryException("Something severe went wrong when accessing the repository", e);
} catch (IOException e) {
throw new FatalModelRepositoryException("Something severe went wrong when trying to read image content", e);
}
return null;
}
use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method getEMFResource.
private ModelEMFResource getEMFResource(ModelId modelId) {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node fileNode = (Node) folderNode.getNodes().next();
Node fileItem = (Node) fileNode.getPrimaryItem();
InputStream is = fileItem.getProperty("jcr:data").getBinary().getStream();
return (ModelEMFResource) ModelParserFactory.getParser(fileNode.getName()).parse(is);
} catch (Exception e) {
throw new FatalModelRepositoryException("Something went wrong accessing the repository", e);
}
}
use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class ModelSequencer method execute.
@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
ModelInfo modelResource = ModelParserFactory.getParser(outputNode.getPath()).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());
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()]));
}
return true;
}
use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method getById.
@Override
public ModelInfo getById(ModelId modelId) {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node modelFileNode = folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").nextNode();
ModelInfo modelResource = createModelResource(modelFileNode);
if (modelResource.getType() == ModelType.InformationModel) {
NodeIterator imageNodeIterator = folderNode.getNodes("img.png*");
if (imageNodeIterator.hasNext()) {
modelResource.setHasImage(true);
}
}
return modelResource;
} catch (PathNotFoundException e) {
return null;
} catch (RepositoryException e) {
throw new RuntimeException("Retrieving Content of Resource: Problem accessing repository", e);
}
}
use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method createNodeForModelId.
private Node createNodeForModelId(ModelId id) throws RepositoryException {
ModelIdHelper modelIdHelper = new ModelIdHelper(id);
StringBuilder pathBuilder = new StringBuilder();
Iterator<String> modelIdIterator = modelIdHelper.iterator();
Node rootNode = session.getRootNode();
while (modelIdIterator.hasNext()) {
String nextPathFragment = modelIdIterator.next();
pathBuilder.append(nextPathFragment).append("/");
try {
rootNode.getNode(pathBuilder.toString());
} catch (PathNotFoundException pathNotFound) {
Node addedNode = rootNode.addNode(pathBuilder.toString(), "nt:folder");
addedNode.setPrimaryType("nt:folder");
}
}
return rootNode.getNode(modelIdHelper.getFullPath().substring(1));
}
Aggregations