use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method getEMFResource.
@Override
public ModelResource getEMFResource(ModelId modelId) {
return doInSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
if (!folderNode.getNodes(FILE_NODES).hasNext()) {
LOGGER.warn("Folder Node :" + folderNode + " does not have any files as children. Cannot load EMF Model.");
return null;
}
Node fileNode = (Node) folderNode.getNodes(FILE_NODES).next();
Node fileItem = (Node) fileNode.getPrimaryItem();
InputStream is = fileItem.getProperty(JCR_DATA).getBinary().getStream();
IModelParser parser = modelParserFactory.getParser(fileNode.getName());
return (ModelResource) parser.parse(is);
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
});
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method getBasicInfo.
public ModelInfo getBasicInfo(ModelId modelId) {
return doInSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node modelFileNode = folderNode.getNodes(FILE_NODES).nextNode();
ModelInfo modelInfo = createMinimalModelInfo(modelFileNode);
setReferencesOnResource(folderNode, modelInfo);
Map<String, List<ModelInfo>> referencingModels = modelRetrievalService.getModelsReferencing(modelId);
for (Map.Entry<String, List<ModelInfo>> entry : referencingModels.entrySet()) {
for (ModelInfo referencee : entry.getValue()) {
modelInfo.getReferencedBy().add(referencee.getId());
}
}
return modelInfo;
} catch (PathNotFoundException e) {
return null;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
});
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method doAttachFileInSession.
private boolean doAttachFileInSession(ModelId modelId, FileContent fileContent, IUserContext userContext, Session session, Tag[] tags) throws RepositoryException {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node modelFolderNode = session.getNode(modelIdHelper.getFullPath());
Node attachmentFolderNode;
if (!modelFolderNode.hasNode(ATTACHMENTS_NODE)) {
attachmentFolderNode = modelFolderNode.addNode(ATTACHMENTS_NODE, NT_FOLDER);
} else {
attachmentFolderNode = modelFolderNode.getNode(ATTACHMENTS_NODE);
}
String[] tagIds = Arrays.stream(tags).filter(Objects::nonNull).map(Tag::getId).collect(Collectors.toList()).toArray(new String[tags.length]);
// purposes), removes the tag from all other attachments
if (Arrays.asList(tags).contains(TAG_DISPLAY_IMAGE)) {
NodeIterator attachments = attachmentFolderNode.getNodes();
while (attachments.hasNext()) {
Node next = attachments.nextNode();
Property attachmentTags = next.getProperty(VORTO_TAGS);
Value[] attachmentTagsValuesFiltered = Arrays.stream(attachmentTags.getValues()).filter(v -> {
try {
return !v.getString().equals(TAG_DISPLAY_IMAGE.getId());
// swallowing here
} catch (RepositoryException re) {
return false;
}
}).toArray(Value[]::new);
next.setProperty(VORTO_TAGS, attachmentTagsValuesFiltered);
}
}
Node contentNode;
if (attachmentFolderNode.hasNode(fileContent.getFileName())) {
Node attachmentNode = attachmentFolderNode.getNode(fileContent.getFileName());
attachmentNode.addMixin(VORTO_META);
attachmentNode.setProperty(VORTO_TAGS, tagIds, PropertyType.STRING);
contentNode = (Node) attachmentNode.getPrimaryItem();
} else {
Node attachmentNode = attachmentFolderNode.addNode(fileContent.getFileName(), NT_FILE);
attachmentNode.addMixin(VORTO_META);
attachmentNode.setProperty(VORTO_TAGS, tagIds, PropertyType.STRING);
contentNode = attachmentNode.addNode(JCR_CONTENT, NT_RESOURCE);
}
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(fileContent.getContent()));
contentNode.setProperty(JCR_DATA, binary);
session.save();
eventPublisher.publishEvent(new AppEvent(this, getById(modelId), userContext, EventType.MODEL_UPDATED));
return true;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method updateProperty.
private ModelId updateProperty(ModelId modelId, NodeConsumer nodeConsumer) {
return doInSession(session -> {
try {
Node folderNode = createNodeForModelId(session, modelId);
Node fileNode = folderNode.getNodes(FILE_NODES).hasNext() ? folderNode.getNodes(FILE_NODES).nextNode() : null;
nodeConsumer.accept(fileNode);
fileNode.addMixin(MIX_LAST_MODIFIED);
session.save();
eventPublisher.publishEvent(new AppEvent(this, getBasicInfo(modelId), null, EventType.MODEL_UPDATED));
return modelId;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
});
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method getBasicInfoInElevatedSession.
public ModelInfo getBasicInfoInElevatedSession(ModelId modelId, IUserContext context) {
return doInElevatedSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node modelFileNode = folderNode.getNodes(FILE_NODES).nextNode();
ModelInfo modelInfo = createMinimalModelInfo(modelFileNode, true, context);
setReferencesOnResource(folderNode, modelInfo);
Map<String, List<ModelInfo>> referencingModels = modelRetrievalService.getModelsReferencing(modelId);
for (Map.Entry<String, List<ModelInfo>> entry : referencingModels.entrySet()) {
for (ModelInfo referencee : entry.getValue()) {
modelInfo.getReferencedBy().add(referencee.getId());
}
}
return modelInfo;
} catch (PathNotFoundException e) {
return null;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
}, context, privilegeService);
}
Aggregations