Search in sources :

Example 16 with TechnicalManagementException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) DuplicateThemeNameException(io.gravitee.rest.api.service.exceptions.DuplicateThemeNameException) ThemeNotFoundException(io.gravitee.rest.api.service.exceptions.ThemeNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 17 with TechnicalManagementException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Token(io.gravitee.repository.management.model.Token) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 18 with TechnicalManagementException

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);
    }
}
Also used : TokenService(io.gravitee.rest.api.service.TokenService) java.util(java.util) Logger(org.slf4j.Logger) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) TokenEntity(io.gravitee.rest.api.model.TokenEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) TokenReferenceType(io.gravitee.rest.api.model.TokenReferenceType) AuditService(io.gravitee.rest.api.service.AuditService) TOKEN(io.gravitee.repository.management.model.Audit.AuditProperties.TOKEN) NewTokenEntity(io.gravitee.rest.api.model.NewTokenEntity) TokenNameAlreadyExistsException(io.gravitee.rest.api.service.exceptions.TokenNameAlreadyExistsException) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UUID(io.gravitee.common.utils.UUID) Token(io.gravitee.repository.management.model.Token) AuditEvent(io.gravitee.repository.management.model.Token.AuditEvent) TokenRepository(io.gravitee.repository.management.api.TokenRepository) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Token(io.gravitee.repository.management.model.Token) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 19 with TechnicalManagementException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Workflow(io.gravitee.repository.management.model.Workflow) UuidString(io.gravitee.rest.api.service.common.UuidString) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 20 with TechnicalManagementException

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);
    }
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)149 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)120 UuidString (io.gravitee.rest.api.service.common.UuidString)26 Date (java.util.Date)23 Component (org.springframework.stereotype.Component)18 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)16 Collectors (java.util.stream.Collectors)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 IOException (java.io.IOException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Rating (io.gravitee.repository.management.model.Rating)9 ApiRatingUnavailableException (io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Dictionary (io.gravitee.repository.management.model.Dictionary)8 AuditService (io.gravitee.rest.api.service.AuditService)8 java.util (java.util)8 Theme (io.gravitee.repository.management.model.Theme)6 List (java.util.List)6