예제 #1
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()));
  }
예제 #2
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;
  }
  private Content checkExceptionBeforeUpdateProperties(
      CallContext callContext,
      String repositoryId,
      Holder<String> objectId,
      Properties properties,
      Holder<String> changeToken) {
    // //////////////////
    // General Exception
    // //////////////////
    exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList());
    Content content = contentService.getContent(repositoryId, objectId.getValue());
    exceptionService.objectNotFound(DomainType.OBJECT, content, objectId.getValue());
    if (content.isDocument()) {
      Document d = (Document) content;
      exceptionService.versioning(d);
      exceptionService.constraintUpdateWhenCheckedOut(repositoryId, callContext.getUsername(), d);
      TypeDefinition typeDef = typeManager.getTypeDefinition(repositoryId, d);
      exceptionService.constraintImmutable(repositoryId, d, typeDef);
    }
    exceptionService.permissionDenied(
        callContext, repositoryId, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT, content);
    exceptionService.updateConflict(content, changeToken);

    TypeDefinition tdf = typeManager.getTypeDefinition(repositoryId, content);
    exceptionService.constraintPropertyValue(repositoryId, tdf, properties, objectId.getValue());

    return content;
  }
예제 #4
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);
  }
  @Override
  public String createRelationship(
      CallContext callContext,
      String repositoryId,
      Properties properties,
      List<String> policies,
      Acl addAces,
      Acl removeAces,
      ExtensionsData extension) {
    String objectTypeId = DataUtil.getIdProperty(properties, PropertyIds.OBJECT_TYPE_ID);
    RelationshipTypeDefinition td =
        (RelationshipTypeDefinition) typeManager.getTypeDefinition(repositoryId, objectTypeId);
    // //////////////////
    // Exception
    // //////////////////
    exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList());
    String sourceId = DataUtil.getIdProperty(properties, PropertyIds.SOURCE_ID);
    if (sourceId != null) {
      Content source = contentService.getContent(repositoryId, sourceId);
      if (source == null) exceptionService.constraintAllowedSourceTypes(td, source);
      exceptionService.permissionDenied(
          callContext, repositoryId, PermissionMapping.CAN_CREATE_RELATIONSHIP_SOURCE, source);
    }
    String targetId = DataUtil.getIdProperty(properties, PropertyIds.TARGET_ID);
    if (targetId != null) {
      Content target = contentService.getContent(repositoryId, targetId);
      if (target == null) exceptionService.constraintAllowedTargetTypes(td, target);
      exceptionService.permissionDenied(
          callContext, repositoryId, PermissionMapping.CAN_CREATE_RELATIONSHIP_TARGET, target);
    }

    exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_RELATIONSHIP);
    exceptionService.constraintPropertyValue(
        repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID));
    exceptionService.constraintCotrollablePolicies(td, policies, properties);
    exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties);
    exceptionService.constraintPermissionDefined(repositoryId, addAces, null);
    exceptionService.constraintPermissionDefined(repositoryId, removeAces, null);
    exceptionService.nameConstraintViolation(properties, null);

    // //////////////////
    // Body of the method
    // //////////////////
    Relationship relationship =
        contentService.createRelationship(
            callContext, repositoryId, properties, policies, addAces, removeAces, extension);
    nemakiCachePool.get(repositoryId).removeCmisCache(relationship.getSourceId());
    nemakiCachePool.get(repositoryId).removeCmisCache(relationship.getTargetId());

    return relationship.getId();
  }
  @Override
  public <T> void constraintPropertyValue(
      String repositoryId, TypeDefinition typeDefinition, Properties properties, String objectId) {
    Map<String, PropertyDefinition<?>> propertyDefinitions =
        typeDefinition.getPropertyDefinitions();

    // Adding secondary types and its properties MAY be done in the same
    // operation
    List<String> secIds =
        DataUtil.getIdListProperty(properties, PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    if (CollectionUtils.isNotEmpty(secIds)) {
      for (String secId : secIds) {
        TypeDefinition sec = typeManager.getTypeById(repositoryId, secId).getTypeDefinition();
        for (Entry<String, PropertyDefinition<?>> entry : sec.getPropertyDefinitions().entrySet()) {
          if (!propertyDefinitions.containsKey(entry.getKey())) {
            propertyDefinitions.put(entry.getKey(), entry.getValue());
          }
        }
      }
    }

    for (PropertyData<?> _pd : properties.getPropertyList()) {
      PropertyData<T> pd = (PropertyData<T>) _pd;
      PropertyDefinition<T> propertyDefinition =
          (PropertyDefinition<T>) propertyDefinitions.get(pd.getId());
      // If an input property is not defined one, output error.
      if (propertyDefinition == null) constraint(objectId, "An undefined property is provided!");

      // Check "required" flag
      if (propertyDefinition.isRequired() && !DataUtil.valueExist(pd.getValues()))
        constraint(objectId, "An required property is not provided!");

      // Check choices
      constraintChoices(propertyDefinition, pd, objectId);

      // Check min/max length
      switch (propertyDefinition.getPropertyType()) {
        case STRING:
          constraintStringPropertyValue(propertyDefinition, pd, objectId);
          break;
        case DECIMAL:
          constraintDecimalPropertyValue(propertyDefinition, pd, objectId);
        case INTEGER:
          constraintIntegerPropertyValue(propertyDefinition, pd, objectId);
          break;
        default:
          break;
      }
    }
  }
  @Override
  public String createItem(
      CallContext callContext,
      String repositoryId,
      Properties properties,
      String folderId,
      List<String> policies,
      Acl addAces,
      Acl removeAces,
      ExtensionsData extension) {
    // //////////////////
    // General Exception
    // //////////////////
    TypeDefinition td =
        typeManager.getTypeDefinition(repositoryId, DataUtil.getObjectTypeId(properties));
    Folder parentFolder = contentService.getFolder(repositoryId, folderId);
    exceptionService.objectNotFoundParentFolder(repositoryId, folderId, parentFolder);
    exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList());

    // //////////////////
    // Specific Exception
    // //////////////////
    exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_ITEM);
    exceptionService.constraintPropertyValue(
        repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID));
    exceptionService.constraintCotrollablePolicies(td, policies, properties);
    exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties);

    // //////////////////
    // Body of the method
    // //////////////////
    Item item =
        contentService.createItem(
            callContext,
            repositoryId,
            properties,
            folderId,
            policies,
            addAces,
            removeAces,
            extension);
    return item.getId();
  }
