use of org.entando.entando.aps.system.services.language.LanguageDto in project entando-core by entando.
the class LanguageController method getLanguage.
@RestAccessControl(permission = Permission.ENTER_BACKEND)
@RequestMapping(value = "/{code}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<LanguageDto>> getLanguage(@PathVariable String code) {
logger.trace("loading language {}", code);
LanguageDto result = this.getLanguageService().getLanguage(code);
return new ResponseEntity<>(new SimpleRestResponse<>(result), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.language.LanguageDto in project entando-core by entando.
the class LanguageControllerIntegrationTest method testDeactivateDefaultLang.
@Test
public void testDeactivateDefaultLang() throws Exception {
String langCode = this.langManager.getDefaultLang().getCode();
try {
LanguageDto lang = this.languageService.getLanguage(langCode);
assertThat(lang, is(not(nullValue())));
assertThat(lang.isActive(), is(true));
UserDetails user = createAdminUser();
String accessToken = mockOAuthInterceptor(user);
String payload = "{\"isActive\": true}";
ResultActions result = mockMvc.perform(put("/languages/{code}", new Object[] { langCode }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
LanguageDto updatedLang = this.languageService.getLanguage(langCode);
assertThat(updatedLang, is(not(nullValue())));
assertThat(updatedLang.isActive(), is(true));
// --
payload = "{\"isActive\": false}";
result = mockMvc.perform(put("/languages/{code}", new Object[] { langCode }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isConflict());
result.andExpect(jsonPath("$.errors[0].code", is("1")));
updatedLang = this.languageService.getLanguage(langCode);
assertThat(updatedLang, is(not(nullValue())));
assertThat(updatedLang.isActive(), is(true));
} finally {
this.languageService.updateLanguage(langCode, true);
}
}
use of org.entando.entando.aps.system.services.language.LanguageDto in project entando-core by entando.
the class LanguageController method getLanguages.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getLanguages(RestListRequest requestList) {
logger.trace("loading languages list");
this.getLanguageValidator().validateRestListRequest(requestList);
PagedMetadata<LanguageDto> result = this.getLanguageService().getLanguages(requestList);
this.getLanguageValidator().validateRestListResult(requestList, result);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.language.LanguageDto in project entando-core by entando.
the class LanguageController method updateLanguage.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{code}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<LanguageDto>> updateLanguage(@PathVariable String code, @Valid @RequestBody LanguageRequest languageRequest, BindingResult bindingResult) {
logger.trace("loading language {}", code);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
LanguageDto result = this.getLanguageService().updateLanguage(code, languageRequest.getStatus());
return new ResponseEntity<>(new SimpleRestResponse<>(result), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.language.LanguageDto in project entando-core by entando.
the class LanguageControllerIntegrationTest method testActivateDeactivateLang.
@Test
public void testActivateDeactivateLang() throws Exception {
String langCode = "de";
try {
LanguageDto lang = this.languageService.getLanguage(langCode);
assertThat(lang, is(not(nullValue())));
assertThat(lang.isActive(), is(false));
UserDetails user = createAdminUser();
String accessToken = mockOAuthInterceptor(user);
String payload = "{\"isActive\": true}";
ResultActions result = mockMvc.perform(put("/languages/{code}", new Object[] { langCode }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
LanguageDto updatedLang = this.languageService.getLanguage(langCode);
assertThat(updatedLang, is(not(nullValue())));
assertThat(updatedLang.isActive(), is(true));
// --
payload = "{\"isActive\": false}";
result = mockMvc.perform(put("/languages/{code}", new Object[] { langCode }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
updatedLang = this.languageService.getLanguage(langCode);
assertThat(updatedLang, is(not(nullValue())));
assertThat(updatedLang.isActive(), is(false));
} finally {
this.languageService.updateLanguage(langCode, false);
}
}
Aggregations