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