org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkDocumentTypeForContent(TypeDefinitionWrapper type)
{
    if (type == null)
    {
        throw new CmisObjectNotFoundException("No corresponding type found! Not a CMIS object?");
    }
    if (!(type instanceof DocumentTypeDefinitionWrapper))
    {
        throw new CmisStreamNotSupportedException("Object is not a document!");
    }
    if (((DocumentTypeDefinition) type.getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
    {
        throw new CmisConstraintException("Document cannot have content!");
    }
}
 
Example #2
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets default value of <code>VersioningState</code> based on whether document is versionable or not.
 * 
 * @param versioningState
 * @param type
 * @return <code>VersioningState.MAJOR</code> if versioningState is {@code null} and object is versionable
 *         <code>VersioningState.NONE</code> if versioningState is {@code null} and object is not versionable
 *         versioningState if it's value is not {@code null}
 */
private VersioningState getDocumentDefaultVersioningState(VersioningState versioningState, TypeDefinitionWrapper type)
{
    if (versioningState == null)
    {
        DocumentTypeDefinition docType = (DocumentTypeDefinition) type.getTypeDefinition(false);
        versioningState = docType.isVersionable() ? VersioningState.MAJOR : VersioningState.NONE;
    }
    return versioningState;
}
 
Example #3
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void checkOut(
        String repositoryId, final Holder<String> objectId, ExtensionsData extension,
        final Holder<Boolean> contentCopied)
{
    checkRepositoryId(repositoryId);

    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");

    // Check for current version
    if (info.isVariant(CMISObjectVariant.CURRENT_VERSION))
    {
        // Good
    }
    else if (info.isVariant(CMISObjectVariant.VERSION))
    {
        throw new CmisInvalidArgumentException("Can't check out an old version of a document");
    }
    else {   
        throw new CmisInvalidArgumentException("Only documents can be checked out! Object was a " + info.getObjectVariant().toString());
    }

    // get object
    final NodeRef nodeRef = info.getNodeRef();

    if (!((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).isVersionable())
    {
        throw new CmisConstraintException("Document is not versionable!");
    }
    
    // check out
    NodeRef pwcNodeRef = connector.getCheckOutCheckInService().checkout(nodeRef);
    CMISNodeInfo pwcNodeInfo = createNodeInfo(pwcNodeRef);
    objectId.setValue(pwcNodeInfo.getObjectId());

    if (contentCopied != null)
    {
        contentCopied.setValue(connector.getFileFolderService().getReader(pwcNodeRef) != null);
    }
}
 
Example #4
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public String createDocument(
        String repositoryId, final Properties properties, String folderId,
        final ContentStream contentStream, VersioningState versioningState, final List<String> policies,
        final Acl addAces, final Acl removeAces, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);
    
    // get the parent folder node ref
    final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "Parent folder");

    // get name and type
    final String name = connector.getNameProperty(properties, null);
    final String objectTypeId = connector.getObjectTypeIdProperty(properties);
    final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_DOCUMENT);
    
    connector.checkChildObjectType(parentInfo, type.getTypeId());

    DocumentTypeDefinition docType = (DocumentTypeDefinition) type.getTypeDefinition(false);

    if ((docType.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) && (contentStream != null))
    {
        throw new CmisConstraintException("This document type does not support content!");
    }

    if ((docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) && (contentStream == null))
    {
        throw new CmisConstraintException("This document type does requires content!");
    }

    if (!docType.isVersionable() && (versioningState != VersioningState.NONE))
    {
        throw new CmisConstraintException("This document type is not versionable!");
    }
    
    versioningState = getDocumentDefaultVersioningState(versioningState, type);

    FileInfo fileInfo = connector.getFileFolderService().create(
            parentInfo.getNodeRef(), name, type.getAlfrescoClass());
    NodeRef nodeRef = fileInfo.getNodeRef();
    connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
    connector.applyPolicies(nodeRef, type, policies);
    connector.applyACL(nodeRef, type, addAces, removeAces);

    // handle content
    if (contentStream != null)
    {
        // write content
        String mimeType = parseMimeType(contentStream);
        String encoding = getEncoding(contentStream.getStream(), mimeType);
        ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
        writer.setMimetype(mimeType);
        writer.setEncoding(encoding);
        writer.putContent(contentStream.getStream());
    }

    connector.extractMetadata(nodeRef);

    // generate "doclib" thumbnail asynchronously
    connector.createThumbnails(nodeRef, Collections.singleton("doclib"));

    connector.applyVersioningState(nodeRef, versioningState);

    String objectId = connector.createObjectId(nodeRef);

    connector.getActivityPoster().postFileFolderAdded(nodeRef);

    return objectId;
}
 
Example #5
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken,
        ContentStream contentStream, boolean isLastChunk, ExtensionsData extension)
{
    if ((contentStream == null) || (contentStream.getStream() == null))
    {
        throw new CmisInvalidArgumentException("No content!");
    }

    checkRepositoryId(repositoryId);

    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    NodeRef nodeRef = info.getNodeRef();

    if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
    {
        throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
    }

    //ALF-21852 - Separated appendContent and objectId.setValue in two different transactions because
    //after executing appendContent, the new objectId is not visible.
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    helper.doInTransaction(new RetryingTransactionCallback<Void>()
    {
       public Void execute() throws Throwable
       {
           try
           {
               connector.appendContent(info, contentStream, isLastChunk);
           }
           catch(IOException e)
           {
                throw new ContentIOException("", e);
           }
            return null;
       }
    }, false, true);

   String objId = helper.doInTransaction(new RetryingTransactionCallback<String>()
   {
       public String execute() throws Throwable
       {
           return connector.createObjectId(nodeRef);
       }
   }, true, true);

   objectId.setValue(objId);
}
 
