use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class ModelRepositoryController method getUserModels.
// ##################### Downloads ################################
@GetMapping(value = { "/mine/download" })
public void getUserModels(Principal principal, final HttpServletResponse response) {
List<ModelId> userModels = Lists.newArrayList();
User user = accountService.getUser(principal.getName());
Collection<Namespace> namespaces = null;
try {
namespaces = userNamespaceRoleService.getNamespaces(user, user);
} catch (OperationForbiddenException | DoesNotExistException e) {
LOGGER.error(e.getMessage(), e);
}
for (Namespace namespace : namespaces) {
IModelRepository modelRepo = getModelRepository(namespace.getWorkspaceId());
List<ModelInfo> modelInfos = modelRepo.search(String.format("author:%s", user.getUsername()));
List<ModelId> modelIds = modelInfos.stream().map(modelInfo -> modelInfo.getId()).collect(Collectors.toList());
userModels.addAll(modelIds);
}
LOGGER.info("Exporting information models for user - results: " + userModels.size());
sendAsZipFile(response, user.getUsername() + "-models.zip", getModelsAndDependencies(userModels));
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class PendingApprovalNotification method execute.
@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
LOGGER.debug("Executing workflow function: " + this.getClass());
User account = accountService.getUser(user.getUsername());
if (account != null) {
notificationService.sendNotification(new WorkItemPendingMessage(account, model));
}
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class DefaultUserAccountService method createNonTechnicalUser.
/**
* Creates and persists a new, non-technical user contextually to a new user signing up.<br/>
* The entity will be saved twice, so the generated ID can be used to populate the
* {@code created_by} value.<br/>
* Will fail is the user already exists or cannot be persisted for extraneous reasons.
*
* @param username
* @param provider
* @param subject
* @return
* @throws
*/
@Transactional(rollbackOn = { IllegalArgumentException.class, IllegalStateException.class, InvalidUserException.class })
public User createNonTechnicalUser(String username, String provider, String subject) throws InvalidUserException {
if (cache.withUser(username).getUser() != null) {
throw new IllegalArgumentException("User with given username already exists");
}
User saved = userRepository.save(new UserBuilder().withName(username).withAuthenticationProviderID(provider).withAuthenticationSubject(subject).build());
if (null == saved) {
throw new IllegalStateException("Could not persist new user");
}
// sets "created by" field once ID is generated and saves again
saved.setCreatedBy(saved.getId());
return userRepository.save(saved);
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class UserDto method toUser.
public User toUser() {
User user = new User();
user.setAuthenticationProviderId(getAuthenticationProvider());
user.setDateCreated(getDateCreated());
user.setEmailAddress(getEmail());
user.setLastUpdated(getLastUpdated());
user.setSubject(getSubject());
user.setTechnicalUser(isTechnicalUser());
user.setUsername(getUsername());
user.setAckOfTermsAndCondTimestamp(Timestamp.from(Instant.now()));
return user;
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class UserRepositoryRoleService method setSysadmin.
/**
* Sets a user as sysadmin.
*
* @param username
* @return
*/
@Transactional
public void setSysadmin(String username) {
User user = cache.withUser(username).getUser();
if (user == null) {
throw new IllegalArgumentException("User is null");
}
if (isSysadmin(user)) {
return;
}
updateOrInsertSysadminRole(user);
}
Aggregations