@Test public void testGETQuerySuccess() throws BadRequestException, PersistenceException { final List<SimpleObject> filteredResult = Arrays.asList(new SimpleObject(), new SimpleObject()); doReturn(new DataObjectFeed<>()).when(mockObjectPersister).retrieve(anyList()); request.setQueries(Collections.singletonList(new ByTitle("xyz"))); doReturn(filteredResult).when(mockVisibilityFilter).filterByVisible(any(), any()); DataObjectResponse<SimpleObject> response = processor.handleGET(request); Assert.assertFalse(response.isError()); Assert.assertEquals(response.getAll().size(), filteredResult.size()); }
@Override public DataObjectResponse<T> handleGET(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateGET(request); DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); try { VisibilityFilter<T, DataObjectRequest<T>> visibilityFilter = visibilityFilterMap.get(VisibilityMethod.GET); List<Query> queryList = new LinkedList<>(); if(request.getQueries() != null) queryList.addAll(request.getQueries()); if(request.getId() != null) { queryList.add(new ById(request.getId())); } DataObjectFeed<T> feed = objectPersister.retrieve(queryList); if(feed == null) feed = new DataObjectFeed<>(); List<T> filteredObjects = visibilityFilter.filterByVisible(request, feed.getAll()); response.setCount(feed.getCount()); response.addAll(filteredObjects); } catch(PersistenceException e) { ObjectNotFoundException objectNotFoundException = new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getId()), e); response.setErrorResponse(ErrorResponseFactory.objectNotFound(objectNotFoundException, request.getCID())); } return response; }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleGET(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateGET(request); DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); try { VisibilityFilter<T, DataObjectRequest<T>> visibilityFilter = visibilityFilterMap.get(VisibilityMethod.GET); List<Query> queryList = new LinkedList<>(); if(request.getQueries() != null) queryList.addAll(request.getQueries()); if(request.getId() != null) { queryList.add(new ById(request.getId())); } DataObjectFeed<T> feed = objectPersister.retrieve(queryList); if(feed == null) feed = new DataObjectFeed<>(); List<T> filteredObjects = visibilityFilter.filterByVisible(request, feed.getAll()); response.setCount(feed.getCount()); response.addAll(filteredObjects); } catch(PersistenceException e) { ObjectNotFoundException objectNotFoundException = new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getId()), e); response.setErrorResponse(ErrorResponseFactory.objectNotFound(objectNotFoundException, request.getCID())); } return response; } }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleGET(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateGET(request); DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); try { VisibilityFilter<T, DataObjectRequest<T>> visibilityFilter = visibilityFilterMap.get(VisibilityMethod.GET); List<Query> queryList = new LinkedList<>(); if(request.getQueries() != null) queryList.addAll(request.getQueries()); if(request.getId() != null) { queryList.add(new ById(request.getId())); } DataObjectFeed<T> feed = objectPersister.retrieve(queryList); if(feed == null) feed = new DataObjectFeed<>(); List<T> filteredObjects = visibilityFilter.filterByVisible(request, feed.getAll()); response.setCount(feed.getCount()); response.addAll(filteredObjects); } catch(PersistenceException e) { ObjectNotFoundException objectNotFoundException = new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getId()), e); response.setErrorResponse(ErrorResponseFactory.objectNotFound(objectNotFoundException, request.getCID())); } return response; } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleGET(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateGET(request); DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); try { VisibilityFilter<T, DataObjectRequest<T>> visibilityFilter = visibilityFilterMap.get(VisibilityMethod.GET); List<Query> queryList = new LinkedList<>(); if(request.getQueries() != null) queryList.addAll(request.getQueries()); if(request.getId() != null) { queryList.add(new ById(request.getId())); } DataObjectFeed<T> feed = objectPersister.retrieve(queryList); if(feed == null) feed = new DataObjectFeed<>(); List<T> filteredObjects = visibilityFilter.filterByVisible(request, feed.getAll()); response.setCount(feed.getCount()); response.addAll(filteredObjects); } catch(PersistenceException e) { ObjectNotFoundException objectNotFoundException = new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getId()), e); response.setErrorResponse(ErrorResponseFactory.objectNotFound(objectNotFoundException, request.getCID())); } return response; } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); @Override DataObjectResponse<T> handleGET(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePOST(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePUT(DataObjectRequest<T> request); DataObjectResponse<T> handlePUT(DataObjectRequest<T> request, T previouslyRetrievedObject); @Override DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request); DataObjectRequestProcessor<T> setVisibilityFilterMap(
        VisibilityFilterMap<T, DataObjectRequest<T>> map); DataObjectRequestProcessor<T> setVisibilityFilter(VisibilityMethod method,
        VisibilityFilter<T, DataObjectRequest<T>> filter); RequestValidator<DataObjectRequest<T>> getRequestValidator(); void setRequestValidator(RequestValidator<DataObjectRequest<T>> requestValidator); ObjectPersister<T> getObjectPersister(); }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleGET(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateGET(request); DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); try { VisibilityFilter<T, DataObjectRequest<T>> visibilityFilter = visibilityFilterMap.get(VisibilityMethod.GET); List<Query> queryList = new LinkedList<>(); if(request.getQueries() != null) queryList.addAll(request.getQueries()); if(request.getId() != null) { queryList.add(new ById(request.getId())); } DataObjectFeed<T> feed = objectPersister.retrieve(queryList); if(feed == null) feed = new DataObjectFeed<>(); List<T> filteredObjects = visibilityFilter.filterByVisible(request, feed.getAll()); response.setCount(feed.getCount()); response.addAll(filteredObjects); } catch(PersistenceException e) { ObjectNotFoundException objectNotFoundException = new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getId()), e); response.setErrorResponse(ErrorResponseFactory.objectNotFound(objectNotFoundException, request.getCID())); } return response; } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); @Override DataObjectResponse<T> handleGET(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePOST(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePUT(DataObjectRequest<T> request); DataObjectResponse<T> handlePUT(DataObjectRequest<T> request, T previouslyRetrievedObject); @Override DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request); DataObjectRequestProcessor<T> setVisibilityFilterMap(
        VisibilityFilterMap<T, DataObjectRequest<T>> map); DataObjectRequestProcessor<T> setVisibilityFilter(VisibilityMethod method,
        VisibilityFilter<T, DataObjectRequest<T>> filter); RequestValidator<DataObjectRequest<T>> getRequestValidator(); void setRequestValidator(RequestValidator<DataObjectRequest<T>> requestValidator); ObjectPersister<T> getObjectPersister(); static final String OBJECT_NOT_FOUND_EXCEPTION; static final String AUTHORIZATION_EXCEPTION; static final String UNABLE_TO_CREATE_EXCEPTION; static final String UNABLE_TO_UPDATE_EXCEPTION; static final String UNABLE_TO_DELETE_EXCEPTION; }