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;
  }
  @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 setContentStream(
      CallContext callContext,
      String repositoryId,
      Holder<String> objectId,
      boolean overwriteFlag,
      ContentStream contentStream,
      Holder<String> changeToken) {

    exceptionService.invalidArgumentRequiredHolderString("objectId", objectId);

    Lock lock = threadLockService.getWriteLock(repositoryId, objectId.getValue());
    try {
      lock.lock();
      // //////////////////
      // General Exception
      // //////////////////

      exceptionService.invalidArgumentRequired("contentStream", contentStream);
      Document doc = (Document) contentService.getContent(repositoryId, objectId.getValue());
      exceptionService.objectNotFound(DomainType.OBJECT, doc, objectId.getValue());
      exceptionService.permissionDenied(
          callContext, repositoryId, PermissionMapping.CAN_SET_CONTENT_DOCUMENT, doc);
      DocumentTypeDefinition td =
          (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, doc.getObjectType());
      exceptionService.constraintImmutable(repositoryId, doc, td);

      // //////////////////
      // Specific Exception
      // //////////////////
      exceptionService.contentAlreadyExists(doc, overwriteFlag);
      exceptionService.streamNotSupported(td, contentStream);
      exceptionService.updateConflict(doc, changeToken);
      exceptionService.versioning(doc);
      Folder parent = contentService.getParent(repositoryId, objectId.getValue());
      exceptionService.objectNotFoundParentFolder(repositoryId, objectId.getValue(), parent);

      // //////////////////
      // Body of the method
      // //////////////////
      String oldId = objectId.getValue();

      // TODO Externalize versioningState
      if (doc.isPrivateWorkingCopy()) {
        Document result = contentService.replacePwc(callContext, repositoryId, doc, contentStream);
        objectId.setValue(result.getId());
      } else {
        Document result =
            contentService.createDocumentWithNewStream(
                callContext, repositoryId, doc, contentStream);
        objectId.setValue(result.getId());
      }

      nemakiCachePool.get(repositoryId).removeCmisCache(oldId);
    } finally {
      lock.unlock();
    }
  }
 @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 constraintBaseTypeId(
      String repositoryId, Properties properties, BaseTypeId baseTypeId) {
    String objectTypeId = DataUtil.getObjectTypeId(properties);
    TypeDefinition td = typeManager.getTypeDefinition(repositoryId, objectTypeId);

    if (!td.getBaseTypeId().equals(baseTypeId))
      constraint(null, "cmis:objectTypeId is not an object type whose base tyep is " + baseTypeId);
  }
  @Override
  public void invalidArgumentDoesNotExistType(String repositoryId, String typeId) {
    String msg = "";

    TypeDefinition type = typeManager.getTypeDefinition(repositoryId, typeId);
    if (type == null) {
      msg = "Specified type does not exist";
      msg = msg + " [objectTypeId = " + typeId + "]";
      invalidArgument(msg);
    }
  }
 @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.");
   }
 }
  @Override
  public void invalidArgumentDeletableType(String repositoryId, String typeId) {
    TypeDefinition type = typeManager.getTypeDefinition(repositoryId, typeId);

    String msg = "";
    TypeMutability typeMutability = type.getTypeMutability();
    boolean canUpdate = (typeMutability.canDelete() == null) ? true : typeMutability.canDelete();
    if (!canUpdate) {
      msg = "Specified type is not deletable";
      msg = msg + " [objectTypeId = " + type.getId() + "]";
      invalidArgument(msg);
    }
  }
Exemplo n.º 10
0
  @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();
  }
Exemplo n.º 11
0
  @Override
  public void appendContentStream(
      CallContext callContext,
      String repositoryId,
      Holder<String> objectId,
      Holder<String> changeToken,
      ContentStream contentStream,
      boolean isLastChunk,
      ExtensionsData extension) {

    exceptionService.invalidArgumentRequiredHolderString("objectId", objectId);

    Lock lock = threadLockService.getWriteLock(repositoryId, objectId.getValue());
    try {
      lock.lock();

      // //////////////////
      // General Exception
      // //////////////////

      exceptionService.invalidArgumentRequired("contentStream", contentStream);
      Document doc = (Document) contentService.getContent(repositoryId, objectId.getValue());
      exceptionService.objectNotFound(DomainType.OBJECT, doc, objectId.getValue());
      exceptionService.permissionDenied(
          callContext, repositoryId, PermissionMapping.CAN_SET_CONTENT_DOCUMENT, doc);
      DocumentTypeDefinition td =
          (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, doc.getObjectType());
      exceptionService.constraintImmutable(repositoryId, doc, td);

      // //////////////////
      // Specific Exception
      // //////////////////
      exceptionService.streamNotSupported(td, contentStream);
      exceptionService.updateConflict(doc, changeToken);
      exceptionService.versioning(doc);

      // //////////////////
      // Body of the method
      // //////////////////
      contentService.appendAttachment(
          callContext, repositoryId, objectId, changeToken, contentStream, isLastChunk, extension);

      nemakiCachePool.get(repositoryId).removeCmisCache(objectId.getValue());
    } finally {
      lock.unlock();
    }
  }
