use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method removeModel.
@Override
public void removeModel(ModelId modelId) {
try {
ModelInfo modelResource = this.getById(modelId);
if (!modelResource.getReferencedBy().isEmpty()) {
throw new ModelReferentialIntegrityException("Cannot remove model because it is referenced by other model(s)", modelResource.getReferencedBy());
}
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Item item = session.getItem(modelIdHelper.getFullPath());
item.remove();
session.save();
} catch (RepositoryException e) {
throw new FatalModelRepositoryException("Problem occured removing the model", e);
}
}
use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method addModelImage.
@Override
public void addModelImage(ModelId modelId, byte[] imageContent) {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node modelFolderNode = session.getNode(modelIdHelper.getFullPath());
Node contentNode = null;
if (modelFolderNode.hasNode("img.png")) {
Node imageNode = (Node) modelFolderNode.getNode("img.png");
contentNode = (Node) imageNode.getPrimaryItem();
} else {
Node imageNode = modelFolderNode.addNode("img.png", "nt:file");
contentNode = imageNode.addNode("jcr:content", "nt:resource");
}
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(imageContent));
contentNode.setProperty("jcr:data", binary);
session.save();
} catch (PathNotFoundException e) {
throw new ModelNotFoundException("Problem when trying to add image to model", e);
} catch (RepositoryException e) {
throw new FatalModelRepositoryException("Something severe went wrong when accessing the repository", e);
}
}
use of org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper in project vorto by eclipse.
the class JcrModelRepository method getModelContent.
@Override
public IModelContent getModelContent(ModelId modelId, ContentType contentType) {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node fileNode = (Node) folderNode.getNodes(modelId.getName() + "*").next();
Node fileItem = (Node) fileNode.getPrimaryItem();
InputStream is = fileItem.getProperty("jcr:data").getBinary().getStream();
ModelEMFResource resource = (ModelEMFResource) ModelParserFactory.getParser(fileNode.getName()).parse(is);
if (contentType == ContentType.XMI) {
return new DefaultModelContent(resource.getModel(), contentType, resource.toXMI());
} else {
return new DefaultModelContent(resource.getModel(), contentType, resource.toDSL());
}
} catch (PathNotFoundException e) {
throw new ModelNotFoundException("Could not find model with the given model id", e);
} catch (Exception e) {
throw new FatalModelRepositoryException("Something went wrong accessing the repository", e);
}
}
Aggregations