use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class DictionaryServiceImpl method stop.
@Override
public DictionaryEntity stop(String id) {
try {
LOGGER.debug("Stop dictionary {}", id);
Optional<Dictionary> optDictionary = dictionaryRepository.findById(id);
if (!optDictionary.isPresent()) {
throw new DictionaryNotFoundException(id);
}
// add deployment date
Dictionary dictionary = optDictionary.get();
dictionary.setUpdatedAt(new Date());
dictionary.setState(LifecycleState.STOPPED);
dictionary = dictionaryRepository.update(dictionary);
Map<String, String> properties = new HashMap<>();
properties.put(Event.EventProperties.DICTIONARY_ID.getValue(), id);
// And create event
eventService.create(EventType.STOP_DICTIONARY, null, properties);
// Audit
createAuditLog(Dictionary.AuditEvent.DICTIONARY_UPDATED, dictionary.getCreatedAt(), optDictionary.get(), dictionary);
return convert(dictionary);
} catch (Exception ex) {
LOGGER.error("An error occurs while trying to undeploy dictionary {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to undeploy " + id, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderServiceImpl method create.
@Override
public IdentityProviderEntity create(NewIdentityProviderEntity newIdentityProviderEntity) {
try {
LOGGER.debug("Create identity provider {}", newIdentityProviderEntity);
Optional<IdentityProvider> optIdentityProvider = identityProviderRepository.findById(IdGenerator.generate(newIdentityProviderEntity.getName()));
if (optIdentityProvider.isPresent()) {
throw new IdentityProviderAlreadyExistsException(newIdentityProviderEntity.getName());
}
IdentityProvider identityProvider = convert(newIdentityProviderEntity);
identityProvider.setOrganizationId(GraviteeContext.getCurrentOrganization());
// If provider is a social type, we must ensure required parameters
if (identityProvider.getType() == IdentityProviderType.GOOGLE || identityProvider.getType() == IdentityProviderType.GITHUB) {
checkSocialProvider(identityProvider);
}
// Set date fields
identityProvider.setCreatedAt(new Date());
identityProvider.setUpdatedAt(identityProvider.getCreatedAt());
IdentityProvider createdIdentityProvider = identityProviderRepository.create(identityProvider);
identityProviderActivationService.activateIdpOnTargets(createdIdentityProvider.getId(), new IdentityProviderActivationService.ActivationTarget(GraviteeContext.getCurrentOrganization(), IdentityProviderActivationReferenceType.ORGANIZATION));
auditService.createOrganizationAuditLog(singletonMap(IDENTITY_PROVIDER, createdIdentityProvider.getId()), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_CREATED, createdIdentityProvider.getUpdatedAt(), null, createdIdentityProvider);
return convert(createdIdentityProvider);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create identity provider {}", newIdentityProviderEntity, ex);
throw new TechnicalManagementException("An error occurs while trying to create " + newIdentityProviderEntity, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderServiceImpl method update.
@Override
public IdentityProviderEntity update(String id, UpdateIdentityProviderEntity updateIdentityProvider) {
try {
LOGGER.debug("Update identity provider {}", updateIdentityProvider);
Optional<IdentityProvider> optIdentityProvider = identityProviderRepository.findById(id);
if (!optIdentityProvider.isPresent()) {
throw new IdentityProviderNotFoundException(updateIdentityProvider.getName());
}
// TODO: Find a way to validate mapping expression
IdentityProvider identityProvider = convert(updateIdentityProvider);
final IdentityProvider idpToUpdate = optIdentityProvider.get();
identityProvider.setId(id);
identityProvider.setType(idpToUpdate.getType());
identityProvider.setCreatedAt(idpToUpdate.getCreatedAt());
identityProvider.setUpdatedAt(new Date());
identityProvider.setOrganizationId(optIdentityProvider.get().getOrganizationId());
IdentityProvider updatedIdentityProvider = identityProviderRepository.update(identityProvider);
// Audit
auditService.createOrganizationAuditLog(singletonMap(IDENTITY_PROVIDER, id), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_UPDATED, identityProvider.getUpdatedAt(), idpToUpdate, updatedIdentityProvider);
return convert(updatedIdentityProvider);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update identity provider {}", updateIdentityProvider, ex);
throw new TechnicalManagementException("An error occurs while trying to update " + updateIdentityProvider, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class TaskServiceImpl method convert.
private TaskEntity convert(UserEntity user) {
TaskEntity taskEntity = new TaskEntity();
try {
taskEntity.setType(TaskType.USER_REGISTRATION_APPROVAL);
taskEntity.setCreatedAt(user.getCreatedAt());
taskEntity.setData(user);
} catch (Exception e) {
LOGGER.error("Error converting user {} to a Task", user.getId());
throw new TechnicalManagementException("Error converting user " + user.getId() + " to a Task", e);
}
return taskEntity;
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class TaskServiceImpl method findAll.
@Override
public List<TaskEntity> findAll(String userId) {
if (userId == null) {
throw new UnauthorizedAccessException();
}
try {
// because Tasks only consists on subscriptions, we can optimize the search by only look for apis where
// the user has a SUBSCRIPTION_UPDATE permission
// search for PENDING subscriptions
Set<String> apiIds = getApisForAPermission(userId, SUBSCRIPTION.getName());
final List<TaskEntity> tasks;
if (apiIds.isEmpty()) {
tasks = new ArrayList<>();
} else {
SubscriptionQuery query = new SubscriptionQuery();
query.setStatuses(singleton(PENDING));
query.setApis(apiIds);
tasks = subscriptionService.search(query).stream().map(this::convert).collect(toList());
}
// search for PENDING user registration
final Page<UserEntity> pendingUsers = userService.search(new UserCriteria.Builder().statuses(UserStatus.PENDING).build(), new PageableImpl(1, NUMBER_OF_PENDING_USERS_TO_SEARCH));
if (pendingUsers.getContent() != null && !pendingUsers.getContent().isEmpty()) {
tasks.addAll(pendingUsers.getContent().stream().map(this::convert).collect(toList()));
}
// search for IN_REVIEW apis
apiIds = getApisForAPermission(userId, REVIEWS.getName());
if (!apiIds.isEmpty()) {
apiIds.forEach(apiId -> {
final List<Workflow> workflows = workflowService.findByReferenceAndType(API, apiId, WorkflowType.REVIEW);
if (workflows != null && !workflows.isEmpty()) {
final Workflow currentWorkflow = workflows.get(0);
if (WorkflowState.IN_REVIEW.name().equals(currentWorkflow.getState())) {
tasks.add(convert(currentWorkflow));
}
}
});
}
// search for REQUEST_FOR_CHANGES apis
apiIds = getApisForAPermission(userId, DEFINITION.getName());
if (!apiIds.isEmpty()) {
apiIds.forEach(apiId -> {
final List<Workflow> workflows = workflowService.findByReferenceAndType(API, apiId, WorkflowType.REVIEW);
if (workflows != null && !workflows.isEmpty()) {
final Workflow currentWorkflow = workflows.get(0);
if (WorkflowState.REQUEST_FOR_CHANGES.name().equals(currentWorkflow.getState())) {
tasks.add(convert(currentWorkflow));
}
}
});
}
// search for TO_BE_VALIDATED promotions
tasks.addAll(promotionTasksService.getPromotionTasks(GraviteeContext.getCurrentOrganization()));
return tasks;
} catch (TechnicalException e) {
LOGGER.error("Error retrieving user tasks {}", e.getMessage());
throw new TechnicalManagementException("Error retreiving user tasks", e);
}
}
Aggregations