Exemplo n.º 12
0
  @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();
  }
Exemplo n.º 13
0
  @Override
  public String createFolder(
      CallContext callContext,
      String repositoryId,
      Properties properties,
      String folderId,
      List<String> policies,
      Acl addAces,
      Acl removeAces,
      ExtensionsData extension) {
    FolderTypeDefinition td =
        (FolderTypeDefinition)
            typeManager.getTypeDefinition(repositoryId, DataUtil.getObjectTypeId(properties));
    Folder parentFolder = contentService.getFolder(repositoryId, folderId);

    // //////////////////
    // General Exception
    // //////////////////
    exceptionService.objectNotFoundParentFolder(repositoryId, folderId, parentFolder);
    exceptionService.permissionDenied(
        callContext, repositoryId, PermissionMapping.CAN_CREATE_FOLDER_FOLDER, parentFolder);

    // //////////////////
    // Specific Exception
    // //////////////////
    exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_FOLDER);
    exceptionService.constraintAllowedChildObjectTypeId(parentFolder, properties);
    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, parentFolder);

    // //////////////////
    // Body of the method
    // //////////////////
    Folder folder =
        contentService.createFolder(callContext, repositoryId, properties, parentFolder);
    return folder.getId();
  }
Exemplo n.º 14
0
  @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 constraintDuplicatePropertyDefinition(
     String repositoryId, TypeDefinition typeDefinition) {
   Map<String, PropertyDefinition<?>> props = typeDefinition.getPropertyDefinitions();
   if (MapUtils.isNotEmpty(props)) {
     Set<String> keys = props.keySet();
     TypeDefinition parent =
         typeManager.getTypeDefinition(repositoryId, typeDefinition.getParentTypeId());
     Map<String, PropertyDefinition<?>> parentProps = parent.getPropertyDefinitions();
     if (MapUtils.isNotEmpty(parentProps)) {
       Set<String> parentKeys = parentProps.keySet();
       for (String key : keys) {
         if (parentKeys.contains(key)) {
           String msg =
               "Duplicate property definition with parent type definition"
                   + " [property id = "
                   + key
                   + "]";
           throw new CmisConstraintException(msg, HTTP_STATUS_CODE_409);
         }
       }
     }
   }
 }
Exemplo n.º 16
0
  @Override
  public ObjectData create(
      CallContext callContext,
      String repositoryId,
      Properties properties,
      String folderId,
      ContentStream contentStream,
      VersioningState versioningState,
      List<String> policies,
      ExtensionsData extension) {

    String typeId = DataUtil.getObjectTypeId(properties);
    TypeDefinition type = typeManager.getTypeDefinition(repositoryId, typeId);
    if (type == null) {
      throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
    }

    String objectId = null;
    // TODO ACE can be set !
    if (type.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) {
      objectId =
          createDocument(
              callContext,
              repositoryId,
              properties,
              folderId,
              contentStream,
              versioningState,
              null,
              null,
              null);
    } else if (type.getBaseTypeId() == BaseTypeId.CMIS_FOLDER) {
      objectId =
          createFolder(
              callContext, repositoryId, properties, folderId, policies, null, null, extension);
    } else if (type.getBaseTypeId() == BaseTypeId.CMIS_RELATIONSHIP) {
      objectId =
          createRelationship(
              callContext, repositoryId, properties, policies, null, null, extension);
    } else if (type.getBaseTypeId() == BaseTypeId.CMIS_POLICY) {
      objectId =
          createPolicy(
              callContext, repositoryId, properties, folderId, policies, null, null, extension);
    } else if (type.getBaseTypeId() == BaseTypeId.CMIS_ITEM) {
      objectId =
          createItem(
              callContext, repositoryId, properties, folderId, policies, null, null, extension);
    } else {
      throw new CmisObjectNotFoundException("Cannot create object of type '" + typeId + "'!");
    }

    ObjectData object =
        compileService.compileObjectData(
            callContext,
            repositoryId,
            contentService.getContent(repositoryId, objectId),
            null,
            false,
            IncludeRelationships.NONE,
            null,
            false);

    return object;
  }