org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed Java Examples
The following examples show how to use
org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed.
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 |
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: CmisTypeDefinitionFactoryBean.java From spring-content with Apache License 2.0 | 5 votes |
public MutableDocumentTypeDefinition createDocumentTypeDefinition(Class<?> entityClass, Class<?> repoClass, Class<?> storeClass, CmisDocument metadata, CmisVersion cmisVersion, String parentId) { MutableDocumentTypeDefinition documentType = new DocumentTypeDefinitionImpl(); documentType.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT); documentType.setParentTypeId(parentId); documentType.setIsControllableAcl(false); documentType.setIsControllablePolicy(false); documentType.setIsCreatable(repoClass != null); documentType.setDescription("Document"); documentType.setDisplayName("Document"); documentType.setIsFileable(isFileable(repoClass)); documentType.setIsFulltextIndexed(isFulltextIndexed(repoClass)); documentType.setIsIncludedInSupertypeQuery(true); documentType.setLocalName("Document"); documentType.setLocalNamespace(""); documentType.setIsQueryable(false); documentType.setQueryName("cmis:document"); documentType.setId(BaseTypeId.CMIS_DOCUMENT.value()); if (cmisVersion != CmisVersion.CMIS_1_0) { TypeMutabilityImpl typeMutability = new TypeMutabilityImpl(); typeMutability.setCanCreate(false); typeMutability.setCanUpdate(false); typeMutability.setCanDelete(false); documentType.setTypeMutability(typeMutability); } documentType.setIsVersionable(isVersionable(repoClass)); documentType.setContentStreamAllowed((storeClass != null) ? ContentStreamAllowed.ALLOWED : ContentStreamAllowed.NOTALLOWED); this.addBasePropertyDefinitions(documentType, entityClass, cmisVersion, parentId != null); this.addDocumentPropertyDefinitions(documentType, repoClass, storeClass, cmisVersion, parentId != null); return documentType; }
Example #3
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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 #4
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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 #5
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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 #6
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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 #7
Source File: DocumentTypeDefinitionWrapper.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public DocumentTypeDefinitionWrapper(CMISMapping cmisMapping, PropertyAccessorMapping accessorMapping, PropertyLuceneBuilderMapping luceneBuilderMapping, String typeId, DictionaryService dictionaryService, ClassDefinition cmisClassDef) { this.dictionaryService = dictionaryService; alfrescoName = cmisClassDef.getName(); alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName); typeDef = new DocumentTypeDefinitionImpl(); typeDef.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT); typeDef.setId(typeId); typeDef.setLocalName(alfrescoName.getLocalName()); typeDef.setLocalNamespace(alfrescoName.getNamespaceURI()); if (BaseTypeId.CMIS_DOCUMENT.value().equals(typeId)) { typeDef.setQueryName(ISO9075.encodeSQL(typeId)); typeDef.setParentTypeId(null); } else { typeDef.setQueryName(ISO9075.encodeSQL(cmisMapping.buildPrefixEncodedString(alfrescoName))); QName parentQName = cmisMapping.getCmisType(cmisClassDef.getParentName()); if (cmisMapping.isValidCmisDocument(parentQName)) { typeDef.setParentTypeId(cmisMapping.getCmisTypeId(BaseTypeId.CMIS_DOCUMENT, parentQName)); } } typeDef.setDisplayName(null); typeDef.setDescription(null); typeDef.setIsCreatable(true); typeDef.setIsQueryable(true); typeDef.setIsFulltextIndexed(true); typeDef.setIsControllablePolicy(false); typeDef.setIsControllableAcl(true); typeDef.setIsIncludedInSupertypeQuery(cmisClassDef.getIncludedInSuperTypeQuery()); typeDef.setIsFileable(true); typeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED); typeDef.setIsVersionable(true); typeDefInclProperties = CMISUtils.copy(typeDef); setTypeDefinition(typeDef, typeDefInclProperties); createOwningPropertyDefinitions(cmisMapping, accessorMapping, luceneBuilderMapping, dictionaryService, cmisClassDef); createActionEvaluators(accessorMapping, BaseTypeId.CMIS_DOCUMENT); }
Example #8
Source File: CmisServiceBridge.java From spring-content with Apache License 2.0 | 4 votes |
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; }