/** Make sure the invited to map is still usable after re-opening of a review. */
  @Test
  public void testReviewReopening() {
    // From Objects to Disk
    R4EReviewGroup loadedGroup = null;
    try {
      loadedGroup = GoldenStubHandler.serializeStub();
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    // initialise local refs
    String dReviewName = "ReviewTwo";
    String dUser = "******";
    // Save a reference to the initial review
    R4EReview oReview = loadedGroup.getUserReviews().get(dUser).getInvitedToMap().get(dReviewName);
    R4EReview nReview = null;

    // Action: Close the review
    fFactory.closeR4EReview(oReview);

    try {
      nReview = fFactory.openR4EReview(loadedGroup, dReviewName);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertNotNull("Opened Review is null", nReview);

    // A new instance of the review should have been created
    assertNotSame(oReview, nReview);
    // Read the review reference available in the invitedto map
    R4EReview wasInvitedTo =
        loadedGroup.getUserReviews().get(dUser).getInvitedToMap().get(dReviewName);

    // The reference resolved from the invited to, shall be the same as the new one re-opened and
    // without manually
    // refreshing the reference to the new instance
    assertSame(nReview, wasInvitedTo);

    // The container group shall be re-initialised as part of the review opening sequence
    EObject rContainer = nReview.eContainer();
    assertNotNull(rContainer);
    // Make sure that the reference to the parent group is updated to the original parent group
    assertSame(loadedGroup, nReview.eContainer());
  }
 /**
  * Method getOriginalAnomaly.
  *
  * @param aOriginalReview R4EReview
  * @param aCurrentAnomaly R4EAnomaly
  * @return R4EAnomaly
  */
 public static R4EAnomaly getOriginalAnomaly(
     R4EReview aOriginalReview, R4EAnomaly aCurrentAnomaly) {
   if ((null != aOriginalReview) && (null != aCurrentAnomaly)) {
     // Loop through all anomalies and find the one whose R4EID is the same as the currently
     // imported one
     final String[] origIdTokens =
         aCurrentAnomaly
             .getInfoAtt()
             .get(R4EUIConstants.POSTPONED_ATTR_ORIG_ANOMALY_ID)
             .split(
                 R4EUIConstants
                     .SEPARATOR); // First token is user name, second token is sequence number
     if (null != origIdTokens) {
       final R4EUser origUser = aOriginalReview.getUsersMap().get(origIdTokens[0]);
       if (null != origUser) {
         for (R4EComment anomaly : origUser.getAddedComments()) {
           if (anomaly instanceof R4EAnomaly) {
             Integer id = Integer.valueOf(origIdTokens[1]);
             if (null != id) {
               if (id.intValue() == anomaly.getId().getSequenceID()) {
                 return (R4EAnomaly) anomaly;
               }
             }
           }
         }
       }
     }
   }
   return null;
 }
 /**
  * Method getParticipantForReview.
  *
  * @param aReview R4EReview
  * @param aParticipantId String
  * @return R4EParticipant
  * @throws ResourceHandlingException
  */
 public static R4EParticipant getParticipantForReview(R4EReview aReview, String aParticipantId)
     throws ResourceHandlingException {
   if (null == aReview) {
     return null;
   }
   R4EParticipant participant = (R4EParticipant) aReview.getUsersMap().get(aParticipantId);
   if (null == participant) {
     // Add the participant
     final List<R4EUserRole> role = new ArrayList<R4EUserRole>(1);
     role.add(R4EUserRole.R4E_ROLE_REVIEWER);
     participant =
         R4EUIModelController.FModelExt.createR4EParticipant(aReview, aParticipantId, role);
   }
   return participant;
 }
  /** Build elements one by one */
  public void testGroupReviewCreate() {
    R4EReviewGroup group = null;
    // required folder path and group name to build the new group file
    try {
      group = fFactory.createR4EReviewGroup(fGroupPath, GROUP_NAME);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
    }

    assertNotNull(group);
    URI uri = group.eResource().getURI();
    String expectedURI = fGroupPath.appendSegment("Group_One_group_root.xrer").toString();
    assertEquals(expectedURI, uri.toString());

    // Deserialise and assert
    group = null;
    try {
      group = fFactory.openR4EReviewGroup(uri);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
    } catch (CompatibilityException e) {
      e.printStackTrace();
    }

    // validate
    assertNotNull(group);
    assertEquals(GROUP_NAME, group.getName());

    // crate a review
    R4EReview review = null;
    try {
      review = fFactory.createR4EReview(group, REVIEW_NAME1, fUser1);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(REVIEW_NAME1, review.getName());

    // re-open the group
    group = null;
    try {
      group = fFactory.openR4EReviewGroup(uri);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    uri = review.eResource().getURI();
    // read the review
    try {
      review = fFactory.openR4EReview(group, review.getName());
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(REVIEW_NAME1, review.getName());

    // read the participant
    R4EUser participant = review.getUsersMap().values().iterator().next();
    uri = participant.eResource().getURI();
    try {
      ResourceSet resSet = participant.eResource().getResourceSet();
      participant = fReader.deserializeTopElement(uri, resSet, R4EParticipant.class);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(fUser1, participant.getId());

    // Clean up
    File folder = new File(URI.decode(fGroupPath.devicePath()));
    try {
      FileUtils.deleteDirectory(folder);
    } catch (IOException e) {
      e.printStackTrace();
      fail("Exception");
    }
  }