@Override
  public String createDocumentFromSource(
      CallContext callContext,
      String repositoryId,
      String sourceId,
      Properties properties,
      String folderId,
      VersioningState versioningState,
      List<String> policies,
      Acl addAces,
      Acl removeAces) {
    Document original = contentService.getDocument(repositoryId, sourceId);
    DocumentTypeDefinition td =
        (DocumentTypeDefinition)
            typeManager.getTypeDefinition(repositoryId, original.getObjectType());

    // //////////////////
    // General Exception
    // //////////////////
    exceptionService.invalidArgumentRequired("properties", properties);
    exceptionService.invalidArgumentRequiredParentFolderId(repositoryId, folderId);
    Folder parentFolder = contentService.getFolder(repositoryId, folderId);
    exceptionService.objectNotFoundParentFolder(repositoryId, folderId, parentFolder);
    exceptionService.permissionDenied(
        callContext, repositoryId, PermissionMapping.CAN_CREATE_FOLDER_FOLDER, parentFolder);

    // //////////////////
    // Specific Exception
    // //////////////////
    exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_DOCUMENT);
    exceptionService.constraintAllowedChildObjectTypeId(parentFolder, properties);
    exceptionService.constraintPropertyValue(
        repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID));
    exceptionService.constraintControllableVersionable(td, versioningState, null);
    versioningState =
        (td.isVersionable() && versioningState == null) ? VersioningState.MAJOR : versioningState;
    exceptionService.constraintCotrollablePolicies(td, policies, properties);
    exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties);
    exceptionService.constraintPermissionDefined(repositoryId, addAces, null);
    exceptionService.constraintPermissionDefined(repositoryId, removeAces, null);
    exceptionService.nameConstraintViolation(properties, parentFolder);

    // //////////////////
    // Body of the method
    // //////////////////
    Document document =
        contentService.createDocumentFromSource(
            callContext,
            repositoryId,
            properties,
            parentFolder,
            original,
            versioningState,
            policies,
            addAces,
            removeAces);
    return document.getId();
  }
 @Override
 public void constraintVersionable(String repositoryId, String typeId) {
   DocumentTypeDefinition type =
       (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, typeId);
   if (!type.isVersionable()) {
     String msg = "Object type: " + type.getId() + " is not versionbale";
     throw new CmisConstraintException(msg, HTTP_STATUS_CODE_409);
   }
 }
 @Override
 public void constraintContentStreamRequired(
     DocumentTypeDefinition typeDefinition, ContentStream contentStream) {
   if (ContentStreamAllowed.REQUIRED.equals(typeDefinition.getContentStreamAllowed())) {
     if (contentStream == null || contentStream.getStream() == null) {
       constraint(
           "[typeId="
               + typeDefinition.getId()
               + "]This document type does not allow no content stream");
     }
   }
 }
 @Override
 public void constraintContentStreamRequired(String repositoryId, Document document) {
   String objectTypeId = document.getObjectType();
   DocumentTypeDefinition td =
       (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, objectTypeId);
   if (td.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
     if (document.getAttachmentNodeId() == null
         || contentService.getAttachment(repositoryId, document.getAttachmentNodeId()) == null) {
       constraint(document.getId(), "This document type does not allow no content stream");
     }
   }
 }
 @Override
 public void constraintContentStreamDownload(String repositoryId, Document document) {
   DocumentTypeDefinition documentTypeDefinition =
       (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, document);
   ContentStreamAllowed csa = documentTypeDefinition.getContentStreamAllowed();
   if (ContentStreamAllowed.NOTALLOWED == csa
       || ContentStreamAllowed.ALLOWED == csa
           && StringUtils.isBlank(document.getAttachmentNodeId())) {
     constraint(
         document.getId(),
         "This document has no ContentStream. getContentStream is not supported.");
   }
 }
  private void updateDocument(Session session, Folder testFolder) {
    CmisTestResult f;

    // create document
    Document doc1 = createDocument(session, testFolder, DOC_NAME1, "rename me!");
    Document workDoc = doc1;

    f = createResult(FAILURE, "Document name doesn't match the given name!");
    addResult(assertEquals(DOC_NAME1, doc1.getName(), null, f));

    // test if check out is required
    boolean checkedout = false;
    DocumentTypeDefinition type = (DocumentTypeDefinition) doc1.getType();
    PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
    if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT
        || (!doc1.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)
            && Boolean.TRUE.equals(type.isVersionable()))) {
      workDoc = (Document) session.getObject(doc1.checkOut(), SELECT_ALL_NO_CACHE_OC);
      checkedout = true;
    }

    // update
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, DOC_NAME2);

    ObjectId newId = workDoc.updateProperties(properties, false);
    Document doc2 = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);

    addResult(checkObject(session, doc2, getAllProperties(doc2), "Updated document compliance"));

    f = createResult(FAILURE, "Document name doesn't match updated value!");
    addResult(assertEquals(DOC_NAME2, doc2.getName(), null, f));

    // delete
    if (!workDoc.getId().equals(doc2.getId())) {
      deleteObject(doc2);
    }

    // cancel a possible check out
    if (checkedout) {
      workDoc.cancelCheckOut();
    }

    if (!doc1.getId().equals(doc2.getId())) {
      if (exists(doc1)) {
        deleteObject(doc1);
      }
    }
  }
 @Override
 public void constraintControllableVersionable(
     DocumentTypeDefinition documentTypeDefinition,
     VersioningState versioningState,
     String objectId) {
   if (!documentTypeDefinition.isVersionable()
       && (versioningState != null && versioningState != VersioningState.NONE)) {
     String msg = "Versioning state must not be set for a non-versionable object-type";
     throw new CmisConstraintException(buildMsgWithId(msg, objectId), HTTP_STATUS_CODE_409);
   }
   if (documentTypeDefinition.isVersionable() && versioningState == VersioningState.NONE) {
     String msg = "Versioning state is set for a non-versionable object-type";
     throw new CmisConstraintException(buildMsgWithId(msg, objectId), HTTP_STATUS_CODE_409);
   }
 }
 @Override
 public void streamNotSupported(
     DocumentTypeDefinition documentTypeDefinition, ContentStream contentStream) {
   if (documentTypeDefinition.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED
       && contentStream != null) {
     String msg = "A Content stream must not be included";
     throw new CmisStreamNotSupportedException(msg, HTTP_STATUS_CODE_403);
   }
 }