@Test public void listPatientsNullOrder() throws QueryException { Query query = mock(DefaultQuery.class); doReturn(query).when(this.queries).createQuery(anyString(), anyString()); doReturn(query).when(query).bindValue(anyString(), anyString()); doReturn(new ArrayList<Object[]>()).when(query).execute(); this.patientsResource.listPatients(0, 30, "id", null); verify(this.queries).createQuery( "select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date" + " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by " + "doc.name" + " asc", "xwql"); }
@Override public Patients listPatients(Integer start, Integer number, String orderField, String order) { Patients result = new Patients(); try { String safeOrderField = "doc.name"; if ("eid".equals(orderField)) { safeOrderField = "p.external_id"; } String safeOrder = " asc"; if ("desc".equals(order)) { safeOrder = " desc"; } Query query = this.queries.createQuery( "select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date" + " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by " + safeOrderField + safeOrder, "xwql"); query.bindValue("t", "PatientTemplate"); List<Object[]> records = query.execute(); int skipped = 0; for (Object[] record : records) { PatientSummary summary = this.factory.createPatientSummary(record, this.uriInfo); if (summary != null) { if (++skipped > start) { result.getPatientSummaries().add(summary); } if (result.getPatientSummaries().size() >= number) { break; } } } result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(getGrantedRight()).build()); } catch (Exception ex) { this.slf4Jlogger.error("Failed to list patients: {}", ex.getMessage(), ex); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return result; }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Patients listPatients(Integer start, Integer number, String orderField, String order) { Patients result = new Patients(); try { String safeOrderField = "doc.name"; if ("eid".equals(orderField)) { safeOrderField = "p.external_id"; } String safeOrder = " asc"; if ("desc".equals(order)) { safeOrder = " desc"; } Query query = this.queries.createQuery( "select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date" + " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by " + safeOrderField + safeOrder, "xwql"); query.bindValue("t", "PatientTemplate"); List<Object[]> records = query.execute(); int skipped = 0; for (Object[] record : records) { PatientSummary summary = this.factory.createPatientSummary(record, this.uriInfo); if (summary != null) { if (++skipped > start) { result.getPatientSummaries().add(summary); } if (result.getPatientSummaries().size() >= number) { break; } } } result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(getGrantedRight()).build()); } catch (Exception ex) { this.slf4Jlogger.error("Failed to list patients: {}", ex.getMessage(), ex); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return result; } }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Patients listPatients(Integer start, Integer number, String orderField, String order) { Patients result = new Patients(); try { String safeOrderField = "doc.name"; if ("eid".equals(orderField)) { safeOrderField = "p.external_id"; } String safeOrder = " asc"; if ("desc".equals(order)) { safeOrder = " desc"; } Query query = this.queries.createQuery( "select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date" + " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by " + safeOrderField + safeOrder, "xwql"); query.bindValue("t", "PatientTemplate"); List<Object[]> records = query.execute(); int skipped = 0; for (Object[] record : records) { PatientSummary summary = this.factory.createPatientSummary(record, this.uriInfo); if (summary != null) { if (++skipped > start) { result.getPatientSummaries().add(summary); } if (result.getPatientSummaries().size() >= number) { break; } } } result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(getGrantedRight()).build()); } catch (Exception ex) { this.slf4Jlogger.error("Failed to list patients: {}", ex.getMessage(), ex); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return result; }  }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Patients listPatients(Integer start, Integer number, String orderField, String order) { Patients result = new Patients(); try { String safeOrderField = "doc.name"; if ("eid".equals(orderField)) { safeOrderField = "p.external_id"; } String safeOrder = " asc"; if ("desc".equals(order)) { safeOrder = " desc"; } Query query = this.queries.createQuery( "select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date" + " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by " + safeOrderField + safeOrder, "xwql"); query.bindValue("t", "PatientTemplate"); List<Object[]> records = query.execute(); int skipped = 0; for (Object[] record : records) { PatientSummary summary = this.factory.createPatientSummary(record, this.uriInfo); if (summary != null) { if (++skipped > start) { result.getPatientSummaries().add(summary); } if (result.getPatientSummaries().size() >= number) { break; } } } result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(getGrantedRight()).build()); } catch (Exception ex) { this.slf4Jlogger.error("Failed to list patients: {}", ex.getMessage(), ex); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return result; }  @Override Response add(final String json); @Override Patients listPatients(Integer start, Integer number, String orderField, String order); }
DefaultPatientsResourceImpl extends XWikiResource implements PatientsResource { @Override public Patients listPatients(Integer start, Integer number, String orderField, String order) { Patients result = new Patients(); try { String safeOrderField = "doc.name"; if ("eid".equals(orderField)) { safeOrderField = "p.external_id"; } String safeOrder = " asc"; if ("desc".equals(order)) { safeOrder = " desc"; } Query query = this.queries.createQuery( "select doc.fullName, p.external_id, doc.creator, doc.creationDate, doc.version, doc.author, doc.date" + " from Document doc, doc.object(PhenoTips.PatientClass) p where doc.name <> :t order by " + safeOrderField + safeOrder, "xwql"); query.bindValue("t", "PatientTemplate"); List<Object[]> records = query.execute(); int skipped = 0; for (Object[] record : records) { PatientSummary summary = this.factory.createPatientSummary(record, this.uriInfo); if (summary != null) { if (++skipped > start) { result.getPatientSummaries().add(summary); } if (result.getPatientSummaries().size() >= number) { break; } } } result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(getGrantedRight()).build()); } catch (Exception ex) { this.slf4Jlogger.error("Failed to list patients: {}", ex.getMessage(), ex); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return result; }  @Override Response add(final String json); @Override Patients listPatients(Integer start, Integer number, String orderField, String order);  }