use of org.eclipse.vorto.repository.core.events.AppEvent in project vorto by eclipse.
the class ModelRepository method save.
@Override
public ModelInfo save(final ModelResource modelInfo, IUserContext userContext) {
return doInSession(jcrSession -> {
org.modeshape.jcr.api.Session session = (org.modeshape.jcr.api.Session) jcrSession;
LOGGER.info("Saving " + modelInfo.toString() + " as " + modelInfo.getFileName() + " in Workspace: " + session.getWorkspace().getName());
try {
Node folderNode = createNodeForModelId(session, modelInfo.getId());
folderNode.addMixin(MIX_REFERENCEABLE);
folderNode.addMixin(VORTO_META);
folderNode.addMixin(MIX_LAST_MODIFIED);
NodeIterator nodeIt = folderNode.getNodes(FILE_NODES);
if (!nodeIt.hasNext()) {
// new node
Node fileNode = folderNode.addNode(modelInfo.getFileName(), NT_FILE);
fileNode.addMixin(VORTO_META);
fileNode.setProperty(VORTO_AUTHOR, userContext.getUsername());
fileNode.setProperty(VORTO_VISIBILITY, VISIBILITY_PRIVATE);
fileNode.addMixin(MODE_ACCESS_CONTROLLABLE);
fileNode.addMixin(MIX_LAST_MODIFIED);
Node contentNode = fileNode.addNode(JCR_CONTENT, NT_RESOURCE);
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(modelInfo.toDSL()));
Property input = contentNode.setProperty(JCR_DATA, binary);
boolean success = session.sequence("Vorto Sequencer", input, fileNode);
if (!success) {
throw new FatalModelRepositoryException("Problem indexing new node for search" + modelInfo.getId(), null);
}
} else {
// node already exists, so just update it.
Node fileNode = nodeIt.nextNode();
fileNode.addMixin(VORTO_META);
fileNode.addMixin(MIX_LAST_MODIFIED);
Node contentNode = fileNode.getNode(JCR_CONTENT);
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(modelInfo.toDSL()));
Property input = contentNode.setProperty(JCR_DATA, binary);
boolean success = session.sequence("Vorto Sequencer", input, fileNode);
if (!success) {
throw new FatalModelRepositoryException("Problem indexing new node for search" + modelInfo.getId(), null);
}
}
session.save();
LOGGER.info("Model was saved successfully");
ModelInfo createdModel = getById(modelInfo.getId());
eventPublisher.publishEvent(new AppEvent(this, createdModel, userContext, EventType.MODEL_CREATED));
return createdModel;
} catch (Exception e) {
LOGGER.error("Error checking in model", e);
throw new FatalModelRepositoryException("Problem saving model " + modelInfo.getId(), e);
}
});
}
use of org.eclipse.vorto.repository.core.events.AppEvent 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.core.events.AppEvent in project vorto by eclipse.
the class UserService method delete.
@Transactional
public void delete(final String userId) {
User userToDelete = cache.withUser(userId).getUser();
if (userToDelete != null) {
eventPublisher.publishEvent(new AppEvent(this, userId, EventType.USER_DELETED));
userRepository.delete(userToDelete);
if (userToDelete.hasEmailAddress()) {
notificationService.sendNotification(new DeleteAccountMessage(userToDelete));
}
}
}
use of org.eclipse.vorto.repository.core.events.AppEvent in project vorto by eclipse.
the class UserService method createOrUpdateTechnicalUser.
/**
* Validates and persists the given {@link User} as technical user.<br/>
* This functionality is available to all users regardless of their privileges. <br/>
* Failures in authorization may occur in a broader context, as technical users are created
* and specifically associated to a {@link org.eclipse.vorto.repository.domain.Namespace}, so the
* user performing the operation must have the right authorities to do so in context.
*
* @param technicalUser
* @return
* @throws InvalidUserException
*/
public User createOrUpdateTechnicalUser(User actor, User technicalUser) throws InvalidUserException {
// boilerplate null validation
ServiceValidationUtil.validateNulls(technicalUser);
// validates technical user
userUtil.validateNewUser(technicalUser);
// sets createdby for tech user
technicalUser.setCreatedBy(actor.getId());
// save the technical user
User result = userRepository.save(technicalUser);
if (result != null) {
eventPublisher.publishEvent(new AppEvent(this, technicalUser.getUsername(), EventType.USER_ADDED));
}
return result;
}
Aggregations