Search in sources :

Example 6 with WidgetDto

use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.

the class WidgetControllerTest method testUpdateWidget.

@Test
public void testUpdateWidget() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(widgetService.updateWidget(any(), any())).thenReturn(new WidgetDto());
    this.controller.setWidgetValidator(new WidgetValidator());
    // @formatter:off
    ResultActions result = mockMvc.perform(put("/widgets/test").contentType(MediaType.APPLICATION_JSON).content(convertObjectToJsonBytes(createMockRequest())).header("Authorization", "Bearer " + accessToken));
    String response = result.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    assertNotNull(response);
}
Also used : WidgetValidator(org.entando.entando.web.widget.validator.WidgetValidator) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 7 with WidgetDto

use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.

the class WidgetController method getWidget.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets/{widgetCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getWidget(@PathVariable String widgetCode) {
    logger.trace("getWidget by code {}", widgetCode);
    WidgetDto group = this.widgetService.getWidget(widgetCode);
    return new ResponseEntity<>(new RestResponse(group), 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 8 with WidgetDto

use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.

the class WidgetService method addWidget.

@Override
public WidgetDto addWidget(WidgetRequest widgetRequest) {
    WidgetType widgetType = new WidgetType();
    this.processWidgetType(widgetType, widgetRequest);
    WidgetType oldWidgetType = this.getWidgetManager().getWidgetType(widgetType.getCode());
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(widgetType, "widget");
    if (null != oldWidgetType) {
        bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_ALREADY_EXISTS, new String[] { widgetType.getCode() }, "widgettype.exists");
        throw new ValidationGenericException(bindingResult);
    } else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
        bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
        throw new ValidationGenericException(bindingResult);
    }
    WidgetDto widgetDto = null;
    try {
        this.getWidgetManager().addWidgetType(widgetType);
        this.createAndAddFragment(widgetType, widgetRequest);
        widgetDto = this.dtoBuilder.convert(widgetType);
        this.addFragments(widgetDto);
    } catch (Exception e) {
        logger.error("Failed to add widget type for request {} ", widgetRequest);
        throw new RestServerError("error in add widget", e);
    }
    return widgetDto;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 9 with WidgetDto

use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.

the class WidgetService method getWidget.

@Override
public WidgetDto getWidget(String widgetCode) {
    WidgetType widgetType = this.getWidgetManager().getWidgetType(widgetCode);
    if (null == widgetType) {
        logger.warn("no widget type found with code {}", widgetCode);
        throw new RestRourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_NOT_FOUND, "widget type", widgetCode);
    }
    WidgetDto widgetDto = dtoBuilder.convert(widgetType);
    try {
        this.addFragments(widgetDto);
    } catch (Exception e) {
        logger.error("Failed to fetch gui fragment for widget type code ", e);
    }
    return widgetDto;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 10 with WidgetDto

use of org.entando.entando.aps.system.services.widgettype.model.WidgetDto in project entando-core by entando.

the class WidgetControllerTest method testGetWidgetList.

@Test
public void testGetWidgetList() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PagedMetadata<WidgetDto> pagedDto = new PagedMetadata<>();
    when(widgetService.getWidgets(any())).thenReturn(pagedDto);
    // @formatter:off
    ResultActions result = mockMvc.perform(get("/widgets").header("Authorization", "Bearer " + accessToken));
    String response = result.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    assertNotNull(response);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

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