Search in sources :

Example 1 with HasGuid

use of org.sagebionetworks.bridge.models.schedules2.HasGuid 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);
    }
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) Study(org.sagebionetworks.bridge.models.studies.Study) CAN_EDIT_SCHEDULES(org.sagebionetworks.bridge.AuthUtils.CAN_EDIT_SCHEDULES) INCLUDE_DELETED(org.sagebionetworks.bridge.models.ResourceList.INCLUDE_DELETED) OFFSET_BY(org.sagebionetworks.bridge.models.ResourceList.OFFSET_BY) LoggerFactory(org.slf4j.LoggerFactory) NEGATIVE_OFFSET_ERROR(org.sagebionetworks.bridge.BridgeConstants.NEGATIVE_OFFSET_ERROR) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestContext(org.sagebionetworks.bridge.RequestContext) StringUtils(org.apache.commons.lang3.StringUtils) Timeline(org.sagebionetworks.bridge.models.schedules2.timelines.Timeline) ParticipantScheduleGenerator(org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantScheduleGenerator) Session(org.sagebionetworks.bridge.models.schedules2.Session) ORG_ID(org.sagebionetworks.bridge.AuthEvaluatorField.ORG_ID) Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) PAGE_SIZE(org.sagebionetworks.bridge.models.ResourceList.PAGE_SIZE) API_MAXIMUM_PAGE_SIZE(org.sagebionetworks.bridge.BridgeConstants.API_MAXIMUM_PAGE_SIZE) Account(org.sagebionetworks.bridge.models.accounts.Account) ADMIN(org.sagebionetworks.bridge.Roles.ADMIN) List(java.util.List) Schedule2Dao(org.sagebionetworks.bridge.dao.Schedule2Dao) Optional(java.util.Optional) BridgeUtils(org.sagebionetworks.bridge.BridgeUtils) API_MINIMUM_PAGE_SIZE(org.sagebionetworks.bridge.BridgeConstants.API_MINIMUM_PAGE_SIZE) CAN_READ_STUDIES(org.sagebionetworks.bridge.AuthUtils.CAN_READ_STUDIES) TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Stopwatch(com.google.common.base.Stopwatch) Validate(org.sagebionetworks.bridge.validators.Validate) Scheduler(org.sagebionetworks.bridge.models.schedules2.timelines.Scheduler) INSTANCE(org.sagebionetworks.bridge.validators.Schedule2Validator.INSTANCE) TimelineMetadata(org.sagebionetworks.bridge.models.schedules2.timelines.TimelineMetadata) ParticipantSchedule(org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantSchedule) StudyActivityEventIdsMap(org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap) PAGE_SIZE_ERROR(org.sagebionetworks.bridge.BridgeConstants.PAGE_SIZE_ERROR) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) PublishedEntityException(org.sagebionetworks.bridge.exceptions.PublishedEntityException) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SUPERADMIN(org.sagebionetworks.bridge.Roles.SUPERADMIN) DateTime(org.joda.time.DateTime) CAN_READ_SCHEDULES(org.sagebionetworks.bridge.AuthUtils.CAN_READ_SCHEDULES) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) STUDY_ID(org.sagebionetworks.bridge.AuthEvaluatorField.STUDY_ID) BridgeUtils.formatActivityEventId(org.sagebionetworks.bridge.BridgeUtils.formatActivityEventId) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) CAN_CREATE_SCHEDULES(org.sagebionetworks.bridge.AuthUtils.CAN_CREATE_SCHEDULES) HasGuid(org.sagebionetworks.bridge.models.schedules2.HasGuid) StudyActivityEventIdsMap(org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap) TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Stopwatch (com.google.common.base.Stopwatch)1 List (java.util.List)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 Collectors.toList (java.util.stream.Collectors.toList)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1 ORG_ID (org.sagebionetworks.bridge.AuthEvaluatorField.ORG_ID)1 STUDY_ID (org.sagebionetworks.bridge.AuthEvaluatorField.STUDY_ID)1 CAN_CREATE_SCHEDULES (org.sagebionetworks.bridge.AuthUtils.CAN_CREATE_SCHEDULES)1 CAN_EDIT_SCHEDULES (org.sagebionetworks.bridge.AuthUtils.CAN_EDIT_SCHEDULES)1 CAN_READ_SCHEDULES (org.sagebionetworks.bridge.AuthUtils.CAN_READ_SCHEDULES)1 CAN_READ_STUDIES (org.sagebionetworks.bridge.AuthUtils.CAN_READ_STUDIES)1 API_MAXIMUM_PAGE_SIZE (org.sagebionetworks.bridge.BridgeConstants.API_MAXIMUM_PAGE_SIZE)1 API_MINIMUM_PAGE_SIZE (org.sagebionetworks.bridge.BridgeConstants.API_MINIMUM_PAGE_SIZE)1 NEGATIVE_OFFSET_ERROR (org.sagebionetworks.bridge.BridgeConstants.NEGATIVE_OFFSET_ERROR)1 PAGE_SIZE_ERROR (org.sagebionetworks.bridge.BridgeConstants.PAGE_SIZE_ERROR)1