Example #1
0
 private void buildJavaScriptStudyList(
     JSONObject studies,
     String key,
     boolean canProvisionAll,
     Collection<Study> provisionableStudies)
     throws JSONException {
   List<JSONObject> a = new ArrayList<JSONObject>(1 + provisionableStudies.size());
   if (canProvisionAll) {
     a.add(
         new JSONObject(
             new MapBuilder<String, String>()
                 .put("identifier", JSON_ALL_SCOPE_IDENTIFIER)
                 .put("name", allName(ScopeType.STUDY))
                 .toMap()));
   }
   for (Study study : provisionableStudies) {
     a.add(
         new JSONObject(
             new MapBuilder<String, String>()
                 .put("identifier", study.getAssignedIdentifier())
                 .put("name", study.getName())
                 .toMap()));
   }
   Collections.sort(a, StudyJSONObjectComparator.INSTANCE);
   studies.put(key, a);
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    pscUserService = registerMockFor(PscUserService.class);
    ssaXmlSerializer = registerNiceMockFor(StudySubjectAssignmentXmlSerializer.class);

    Site nu = createSite("NU", "IL036");
    Study a = createBasicTemplate("A");
    StudySite a_nu = createStudySite(a, nu);
    a_nu.approveAmendment(a.getAmendment(), new Date());
    a_nu_1 = createAssignment(a_nu, createSubject("First", "One"));

    StudySegment ae0s1 = a.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(0);
    ScheduledStudySegment scheduledStudySegment = createScheduledStudySegment(ae0s1);
    a_nu_1.getScheduledCalendar().addStudySegment(scheduledStudySegment);

    jo =
        new PscUserBuilder("jo")
            .add(PscRole.STUDY_SUBJECT_CALENDAR_MANAGER)
            .forAllSites()
            .forAllStudies()
            .toUser();
    alice =
        new PscUserBuilder("alice")
            .add(PscRole.STUDY_SUBJECT_CALENDAR_MANAGER)
            .forAllSites()
            .forAllStudies()
            .toUser();

    setCurrentUser(alice);
    UriTemplateParameters.USERNAME.putIn(request, "jo");
    expect(pscUserService.getAuthorizableUser("jo")).andStubReturn(jo);
    expect(pscUserService.getManagedAssignments(jo, alice))
        .andStubReturn(createExpectedUssars(jo, a_nu_1));
  }
Example #3
0
 public void testRevisionWorkflowWhenInDevelopment() throws Exception {
   study.setDevelopmentAmendment(new Amendment());
   RevisionWorkflowStatus actual = actual().getRevisionWorkflowStatus();
   assertNotNull("Should be present", actual);
   assertEquals(
       "For wrong study",
       study.getAssignedIdentifier(),
       actual.getRevisedStudy().getAssignedIdentifier());
 }
Example #4
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    study = assignIds(createBasicTemplate("CRM 114"));
    for (Epoch e : study.getPlannedCalendar().getEpochs()) {
      for (StudySegment segment : e.getStudySegments()) {
        Period p = createPeriod(1, 1, 1);
        p.addPlannedActivity(createPlannedActivity("T", 1));
        segment.addPeriod(p);
      }
    }
    nu = createSite("NU", "IL675");
    vanderbilt = createSite("VU", "TN054");
    StudySite ss = study.addSite(nu);
    ss.approveAmendment(study.getAmendment(), new Date());
    configuration = registerMockFor(Configuration.class);
  }
Example #5
0
 public void testStudySiteWorkflowsHasOnePerVisibleStudySite() throws Exception {
   study.addSite(createSite("mayo", "MN567")); // not visible
   List<StudySiteWorkflowStatus> actual = actual().getStudySiteWorkflowStatuses();
   assertEquals("Wrong number of statuses", 1, actual.size());
   assertEquals(
       "1st status is for wrong study site",
       "IL675",
       actual.get(0).getStudySite().getSite().getAssignedIdentifier());
 }
