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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations