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