/**
   * Verifies whether this element in a Review element and, if so, if we are part of it
   *
   * @param aElement - the model element
   * @return - true if this is a review and we are part of it, false otherwise
   */
  private boolean isMyReview(IR4EUIModelElement aElement) {

    IR4EUIModelElement currentElement = aElement;
    while (null != currentElement) {
      if (currentElement instanceof R4EUIReviewBasic) {
        if (((R4EUIReviewBasic) currentElement).isParticipant(R4EUIModelController.getReviewer())) {
          return true;
        }
      }
      currentElement = currentElement.getParent();
    }
    return false;
  }
Exemplo n.º 2
0
  /**
   * Method copyAnomalyData.
   *
   * @param aTargetAnomaly R4EAnomaly
   * @param aSourceAnomaly R4EAnomaly
   * @throws ResourceHandlingException
   * @throws OutOfSyncException
   */
  public static void copyAnomalyData(R4EAnomaly aTargetAnomaly, R4EAnomaly aSourceAnomaly)
      throws ResourceHandlingException, OutOfSyncException {
    if ((null != aTargetAnomaly) && (null != aSourceAnomaly)) {
      final Long bookNum =
          R4EUIModelController.FResourceUpdater.checkOut(
              aTargetAnomaly, R4EUIModelController.getReviewer());

      // Data copied unconditionally
      aTargetAnomaly.setCreatedOn(aSourceAnomaly.getCreatedOn());
      aTargetAnomaly.setDecidedByID(aSourceAnomaly.getDecidedByID());
      aTargetAnomaly.setFixedByID(aSourceAnomaly.getFixedByID());
      aTargetAnomaly.setFollowUpByID(aSourceAnomaly.getFollowUpByID());
      aTargetAnomaly.setState(aSourceAnomaly.getState());
      aTargetAnomaly.setFixedInVersion(aSourceAnomaly.getFixedInVersion());
      aTargetAnomaly.setNotAcceptedReason(aSourceAnomaly.getNotAcceptedReason());

      // Data copied only if not set previously
      if (null == aTargetAnomaly.getTitle() || ("").equals(aTargetAnomaly.getTitle())) {
        aTargetAnomaly.setTitle(aSourceAnomaly.getTitle());
      }
      if (null == aTargetAnomaly.getDescription() || ("").equals(aTargetAnomaly.getDescription())) {
        aTargetAnomaly.setDescription(aSourceAnomaly.getDescription());
      }
      if (null == aTargetAnomaly.getRank()) {
        aTargetAnomaly.setRank(aSourceAnomaly.getRank());
      }
      if (null == aTargetAnomaly.getRuleID() && null != aSourceAnomaly.getRuleID()) {
        aTargetAnomaly.setRuleID(aSourceAnomaly.getRuleID());
      }
      if (null != aSourceAnomaly.getType()) {
        final R4ECommentType oldCommentType = (R4ECommentType) aSourceAnomaly.getType();
        R4ECommentType commentType = (R4ECommentType) aTargetAnomaly.getType();
        if (null != oldCommentType) {
          if (null == commentType) {
            commentType = RModelFactory.eINSTANCE.createR4ECommentType();
            if (null != commentType) {
              commentType.setType(oldCommentType.getType());
            }
            aTargetAnomaly.setType(commentType);
          }
        }
      }
      R4EUIModelController.FResourceUpdater.checkIn(bookNum);
    }
  }
  /** Method createReviewItems */
  private void createReviewItems() throws CoreException {
    fItem = fProxy.getItemProxy().createCommitItem(TestUtils.FJavaIProject, 0);
    // close and re-open, so the validation takes de-serialized information
    String itemName = fItem.getName();
    fProxy.getCommandProxy().closeElement(fReview);
    fProxy.getCommandProxy().openElement(fReview);
    for (IR4EUIModelElement elem : fReview.getChildren()) {
      if (elem.getName().equals(itemName)) {
        fItem = (R4EUIReviewItem) elem;
      }
    }

    // Now validate
    Assert.assertNotNull(fItem);
    Assert.assertEquals(R4EUIModelController.getReviewer(), fItem.getItem().getAddedById());
    Assert.assertEquals("*****@*****.**", fItem.getItem().getAuthorRep());
    Assert.assertEquals("second Java Commit", fItem.getItem().getDescription());
    Assert.assertEquals(4, fItem.getChildren().length);
    for (int i = 0; i < fItem.getChildren().length; i++) {
      if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
        fAnomalyFileIndex = i; // Used later to add anomalies
        Assert.assertEquals(
            TestUtils.JAVA_FILE1_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getBase().getName());
        Assert.assertEquals(
            TestUtils.JAVA_FILE1_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getTarget().getName());
        Assert.assertEquals(
            606,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(0)
                        .getTarget()
                        .getLocation())
                .getStartPosition());
        Assert.assertEquals(
            25,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(0)
                        .getTarget()
                        .getLocation())
                .getLength());
        Assert.assertEquals(
            665,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(1)
                        .getTarget()
                        .getLocation())
                .getStartPosition());
        Assert.assertEquals(
            63,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(1)
                        .getTarget()
                        .getLocation())
                .getLength());
        Assert.assertEquals(
            733,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(2)
                        .getTarget()
                        .getLocation())
                .getStartPosition());
        Assert.assertEquals(
            61,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(2)
                        .getTarget()
                        .getLocation())
                .getLength());
        Assert.assertTrue(
            fProxy
                .getCommandProxy()
                .verifyAnnotations(
                    ((R4EUIFileContext) fItem.getChildren()[i])
                        .getContentsContainerElement()
                        .getChildren(),
                    true,
                    R4EUIConstants.DELTA_ANNOTATION_ID));
      } else if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE4_PROJ_NAME)) {
        Assert.assertNull(fItem.getItem().getFileContextList().get(i).getBase());
        Assert.assertEquals(
            TestUtils.JAVA_FILE4_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getTarget().getName());
      } else if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE3_PROJ_NAME)) {
        Assert.assertNull(fItem.getItem().getFileContextList().get(i).getBase());
        Assert.assertEquals(
            TestUtils.JAVA_FILE3_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getTarget().getName());
      } else if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE2_PROJ_NAME)) {
        Assert.assertEquals(
            TestUtils.JAVA_FILE2_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getBase().getName());
        Assert.assertNull(fItem.getItem().getFileContextList().get(i).getTarget());
      }
    }

    fItem2 = fProxy.getItemProxy().createManualTreeItem(TestUtils.FJavaFile3);
    Assert.assertNotNull(fItem2);
    Assert.assertEquals(R4EUIModelController.getReviewer(), fItem2.getItem().getAddedById());
    Assert.assertEquals(
        TestUtils.JAVA_FILE3_PROJ_NAME,
        fItem2.getItem().getFileContextList().get(0).getBase().getName());
    Assert.assertEquals(
        TestUtils.JAVA_FILE3_PROJ_NAME,
        fItem2.getItem().getFileContextList().get(0).getTarget().getName());
    Assert.assertEquals(
        0,
        ((R4ETextPosition)
                fItem2
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getStartPosition());
    Assert.assertEquals(
        755,
        ((R4ETextPosition)
                fItem2
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getLength());
    Assert.assertTrue(
        fProxy
            .getCommandProxy()
            .verifyAnnotations(
                ((R4EUIFileContext) fItem2.getChildren()[0])
                    .getContentsContainerElement()
                    .getChildren(),
                false,
                R4EUIConstants.SELECTION_ANNOTATION_ID));

    fItem3 = fProxy.getItemProxy().createManualTextItem(TestUtils.FJavaFile4, 50, 20);
    Assert.assertNotNull(fItem3);
    Assert.assertEquals(R4EUIModelController.getReviewer(), fItem3.getItem().getAddedById());
    Assert.assertEquals(
        TestUtils.JAVA_FILE4_PROJ_NAME,
        fItem3.getItem().getFileContextList().get(0).getBase().getName());
    Assert.assertEquals(
        TestUtils.JAVA_FILE4_PROJ_NAME,
        fItem3.getItem().getFileContextList().get(0).getTarget().getName());
    Assert.assertEquals(
        50,
        ((R4ETextPosition)
                fItem3
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getStartPosition());
    Assert.assertEquals(
        20,
        ((R4ETextPosition)
                fItem3
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getLength());
    Assert.assertTrue(
        fProxy
            .getCommandProxy()
            .verifyAnnotations(
                ((R4EUIFileContext) fItem3.getChildren()[0])
                    .getContentsContainerElement()
                    .getChildren(),
                true,
                R4EUIConstants.SELECTION_ANNOTATION_ID));
  }