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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations