예제 #1
0
  private boolean checkAddProperty(
      Properties properties, String typeId, Set<String> filter, String id) {
    if ((properties == null) || (properties.getProperties() == null)) {
      throw new IllegalArgumentException("Properties must not be null!");
    }

    if (id == null) {
      throw new IllegalArgumentException("Id must not be null!");
    }

    TypeDefinition type = repository.getTypeDefinitionsManager().getInternalTypeDefinition(typeId);
    if (type == null) {
      throw new IllegalArgumentException("Unknown type: " + typeId);
    }
    if (!type.getPropertyDefinitions().containsKey(id)) {
      throw new IllegalArgumentException("Unknown property: " + id);
    }

    String queryName = type.getPropertyDefinitions().get(id).getQueryName();

    if ((queryName != null) && (filter != null)) {
      if (!filter.contains(queryName)) {
        return false;
      } else {
        filter.remove(queryName);
      }
    }

    return true;
  }
예제 #2
0
  @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()));
  }
예제 #3
0
  @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);
  }
예제 #4
0
  /**
   * See CMIS 1.0 section 2.2.4.2 createDocumentFromSource
   *
   * @throws CmisStorageException
   */
  public JcrNode addNodeFromSource(JcrDocument source, Properties properties) {
    try {
      String destPath = PathManager.createCmisPath(getNode().getPath(), source.getName());
      Session session = getNode().getSession();

      session.getWorkspace().copy(source.getNode().getPath(), destPath);
      JcrNode jcrNode = create(session.getNode(destPath));

      // overlay new properties
      if (properties != null && properties.getProperties() != null) {
        updateProperties(jcrNode.getNode(), jcrNode.getTypeId(), properties);
      }

      session.save();
      return jcrNode;
    } catch (RepositoryException e) {
      log.debug(e.getMessage(), e);
      throw new CmisStorageException(e.getMessage(), e);
    }
  }
  @Override
  public void invalidArgumentSecondaryTypeIds(String repositoryId, Properties properties) {
    if (properties == null) return;
    Map<String, PropertyData<?>> map = properties.getProperties();
    if (MapUtils.isEmpty(map)) return;

    List<String> results = new ArrayList<String>();
    PropertyData<?> ids = map.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    if (ids == null || CollectionUtils.isEmpty(ids.getValues())) return;
    for (Object _id : ids.getValues()) {
      String id = (String) _id;
      TypeDefinitionContainer tdc = typeManager.getTypeById(repositoryId, id);
      if (tdc == null) {
        results.add(id);
      }
    }

    if (CollectionUtils.isNotEmpty(results)) {
      String msg =
          "Invalid cmis:SecondaryObjectTypeIds are provided:" + StringUtils.join(results, ",");
      invalidArgument(msg);
    }
  }
예제 #6
0
 private boolean isCheckedOut(String objectId) {
   Properties props = fObjSvc.getProperties(fRepositoryId, objectId, "*", null);
   return isCheckedOut(props.getProperties());
 }
예제 #7
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());
  }
예제 #8
0
  public static void setProperties(Node node, TypeDefinition type, Properties properties) {
    if (properties == null || properties.getProperties() == null) {
      throw new CmisConstraintException("No properties!");
    }

    Set<String> addedProps = new HashSet<String>();

    try {
      // check if all required properties are there
      for (PropertyData<?> prop : properties.getProperties().values()) {
        PropertyDefinition<?> propDef = type.getPropertyDefinitions().get(prop.getId());

        // do we know that property?
        if (propDef == null) {
          throw new CmisConstraintException("Property '" + prop.getId() + "' is unknown!");
        }

        // skip type id
        if (propDef.getId().equals(PropertyIds.OBJECT_TYPE_ID)) {
          log.warn("Cannot set " + PropertyIds.OBJECT_TYPE_ID + ". Ignoring");
          addedProps.add(prop.getId());
          continue;
        }

        // skip content stream file name
        if (propDef.getId().equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
          log.warn("Cannot set " + PropertyIds.CONTENT_STREAM_FILE_NAME + ". Ignoring");
          addedProps.add(prop.getId());
          continue;
        }

        // can it be set?
        if (propDef.getUpdatability() == Updatability.READONLY) {
          throw new CmisConstraintException("Property '" + prop.getId() + "' is readonly!");
        }

        // empty properties are invalid
        if (PropertyHelper.isPropertyEmpty(prop)) {
          throw new CmisConstraintException("Property '" + prop.getId() + "' must not be empty!");
        }

        // add it
        JcrConverter.setProperty(node, prop);
        addedProps.add(prop.getId());
      }

      // check if required properties are missing and try to add default values if defined
      for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
        if (!addedProps.contains(propDef.getId())
            && propDef.getUpdatability() != Updatability.READONLY) {
          PropertyData<?> prop = PropertyHelper.getDefaultValue(propDef);
          if (prop == null && propDef.isRequired()) {
            throw new CmisConstraintException("Property '" + propDef.getId() + "' is required!");
          } else if (prop != null) {
            JcrConverter.setProperty(node, prop);
          }
        }
      }
    } catch (RepositoryException e) {
      log.debug(e.getMessage(), e);
      throw new CmisStorageException(e.getMessage(), e);
    }
  }