Search in sources :

Example 6 with FatalModelRepositoryException

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);
    }
}
Also used : Item(javax.jcr.Item) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) RepositoryException(javax.jcr.RepositoryException) ModelReferentialIntegrityException(org.eclipse.vorto.repository.core.ModelReferentialIntegrityException)

Example 7 with FatalModelRepositoryException

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;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) Node(javax.jcr.Node) Binary(javax.jcr.Binary) ModelReferentialIntegrityException(org.eclipse.vorto.repository.core.ModelReferentialIntegrityException) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException)

Example 8 with FatalModelRepositoryException

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);
    }
}
Also used : ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) Node(javax.jcr.Node) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) RepositoryException(javax.jcr.RepositoryException) Binary(javax.jcr.Binary) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 9 with FatalModelRepositoryException

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);
    }
}
Also used : ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) Node(javax.jcr.Node) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) PathNotFoundException(javax.jcr.PathNotFoundException) ModelReferentialIntegrityException(org.eclipse.vorto.repository.core.ModelReferentialIntegrityException) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException)

Aggregations

FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)9 RepositoryException (javax.jcr.RepositoryException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Node (javax.jcr.Node)6 PathNotFoundException (javax.jcr.PathNotFoundException)5 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)5 ModelIdHelper (org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper)5 IOException (java.io.IOException)4 ModelReferentialIntegrityException (org.eclipse.vorto.repository.core.ModelReferentialIntegrityException)4 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)4 InputStream (java.io.InputStream)3 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)3 Binary (javax.jcr.Binary)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 Item (javax.jcr.Item)1 QueryManager (javax.jcr.query.QueryManager)1 UploadModelResult (org.eclipse.vorto.repository.api.upload.UploadModelResult)1