use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceImpl method updateDefaultTheme.
@Override
public void updateDefaultTheme() {
try {
final Set<Theme> themes = themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ThemeReferenceType.ENVIRONMENT.name());
String defaultDefinition = this.getDefaultDefinition();
if (themes != null && !themes.isEmpty()) {
themes.forEach(theme -> {
if (!MAPPER.isSame(defaultDefinition, theme.getDefinition())) {
try {
ThemeDefinition mergeDefinition = MAPPER.merge(defaultDefinition, theme.getDefinition());
Theme themeUpdate = new Theme(theme);
themeUpdate.setDefinition(MAPPER.writeValueAsString(mergeDefinition));
theme.setUpdatedAt(new Date());
this.themeRepository.update(themeUpdate);
auditService.createEnvironmentAuditLog(Collections.singletonMap(THEME, theme.getId()), THEME_UPDATED, new Date(), theme, themeUpdate);
} catch (IOException ex) {
final String error = "Error while trying to merge default theme from the definition path: " + themesPath + DEFAULT_THEME_PATH + " with theme " + theme.toString();
LOGGER.error(error, ex);
} catch (TechnicalException ex) {
final String error = "Error while trying to update theme after merge with default" + theme.toString();
LOGGER.error(error, ex);
}
}
});
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find all themes", ex);
}
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceImpl method findByIdWithoutConvert.
private Theme findByIdWithoutConvert(String themeId) {
try {
LOGGER.debug("Find theme by ID: {}", themeId);
Optional<Theme> optTheme = themeRepository.findById(themeId);
if (!optTheme.isPresent()) {
throw new ThemeNotFoundException(themeId);
}
Theme theme = optTheme.get();
if (!theme.getReferenceId().equals(GraviteeContext.getCurrentEnvironment())) {
LOGGER.warn("Theme is not in current environment " + GraviteeContext.getCurrentEnvironment() + " actual:" + theme.getReferenceId());
throw new ThemeNotFoundException(themeId);
}
return theme;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find theme by ID", ex);
throw new TechnicalManagementException("An error occurs while trying to find theme by ID", ex);
}
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceImpl method convert.
private Theme convert(NewThemeEntity themeEntity) {
try {
final Date now = new Date();
final Theme theme = new Theme();
theme.setId(DEFAULT_THEME_ID);
theme.setCreatedAt(now);
theme.setUpdatedAt(now);
theme.setReferenceId(GraviteeContext.getCurrentEnvironment());
theme.setReferenceType(ThemeReferenceType.ENVIRONMENT.name());
theme.setLogo(themeEntity.getLogo());
theme.setName(themeEntity.getName());
theme.setDefinition(MAPPER.writeValueAsString(themeEntity.getDefinition()));
theme.setEnabled(themeEntity.isEnabled());
theme.setBackgroundImage(themeEntity.getBackgroundImage());
theme.setOptionalLogo(themeEntity.getOptionalLogo());
theme.setFavicon(themeEntity.getFavicon());
return theme;
} catch (JsonProcessingException e) {
throw new TechnicalManagementException("Cannot convert new theme entity", e);
}
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceImpl method delete.
@Override
public void delete(String themeId) {
try {
Optional<Theme> themeOptional = themeRepository.findById(themeId);
if (themeOptional.isPresent()) {
themeRepository.delete(themeId);
auditService.createEnvironmentAuditLog(Collections.singletonMap(THEME, themeId), THEME_DELETED, new Date(), null, themeOptional.get());
}
} catch (TechnicalException ex) {
final String error = "An error occurs while trying to delete theme " + themeId;
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldThrowThemeNotFoundExceptionWhenThemeIsNotInDefaultEnv.
@Test(expected = ThemeNotFoundException.class)
public void shouldThrowThemeNotFoundExceptionWhenThemeIsNotInDefaultEnv() throws TechnicalException, JsonProcessingException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
ThemeDefinition themeDefinition = new ThemeDefinition();
themeDefinition.setData(Collections.EMPTY_LIST);
String definition = definitionMapper.writeValueAsString(themeDefinition);
final Theme theme = mock(Theme.class);
when(theme.getReferenceId()).thenReturn("NOT-DEFAULT");
when(themeRepository.findById(THEME_ID)).thenReturn(of(theme));
final ThemeEntity themeEntity = themeService.findById(THEME_ID);
assertEquals(THEME_ID, themeEntity.getId());
assertEquals("NAME", themeEntity.getName());
assertEquals(definition, definitionMapper.writeValueAsString(themeEntity.getDefinition()));
assertEquals(new Date(1), themeEntity.getCreatedAt());
assertEquals(new Date(2), themeEntity.getUpdatedAt());
}
Aggregations