Example #6
0
  public void testRemoveDetachedNodesWhileIterating() {
    Study s = Fixtures.createReleasedTemplate();
    Delta pc = Delta.createDeltaFor(s.getPlannedCalendar());
    Delta epoch2 = Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0));
    StudySegment segment1 = s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(1);
    Delta ss1 = Delta.createDeltaFor(segment1);
    Delta ss2 =
        Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(2));
    List<Delta<?>> deltaList = new ArrayList<Delta<?>>();
    deltaList.add(ss1);
    deltaList.add(epoch2);
    deltaList.add(pc);
    deltaList.add(ss2);

    expect(templateService.findEquivalentChild(s, pc.getNode())).andReturn(pc.getNode());
    expect(templateService.findEquivalentChild(s, epoch2.getNode())).andReturn(epoch2.getNode());
    expect(templateService.findEquivalentChild(s, ss1.getNode())).andReturn(ss1.getNode());
    expect(templateService.findEquivalentChild(s, ss2.getNode())).andReturn(ss2.getNode());

    replayMocks();
    DeltaIterator di = new DeltaIterator(deltaList, s, templateService, false);
    List<Delta> encountered = new LinkedList<Delta>();
    while (di.hasNext()) {
      Delta delta = di.next();
      encountered.add(delta);

      if (delta == epoch2) {
        segment1.setParent(null);
      }
    }

    assertEquals("Wrong number of deltas encountered: " + encountered, 3, encountered.size());
    assertEquals("Wrong delta 0", pc, encountered.get(0));
    assertEquals("Wrong delta 1", epoch2, encountered.get(1));
    assertEquals("Wrong delta 2", ss2, encountered.get(2));
    verifyMocks();
  }
Example #7
0
 public void testIsNotDevelopmentWhenUserCannotSeeDevelopment() throws Exception {
   study.setDevelopmentAmendment(new Amendment());
   SuiteRoleMembership mem =
       AuthorizationScopeMappings.createSuiteRoleMembership(
               PscRole.STUDY_SITE_PARTICIPATION_ADMINISTRATOR)
           .forSites(nu, vanderbilt)
           .forAllStudies();
   StudyWorkflowStatus actual =
       new StudyWorkflowStatus(
           study,
           AuthorizationObjectFactory.createPscUser("jo", mem),
           new WorkflowMessageFactory(),
           Fixtures.getTestingDeltaService(),
           configuration);
   assertEquals("Unexpected availability present", 1, actual.getTemplateAvailabilities().size());
   assertFalse(
       "Unexpected availability present",
       actual.getTemplateAvailabilities().contains(TemplateAvailability.IN_DEVELOPMENT));
 }
  @Override
  public void doInit() {
    super.doInit();

    study = studyDao.getByAssignedIdentifier(STUDY_IDENTIFIER.extractFrom(getRequest()));
    log.debug("Resolved study from {} as {}", STUDY_IDENTIFIER.extractFrom(getRequest()), study);
    site = siteDao.getByAssignedIdentifier(SITE_IDENTIFIER.extractFrom(getRequest()));
    log.debug("Resolved site from {} as {}", SITE_IDENTIFIER.extractFrom(getRequest()), site);

    if (study != null && site != null) {
      studySite = study.getStudySite(site);
    }
    setExisting(studySite != null);
    log.debug("Site {} participating in study", isExisting() ? "is" : "is not");

    getVariants().add(new Variant(MediaType.TEXT_XML));
    getAllowedMethods().add(Method.GET);
    getAllowedMethods().add(Method.POST);
  }
Example #9
0
 public void testIncludesAssignSitesMessageWhenNoSites() throws Exception {
   study.getStudySites().clear();
   assertMessage(WorkflowStep.ASSIGN_SITE);
 }
Example #10
0
 public void testDoesNotIncludeReleaseMessageWhenReleasedAtLeastOnce() throws Exception {
   study.setDevelopmentAmendment(new Amendment());
   assertNull(actual().getMessagesIgnoringRevisionMessages());
 }
Example #11
0
 public void testIncludesIdentifierMessageWhenHasTemporaryIdentifier() throws Exception {
   study.setAssignedIdentifier("[ABC 1450]");
   assertMessage(WorkflowStep.SET_ASSIGNED_IDENTIFIER);
 }
Example #12
0
 public void testDoesNotIncludeIdentifierMessageWhenDoesNotHaveTemporaryIdentifier()
     throws Exception {
   study.setAssignedIdentifier("ABC 1450");
   assertNoMessages();
 }
Example #13
0
 public void testTemplateAvailabilityIsAvailableAndInDevelopment() throws Exception {
   study.setDevelopmentAmendment(new Amendment());
   assertAvailabilityPresent(TemplateAvailability.AVAILABLE);
   assertAvailabilityPresent(TemplateAvailability.IN_DEVELOPMENT);
   assertAvailabilityNotPresent(TemplateAvailability.PENDING);
 }
