Search in sources :

Example 1 with FatalModelRepositoryException

use of org.eclipse.vorto.repository.core.FatalModelRepositoryException in project vorto by eclipse.

the class ModelSearchUtil method createQueryFromExpression.

public Query createQueryFromExpression(Session session, String queryExpression) {
    try {
        QueryManager queryManager = session.getWorkspace().getQueryManager();
        String jcrStatementQuery = this.getJCRStatementQuery(queryExpression);
        if (jcrStatementQuery.equals(queryExpression)) {
            return queryManager.createQuery(jcrStatementQuery, org.modeshape.jcr.api.query.Query.FULL_TEXT_SEARCH);
        } else {
            return queryManager.createQuery(jcrStatementQuery, org.modeshape.jcr.api.query.Query.JCR_SQL2);
        }
    } catch (RepositoryException repoException) {
        throw new FatalModelRepositoryException("Could not create query from expression", repoException);
    }
}
Also used : FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) QueryManager(javax.jcr.query.QueryManager) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 2 with FatalModelRepositoryException

use of org.eclipse.vorto.repository.core.FatalModelRepositoryException in project vorto by eclipse.

the class BulkUploadHelper method uploadMultiple.

public List<UploadModelResult> uploadMultiple(byte[] content, String zipFileName, String callerId) {
    if (!isValid(zipFileName)) {
        throw new FatalModelRepositoryException("Filename/type is invalid", null);
    }
    List<UploadModelResult> invalidResult = new ArrayList<UploadModelResult>();
    List<UploadModelResult> validResult = new ArrayList<UploadModelResult>();
    Set<ModelInfo> parsedModels = new HashSet<>();
    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(content));
    ZipEntry entry = null;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            if (!entry.isDirectory()) {
                final String fileName = entry.getName();
                if (ModelParserFactory.hasParserFor(fileName)) {
                    try {
                        parsedModels.add(ModelParserFactory.getParser(fileName).parse(new ByteArrayInputStream(copyStream(zis, entry))));
                    } catch (ValidationException grammarProblem) {
                        invalidResult.add(UploadModelResultFactory.create(grammarProblem));
                    }
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    try {
        List<IModelValidator> bulkUploadValidators = constructBulkUploadValidators(parsedModels);
        for (ModelInfo modelResource : parsedModels) {
            try {
                for (IModelValidator validator : bulkUploadValidators) {
                    validator.validate(modelResource, InvocationContext.create(callerId));
                }
                UploadModelResult result = UploadModelResult.valid(modelResource);
                if (!invalidResult.contains(result)) {
                    validResult.add(result);
                }
            } catch (ValidationException validationException) {
                invalidResult.add(UploadModelResultFactory.create(validationException));
            }
        }
        if (invalidResult.isEmpty()) {
            DependencyManager dm = new DependencyManager(parsedModels);
            return safelyUpload(dm.getSorted());
        } else {
            List<UploadModelResult> completeResult = new ArrayList<>();
            completeResult.addAll(invalidResult);
            completeResult.addAll(validResult);
            return completeResult;
        }
    } catch (Exception e) {
        throw new FatalModelRepositoryException("Invalid zip file", e);
    }
}
Also used : UploadModelResult(org.eclipse.vorto.repository.api.upload.UploadModelResult) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) IModelValidator(org.eclipse.vorto.repository.core.impl.validation.IModelValidator) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) HashSet(java.util.HashSet)

Example 3 with FatalModelRepositoryException

use of org.eclipse.vorto.repository.core.FatalModelRepositoryException 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;
}
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) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) IOException(java.io.IOException)

Example 4 with FatalModelRepositoryException

use of org.eclipse.vorto.repository.core.FatalModelRepositoryException 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);
    }
}
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) 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 5 with FatalModelRepositoryException

use of org.eclipse.vorto.repository.core.FatalModelRepositoryException in project vorto by eclipse.

the class JcrModelRepository method updateMeta.

@Override
public ModelInfo updateMeta(ModelInfo model) {
    try {
        Node folderNode = createNodeForModelId(model.getId());
        Node fileNode = folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").hasNext() ? folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").nextNode() : null;
        fileNode.setProperty("vorto:author", model.getAuthor());
        session.save();
        return model;
    } catch (RepositoryException e) {
        throw new FatalModelRepositoryException("Problem occured removing the model", e);
    }
}
Also used : FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) Node(javax.jcr.Node) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) RepositoryException(javax.jcr.RepositoryException)

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