public List<IncidentModel> getIncidents(String propertyId) throws ExecutionException, InterruptedException { Query query = new Query() .select(IncidentModel.SELECT) .expand(IncidentModel.EXPAND) .orderBy("sl_date", QueryOrder.Descending) .field("sl_propertyIDId") .eq(propertyId) .and() .field("sl_inspectionIDId") .gt(0) .and() .field("sl_roomIDId") .gt(0); List<SPListItem> items = mClient.getListItems(Constants.LIST_NAME_INCIDENTS, query).get(); List<IncidentModel> models = new ArrayList<IncidentModel>(); for (SPListItem item : items) { IncidentModel model = new IncidentModel(item); if (model.getPropertyId() > 0 && model.getInspectionId() > 0 && model.getRoomId() > 0) { models.add(new IncidentModel(item)); } } return models; }
public IncidentModel getIncident(String incidentId) throws ExecutionException, InterruptedException { Query query = new Query() .select(IncidentModel.SELECT) .expand(IncidentModel.EXPAND) .top(1) .orderBy("sl_date", QueryOrder.Descending) .field("ID") .eq(incidentId) .and() .field("sl_propertyIDId") .gt(0) .and() .field("sl_inspectionIDId") .gt(0) .and() .field("sl_roomIDId") .gt(0); List<SPListItem> items = mClient.getListItems(Constants.LIST_NAME_INCIDENTS, query).get(); if (items != null && items.size() > 0) { IncidentModel model = new IncidentModel(items.get(0)); if (model.getPropertyId() > 0 && model.getInspectionId() > 0 && model.getRoomId() > 0) { return model; } } return null; }