use of org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap in project BridgeServer2 by Sage-Bionetworks.
the class ActivityEventController method deleteActivityEventForSelf.
@DeleteMapping("/v5/studies/{studyId}/participants/self/activityevents/{eventId}")
public StatusMessage deleteActivityEventForSelf(@PathVariable String studyId, @PathVariable String eventId, @RequestParam(required = false) String showError) {
UserSession session = getAuthenticatedAndConsentedSession();
if (!session.getParticipant().getStudyIds().contains(studyId)) {
throw new EntityNotFoundException(Account.class);
}
StudyActivityEventRequest request = new StudyActivityEventRequest(eventId, null, null, null);
StudyActivityEventIdsMap eventMap = studyService.getStudyActivityEventIdsMap(session.getAppId(), studyId);
boolean showErrorBool = "true".equals(showError);
studyActivityEventService.deleteEvent(request.parse(eventMap).withAppId(session.getAppId()).withStudyId(studyId).withUserId(session.getId()).build(), showErrorBool);
return EVENT_DELETED_MSG;
}
use of org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap in project BridgeServer2 by Sage-Bionetworks.
the class AdherenceService method cleanupSearch.
protected AdherenceRecordsSearch cleanupSearch(String appId, AdherenceRecordsSearch search) {
checkNotNull(appId);
checkNotNull(search);
// optimization: skip all this if not relevant to the search
boolean skipFixes = search.getEventTimestamps().isEmpty() && search.getInstanceGuids().isEmpty() && Boolean.FALSE.equals(search.getCurrentTimestampsOnly());
if (skipFixes) {
return search;
}
AdherenceRecordsSearch.Builder builder = search.toBuilder();
if (TRUE.equals(search.getCurrentTimestampsOnly()) || !search.getEventTimestamps().isEmpty()) {
StudyActivityEventIdsMap eventMap = studyService.getStudyActivityEventIdsMap(appId, search.getStudyId());
Map<String, DateTime> fixedMap = new HashMap<>();
if (TRUE.equals(search.getCurrentTimestampsOnly())) {
// This adds current server timestamps to the search filters
Map<String, DateTime> events = studyActivityEventService.getRecentStudyActivityEvents(appId, search.getStudyId(), search.getUserId()).getItems().stream().collect(toMap(StudyActivityEvent::getEventId, StudyActivityEvent::getTimestamp));
addToMap(events, eventMap, fixedMap);
}
if (!search.getEventTimestamps().isEmpty()) {
// This fixes things like failing to put a "custom:" prefix on a custom event.
addToMap(search.getEventTimestamps(), eventMap, fixedMap);
}
builder.withEventTimestamps(fixedMap);
}
// to a different map.
if (!search.getInstanceGuids().isEmpty()) {
Map<String, DateTime> map = new HashMap<>();
Set<String> instanceGuids = new HashSet<>();
for (String instanceGuid : search.getInstanceGuids()) {
String[] split = instanceGuid.split("@", 2);
if (split.length == 2) {
map.put(split[0], DateTime.parse(split[1]));
} else {
instanceGuids.add(instanceGuid);
}
}
builder.withInstanceGuidStartedOnMap(map);
builder.withInstanceGuids(instanceGuids);
}
return builder.build();
}
use of org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap in project BridgeServer2 by Sage-Bionetworks.
the class StudyService method getStudyActivityEventIdsMap.
public StudyActivityEventIdsMap getStudyActivityEventIdsMap(String appId, String studyId) {
StudyActivityEventIdsMap map = new StudyActivityEventIdsMap();
Study study = getStudy(appId, studyId, true);
map.addCustomEvents(study.getCustomEvents());
Schedule2 schedule = scheduleService.getScheduleForStudy(appId, study).orElse(null);
if (schedule != null) {
map.addStudyBursts(schedule.getStudyBursts());
}
return map;
}
use of org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap in project BridgeServer2 by Sage-Bionetworks.
the class Schedule2Service method preValidationCleanup.
/**
* Set GUIDs on objects that don't have them; clean up event keys or set
* them to null if they're not valid, so they will fail validation.
*/
void preValidationCleanup(Study study, Schedule2 schedule, Consumer<HasGuid> consumer) {
checkNotNull(study);
checkNotNull(schedule);
StudyActivityEventIdsMap map = new StudyActivityEventIdsMap();
map.addCustomEvents(study.getCustomEvents());
map.addStudyBursts(schedule.getStudyBursts());
for (Session session : schedule.getSessions()) {
consumer.accept(session);
session.setSchedule(schedule);
for (TimeWindow window : session.getTimeWindows()) {
consumer.accept(window);
}
List<String> events = session.getStartEventIds().stream().map(s -> formatActivityEventId(map, s)).collect(toList());
session.setStartEventIds(events);
}
}
use of org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap in project BridgeServer2 by Sage-Bionetworks.
the class StudyActivityEventServiceTest method getStudyActivityEventHistory.
@Test
public void getStudyActivityEventHistory() {
List<StudyActivityEvent> list = new ArrayList<>();
PagedResourceList<StudyActivityEvent> page = new PagedResourceList<>(list, 100);
when(mockDao.getStudyActivityEventHistory(TEST_USER_ID, TEST_STUDY_ID, "custom:event1", 10, 100)).thenReturn(page);
Account account = Account.create();
account.setId(TEST_USER_ID);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
StudyActivityEventIdsMap eventMap = new StudyActivityEventIdsMap();
eventMap.addCustomEvents(ImmutableList.of(new StudyCustomEvent("event1", MUTABLE)));
when(mockStudyService.getStudyActivityEventIdsMap(TEST_APP_ID, TEST_STUDY_ID)).thenReturn(eventMap);
PagedResourceList<StudyActivityEvent> retValue = service.getStudyActivityEventHistory(ACCOUNT_ID, TEST_STUDY_ID, "custom:event1", 10, 100);
assertSame(retValue, page);
assertEquals(retValue.getRequestParams().get("offsetBy"), Integer.valueOf(10));
assertEquals(retValue.getRequestParams().get("pageSize"), Integer.valueOf(100));
}
Aggregations