Search in sources :

Example 1 with WidgetDto

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

Example 2 with WidgetDto

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

Example 3 with WidgetDto

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

Example 4 with WidgetDto

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);
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) LoggerFactory(org.slf4j.LoggerFactory) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) Service(org.springframework.stereotype.Service) IManager(com.agiletec.aps.system.common.IManager) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Logger(org.slf4j.Logger) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) WidgetValidator(org.entando.entando.web.widget.validator.WidgetValidator) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 5 with WidgetDto

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;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Aggregations

WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)10 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)4 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)4 RestResponse (org.entando.entando.web.common.model.RestResponse)4 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)3 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)2 WidgetValidator (org.entando.entando.web.widget.validator.WidgetValidator)2 Test (org.junit.Test)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 IManager (com.agiletec.aps.system.common.IManager)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1