@Test void testGetEntities() { String entityTypeId = "MyEntityTypeId"; Selection filter = Selection.FULL_SELECTION; Selection expand = Selection.FULL_SELECTION; Query query = Query.builder().setOperator(Operator.MATCHES).setValue("value").build(); Sort sort = Sort.create("field", Direction.ASC); ReadEntitiesRequest entityRequest = new ReadEntitiesRequest(); entityRequest.setEntityTypeId(entityTypeId); entityRequest.setQ(query); entityRequest.setSort(sort); entityRequest.setFilter(filter); entityRequest.setExpand(expand); entityRequest.setSize(10); entityRequest.setPage(2); Entities entities = Entities.create(emptyList(), 30); when(dataServiceV3.findAll(entityTypeId, query, filter, expand, sort, 10, 2)) .thenReturn(entities); EntityCollection entityCollection = EntityCollection.builder() .setEntityTypeId(entityTypeId) .setEntities(emptyList()) .setPage(Page.builder().setOffset(20).setPageSize(10).setTotal(30).build()) .build(); EntitiesResponse entitiesResponse = mock(EntitiesResponse.class); when(entityMapper.map(entityCollection, filter, expand, 10, 2, 30)) .thenReturn(entitiesResponse); assertEquals(entitiesResponse, entityController.getEntities(entityRequest)); }
@Transactional(readOnly = true) @GetMapping("/{entityTypeId}") public EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest) { String entityTypeId = entitiesRequest.getEntityTypeId(); Selection filter = entitiesRequest.getFilter(); Selection expand = entitiesRequest.getExpand(); int size = entitiesRequest.getSize(); int page = entitiesRequest.getPage(); Sort sort = entitiesRequest.getSort(); Entities entities = dataServiceV3.findAll( entityTypeId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page); EntityCollection entityCollection = EntityCollection.builder() .setEntityTypeId(entityTypeId) .setEntities(entities.getEntities()) .setPage( Page.builder() .setOffset(size * page) .setPageSize(size) .setTotal(entities.getTotal()) .build()) .build(); return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal()); }
EntityController extends ApiController { @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") public EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest) { String entityTypeId = entitiesRequest.getEntityTypeId(); Selection filter = entitiesRequest.getFilter(); Selection expand = entitiesRequest.getExpand(); int size = entitiesRequest.getSize(); int page = entitiesRequest.getPage(); Sort sort = entitiesRequest.getSort(); Entities entities = dataServiceV3.findAll( entityTypeId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page); EntityCollection entityCollection = EntityCollection.builder() .setEntityTypeId(entityTypeId) .setEntities(entities.getEntities()) .setPage( Page.builder() .setOffset(size * page) .setPageSize(size) .setTotal(entities.getTotal()) .build()) .build(); return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal()); } }
EntityController extends ApiController { @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") public EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest) { String entityTypeId = entitiesRequest.getEntityTypeId(); Selection filter = entitiesRequest.getFilter(); Selection expand = entitiesRequest.getExpand(); int size = entitiesRequest.getSize(); int page = entitiesRequest.getPage(); Sort sort = entitiesRequest.getSort(); Entities entities = dataServiceV3.findAll( entityTypeId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page); EntityCollection entityCollection = EntityCollection.builder() .setEntityTypeId(entityTypeId) .setEntities(entities.getEntities()) .setPage( Page.builder() .setOffset(size * page) .setPageSize(size) .setTotal(entities.getTotal()) .build()) .build(); return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal()); } EntityController(DataServiceV3 dataServiceV3, EntityMapper entityMapper); }
EntityController extends ApiController { @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") public EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest) { String entityTypeId = entitiesRequest.getEntityTypeId(); Selection filter = entitiesRequest.getFilter(); Selection expand = entitiesRequest.getExpand(); int size = entitiesRequest.getSize(); int page = entitiesRequest.getPage(); Sort sort = entitiesRequest.getSort(); Entities entities = dataServiceV3.findAll( entityTypeId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page); EntityCollection entityCollection = EntityCollection.builder() .setEntityTypeId(entityTypeId) .setEntities(entities.getEntities()) .setPage( Page.builder() .setOffset(size * page) .setPageSize(size) .setTotal(entities.getTotal()) .build()) .build(); return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal()); } EntityController(DataServiceV3 dataServiceV3, EntityMapper entityMapper); @Transactional @PostMapping("/{entityTypeId}") ResponseEntity createEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody Map<String, Object> entityMap); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}") EntityResponse getEntity(@Valid ReadEntityRequest entityRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}/{fieldId}") EntitiesResponse getReferencedEntities(@Valid ReadSubresourceRequest entitiesRequest); @Transactional @PutMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updateEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @PatchMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updatePartialEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @DeleteMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntity(@Valid DeleteEntityRequest deleteRequest); @DeleteMapping("/{entityTypeId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntities(@Valid DeleteEntitiesRequest deleteRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest); }
EntityController extends ApiController { @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") public EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest) { String entityTypeId = entitiesRequest.getEntityTypeId(); Selection filter = entitiesRequest.getFilter(); Selection expand = entitiesRequest.getExpand(); int size = entitiesRequest.getSize(); int page = entitiesRequest.getPage(); Sort sort = entitiesRequest.getSort(); Entities entities = dataServiceV3.findAll( entityTypeId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page); EntityCollection entityCollection = EntityCollection.builder() .setEntityTypeId(entityTypeId) .setEntities(entities.getEntities()) .setPage( Page.builder() .setOffset(size * page) .setPageSize(size) .setTotal(entities.getTotal()) .build()) .build(); return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal()); } EntityController(DataServiceV3 dataServiceV3, EntityMapper entityMapper); @Transactional @PostMapping("/{entityTypeId}") ResponseEntity createEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody Map<String, Object> entityMap); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}") EntityResponse getEntity(@Valid ReadEntityRequest entityRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}/{fieldId}") EntitiesResponse getReferencedEntities(@Valid ReadSubresourceRequest entitiesRequest); @Transactional @PutMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updateEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @PatchMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updatePartialEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @DeleteMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntity(@Valid DeleteEntityRequest deleteRequest); @DeleteMapping("/{entityTypeId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntities(@Valid DeleteEntitiesRequest deleteRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest); static final String API_ENTITY_PATH; }