Search in sources :

Example 11 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class SocialIdentityProviderImpl method findAll.

@Override
public Set<SocialIdentityProviderEntity> findAll(IdentityProviderActivationService.ActivationTarget target) {
    try {
        Set<String> allIdpByTarget = identityProviderActivationService.findAllByTarget(target).stream().map(IdentityProviderActivationEntity::getIdentityProvider).collect(Collectors.toSet());
        Stream<IdentityProviderEntity> identityProviderEntityStream = identityProviderService.findAll().stream().filter(idp -> allIdpByTarget.contains(idp.getId()));
        if (target.getReferenceType() == IdentityProviderActivationReferenceType.ENVIRONMENT) {
            identityProviderEntityStream = identityProviderEntityStream.filter(IdentityProviderEntity::isEnabled);
        }
        return identityProviderEntityStream.sorted((idp1, idp2) -> String.CASE_INSENSITIVE_ORDER.compare(idp1.getName(), idp2.getName())).map(this::convert).collect(Collectors.toSet());
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to retrieve identity providers", ex);
        throw new TechnicalManagementException("An error occurs while trying to retrieve identity providers", ex);
    }
}
Also used : GitHubIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.github.GitHubIdentityProviderEntity) OIDCIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.oidc.OIDCIdentityProviderEntity) GoogleIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.google.GoogleIdentityProviderEntity) AMIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.am.AMIdentityProviderEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 12 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class PromotionTasksServiceImpl method convert.

