use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method getById.
@Override
public ModelInfo getById(ModelId modelId) {
final ModelId finalModelId = getLatestModelVersionIfLatestTagIsSet(modelId);
return doInSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(finalModelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
return getModelResource(finalModelId, folderNode);
} catch (PathNotFoundException e) {
return null;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(finalModelId, e);
}
});
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method getFileContent.
@Override
public Optional<FileContent> getFileContent(ModelId modelId, Optional<String> fileName) {
return doInSession(session -> {
try {
ModelId finalModelId = getLatestModelVersionIfLatestTagIsSet(modelId);
ModelIdHelper modelIdHelper = new ModelIdHelper(finalModelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node fileNode;
if (fileName.isPresent()) {
fileNode = folderNode.getNode(fileName.get());
} else {
if (!folderNode.getNodes(FILE_NODES).hasNext()) {
throw new NotAuthorizedException(finalModelId);
}
fileNode = (Node) folderNode.getNodes(FILE_NODES).next();
}
Node fileItem = (Node) fileNode.getPrimaryItem();
InputStream is = fileItem.getProperty(JCR_DATA).getBinary().getStream();
final String fileContent = IOUtils.toString(is);
return Optional.of(new FileContent(fileNode.getName(), fileContent.getBytes()));
} catch (PathNotFoundException e) {
return Optional.empty();
} catch (IOException e) {
throw new FatalModelRepositoryException("Something went wrong accessing the repository", e);
} 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 getAttachmentsInElevatedSession.
@Override
public List<Attachment> getAttachmentsInElevatedSession(ModelId modelId, IUserContext context) {
return doInElevatedSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node modelFolderNode = session.getNode(modelIdHelper.getFullPath());
if (modelFolderNode.hasNode(ATTACHMENTS_NODE)) {
Node attachmentFolderNode = modelFolderNode.getNode(ATTACHMENTS_NODE);
List<Attachment> attachments = new ArrayList<>();
NodeIterator nodeIt = attachmentFolderNode.getNodes();
while (nodeIt.hasNext()) {
Node fileNode = (Node) nodeIt.next();
Attachment attachment = Attachment.newInstance(modelId, fileNode.getName());
if (fileNode.hasProperty(VORTO_TAGS)) {
final List<Value> tags = Arrays.asList(fileNode.getProperty(VORTO_TAGS).getValues());
attachment.setTags(tags.stream().map(ModelRepository::fromModeshapeValue).filter(Objects::nonNull).collect(Collectors.toList()));
}
attachments.add(attachment);
}
return attachments;
}
return Collections.emptyList();
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
}, context, privilegeService);
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method updatePropertyInElevatedSession.
@Override
public ModelId updatePropertyInElevatedSession(ModelId modelId, Map<String, String> properties, IUserContext context) {
return doInElevatedSession(session -> {
try {
Node folderNode = createNodeForModelId(session, modelId);
Node fileNode = folderNode.getNodes(FILE_NODES).hasNext() ? folderNode.getNodes(FILE_NODES).nextNode() : null;
for (Map.Entry<String, String> entry : properties.entrySet()) {
fileNode.setProperty(entry.getKey(), entry.getValue());
}
fileNode.addMixin(MIX_LAST_MODIFIED);
session.save();
eventPublisher.publishEvent(new AppEvent(this, getBasicInfoInElevatedSession(modelId, context), null, EventType.MODEL_UPDATED));
return modelId;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
}, context, privilegeService);
}
use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.
the class ModelRepository method getAttachments.
@Override
public List<Attachment> getAttachments(ModelId modelId) {
return doInSession(session -> {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node modelFolderNode = session.getNode(modelIdHelper.getFullPath());
if (modelFolderNode.hasNode(ATTACHMENTS_NODE)) {
Node attachmentFolderNode = modelFolderNode.getNode(ATTACHMENTS_NODE);
List<Attachment> attachments = new ArrayList<>();
NodeIterator nodeIt = attachmentFolderNode.getNodes();
while (nodeIt.hasNext()) {
Node fileNode = (Node) nodeIt.next();
Attachment attachment = Attachment.newInstance(modelId, fileNode.getName());
if (fileNode.hasProperty(VORTO_TAGS)) {
final List<Value> tags = Arrays.asList(fileNode.getProperty(VORTO_TAGS).getValues());
attachment.setTags(tags.stream().map(ModelRepository::fromModeshapeValue).filter(Objects::nonNull).collect(Collectors.toList()));
}
attachments.add(attachment);
}
return attachments;
}
return Collections.emptyList();
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
});
}
Aggregations