@Test
  public void testCheckInWithContent() {
    String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);

    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);

    assertFalse(isCheckedOut(version.getProperties().getProperties()));

    Holder<Boolean> contentCopied = new Holder<Boolean>();
    Holder<String> idHolder = new Holder<String>(verId); // or should this
    // be version
    // series?
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    String pwcId = idHolder.getValue();

    ContentStream altContent = fCreator.createAlternateContent();
    Properties newProps =
        fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
    idHolder = new Holder<String>(pwcId);
    //        assertTrue(isCheckedOut(docId));
    assertTrue(isCheckedOut(pwcId));

    // Test check-in and pass content and properties
    String checkinComment = "Checkin with content and properties.";
    fVerSvc.checkIn(
        fRepositoryId,
        idHolder,
        true,
        newProps,
        altContent,
        checkinComment,
        null,
        null,
        null,
        null);
    // Neither the version nor the version series should be checked out any
    // longer:
    assertFalse(isCheckedOut(idHolder.getValue()));
    //        assertFalse(isCheckedOut(docId));
    ContentStream retrievedContent =
        fObjSvc.getContentStream(
            fRepositoryId,
            idHolder.getValue(),
            null,
            BigInteger.valueOf(-1) /* offset */,
            BigInteger.valueOf(-1) /* length */,
            null);

    // New content and property should be set
    assertTrue(fCreator.verifyContent(fCreator.createAlternateContent(), retrievedContent));
    assertTrue(
        fCreator.verifyProperty(
            idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW));
  }
  @Test
  public void testCancelCheckout() {
    String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String idOfLastVersion = version.getId();
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);
    assertFalse(isCheckedOut(version.getProperties().getProperties()));
    Holder<Boolean> contentCopied = new Holder<Boolean>();
    Holder<String> idHolder = new Holder<String>(verId); // or should this
    // be version
    // series?
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    String pwcId = idHolder.getValue();

    // Set a new content and modify property
    Properties props = fObjSvc.getProperties(fRepositoryId, pwcId, "*", null);
    String changeToken =
        (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
    ContentStream altContent = fCreator.createAlternateContent();
    idHolder = new Holder<String>(pwcId);
    Holder<String> tokenHolder = new Holder<String>(changeToken);
    fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null);
    fCreator.updateProperty(
        idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);

    // cancel checkout
    fVerSvc.cancelCheckOut(fRepositoryId, pwcId, null);
    try {
      // Verify that pwc no longer exists
      fObjSvc.getObject(
          fRepositoryId, pwcId, "*", false, IncludeRelationships.NONE, null, false, false, null);
      fail("Getting pwc after cancel checkout should fail.");
    } catch (CmisObjectNotFoundException e1) {
    } catch (Exception e2) {
      fail(
          "Expected a CmisObjectNotFoundException after cancel checkin, but got a "
              + e2.getClass().getName());
    }

    // verify that the old content and properties are still valid
    assertTrue(
        fCreator.verifyProperty(
            idOfLastVersion, VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE));
    ContentStream retrievedContent =
        fObjSvc.getContentStream(
            fRepositoryId,
            idOfLastVersion,
            null,
            BigInteger.valueOf(-1) /* offset */,
            BigInteger.valueOf(-1) /* length */,
            null);
    assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent()));
  }
 @Override
 public String getDocument(String id) {
   String returnedId = null;
   try {
     ObjectData res =
         fObjSvc.getObject(
             fRepositoryId, id, "*", false, IncludeRelationships.NONE, null, false, false, null);
     assertNotNull(res);
     testReturnedProperties(res.getProperties().getProperties());
     returnedId = res.getId();
     assertEquals(id, returnedId);
   } catch (Exception e) {
     fail("getObject() failed with exception: " + e);
   }
   return returnedId;
 }
  @Test
  public void testGetPropertiesOfLatestVersion() {
    VersioningState versioningState = VersioningState.MAJOR;
    String verId = createDocument(PROP_NAME, fRootFolderId, versioningState);
    getDocument(verId);

    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);

    Holder<Boolean> contentCopied = new Holder<Boolean>();
    Holder<String> idHolder = new Holder<String>(verId); // or should this
    // be version
    // series?
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    String pwcId = idHolder.getValue();

    ContentStream altContent = fCreator.createAlternateContent();
    Properties newProps =
        fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
    idHolder = new Holder<String>(pwcId);
    //        assertTrue(isCheckedOut(docId));
    assertTrue(isCheckedOut(pwcId));

    // Test check-in and pass content and properties
    String checkinComment = "Checkin with content and properties.";
    fVerSvc.checkIn(
        fRepositoryId,
        idHolder,
        true,
        newProps,
        altContent,
        checkinComment,
        null,
        null,
        null,
        null);

    Properties latest =
        fVerSvc.getPropertiesOfLatestVersion(fRepositoryId, docId, docId, true, "*", null);
    assertNotNull(latest);

    checkVersionProperties(verId, versioningState, latest.getProperties(), checkinComment);
  }
  /** Test of the <code>PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS</code> of the CMIS object. */
  @Test
  public void testJcrTypeProperty() {
    getRootFolder().getProperties();
    PropertiesImpl properties = new PropertiesImpl();

    properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"));
    properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, "TestFolder"));
    String testFolderId =
        getJcrRepository().createFolder(getSession(), properties, getRootFolder().getId());
    ObjectData testFolder =
        getJcrRepository().getObject(getSession(), testFolderId, null, null, null, false);
    Assert.assertNotNull(
        testFolder
            .getProperties()
            .getProperties()
            .get(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS)
            .getValues());
  }
  private void createVersionedDocument(VersioningState versioningState) {
    // type id is:
    // VersionTestTypeSystemCreator.VERSION_TEST_DOCUMENT_TYPE_ID
    String verId = createDocument(PROP_NAME, fRootFolderId, versioningState);
    getDocument(verId);

    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);

    List<ObjectData> allVersions =
        fVerSvc.getAllVersions(fRepositoryId, docId, docId, "*", false, null);
    assertEquals(1, allVersions.size());

    checkVersionProperties(
        verId, versioningState, allVersions.get(0).getProperties().getProperties(), null);
  }
 // //////////////////////////////////////////////////////////////////////////
 // Permission Check called from each CMIS method
 // //////////////////////////////////////////////////////////////////////////
 @Override
 public boolean checkPermission(CallContext callContext, Action action, ObjectData objectData) {
   AllowableActions _actions = objectData.getAllowableActions();
   if (_actions == null) {
     return false;
   } else {
     Set<Action> actions = _actions.getAllowableActions();
     if (CollectionUtils.isEmpty(actions)) {
       return false;
     } else {
       return actions.contains(action);
     }
   }
 }
  private String createVersionSeriesWithThreeVersions() {
    String verIdV1 = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
    getDocument(verIdV1);

    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId,
            verIdV1,
            "*",
            false,
            IncludeRelationships.NONE,
            null,
            false,
            false,
            null);
    String verSeriesId = getVersionSeriesId(verIdV1, version.getProperties().getProperties());

    // create second version with different content
    Holder<String> idHolder = new Holder<String>(verIdV1);
    Holder<Boolean> contentCopied = new Holder<Boolean>(false);
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);

    ContentStream content2 = createContent('a');
    Properties newProps =
        fCreator.getUpdatePropertyList(
            VersionTestTypeSystemCreator.PROPERTY_ID, "PropertyFromVersion2");
    idHolder = new Holder<String>(verIdV1);
    // Test check-in and pass content and properties
    String checkinComment = "Checkin from Unit Test-2.";
    fVerSvc.checkIn(
        fRepositoryId, idHolder, true, newProps, content2, checkinComment, null, null, null, null);
    String verIdV2 = idHolder.getValue();

    // create third version with different content
    contentCopied = new Holder<Boolean>(false);
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    ContentStream content3 = super.createContent('a');
    newProps =
        fCreator.getUpdatePropertyList(
            VersionTestTypeSystemCreator.PROPERTY_ID, "PropertyFromVersion3");
    // Test check-in and pass content and properties
    checkinComment = "Checkin from Unit Test-3.";
    fVerSvc.checkIn(
        fRepositoryId, idHolder, true, newProps, content3, checkinComment, null, null, null, null);
    /* String verIdV3 = */ idHolder.getValue();

    // Try to update version2 which should fail (on a versioned document
    // only a document that
    // is checked out can be modified.
    try {
      fCreator.updateProperty(
          verIdV2, VersionTestTypeSystemCreator.PROPERTY_ID, "ChangeWithoutCheckout");
      fail("updateProperty for an older version should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }
    // try to set content on an older version
    ContentStream content4 = super.createContent('x');
    idHolder = new Holder<String>(verIdV2);
    try {
      fObjSvc.setContentStream(fRepositoryId, idHolder, true, null, content4, null);
      fail("setContentStream for an older version should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }

    return verSeriesId;
  }
  @Test
  public void testGetLatestVersion() {
    VersioningState versioningState = VersioningState.MINOR;
    String verId = createDocument(PROP_NAME, fRootFolderId, versioningState);
    getDocument(verId);

    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);

    Holder<Boolean> contentCopied = new Holder<Boolean>();
    Holder<String> idHolder = new Holder<String>(verId); // or should this
    // be version
    // series?
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    String pwcId = idHolder.getValue();

    ContentStream altContent = fCreator.createAlternateContent();
    Properties newProps =
        fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
    idHolder = new Holder<String>(pwcId);
    //        assertTrue(isCheckedOut(docId));
    assertTrue(isCheckedOut(pwcId));

    // Test check-in and pass content and properties
    String checkinComment = "Checkin with content and properties.";
    fVerSvc.checkIn(
        fRepositoryId,
        idHolder,
        true,
        newProps,
        altContent,
        checkinComment,
        null,
        null,
        null,
        null);

    // get latest major version
    versioningState = VersioningState.MAJOR;
    boolean isMajor = true;
    ObjectData objData =
        fVerSvc.getObjectOfLatestVersion(
            fRepositoryId,
            docId,
            docId,
            isMajor,
            "*",
            false,
            IncludeRelationships.NONE,
            null,
            false,
            false,
            null);
    checkVersionProperties(
        verId, versioningState, objData.getProperties().getProperties(), checkinComment);
    ContentStream retrievedContent =
        fObjSvc.getContentStream(
            fRepositoryId,
            objData.getId(),
            null,
            BigInteger.valueOf(-1) /* offset */,
            BigInteger.valueOf(-1) /* length */,
            null);
    assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createAlternateContent()));

    // get latest non-major version, must be the same as before
    versioningState = VersioningState.MAJOR;
    isMajor = false;
    objData =
        fVerSvc.getObjectOfLatestVersion(
            fRepositoryId,
            docId,
            docId,
            isMajor,
            "*",
            false,
            IncludeRelationships.NONE,
            null,
            false,
            false,
            null);
    checkVersionProperties(
        verId, versioningState, objData.getProperties().getProperties(), checkinComment);
    retrievedContent =
        fObjSvc.getContentStream(
            fRepositoryId,
            objData.getId(),
            null,
            BigInteger.valueOf(-1) /* offset */,
            BigInteger.valueOf(-1) /* length */,
            null);
    assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createAlternateContent()));
  }
