use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceImpl method resetToDefaultTheme.
@Override
public ThemeEntity resetToDefaultTheme(String themeId) {
try {
LOGGER.debug("Reset to default theme by ID: {}", themeId);
final ThemeEntity previousTheme = findEnabled();
themeRepository.delete(DEFAULT_THEME_ID);
auditService.createEnvironmentAuditLog(Collections.singletonMap(THEME, themeId), THEME_RESET, new Date(), previousTheme, null);
return findEnabled();
} catch (Exception ex) {
final String error = "Error while trying to reset a default theme";
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class TokenServiceImpl method revoke.
@Override
public void revoke(String tokenId) {
try {
Optional<Token> tokenOptional = tokenRepository.findById(tokenId);
if (tokenOptional.isPresent()) {
tokenRepository.delete(tokenId);
auditService.createEnvironmentAuditLog(Collections.singletonMap(TOKEN, tokenId), TOKEN_DELETED, new Date(), null, tokenOptional.get());
}
} catch (TechnicalException ex) {
final String error = "An error occurs while trying to delete token " + tokenId;
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class TokenServiceImpl method findByToken.
@Override
public Token findByToken(String token) {
try {
LOGGER.debug("Find token entity by token value");
final Optional<Token> optionalToken = tokenRepository.findAll().stream().filter(t -> passwordEncoder.matches(token, t.getToken())).findAny();
if (optionalToken.isPresent()) {
final Token t = optionalToken.get();
t.setLastUseAt(new Date());
return tokenRepository.update(t);
}
throw new IllegalStateException("Token not found");
} catch (TechnicalException ex) {
final String error = "An error occurs while trying to find token entity for a given token value";
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class WorkflowServiceImpl method create.
@Override
public Workflow create(final WorkflowReferenceType referenceType, final String referenceId, final WorkflowType type, final String user, final WorkflowState state, final String comment) {
final Workflow workflow = new Workflow();
workflow.setId(UuidString.generateRandom());
workflow.setReferenceType(referenceType.name());
workflow.setReferenceId(referenceId);
workflow.setType(type.name());
workflow.setUser(user);
workflow.setState(state.name());
workflow.setComment(comment);
workflow.setCreatedAt(new Date());
try {
return workflowRepository.create(workflow);
} catch (TechnicalException ex) {
final String message = "An error occurs while trying to create workflow of type " + workflow.getType();
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderActivationServiceImpl method deactivateIdpOnAllTargets.
@Override
public void deactivateIdpOnAllTargets(String identityProviderId) {
LOGGER.debug("Deactivate identity provider {} on all targets", identityProviderId);
try {
Set<IdentityProviderActivation> iPAsToRemove = identityProviderActivationRepository.findAllByIdentityProviderId(identityProviderId);
identityProviderActivationRepository.deleteByIdentityProviderId(identityProviderId);
for (IdentityProviderActivation ipa : iPAsToRemove) {
auditService.createAuditLog(Audit.AuditReferenceType.valueOf(ipa.getReferenceType().name()), ipa.getReferenceId(), Collections.singletonMap(Audit.AuditProperties.IDENTITY_PROVIDER, ipa.getIdentityProviderId()), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED, new Date(), ipa, null);
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to deactivate identity provider {} on all targets", identityProviderId, ex);
throw new TechnicalManagementException("An error occurs while trying to deactivate identity provider " + identityProviderId + " on all targets", ex);
}
}
Aggregations