Search in sources :

Example 1 with API_MAXIMUM_PAGE_SIZE

use of org.sagebionetworks.bridge.BridgeConstants.API_MAXIMUM_PAGE_SIZE in project BridgeServer2 by Sage-Bionetworks.

the class ScheduledActivityService method retrieveAllPersistedActivitiesIntoMap.

private Map<String, ScheduledActivity> retrieveAllPersistedActivitiesIntoMap(ScheduleContext context, List<ScheduledActivity> scheduledActivities) {
    Set<String> activityGuids = scheduledActivities.stream().map((activity) -> {
        return activity.getGuid().split(":")[0];
    }).collect(Collectors.toSet());
    Map<String, ScheduledActivity> dbMap = Maps.newHashMap();
    // lose existing activities. So during the time window the user is looking at, we will return any activities that exist.
    for (String activityGuid : activityGuids) {
        ForwardCursorPagedResourceList<ScheduledActivity> list = activityDao.getActivityHistoryV2(context.getCriteriaContext().getHealthCode(), activityGuid, context.getStartsOn(), context.getEndsOn(), null, API_MAXIMUM_PAGE_SIZE);
        if (list != null) {
            for (ScheduledActivity activity : list.getItems()) {
                dbMap.put(activity.getGuid(), activity);
            }
        }
    }
    // IA-587: When a one-time task falls outside the schedule window, it's not returned by the
    // query above, so it is recreated, and it loses its finished state. Load all remaining scheduled activities.
    String healthCode = context.getCriteriaContext().getHealthCode();
    for (ScheduledActivity activity : scheduledActivities) {
        if (!dbMap.containsKey(activity.getGuid())) {
            ScheduledActivity dbActivity = activityDao.getActivity(context.getStartsOn().getZone(), healthCode, activity.getGuid(), false);
            if (dbActivity != null) {
                dbMap.put(dbActivity.getGuid(), dbActivity);
            }
        }
    }
    return dbMap;
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) ScheduleContextValidator(org.sagebionetworks.bridge.validators.ScheduleContextValidator) BridgeCollectors.toImmutableList(org.sagebionetworks.bridge.util.BridgeCollectors.toImmutableList) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) Schedule(org.sagebionetworks.bridge.models.schedules.Schedule) AppConfig(org.sagebionetworks.bridge.models.appconfig.AppConfig) SurveyReference(org.sagebionetworks.bridge.models.schedules.SurveyReference) Validate(org.sagebionetworks.bridge.validators.Validate) ActivityType(org.sagebionetworks.bridge.models.schedules.ActivityType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ScheduleContext(org.sagebionetworks.bridge.models.schedules.ScheduleContext) ArrayList(java.util.ArrayList) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) Map(java.util.Map) App(org.sagebionetworks.bridge.models.apps.App) JsonNode(com.fasterxml.jackson.databind.JsonNode) Comparator.comparing(java.util.Comparator.comparing) LinkedList(java.util.LinkedList) ScheduledActivityDao(org.sagebionetworks.bridge.dao.ScheduledActivityDao) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DateTime(org.joda.time.DateTime) API_MAXIMUM_PAGE_SIZE(org.sagebionetworks.bridge.BridgeConstants.API_MAXIMUM_PAGE_SIZE) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) CLIENT_DATA_MAX_BYTES(org.sagebionetworks.bridge.BridgeConstants.CLIENT_DATA_MAX_BYTES) MAX_DATE_RANGE_IN_DAYS(org.sagebionetworks.bridge.validators.ScheduleContextValidator.MAX_DATE_RANGE_IN_DAYS) Objects(java.util.Objects) BridgeConstants(org.sagebionetworks.bridge.BridgeConstants) List(java.util.List) Component(org.springframework.stereotype.Component) SchemaReference(org.sagebionetworks.bridge.models.schedules.SchemaReference) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) DateUtils(org.sagebionetworks.bridge.time.DateUtils) ScheduledActivityStatus(org.sagebionetworks.bridge.models.schedules.ScheduledActivityStatus) UPDATABLE_STATUSES(org.sagebionetworks.bridge.models.schedules.ScheduledActivityStatus.UPDATABLE_STATUSES) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) API_MINIMUM_PAGE_SIZE(org.sagebionetworks.bridge.BridgeConstants.API_MINIMUM_PAGE_SIZE) RangeTuple(org.sagebionetworks.bridge.models.RangeTuple) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Comparator.comparing (java.util.Comparator.comparing)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1