private TaskEntity convert(PromotionEntity promotionEntity, boolean isUpdate, Optional<String> foundTargetApiId) {
    TaskEntity taskEntity = new TaskEntity();
    taskEntity.setType(TaskType.PROMOTION_APPROVAL);
    taskEntity.setCreatedAt(promotionEntity.getCreatedAt());
    ApiEntity apiEntity;
    try {
        apiEntity = objectMapper.readValue(promotionEntity.getApiDefinition(), ApiEntity.class);
    } catch (JsonProcessingException e) {
        logger.warn("Problem while deserializing api definition for promotion {}", promotionEntity.getId());
        throw new TechnicalManagementException();
    }
    Map<String, Object> data = new HashMap<>();
    data.put("apiName", apiEntity.getName());
    data.put("apiId", promotionEntity.getApiId());
    data.put("sourceEnvironmentName", promotionEntity.getSourceEnvName());
    data.put("targetEnvironmentName", promotionEntity.getTargetEnvName());
    data.put("authorDisplayName", promotionEntity.getAuthor().getDisplayName());
    data.put("authorEmail", promotionEntity.getAuthor().getEmail());
    data.put("authorPicture", promotionEntity.getAuthor().getPicture());
    data.put("promotionId", promotionEntity.getId());
    data.put("isApiUpdate", isUpdate);
    foundTargetApiId.ifPresent(targetApiId -> data.put("targetApiId", targetApiId));
    taskEntity.setData(data);
    return taskEntity;
}
Also used : TaskEntity(io.gravitee.rest.api.model.TaskEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 13 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ThemeServiceImpl method update.

@Override
public ThemeEntity update(final UpdateThemeEntity updateThemeEntity) {
    try {
        final Optional<Theme> themeOptional = themeRepository.findById(updateThemeEntity.getId());
        if (themeOptional.isPresent()) {
            final Theme theme = new Theme(themeOptional.get());
            if (this.findByName(theme.getName(), theme.getId()).isPresent()) {
                throw new DuplicateThemeNameException(theme.getName());
            }
            theme.setEnabled(updateThemeEntity.isEnabled());
            final Date now = new Date();
            theme.setUpdatedAt(now);
            theme.setReferenceType(ThemeReferenceType.ENVIRONMENT.name());
            theme.setReferenceId(GraviteeContext.getCurrentEnvironment());
            if (updateThemeEntity.getName() != null) {
                theme.setName(updateThemeEntity.getName());
            }
            theme.setDefinition(MAPPER.writeValueAsString(updateThemeEntity.getDefinition()));
            if (updateThemeEntity.getLogo() != null) {
                theme.setLogo(updateThemeEntity.getLogo());
            } else {
                theme.setLogo(this.getDefaultLogo());
            }
            theme.setBackgroundImage(updateThemeEntity.getBackgroundImage());
            if (updateThemeEntity.getOptionalLogo() != null) {
                theme.setOptionalLogo(updateThemeEntity.getOptionalLogo());
            } else {
                theme.setOptionalLogo(this.getDefaultOptionalLogo());
            }
            if (updateThemeEntity.getFavicon() != null) {
                theme.setFavicon(updateThemeEntity.getFavicon());
            } else {
                theme.setFavicon(this.getDefaultFavicon());
            }
            final ThemeEntity savedTheme = convert(themeRepository.update(theme));
            auditService.createEnvironmentAuditLog(Collections.singletonMap(THEME, theme.getId()), THEME_UPDATED, new Date(), themeOptional.get(), theme);
            return savedTheme;
        } else {
            final NewThemeEntity newTheme = new NewThemeEntity();
            newTheme.setName(updateThemeEntity.getName());
            newTheme.setDefinition(updateThemeEntity.getDefinition());
            newTheme.setBackgroundImage(updateThemeEntity.getBackgroundImage());
            newTheme.setLogo(updateThemeEntity.getLogo());
            newTheme.setOptionalLogo(updateThemeEntity.getOptionalLogo());
            newTheme.setFavicon(updateThemeEntity.getFavicon());
            newTheme.setEnabled(updateThemeEntity.isEnabled());
            return create(newTheme);
        }
    } catch (TechnicalException | JsonProcessingException ex) {
        final String error = "An error occurred while trying to update theme " + updateThemeEntity;
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Theme(io.gravitee.repository.management.model.Theme) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DuplicateThemeNameException(io.gravitee.rest.api.service.exceptions.DuplicateThemeNameException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 14 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ThemeServiceImpl method create.

@Override
public ThemeEntity create(final NewThemeEntity themeEntity) {
    // First we prevent the duplicate name
    try {
        if (this.findByName(themeEntity.getName(), null).isPresent()) {
            throw new DuplicateThemeNameException(themeEntity.getName());
        }
        Theme theme = themeRepository.create(convert(themeEntity));
        auditService.createEnvironmentAuditLog(Collections.singletonMap(THEME, theme.getId()), THEME_CREATED, theme.getCreatedAt(), null, theme);
        return convert(theme);
    } catch (TechnicalException ex) {
        final String error = "An error occurred while trying to create theme " + themeEntity;
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Theme(io.gravitee.repository.management.model.Theme) DuplicateThemeNameException(io.gravitee.rest.api.service.exceptions.DuplicateThemeNameException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 15 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ThemeServiceImpl method findEnabled.

@Override
public ThemeEntity findEnabled() {
    try {
        LOGGER.debug("Find all themes by reference type");
        Optional<Theme> themeEnabled = themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ThemeReferenceType.ENVIRONMENT.name()).stream().filter(theme -> theme.isEnabled()).findFirst();
        if (themeEnabled.isPresent()) {
            return convert(themeEnabled.get());
        }
        final ThemeEntity theme = new ThemeEntity();
        theme.setId(DEFAULT_THEME_ID);
        theme.setName("Default theme");
        theme.setDefinition(MAPPER.readDefinition(getDefaultDefinition()));
        theme.setLogo(this.getDefaultLogo());
        theme.setOptionalLogo(this.getDefaultOptionalLogo());
        theme.setFavicon(this.getDefaultFavicon());
        return theme;
    } catch (IOException ex) {
        final String error = "Error while trying to get the default theme";
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    } catch (TechnicalException ex) {
        final String error = "An error occurs while trying to find all themes by reference type";
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    }
}
Also used : Charset.defaultCharset(java.nio.charset.Charset.defaultCharset) java.util(java.util) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Theme(io.gravitee.repository.management.model.Theme) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) Value(org.springframework.beans.factory.annotation.Value) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) DuplicateThemeNameException(io.gravitee.rest.api.service.exceptions.DuplicateThemeNameException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ThemeReferenceType(io.gravitee.repository.management.model.ThemeReferenceType) ThemeNotFoundException(io.gravitee.rest.api.service.exceptions.ThemeNotFoundException) THEME(io.gravitee.repository.management.model.Audit.AuditProperties.THEME) AuditEvent(io.gravitee.repository.management.model.Theme.AuditEvent) Logger(org.slf4j.Logger) PictureEntity(io.gravitee.rest.api.model.PictureEntity) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AuditService(io.gravitee.rest.api.service.AuditService) IOException(java.io.IOException) ThemeRepository(io.gravitee.repository.management.api.ThemeRepository) Collectors(java.util.stream.Collectors) File(java.io.File) UrlPictureEntity(io.gravitee.rest.api.model.UrlPictureEntity) ThemeService(io.gravitee.rest.api.service.ThemeService) Component(org.springframework.stereotype.Component) io.gravitee.rest.api.model.theme(io.gravitee.rest.api.model.theme) DatatypeConverter(javax.xml.bind.DatatypeConverter) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Theme(io.gravitee.repository.management.model.Theme) IOException(java.io.IOException) 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