Skip to content

Commit 479ba6e

Browse files
Timeline API cleanup (#895)
* Add qcState to getScheduledTimelinesForSpecies API * Update current location query * Revert "Update current location query" This reverts commit 998455b.
1 parent 65e4a63 commit 479ba6e

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

snprc_scheduler/api-src/org/labkey/api/snprc_scheduler/SNPRC_schedulerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static SNPRC_schedulerService get()
2727
}
2828

2929
List<JSONObject> getActiveTimelines(Container c, User u, String ProjectObjectId, BatchValidationException errors);
30-
List<JSONObject> getScheduledTimelinesForSpecies(Container c, User u, String species, Date date, BatchValidationException errors);
30+
List<JSONObject> getScheduledTimelinesForSpecies(Container c, User u, String species, Date date, String qcState, BatchValidationException errors);
3131
List<Map<String, Object>> getActiveProjects(Container c, User u, ArrayList<SimpleFilter> filters, Boolean activeProjectItemsOnly, Date eventDate);
3232
JSONObject saveTimelineData(Container c, User u, JSONObject json, BatchValidationException errors);
3333
}

snprc_scheduler/src/org/labkey/snprc_scheduler/SNPRC_schedulerController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ public ApiResponse execute(SimpleApiJsonForm form, BindException errors)
118118
{
119119
species = url.getParameter("species");
120120
dateString = url.getParameter("date");
121+
String qcState = url.getParameter("qcState");
121122

122123
// assume current date if date is not passed in
123124
date = (dateString == null ? new Date() : DateUtil.parseDateTime(dateString, Timeline.TIMELINE_DATE_FORMAT));
124125
if (species != null && date != null)
125126
{
126127
timelines = SNPRC_schedulerService.get().getScheduledTimelinesForSpecies(getContainer(), getUser(),
127-
species, date, new BatchValidationException());
128+
species, date, qcState, new BatchValidationException());
128129

129130
props.put("success", true);
130131
props.put("rows", timelines);

snprc_scheduler/src/org/labkey/snprc_scheduler/services/SNPRC_schedulerServiceImpl.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525
import org.labkey.snprc_scheduler.domains.TimelineAnimalJunction;
2626
import org.labkey.snprc_scheduler.domains.TimelineItem;
2727
import org.labkey.snprc_scheduler.domains.TimelineProjectItem;
28+
import org.labkey.snprc_scheduler.security.QCStateEnum;
2829

2930
import java.util.ArrayList;
3031
import java.util.Date;
3132
import java.util.List;
3233
import java.util.Map;
3334

35+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
36+
3437
/**
3538
* Created by thawkins on 10/21/2018
3639
*/
@@ -87,37 +90,59 @@ public List<JSONObject> getActiveTimelines(Container c, User u, String projectOb
8790
}
8891

8992

90-
//TODO: need to add scheduleDate criteria
93+
/**
94+
* Retrieves timelines for a given species that have procedures scheduled on a specific date.
95+
* Optionally filters by QC state.
96+
*
97+
* @param c = Container object
98+
* @param u = User object
99+
* @param species = species identifier to filter timelines
100+
* @param date = schedule date to match against timeline items
101+
* @param qcState = optional QC state name to further filter timelines
102+
* @param errors = exception object for collecting validation errors
103+
* @return list of timeline JSON objects matching the criteria
104+
*/
91105
@Override
92-
public List<JSONObject> getScheduledTimelinesForSpecies(Container c, User u, String species, Date date, BatchValidationException errors) throws ApiUsageException
106+
public List<JSONObject> getScheduledTimelinesForSpecies(Container c, User u, String species, Date date, String qcState, BatchValidationException errors) throws ApiUsageException
93107
{
94108
List<JSONObject> timelinesJson = new ArrayList<>();
95109
try
96110
{
97111
SNPRC_schedulerUserSchema schema = SNPRC_schedulerManager.getSNPRC_schedulerUserSchema(c, u);
98112
TableInfo timelineTable = schema.getTable(SNPRC_schedulerSchema.TABLE_NAME_TIMELINE, schema.getDefaultContainerFilter(), false, false);
99113

100-
// only return timelines with procedures scheduled on specified date
114+
// Query for timeline ObjectIds that have items scheduled on the given date
101115
SQLFragment sql = new SQLFragment();
102116
sql.append("SELECT DISTINCT t." + Timeline.TIMELINE_OBJECTID);
103117
sql.append(" FROM ");
104118
sql.append(SNPRC_schedulerSchema.getInstance().getTableInfoTimeline(), "t");
105119
sql.append(" JOIN ");
106120
sql.append(SNPRC_schedulerSchema.getInstance().getTableInfoTimelineItem(), "ti");
107121
sql.append(" ON t." + Timeline.TIMELINE_OBJECTID + " = ti." + TimelineItem.TIMELINEITEM_TIMELINE_OBJECT_ID);
108-
sql.append(" WHERE " + "ti." + TimelineItem.TIMELINEITEM_SCHEDULE_DATE + " = ?" ).add(date);
122+
sql.append(" WHERE ti." + TimelineItem.TIMELINEITEM_SCHEDULE_DATE + " = ?").add(date);
109123

110124
SqlSelector selector = new SqlSelector(SNPRC_schedulerSchema.getInstance().getSchema(), sql);
111125

112126
List<String> objectIds = new ArrayList<>();
113127
selector.forEachMap(row -> objectIds.add( (String) row.get(Timeline.TIMELINE_OBJECTID)));
114128

115-
//SimpleFilter filter = new SimpleFilter(FieldKey.fromParts(Timeline.TIMELINE_SPECIES, "referenceId", "species"), species, CompareType.EQUAL);
129+
// Build filter for species, matching ObjectIds, and optional QC state
116130
SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("sndProject", "referenceId", "species"), species, CompareType.EQUAL);
117-
filter.addInClause(FieldKey.fromParts(Timeline.TIMELINE_OBJECTID), objectIds );
131+
filter.addInClause(FieldKey.fromParts(Timeline.TIMELINE_OBJECTID), objectIds);
132+
133+
if (isNotBlank(qcState))
134+
{
135+
Integer qcStateId = QCStateEnum.getQCStateEnumId(c, u,
136+
QCStateEnum.getQCStateEnumByName(qcState));
137+
if (qcStateId != null)
138+
{
139+
filter.addCondition(FieldKey.fromParts(Timeline.TIMELINE_QCSTATE), qcStateId, CompareType.EQUAL);
140+
}
141+
}
118142

119143
List<Timeline> timelines = new TableSelector(timelineTable, filter, null).getArrayList(Timeline.class);
120144

145+
// Populate nested collections for each timeline and convert to JSON
121146
for (Timeline timeline : timelines)
122147
{
123148
timeline.setTimelineItems(SNPRC_schedulerManager.get().getTimelineItems(c, u, timeline.getObjectId(), date));

0 commit comments

Comments
 (0)