use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.
the class WidgetController method updateWidget.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets/{widgetCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, name = "widget")
public ResponseEntity<RestResponse> updateWidget(@PathVariable String widgetCode, @Valid @RequestBody WidgetRequest widgetRequest, BindingResult bindingResult) {
logger.trace("update widget. Code: {} and body {}: ", widgetCode, widgetRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.widgetValidator.validateWidgetCode(widgetCode, widgetRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
WidgetDto widgetDto = this.widgetService.updateWidget(widgetCode, widgetRequest);
return new ResponseEntity<>(new RestResponse(widgetDto), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.
the class WidgetController method getWidgets.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getWidgets(RestListRequest requestList) {
logger.trace("get widget list {}", requestList);
this.getWidgetValidator().validateRestListRequest(requestList);
PagedMetadata<WidgetDto> result = this.widgetService.getWidgets(requestList);
this.getWidgetValidator().validateRestListResult(requestList, result);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.
the class WidgetController method addWidget.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, name = "widget")
public ResponseEntity<RestResponse> addWidget(@Valid @RequestBody WidgetRequest widgetRequest, BindingResult bindingResult) throws ApsSystemException {
logger.trace("add widget. body {}: ", widgetRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
this.widgetValidator.validate(widgetRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
WidgetDto widgetDto = this.widgetService.addWidget(widgetRequest);
return new ResponseEntity<>(new RestResponse(widgetDto), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.
the class WidgetService method getWidgets.
@SuppressWarnings("rawtypes")
@Override
public PagedMetadata<WidgetDto> getWidgets(RestListRequest restListReq) {
try {
// transforms the filters by overriding the key specified in the request with the correct one known by the dto
List<FieldSearchFilter> filters = new ArrayList<>(restListReq.buildFieldSearchFilters());
filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(WidgetDto.getEntityFieldName(i.getKey())));
SearcherDaoPaginatedResult<WidgetType> widgets = this.getWidgetManager().getWidgetTypes(filters);
List<WidgetDto> dtoList = dtoBuilder.convert(widgets.getList());
for (WidgetDto widgetDto : dtoList) {
this.addFragments(widgetDto);
}
PagedMetadata<WidgetDto> pagedMetadata = new PagedMetadata<>(restListReq, widgets);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in get widgets", t);
throw new RestServerError("error in get widgets", t);
}
}
use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.
the class WidgetService method updateWidget.
@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
if (type == null) {
throw new RestRourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
} else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
throw new ValidationGenericException(bindingResult);
}
this.processWidgetType(type, widgetRequest);
WidgetDto widgetDto = dtoBuilder.convert(type);
try {
this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup());
if (!StringUtils.isEmpty(widgetCode)) {
GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
if (null == guiFragment) {
this.createAndAddFragment(type, widgetRequest);
} else {
guiFragment.setGui(widgetRequest.getCustomUi());
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
this.addFragments(widgetDto);
} catch (Throwable e) {
logger.error("failed to update widget type", e);
throw new RestServerError("Failed to update widget", e);
}
return widgetDto;
}
Aggregations