use of io.gravitee.repository.exceptions.TechnicalException 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);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method connect.
@Override
public UserEntity connect(String userId) {
try {
LOGGER.debug("Connection of {}", userId);
Optional<User> checkUser = userRepository.findById(userId);
if (!checkUser.isPresent()) {
throw new UserNotFoundException(userId);
}
User user = checkUser.get();
User previousUser = new User(user);
// First connection: create default application for user
if (defaultApplicationForFirstConnection && user.getLastConnectionAt() == null) {
LOGGER.debug("Create a default application for {}", userId);
NewApplicationEntity defaultApp = new NewApplicationEntity();
defaultApp.setName("Default application");
defaultApp.setDescription("My default application");
applicationService.create(defaultApp, userId);
}
// Set date fields
user.setLastConnectionAt(new Date());
user.setUpdatedAt(user.getLastConnectionAt());
User updatedUser = userRepository.update(user);
auditService.createPortalAuditLog(Collections.singletonMap(USER, userId), User.AuditEvent.USER_CONNECTED, user.getUpdatedAt(), previousUser, user);
return convert(updatedUser, true);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to connect {}", userId, ex);
throw new TechnicalManagementException("An error occurs while trying to connect " + userId, ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method delete.
@Override
public void delete(final String viewId) {
if (View.ALL_ID.equals(viewId)) {
LOGGER.error("Delete the default view is forbidden");
throw new TechnicalManagementException("Delete the default view is forbidden");
}
try {
Optional<View> viewOptional = viewRepository.findById(viewId);
if (viewOptional.isPresent()) {
viewRepository.delete(viewId);
auditService.createPortalAuditLog(Collections.singletonMap(VIEW, viewId), VIEW_DELETED, new Date(), null, viewOptional.get());
// delete all reference on APIs
apiService.deleteViewFromAPIs(viewId);
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete view {}", viewId, ex);
throw new TechnicalManagementException("An error occurs while trying to delete view " + viewId, ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method create.
@Override
public List<ViewEntity> create(final List<NewViewEntity> viewEntities) {
// First we prevent the duplicate view name
final List<String> viewNames = viewEntities.stream().map(NewViewEntity::getName).collect(Collectors.toList());
final Optional<ViewEntity> optionalView = findAll().stream().filter(view -> viewNames.contains(view.getName())).findAny();
if (optionalView.isPresent()) {
throw new DuplicateViewNameException(optionalView.get().getName());
}
final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
viewEntities.forEach(viewEntity -> {
try {
View view = convert(viewEntity);
savedViews.add(convert(viewRepository.create(view)));
auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_CREATED, new Date(), null, view);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create view {}", viewEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create view " + viewEntity.getName(), ex);
}
});
return savedViews;
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method createDefaultView.
@Override
public void createDefaultView() {
View view = new View();
view.setId(View.ALL_ID);
view.setName("All");
view.setDefaultView(true);
view.setOrder(0);
view.setCreatedAt(new Date());
view.setUpdatedAt(view.getCreatedAt());
try {
viewRepository.create(view);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create view {}", view.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create view " + view.getName(), ex);
}
}
Aggregations