示例#10
0
  @Test
  public void testCheckOutAndOtherUser() {
    String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);
    assertFalse(isCheckedOut(version.getProperties().getProperties()));
    Holder<Boolean> contentCopied = new Holder<Boolean>();
    Holder<String> idHolder = new Holder<String>(verId); // or should this
    // be version
    // series?
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    String pwcId = idHolder.getValue();

    // Test that a checkin as another user is not possible
    setRuntimeContext(TEST_USER_2);
    try {
      fVerSvc.checkIn(
          fRepositoryId, idHolder, true, null, null, "My Comment", null, null, null, null);
      fail("Checking in a document as another user should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }

    // Test that a cancel checkout as another user is not possible
    try {
      fVerSvc.cancelCheckOut(fRepositoryId, pwcId, null);
      fail("Checking in a document as another user should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }

    // Test that an updateProperties as another user is not possible
    try {
      fCreator.updateProperty(pwcId, VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
      fail("updateProperty in a document as another user should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }

    ContentStream altContent = fCreator.createAlternateContent();
    Holder<String> pwcHolder = new Holder<String>(pwcId);
    try {
      fObjSvc.setContentStream(fRepositoryId, pwcHolder, true, null, altContent, null);
      fail("setContentStream in a document as another user should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }

    setRuntimeContext(TEST_USER);
    // Test that a check-in as same user is possible
    fVerSvc.checkIn(
        fRepositoryId,
        pwcHolder,
        true,
        null,
        null,
        "testCheckOutAndOtherUser",
        null,
        null,
        null,
        null);

    // Because nothing was changed we should have a new version with
    // identical content
    ContentStream retrievedContent =
        fObjSvc.getContentStream(
            fRepositoryId,
            pwcHolder.getValue(),
            null,
            BigInteger.valueOf(-1) /* offset */,
            BigInteger.valueOf(-1) /* length */,
            null);
    assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent()));
    assertTrue(
        fCreator.verifyProperty(
            idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE));
  }
示例#11
0
  @Test
  public void testCheckOutBasic() {
    String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);

    ObjectData version =
        fObjSvc.getObject(
            fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null);
    String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
    assertTrue(null != docId && docId.length() > 0);

    assertFalse(isCheckedOut(version.getProperties().getProperties()));

    Holder<Boolean> contentCopied = new Holder<Boolean>();
    Holder<String> idHolder = new Holder<String>(verId); // or should this
    // be version
    // series?
    fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
    String pwcId = idHolder.getValue();
    // test that object is checked out and that all properties are set
    // correctly
    Properties props = fObjSvc.getProperties(fRepositoryId, pwcId, "*", null);
    String changeToken =
        (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
    checkVersionProperties(pwcId, VersioningState.CHECKEDOUT, props.getProperties(), null);

    // Test that a second checkout is not possible
    try {
      fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
      fail("Checking out a document that is already checked-out should fail.");
    } catch (Exception e) {
      assertTrue(e instanceof CmisUpdateConflictException);
    }
    // version and version series should be checked out now
    //        assertTrue(isCheckedOut(docId));
    assertTrue(isCheckedOut(pwcId));

    // Set a new content and modify property
    ContentStream altContent = fCreator.createAlternateContent();
    idHolder = new Holder<String>(pwcId);
    Holder<String> tokenHolder = new Holder<String>(changeToken);
    fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null);
    fCreator.updateProperty(
        idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);

    // Test that a check-in as same user is possible
    String checkinComment = "Checkin without content and properties.";
    fVerSvc.checkIn(
        fRepositoryId, idHolder, true, null, null, checkinComment, null, null, null, null);
    // Neither the version nor the version series should be checked out any
    // longer:
    assertFalse(isCheckedOut(idHolder.getValue()));
    //        assertFalse(isCheckedOut(docId));
    ContentStream retrievedContent =
        fObjSvc.getContentStream(
            fRepositoryId,
            idHolder.getValue(),
            null,
            BigInteger.valueOf(-1) /* offset */,
            BigInteger.valueOf(-1) /* length */,
            null);
    assertTrue(fCreator.verifyContent(fCreator.createAlternateContent(), retrievedContent));
    assertTrue(
        fCreator.verifyProperty(
            idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW));

    List<ObjectData> allVersions =
        fVerSvc.getAllVersions(fRepositoryId, docId, docId, "*", false, null);
    assertEquals(2, allVersions.size());
  }