예제 #8
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 String createPolicy(
      CallContext callContext,
      String repositoryId,
      Properties properties,
      String folderId,
      List<String> policies,
      Acl addAces,
      Acl removeAces,
      ExtensionsData extension) {
    // //////////////////
    // General Exception
    // //////////////////
    exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList());
    // NOTE: folderId is ignored because policy is not filable in Nemaki
    TypeDefinition td =
        typeManager.getTypeDefinition(
            repositoryId, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_TYPE_ID));
    exceptionService.constraintPropertyValue(
        repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID));

    // //////////////////
    // Specific Exception
    // //////////////////
    exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_POLICY);
    // exceptionService.constraintAllowedChildObjectTypeId(parent,
    // properties);
    exceptionService.constraintCotrollablePolicies(td, policies, properties);
    exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties);
    // exceptionService.nameConstraintViolation(properties, parent);

    // //////////////////
    // Body of the method
    // //////////////////
    Policy policy =
        contentService.createPolicy(
            callContext, repositoryId, properties, policies, addAces, removeAces, extension);
    return policy.getId();
  }
  @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);
    }
  }
예제 #11
0
 private boolean isCheckedOut(String objectId) {
   Properties props = fObjSvc.getProperties(fRepositoryId, objectId, "*", null);
   return isCheckedOut(props.getProperties());
 }
예제 #12
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());
  }
예제 #13
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);
    }
  }