Example #6
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setContentStream(
        String repositoryId, Holder<String> objectId, Boolean overwriteFlag,
        Holder<String> changeToken, final ContentStream contentStream, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");

    if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC))
    {
        throw new CmisStreamNotSupportedException("Content can only be set on private working copies or current versions.");
    }

    final NodeRef nodeRef = info.getNodeRef();

    if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
    {
        throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
    }

    boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
    if (existed && !overwriteFlag)
    {
        throw new CmisContentAlreadyExistsException("Content already exists!");
    }

    if ((contentStream == null) || (contentStream.getStream() == null))
    {
        throw new CmisInvalidArgumentException("No content!");
    }

    //ALF-21852 - Separated setContent and objectId.setValue in two different transactions because
    //after executing setContent, the new objectId is not visible.
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    helper.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            String mimeType = parseMimeType(contentStream);
            String encoding = getEncoding(contentStream.getStream(), mimeType);
            ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
            writer.setMimetype(mimeType);
            writer.setEncoding(encoding);
            writer.putContent(contentStream.getStream());
            connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
            return null;
        }
    }, false, true);

    String objId = helper.doInTransaction(new RetryingTransactionCallback<String>()
    {
        public String execute() throws Throwable
        {
            return connector.createObjectId(nodeRef);
        }
    }, true, true);

    objectId.setValue(objId);
}
 
Example #7
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
    public void deleteContentStream(
            String repositoryId, Holder<String> objectId, Holder<String> changeToken,
            ExtensionsData extension)
    {
        checkRepositoryId(repositoryId);

        CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");

        if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC))
        {
            throw new CmisStreamNotSupportedException("Content can only be deleted from ondocuments!");
        }

        final NodeRef nodeRef = info.getNodeRef();

        if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.REQUIRED)
        {
            throw new CmisInvalidArgumentException("Document type requires content!");
        }

        //ALF-21852 - Separated deleteContent and objectId.setValue in two different transactions because
        //after executing deleteContent, the new objectId is not visible.
        RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
        helper.doInTransaction(new RetryingTransactionCallback<Void>()
        {
            public Void execute() throws Throwable
            {

                connector.getNodeService().setProperty(nodeRef, ContentModel.PROP_CONTENT, null);

//              connector.createVersion(nodeRef, VersionType.MINOR, "Delete content");

                connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
                return null;
            }
        }, false, true);

        String objId = helper.doInTransaction(new RetryingTransactionCallback<String>()
        {
            public String execute() throws Throwable
            {
                return connector.createObjectId(nodeRef);
            }
        }, true, true);

        objectId.setValue(objId);
    }
 
Example #8
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 4 votes vote down vote up
static AllowableActions compileAllowableActions(TypeDefinition type, Object object, boolean isRoot, boolean isPrincipalReadOnly) {
	AllowableActionsImpl result = new AllowableActionsImpl();

	Set<Action> aas = EnumSet.noneOf(Action.class);

	addAction(aas, Action.CAN_GET_OBJECT_PARENTS, false /*!isRoot*/);
	addAction(aas, Action.CAN_GET_PROPERTIES, true);
	addAction(aas, Action.CAN_UPDATE_PROPERTIES, !isPrincipalReadOnly /*&& !isReadOnly*/);
	addAction(aas, Action.CAN_MOVE_OBJECT, false /*!userReadOnly && !isRoot*/);
	addAction(aas, Action.CAN_DELETE_OBJECT, !isPrincipalReadOnly && !isRoot /*!userReadOnly && !isReadOnly && !isRoot*/);
	addAction(aas, Action.CAN_GET_ACL, false /*true*/);

	boolean folder = type.getId().equals(BaseTypeId.CMIS_FOLDER.value());
	if (folder) {
		addAction(aas, Action.CAN_GET_DESCENDANTS, false);
		addAction(aas, Action.CAN_GET_CHILDREN, true);
		addAction(aas, Action.CAN_GET_FOLDER_PARENT, !isRoot);
		addAction(aas, Action.CAN_GET_FOLDER_TREE, true);
		addAction(aas, Action.CAN_CREATE_DOCUMENT, !isPrincipalReadOnly);
		addAction(aas, Action.CAN_CREATE_FOLDER, !isPrincipalReadOnly);
		addAction(aas, Action.CAN_DELETE_TREE, !isPrincipalReadOnly /*&& !isReadOnly*/);
	} else {
		ContentStreamAllowed allowed = ((DocumentTypeDefinition)type).getContentStreamAllowed();
		if (allowed == ContentStreamAllowed.ALLOWED || allowed == ContentStreamAllowed.REQUIRED) {
			addAction(aas, Action.CAN_GET_CONTENT_STREAM, contentLength(object) > 0);
			addAction(aas, Action.CAN_SET_CONTENT_STREAM, !isPrincipalReadOnly /*&& !isReadOnly*/);
			addAction(aas, Action.CAN_DELETE_CONTENT_STREAM, !isPrincipalReadOnly /*&& !isReadOnly*/);
			addAction(aas, Action.CAN_GET_ALL_VERSIONS, true);
		}

		if (((DocumentTypeDefinition)type).isVersionable()) {
			addAction(aas, Action.CAN_CHECK_IN, true);
			addAction(aas, Action.CAN_CHECK_OUT, true);
			addAction(aas, Action.CAN_CANCEL_CHECK_OUT, true);
		}
	}

	result.setAllowableActions(aas);

	return result;
}