use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method create.
@Override
public List<TagEntity> create(final List<NewTagEntity> tagEntities) {
// First we prevent the duplicate tag name
final List<String> tagNames = tagEntities.stream().map(NewTagEntity::getName).collect(Collectors.toList());
final Optional<TagEntity> optionalTag = findAll().stream().filter(tag -> tagNames.contains(tag.getName())).findAny();
if (optionalTag.isPresent()) {
throw new DuplicateTagNameException(optionalTag.get().getName());
}
final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
tagEntities.forEach(tagEntity -> {
try {
Tag tag = convert(tagEntity);
savedTags.add(convert(tagRepository.create(tag)));
auditService.createPortalAuditLog(Collections.singletonMap(TAG, tag.getId()), TAG_CREATED, new Date(), null, tag);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create tag {}", tagEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create tag " + tagEntity.getName(), ex);
}
});
return savedTags;
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method create.
@Override
public List<TenantEntity> create(final List<NewTenantEntity> tenantEntities) {
// First we prevent the duplicate tenant name
final List<String> tenantNames = tenantEntities.stream().map(NewTenantEntity::getName).collect(Collectors.toList());
final Optional<TenantEntity> optionalTenant = findAll().stream().filter(tenant -> tenantNames.contains(tenant.getName())).findAny();
if (optionalTenant.isPresent()) {
throw new DuplicateTenantNameException(optionalTenant.get().getName());
}
final List<TenantEntity> savedTenants = new ArrayList<>(tenantEntities.size());
tenantEntities.forEach(tenantEntity -> {
try {
Tenant tenant = convert(tenantEntity);
savedTenants.add(convert(tenantRepository.create(tenant)));
auditService.createPortalAuditLog(Collections.singletonMap(TENANT, tenant.getId()), TENANT_CREATED, new Date(), null, tenant);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create tenant {}", tenantEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create tenant " + tenantEntity.getName(), ex);
}
});
return savedTenants;
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findAll.
@Override
public Set<UserEntity> findAll(boolean loadRoles) {
try {
LOGGER.debug("Find all users");
Set<User> users = userRepository.findAll();
return users.stream().map(u -> convert(u, loadRoles)).collect(Collectors.toSet());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find all users", ex);
throw new TechnicalManagementException("An error occurs while trying to find all users", ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findByUsername.
@Override
public UserEntity findByUsername(String username, boolean loadRoles) {
try {
LOGGER.debug("Find user by name: {}", username);
Optional<User> optionalUser = userRepository.findByUsername(username);
if (optionalUser.isPresent()) {
return convert(optionalUser.get(), loadRoles);
}
// should never happen
throw new UserNotFoundException(username);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find user using its username {}", username, ex);
throw new TechnicalManagementException("An error occurs while trying to find user using its username " + username, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method update.
@Override
public UserEntity update(UpdateUserEntity updateUserEntity) {
try {
LOGGER.debug("Updating {}", updateUserEntity);
Optional<User> checkUser = userRepository.findByUsername(updateUserEntity.getUsername());
if (!checkUser.isPresent()) {
throw new UserNotFoundException(updateUserEntity.getUsername());
}
User user = checkUser.get();
User previousUser = new User(user);
// Set date fields
user.setUpdatedAt(new Date());
// Set variant fields
user.setPicture(updateUserEntity.getPicture());
user.setFirstname(updateUserEntity.getFirstname());
user.setLastname(updateUserEntity.getLastname());
User updatedUser = userRepository.update(user);
auditService.createPortalAuditLog(Collections.singletonMap(USER, user.getUsername()), User.AuditEvent.USER_UPDATED, user.getUpdatedAt(), previousUser, user);
return convert(updatedUser, true);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update {}", updateUserEntity, ex);
throw new TechnicalManagementException("An error occurs while trying update " + updateUserEntity, ex);
}
}
Aggregations