use of org.eclipse.vorto.repository.core.FatalModelRepositoryException 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.FatalModelRepositoryException in project vorto by eclipse.
the class JcrModelRepository method checkin.
@Override
public ModelInfo checkin(String handleId, String author) {
StorageItem uploadedItem = this.uploadStorage.get(handleId);
if (uploadedItem == null) {
throw new IllegalArgumentException("No model found for handleId '" + handleId + "'");
}
final ModelInfo resource = ModelParserFactory.getParser(handleId).parse(new ByteArrayInputStream((byte[]) uploadedItem.getValue()));
try {
Node folderNode = createNodeForModelId(resource.getId());
Node fileNode = folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").hasNext() ? folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").nextNode() : null;
if (fileNode == null) {
fileNode = folderNode.addNode(resource.getId().getName() + resource.getType().getExtension(), "nt:file");
fileNode.addMixin("vorto:meta");
fileNode.addMixin("mix:referenceable");
fileNode.setProperty("vorto:author", author);
Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream((byte[]) uploadedItem.getValue()));
contentNode.setProperty("jcr:data", binary);
} else {
Node contentNode = fileNode.getNode("jcr:content");
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream((byte[]) uploadedItem.getValue()));
contentNode.setProperty("jcr:data", binary);
}
session.save();
logger.info("Checkin successful");
this.uploadStorage.remove(handleId);
// Email Notification
notifyWatchers(resource, author);
} catch (Exception e) {
logger.error("Error checking in model", e);
throw new FatalModelRepositoryException("Problem checking in uploaded model" + resource.getId(), e);
}
return resource;
}
use of org.eclipse.vorto.repository.core.FatalModelRepositoryException 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.FatalModelRepositoryException 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