Example #14
0
  public void testDetailOrder() {
    Study s = Fixtures.createReleasedTemplate();
    Period period = Fixtures.createPeriod("period1", 1, 10, 2);
    PlannedActivity plannedActivity = Fixtures.createPlannedActivity("activity", 3);
    PlannedActivityLabel plannedActivityLabel = Fixtures.createPlannedActivityLabel("label");
    period.addPlannedActivity(plannedActivity);
    plannedActivity.addPlannedActivityLabel(plannedActivityLabel);
    s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(0).getPeriods().add(period);

    Delta studyDelta = Delta.createDeltaFor(s.getPlannedCalendar().getStudy());
    Delta epochDelta = Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0));
    Delta studySegmentDelta =
        Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(1));
    Delta periodDelta =
        Delta.createDeltaFor(
            s.getPlannedCalendar()
                .getEpochs()
                .get(0)
                .getStudySegments()
                .get(0)
                .getPeriods()
                .last());
    Delta plannedActivityDelta =
        Delta.createDeltaFor(
            s.getPlannedCalendar()
                .getEpochs()
                .get(0)
                .getStudySegments()
                .get(0)
                .getPeriods()
                .first()
                .getPlannedActivities()
                .get(0));
    Delta plannedActivityLabelDelta =
        Delta.createDeltaFor(
            s.getPlannedCalendar()
                .getEpochs()
                .get(0)
                .getStudySegments()
                .get(0)
                .getPeriods()
                .first()
                .getPlannedActivities()
                .get(0)
                .getPlannedActivityLabels()
                .first());

    List<Delta<?>> listOfDeltas = new ArrayList<Delta<?>>();
    listOfDeltas.add(plannedActivityDelta);
    listOfDeltas.add(periodDelta);
    listOfDeltas.add(epochDelta);
    listOfDeltas.add(studyDelta);
    listOfDeltas.add(studySegmentDelta);
    listOfDeltas.add(plannedActivityLabelDelta);

    expect(templateService.findEquivalentChild(s, studyDelta.getNode())).andReturn(s);
    expect(templateService.findEquivalentChild(s, periodDelta.getNode())).andReturn(null);
    expect(templateService.findEquivalentChild(s, epochDelta.getNode()))
        .andReturn(epochDelta.getNode());
    expect(templateService.findEquivalentChild(s, studySegmentDelta.getNode()))
        .andReturn(studySegmentDelta.getNode());
    expect(templateService.findEquivalentChild(s, plannedActivityDelta.getNode())).andReturn(null);
    expect(templateService.findEquivalentChild(s, plannedActivityLabelDelta.getNode()))
        .andReturn(plannedActivityLabelDelta.getNode());
    replayMocks();
    DeltaIterator di = new DeltaIterator(listOfDeltas, s, templateService, false);

    assertSame("studyDelta is not the first element", studyDelta, di.next());
    assertSame("epochDelta is not the second element", epochDelta, di.next());
    assertSame("studySegmentDelta is not the third element", studySegmentDelta, di.next());
    assertSame("periodDelta is not the forth element", plannedActivityLabelDelta, di.next());
    assertFalse("deltaIterator has more elements ", di.hasNext());
    verifyMocks();
  }
Example #15
0
 public void testNotAvailableWhenReleasedButHasStudyMessages() throws Exception {
   study.getStudySites().clear();
   assertAvailabilityNotPresent(TemplateAvailability.AVAILABLE);
 }
Example #16
0
 public void testBothAvailableAndPendingWhenOneStudySiteIsReadyAndAnotherIsNot() throws Exception {
   setId(81, study.addSite(vanderbilt));
   assertAvailabilityPresent(TemplateAvailability.AVAILABLE);
   assertAvailabilityPresent(TemplateAvailability.PENDING);
 }
Example #17
0
 public void testIsNotAvailableWhenNotReleased() throws Exception {
   study.setAmendment(null);
   assertAvailabilityNotPresent(TemplateAvailability.AVAILABLE);
 }
Example #18
0
 public void testIsPendingWhenReleasedAndHasStudyMessages() throws Exception {
   study.getStudySites().clear();
   assertAvailabilityPresent(TemplateAvailability.PENDING);
 }
Example #19
0
 public void testStudySiteWorkflowsEmptyWhenNoStudySites() throws Exception {
   study.getStudySites().clear();
   List<StudySiteWorkflowStatus> actual = actual().getStudySiteWorkflowStatuses();
   assertNotNull("Should be a collection", actual);
   assertTrue("But an empty one", actual.isEmpty());
 }
Example #20
0
 public void testIsDevelopmentWhenUserCanSeeDevelopment() throws Exception {
   study.setDevelopmentAmendment(new Amendment());
   assertAvailabilityPresent(TemplateAvailability.IN_DEVELOPMENT);
 }
Example #21
0
 public void testIsNotDevelopmentWhenNotInDevelopment() throws Exception {
   study.setDevelopmentAmendment(null);
   assertAvailabilityNotPresent(TemplateAvailability.IN_DEVELOPMENT);
 }