Search in sources :

Example 1 with LanguageDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 2 with LanguageDto

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);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 3 with LanguageDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with LanguageDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 5 with LanguageDto

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);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Aggregations

LanguageDto (org.entando.entando.aps.system.services.language.LanguageDto)5 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 ResponseEntity (org.springframework.http.ResponseEntity)3 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)2 Test (org.junit.Test)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)1 RestResponse (org.entando.entando.web.common.model.RestResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1