Search in sources :

Example 6 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelControllerTest method should_load_the_list_of_dataModels_2.

@SuppressWarnings("unchecked")
@Test
public void should_load_the_list_of_dataModels_2() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(dataObjectModelService.getDataObjectModels(any(RestListRequest.class))).thenReturn(new PagedMetadata<DataModelDto>());
    ResultActions result = mockMvc.perform(get("/dataModels").param("page", "1").param("pageSize", "4").param("filter[0].attribute", "code").param("filter[0].value", "1").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    restListReq.setPage(1);
    restListReq.setPageSize(4);
    restListReq.addFilter(new Filter("code", "1"));
    Mockito.verify(dataObjectModelService, Mockito.times(1)).getDataObjectModels(restListReq);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 7 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelServiceTest method should_raise_exception_on_delete_referenced_dataModel.

@Test(expected = ValidationConflictException.class)
public void should_raise_exception_on_delete_referenced_dataModel() throws Throwable {
    DataObjectModel mockDataModel = new DataObjectModel();
    mockDataModel.setId(234l);
    when(this.dataObjectModelManager.getDataObjectModel(any(Long.class))).thenReturn(mockDataModel);
    DataModelDto dto = new DataModelDto(mockDataModel);
    when(this.dtoBuilder.convert(mockDataModel)).thenReturn(dto);
    Map<String, List<IPage>> utilizers = new HashMap<>();
    List<IPage> pages = new ArrayList<>();
    Page referencedPage = new Page();
    referencedPage.setCode("referenced");
    pages.add(referencedPage);
    utilizers.put("ABC123", pages);
    when(this.dataObjectModelManager.getReferencingPages(any(Long.class))).thenReturn(utilizers);
    this.dataObjectModelService.removeDataObjectModel(34l);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) IPage(com.agiletec.aps.system.services.page.IPage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) Test(org.junit.Test)

Example 8 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelController method getDataObjectModel.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDataObjectModel(@PathVariable String dataModelId) {
    logger.debug("Requested data object model -> {}", dataModelId);
    MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
    int result = this.getDataObjectModelValidator().checkModelId(dataModelId, bindingResult);
    if (bindingResult.hasErrors()) {
        if (404 == result) {
            throw new RestRourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_DOES_NOT_EXIST, "dataObjectModel", dataModelId);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    DataModelDto dataModelDto = this.getDataObjectModelService().getDataObjectModel(Long.parseLong(dataModelId));
    return new ResponseEntity<>(new RestResponse(dataModelDto), HttpStatus.OK);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) MapBindingResult(org.springframework.validation.MapBindingResult) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelControllerTest method should_load_the_list_of_dataModels.

@SuppressWarnings("unchecked")
@Test
public void should_load_the_list_of_dataModels() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(dataObjectModelService.getDataObjectModels(any(RestListRequest.class))).thenReturn(new PagedMetadata<DataModelDto>());
    ResultActions result = mockMvc.perform(get("/dataModels").param("page", "1").param("pageSize", "4").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    restListReq.setPage(1);
    restListReq.setPageSize(4);
    Mockito.verify(dataObjectModelService, Mockito.times(1)).getDataObjectModels(restListReq);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestListRequest(org.entando.entando.web.common.model.RestListRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)9 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 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3 RestListRequest (org.entando.entando.web.common.model.RestListRequest)3 Test (org.junit.Test)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IPage (com.agiletec.aps.system.services.page.IPage)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RestServerError (org.entando.entando.aps.system.exception.RestServerError)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1