Skip to content

Commit a68fa99

Browse files
Merge 26.3 to develop
2 parents 49d31fb + 92067f5 commit a68fa99

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
@@ -117,13 +117,14 @@ public ApiResponse execute(SimpleApiJsonForm form, BindException errors)
117117
{
118118
species = url.getParameter("species");
119119
dateString = url.getParameter("date");
120+
String qcState = url.getParameter("qcState");
120121

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

128129
props.put("success", true);
129130
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
@@ -27,12 +27,15 @@
2727
import org.labkey.snprc_scheduler.domains.TimelineAnimalJunction;
2828
import org.labkey.snprc_scheduler.domains.TimelineItem;
2929
import org.labkey.snprc_scheduler.domains.TimelineProjectItem;
30+
import org.labkey.snprc_scheduler.security.QCStateEnum;
3031

3132
import java.util.ArrayList;
3233
import java.util.Date;
3334
import java.util.List;
3435
import java.util.Map;
3536

37+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
38+
3639
/**
3740
* Created by thawkins on 10/21/2018
3841
*/
@@ -91,37 +94,59 @@ public List<JSONObject> getActiveTimelines(Container c, User u, String projectOb
9194
}
9295

9396

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

104-
// only return timelines with procedures scheduled on specified date
118+
// Query for timeline ObjectIds that have items scheduled on the given date
105119
SQLFragment sql = new SQLFragment();
106120
sql.append("SELECT DISTINCT t." + Timeline.TIMELINE_OBJECTID);
107121
sql.append(" FROM ");
108122
sql.append(SNPRC_schedulerSchema.getInstance().getTableInfoTimeline(), "t");
109123
sql.append(" JOIN ");
110124
sql.append(SNPRC_schedulerSchema.getInstance().getTableInfoTimelineItem(), "ti");
111125
sql.append(" ON t." + Timeline.TIMELINE_OBJECTID + " = ti." + TimelineItem.TIMELINEITEM_TIMELINE_OBJECT_ID);
112-
sql.append(" WHERE " + "ti." + TimelineItem.TIMELINEITEM_SCHEDULE_DATE + " = ?" ).add(date);
126+
sql.append(" WHERE ti." + TimelineItem.TIMELINEITEM_SCHEDULE_DATE + " = ?").add(date);
113127

114128
SqlSelector selector = new SqlSelector(SNPRC_schedulerSchema.getInstance().getSchema(), sql);
115129

116130
List<String> objectIds = new ArrayList<>();
117131
selector.forEachMap(row -> objectIds.add( (String) row.get(Timeline.TIMELINE_OBJECTID)));
118132

119-
//SimpleFilter filter = new SimpleFilter(FieldKey.fromParts(Timeline.TIMELINE_SPECIES, "referenceId", "species"), species, CompareType.EQUAL);
133+
// Build filter for species, matching ObjectIds, and optional QC state
120134
SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("sndProject", "referenceId", "species"), species, CompareType.EQUAL);
121-
filter.addInClause(FieldKey.fromParts(Timeline.TIMELINE_OBJECTID), objectIds );
135+
filter.addInClause(FieldKey.fromParts(Timeline.TIMELINE_OBJECTID), objectIds);
136+
137+
if (isNotBlank(qcState))
138+
{
139+
Integer qcStateId = QCStateEnum.getQCStateEnumId(c, u,
140+
QCStateEnum.getQCStateEnumByName(qcState));
141+
if (qcStateId != null)
142+
{
143+
filter.addCondition(FieldKey.fromParts(Timeline.TIMELINE_QCSTATE), qcStateId, CompareType.EQUAL);
144+
}
145+
}
122146

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

149+
// Populate nested collections for each timeline and convert to JSON
125150
for (Timeline timeline : timelines)
126151
{
127152
timeline.setTimelineItems(SNPRC_schedulerManager.get().getTimelineItems(c, u, timeline.getObjectId(), date));

0 commit comments

Comments
 (0)