Search in sources :

Example 1 with GuiFragmentDto

use of org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto in project entando-core by entando.

the class GuiFragmentController method addGuiFragment.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addGuiFragment(@Valid @RequestBody GuiFragmentRequestBody guiFragmentRequest, BindingResult bindingResult) throws ApsSystemException {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    this.getGuiFragmentValidator().validate(guiFragmentRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    GuiFragmentDto fragment = this.getGuiFragmentService().addGuiFragment(guiFragmentRequest);
    return new ResponseEntity<>(new RestResponse(fragment), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with GuiFragmentDto

use of org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto in project entando-core by entando.

the class GuiFragmentService method checkFragmentForDelete.

protected BeanPropertyBindingResult checkFragmentForDelete(GuiFragment fragment, GuiFragmentDto dto) throws ApsSystemException {
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(fragment, "fragment");
    if (null == fragment) {
        return bindingResult;
    }
    if (!dto.getFragments().isEmpty() || !dto.getPageModels().isEmpty()) {
        List<String> fragments = dto.getFragments().stream().map(GuiFragmentDto.FragmentRef::getCode).collect(Collectors.toList());
        List<String> pagemodels = dto.getPageModels().stream().map(GuiFragmentDto.PageModelRef::getCode).collect(Collectors.toList());
        bindingResult.reject(GuiFragmentValidator.ERRCODE_FRAGMENT_REFERENCES, new Object[] { fragment.getCode(), fragments, pagemodels }, "guifragment.cannot.delete.references");
    }
    if (fragment.isLocked()) {
        bindingResult.reject(GuiFragmentValidator.ERRCODE_FRAGMENT_LOCKED, new Object[] { fragment.getCode() }, "guifragment.cannot.delete.locked");
    }
    return bindingResult;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)

Example 3 with GuiFragmentDto

use of org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto in project entando-core by entando.

the class GuiFragmentServiceTest method should_raise_exception_on_delete_reserved_fragment.

@Test(expected = ValidationGenericException.class)
public void should_raise_exception_on_delete_reserved_fragment() throws Throwable {
    GuiFragment reference = new GuiFragment();
    reference.setCode("referenced_code");
    reference.setGui("<p>Code</p>");
    GuiFragmentDto dto = new GuiFragmentDto();
    dto.setCode("master");
    dto.setCode("<p>Code of master</p>");
    dto.addFragmentRef(reference);
    when(this.dtoBuilder.convert(any(GuiFragment.class))).thenReturn(dto);
    GuiFragment fragment = new GuiFragment();
    fragment.setCode("test_code");
    when(guiFragmentManager.getGuiFragment("test_code")).thenReturn(fragment);
    this.guiFragmentService.removeGuiFragment(fragment.getCode());
}
Also used : GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto) Test(org.junit.Test)

Example 4 with GuiFragmentDto

use of org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto in project entando-core by entando.

the class GuiFragmentController method updateGuiFragment.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{fragmentCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateGuiFragment(@PathVariable String fragmentCode, @Valid @RequestBody GuiFragmentRequestBody guiFragmentRequest, BindingResult bindingResult) {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    int result = this.getGuiFragmentValidator().validateBody(fragmentCode, guiFragmentRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        if (404 == result) {
            throw new RestRourceNotFoundException(GuiFragmentValidator.ERRCODE_FRAGMENT_DOES_NOT_EXISTS, "fragment", fragmentCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    GuiFragmentDto fragment = this.getGuiFragmentService().updateGuiFragment(guiFragmentRequest);
    return new ResponseEntity<>(new RestResponse(fragment), HttpStatus.OK);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with GuiFragmentDto

use of org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto in project entando-core by entando.

the class GuiFragmentService method removeGuiFragment.

@Override
public void removeGuiFragment(String guiFragmentCode) {
    try {
        GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(guiFragmentCode);
        if (null == fragment) {
            return;
        }
        GuiFragmentDto dto = this.getDtoBuilder().convert(fragment);
        BeanPropertyBindingResult validationResult = this.checkFragmentForDelete(fragment, dto);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        this.getGuiFragmentManager().deleteGuiFragment(guiFragmentCode);
    } catch (ApsSystemException e) {
        logger.error("Error in delete guiFragmentCode {}", guiFragmentCode, e);
        throw new RestServerError("error in delete guiFragmentCode", e);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)

Aggregations

GuiFragmentDto (org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)5 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)2 RestResponse (org.entando.entando.web.common.model.RestResponse)2 ResponseEntity (org.springframework.http.ResponseEntity)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)1 RestServerError (org.entando.entando.aps.system.exception.RestServerError)1 Test (org.junit.Test)1