Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 11888 invoked from network); 23 Apr 2010 09:29:54 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Apr 2010 09:29:54 -0000 Received: (qmail 80002 invoked by uid 500); 23 Apr 2010 09:29:54 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 79949 invoked by uid 500); 23 Apr 2010 09:29:54 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 79941 invoked by uid 99); 23 Apr 2010 09:29:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Apr 2010 09:29:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Apr 2010 09:29:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 760EE23889FD; Fri, 23 Apr 2010 09:28:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r937209 [3/3] - in /incubator/chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main... Date: Fri, 23 Apr 2010 09:28:57 -0000 To: chemistry-commits@incubator.apache.org From: sklevenz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100423092859.760EE23889FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java?rev=937209&r1=937208&r2=937209&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java Fri Apr 23 09:28:57 2010 @@ -55,8 +55,6 @@ import org.apache.chemistry.opencmis.com import org.apache.chemistry.opencmis.commons.api.DiscoveryService; import org.apache.chemistry.opencmis.commons.api.NavigationService; import org.apache.chemistry.opencmis.commons.api.ObjectData; -import org.apache.chemistry.opencmis.commons.api.ObjectInFolderData; -import org.apache.chemistry.opencmis.commons.api.ObjectInFolderList; import org.apache.chemistry.opencmis.commons.api.ObjectList; import org.apache.chemistry.opencmis.commons.api.RepositoryInfo; import org.apache.chemistry.opencmis.commons.api.RepositoryService; @@ -76,774 +74,774 @@ import org.apache.commons.logging.LogFac */ public class PersistentSessionImpl implements Session, Serializable { - private static final OperationContext DEFAULT_CONTEXT = new OperationContextImpl(null, false, true, false, - IncludeRelationships.NONE, null, true, null, true); + private static final OperationContext DEFAULT_CONTEXT = new OperationContextImpl(null, false, true, false, + IncludeRelationships.NONE, null, true, null, true); - private static final Set CREATE_UPDATABILITY = new HashSet(); - static { - CREATE_UPDATABILITY.add(Updatability.ONCREATE); - CREATE_UPDATABILITY.add(Updatability.READWRITE); - } - - private static Log log = LogFactory.getLog(PersistentSessionImpl.class); - - private final ReentrantReadWriteLock fLock = new ReentrantReadWriteLock(); - - /* - * default session context (serializable) - */ - private OperationContext context = DEFAULT_CONTEXT; - - /* - * session parameter (serializable) - */ - private Map parameters = null; - - /* - * CMIS provider (serializable) - */ - private CmisBinding binding = null; - - /* - * Session Locale, determined from session parameter (serializable) - */ - private Locale locale = null; - - /* - * Object cache (serializable) - */ - private Cache cache = null; - - /* - * Lazy loaded repository info. Will be invalid after clear(). Access by - * getter always. (serializable) - */ - private RepositoryInfo repositoryInfo; - - /* - * helper factory (non serializable) - */ - private final ObjectFactory objectFactory = PersistentObjectFactoryImpl.newInstance(this); - - /** - * required for serialization - */ - private static final long serialVersionUID = -4287481628831198383L; - - /** - * Constructor. - */ - public PersistentSessionImpl(Map parameters) { - this.parameters = parameters; - PersistentSessionImpl.log.info("Session Parameters: " + parameters); - - this.locale = this.determineLocale(parameters); - PersistentSessionImpl.log.info("Session Locale: " + this.locale.toString()); - - int cacheSize = this.determineCacheSize(parameters); - - if (cacheSize == -1) { - this.cache = CacheImpl.newInstance(); - } else { - this.cache = CacheImpl.newInstance(cacheSize); - } - PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.getCacheSize()); - } - - private int determineCacheSize(Map parameters) { - int size = -1; - - return size; - } - - private String determineRepositoryId(Map parameters) { - String repositoryId = parameters.get(SessionParameter.REPOSITORY_ID); - // if null then the provider will return a repository id (lazy) - return repositoryId; - } - - private Locale determineLocale(Map parameters) { - Locale locale = null; - - String language = parameters.get(SessionParameter.LOCALE_ISO639_LANGUAGE); - String country = parameters.get(SessionParameter.LOCALE_ISO3166_COUNTRY); - String variant = parameters.get(SessionParameter.LOCALE_VARIANT); - - if (variant != null) { - // all 3 parameter must not be null and valid - locale = new Locale(language, country, variant); - } else { - if (country != null) { - // 2 parameter must not be null and valid - locale = new Locale(language, country); - } else { - if (language != null) { - // 1 parameter must not be null and valid - locale = new Locale(language); - } else { - locale = Locale.getDefault(); - } - } - } - - return locale; - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#clear() - */ - public void clear() { - fLock.writeLock().lock(); - try { - int cacheSize = this.determineCacheSize(this.parameters); - if (cacheSize == -1) { - this.cache = CacheImpl.newInstance(); - } else { - this.cache = CacheImpl.newInstance(cacheSize); - } - PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.getCacheSize()); - - /* - * clear provider cache - */ - getBinding().clearAllCaches(); - } finally { - fLock.writeLock().unlock(); - } - } - - public void save() { - // nop - } - - public void cancel() { - throw new UnsupportedOperationException("cancel"); - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getObjectFactory() - */ - public ObjectFactory getObjectFactory() { - return this.objectFactory; - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getCheckedOutDocs(int) - */ - public PagingIterable getCheckedOutDocs(int itemsPerPage) { - return getCheckedOutDocs(getDefaultContext(), itemsPerPage); - } - - /* - * (non-Javadoc) - * - * @seeorg.apache.opencmis.client.api.Session#getCheckedOutDocs(org.apache. - * opencmis.client.api. OperationContext, int) - */ - public PagingIterable getCheckedOutDocs(OperationContext context, final int itemsPerPage) { - if (itemsPerPage < 1) { - throw new IllegalArgumentException("itemsPerPage must be > 0!"); - } - - final NavigationService navigationService = getBinding().getNavigationService(); - final ObjectFactory objectFactory = getObjectFactory(); - final OperationContext ctxt = new OperationContextImpl(context); - - return new DefaultPagingIterable(new AbstractPageFetch() { - - @Override - protected AbstractPageFetch.PageFetchResult fetchPage(long skipCount) { - - // get all checked out documents - ObjectList checkedOutDocs = navigationService.getCheckedOutDocs(getRepositoryId(), null, ctxt - .getFilterString(), ctxt.getOrderBy(), ctxt.isIncludeAllowableActions(), ctxt - .getIncludeRelationships(), ctxt.getRenditionFilterString(), BigInteger.valueOf(itemsPerPage), - BigInteger.valueOf(skipCount), null); - - // convert objects - List page = new ArrayList(); - if (checkedOutDocs.getObjects() != null) { - for (ObjectData objectData : checkedOutDocs.getObjects()) { - CmisObject doc = objectFactory.convertObject(objectData, ctxt); - if (!(doc instanceof Document)) { - // should not happen... - continue; - } - - page.add((Document) doc); - } - } - - return new AbstractPageFetch.PageFetchResult(page, checkedOutDocs.getNumItems(), - checkedOutDocs.hasMoreItems()) { - }; - } - }); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#getContentChanges(java.lang.String - * , int) - */ - public PagingIterable getContentChanges(String changeLogToken, int itemsPerPage) { - throw new CmisRuntimeException("not implemented"); - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getDefaultContext() - */ - public OperationContext getDefaultContext() { - fLock.readLock().lock(); - try { - return this.context; - } finally { - fLock.readLock().unlock(); - } - } - - /* - * (non-Javadoc) - * - * @seeorg.apache.opencmis.client.api.Session#setDefaultContext(org.apache. - * opencmis.client.api. OperationContext) - */ - public void setDefaultContext(OperationContext context) { - fLock.writeLock().lock(); - try { - this.context = (context == null ? DEFAULT_CONTEXT : context); - } finally { - fLock.writeLock().unlock(); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#createOperationContext(java.util - * .Set, boolean, boolean, boolean, - * org.apache.opencmis.commons.enums.IncludeRelationships, java.util.Set, - * boolean, java.lang.String, boolean) - */ - public OperationContext createOperationContext(Set filter, boolean includeAcls, - boolean includeAllowableActions, boolean includePolicies, IncludeRelationships includeRelationships, - Set renditionFilter, boolean includePathSegments, String orderBy, boolean cacheEnabled) { - return new OperationContextImpl(filter, includeAcls, includeAllowableActions, includePolicies, - includeRelationships, renditionFilter, includePathSegments, orderBy, cacheEnabled); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#createObjectId(java.lang.String) - */ - public ObjectId createObjectId(String id) { - return new ObjectIdImpl(id); - } - - public Locale getLocale() { - return this.locale; - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getObject(java.lang.String) - */ - public CmisObject getObject(ObjectId objectId) { - return getObject(objectId, getDefaultContext()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getObject(java.lang.String, - * org.apache.opencmis.client.api.OperationContext) - */ - public CmisObject getObject(ObjectId objectId, OperationContext context) { - if ((objectId == null) || (objectId.getId() == null)) { - throw new IllegalArgumentException("Object Id must be set!"); - } - if (context == null) { - throw new IllegalArgumentException("Operation context must be set!"); - } - - CmisObject result = null; - - // ask the cache first - if (context.isCacheEnabled()) { - result = this.cache.getById(objectId.getId(), context.getCacheKey()); - if (result != null) { - return result; - } - } - - // get the object - ObjectData objectData = this.binding.getObjectService().getObject(getRepositoryId(), objectId.getId(), - context.getFilterString(), context.isIncludeAllowableActions(), context.getIncludeRelationships(), - context.getRenditionFilterString(), context.isIncludePolicies(), context.isIncludeAcls(), null); - - result = getObjectFactory().convertObject(objectData, context); - - // put into cache - if (context.isCacheEnabled()) { - this.cache.put(result, context.getCacheKey()); - } - - return result; - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#getObjectByPath(java.lang.String) - */ - public CmisObject getObjectByPath(String path) { - return getObjectByPath(path, getDefaultContext()); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#getObjectByPath(java.lang.String, - * org.apache.opencmis.client.api.OperationContext) - */ - public CmisObject getObjectByPath(String path, OperationContext context) { - if (path == null) { - throw new IllegalArgumentException("Path must be set!"); - } - if (context == null) { - throw new IllegalArgumentException("Operation context must be set!"); - } - - CmisObject result = null; - - // ask the cache first - if (context.isCacheEnabled()) { - result = this.cache.getByPath(path, context.getCacheKey()); - if (result != null) { - return result; - } - } - - // get the object - ObjectData objectData = this.binding.getObjectService().getObjectByPath(getRepositoryId(), path, - context.getFilterString(), context.isIncludeAllowableActions(), context.getIncludeRelationships(), - context.getRenditionFilterString(), context.isIncludePolicies(), context.isIncludeAcls(), null); - - result = getObjectFactory().convertObject(objectData, context); - - // put into cache - if (context.isCacheEnabled()) { - this.cache.putPath(path, result, context.getCacheKey()); - } - - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getRepositoryInfo() - */ - public RepositoryInfo getRepositoryInfo() { - fLock.readLock().lock(); - try { - return this.repositoryInfo; - } finally { - fLock.readLock().unlock(); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getRootFolder() - */ - public Folder getRootFolder() { - return getRootFolder(getDefaultContext()); - } - - /* - * (non-Javadoc) - * - * - * - * - * - * - * - * - * @seeorg.apache.opencmis.client.api.Session#getRootFolder(org.apache.opencmis - * .client.api. OperationContext) - */ - public Folder getRootFolder(OperationContext context) { - String rootFolderId = getRepositoryInfo().getRootFolderId(); - - CmisObject rootFolder = getObject(createObjectId(rootFolderId), context); - if (!(rootFolder instanceof Folder)) { - throw new CmisRuntimeException("Root folder object is not a folder!"); - } - - return (Folder) rootFolder; - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#getTypeChildren(java.lang.String, - * boolean, int) - */ - public PagingIterable getTypeChildren(final String typeId, final boolean includePropertyDefinitions, - final int itemsPerPage) { - if (itemsPerPage < 1) { - throw new IllegalArgumentException("itemsPerPage must be > 0!"); - } - - final RepositoryService repositoryService = getBinding().getRepositoryService(); - final ObjectFactory objectFactory = this.getObjectFactory(); - final OperationContext ctxt = new OperationContextImpl(context); - - return new DefaultPagingIterable(new AbstractPageFetch() { - - @Override - protected AbstractPageFetch.PageFetchResult fetchPage(long skipCount) { - - // fetch the data - TypeDefinitionList tdl = repositoryService.getTypeChildren( - PersistentSessionImpl.this.getRepositoryId(), typeId, includePropertyDefinitions, BigInteger - .valueOf(itemsPerPage), BigInteger.valueOf(skipCount), null); - - // convert type definitions - List page = new ArrayList(tdl.getList().size()); - for (TypeDefinition typeDefinition : tdl.getList()) { - page.add(objectFactory.convertTypeDefinition(typeDefinition)); - } - - return new AbstractPageFetch.PageFetchResult(page, tdl.getNumItems(), tdl.hasMoreItems()) { - }; - } - }); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#getTypeDefinition(java.lang.String - * ) - */ - public ObjectType getTypeDefinition(String typeId) { - TypeDefinition typeDefinition = getBinding().getRepositoryService().getTypeDefinition(getRepositoryId(), - typeId, null); - return objectFactory.convertTypeDefinition(typeDefinition); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#getTypeDescendants(java.lang.String - * , int, boolean) - */ - public List> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions) { - List descendants = getBinding().getRepositoryService().getTypeDescendants( - getRepositoryId(), typeId, BigInteger.valueOf(depth), includePropertyDefinitions, null); - - return convertTypeDescendants(descendants); - } - - /** - * Converts provider TypeDefinitionContainer to API - * Container. - */ - private List> convertTypeDescendants(List descendantsList) { - List> result = new ArrayList>(); - - for (TypeDefinitionContainer container : descendantsList) { - ObjectType objectType = objectFactory.convertTypeDefinition(container.getTypeDefinition()); - List> children = convertTypeDescendants(container.getChildren()); - - result.add(new ContainerImpl(objectType, children)); - } - - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#query(java.lang.String, - * boolean, int) - */ - public PagingIterable query(final String statement, final boolean searchAllVersions, - final int itemsPerPage) { - return query(statement, searchAllVersions, getDefaultContext(), itemsPerPage); - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#query(java.lang.String, - * boolean, org.apache.opencmis.client.api.OperationContext, int) - */ - public PagingIterable query(final String statement, final boolean searchAllVersions, - OperationContext context, final int itemsPerPage) { - - if (itemsPerPage < 1) { - throw new IllegalArgumentException("itemsPerPage must be > 0!"); - } - - final DiscoveryService discoveryService = getBinding().getDiscoveryService(); - final ObjectFactory objectFactory = this.getObjectFactory(); - final OperationContext ctxt = new OperationContextImpl(context); - - return new DefaultPagingIterable(new AbstractPageFetch() { - - @Override - protected AbstractPageFetch.PageFetchResult fetchPage(long skipCount) { - - // fetch the data - ObjectList resultList = discoveryService.query(getRepositoryId(), statement, searchAllVersions, ctxt - .isIncludeAllowableActions(), ctxt.getIncludeRelationships(), ctxt.getRenditionFilterString(), - BigInteger.valueOf(itemsPerPage), BigInteger.valueOf(skipCount), null); - - // convert type definitions - List page = new ArrayList(); - if (resultList.getObjects() != null) { - for (ObjectData objectData : resultList.getObjects()) { - if (objectData == null) { - continue; - } - - page.add(objectFactory.convertQueryResult(objectData)); - } - } - - return new AbstractPageFetch.PageFetchResult(page, resultList.getNumItems(), resultList - .hasMoreItems()) { - }; - } - }); - - } - - public String setExtensionContext(String context) { - throw new CmisRuntimeException("not implemented"); - } - - public ExtensionHandler setExtensionHandler(String context, ExtensionHandler extensionHandler) { - throw new CmisRuntimeException("not implemented"); - } - - /** - * Connect session object to the provider. This is the very first call after - * a session is created. - *

- * In dependency of the parameter set an {@code AtomPub}, a {@code - * WebService} or an {@code InMemory} provider is selected. - */ - public void connect() { - fLock.writeLock().lock(); - try { - this.binding = CmisBindingHelper.createProvider(this.parameters); - - /* get initial repository id from session parameter */ - String repositoryId = this.determineRepositoryId(this.parameters); - if (repositoryId == null) { - throw new IllegalStateException("Repository Id is not set!"); - } - - repositoryInfo = getBinding().getRepositoryService().getRepositoryInfo(repositoryId, null); - } finally { - fLock.writeLock().unlock(); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#getBinding() - */ - public CmisBinding getBinding() { - fLock.readLock().lock(); - try { - return this.binding; - } finally { - fLock.readLock().unlock(); - } - } - - public Cache getCache() { - fLock.readLock().lock(); - try { - return this.cache; - } finally { - fLock.readLock().unlock(); - } - } - - /** - * Returns the repository id. - */ - public String getRepositoryId() { - return getRepositoryInfo().getId(); - } - - // creates - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#createDocument(java.util.Map, - * org.apache.opencmis.client.api.ObjectId, - * org.apache.opencmis.client.api.ContentStream, - * org.apache.opencmis.commons.enums.VersioningState, java.util.List, - * java.util.List, java.util.List) - */ - public ObjectId createDocument(Map properties, ObjectId folderId, ContentStream contentStream, - VersioningState versioningState, List policies, List addAces, List removeAces) { - if ((folderId != null) && (folderId.getId() == null)) { - throw new IllegalArgumentException("Folder Id must be set!"); - } - - String newId = getBinding().getObjectService().createDocument(getRepositoryId(), - objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), - (folderId == null ? null : folderId.getId()), objectFactory.convertContentStream(contentStream), - versioningState, objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces), - objectFactory.convertAces(removeAces), null); - - if (newId == null) { - return null; - } - - return createObjectId(newId); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#createDocumentFromSource(org.apache - * .opencmis.client. api.ObjectId, java.util.Map, - * org.apache.opencmis.client.api.ObjectId, - * org.apache.opencmis.commons.enums.VersioningState, java.util.List, - * java.util.List, java.util.List) - */ - public ObjectId createDocumentFromSource(ObjectId source, Map properties, ObjectId folderId, - VersioningState versioningState, List policies, List addAces, List removeAces) { - if ((folderId != null) && (folderId.getId() == null)) { - throw new IllegalArgumentException("Folder Id must be set!"); - } - - // get the type of the source document - ObjectType type = null; - if (source instanceof CmisObject) { - type = ((CmisObject) source).getBaseType(); - } else { - CmisObject sourceObj = getObject(source); - type = sourceObj.getType(); - } - - if (type.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) { - throw new IllegalArgumentException("Source object must be a document!"); - } - - String newId = getBinding().getObjectService().createDocumentFromSource(getRepositoryId(), source.getId(), - objectFactory.convertProperties(properties, type, CREATE_UPDATABILITY), - (folderId == null ? null : folderId.getId()), versioningState, objectFactory.convertPolicies(policies), - objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); - - if (newId == null) { - return null; - } - - return createObjectId(newId); - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#createFolder(java.util.Map, - * org.apache.opencmis.client.api.ObjectId, java.util.List, java.util.List, - * java.util.List) - */ - public ObjectId createFolder(Map properties, ObjectId folderId, List policies, - List addAces, List removeAces) { - if ((folderId != null) && (folderId.getId() == null)) { - throw new IllegalArgumentException("Folder Id must be set!"); - } - - String newId = getBinding().getObjectService().createFolder(getRepositoryId(), - objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), - (folderId == null ? null : folderId.getId()), objectFactory.convertPolicies(policies), - objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); - - if (newId == null) { - return null; - } - - return createObjectId(newId); - } - - /* - * (non-Javadoc) - * - * @see org.apache.opencmis.client.api.Session#createPolicy(java.util.Map, - * org.apache.opencmis.client.api.ObjectId, java.util.List, java.util.List, - * java.util.List) - */ - public ObjectId createPolicy(Map properties, ObjectId folderId, List policies, - List addAces, List removeAces) { - if ((folderId != null) && (folderId.getId() == null)) { - throw new IllegalArgumentException("Folder Id must be set!"); - } - - String newId = getBinding().getObjectService().createPolicy(getRepositoryId(), - objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), - (folderId == null ? null : folderId.getId()), objectFactory.convertPolicies(policies), - objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); - - if (newId == null) { - return null; - } - - return createObjectId(newId); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.api.Session#createRelationship(java.util.Map, - * java.util.List, java.util.List, java.util.List) - */ - public ObjectId createRelationship(Map properties, List policies, List addAces, - List removeAces) { - String newId = getBinding().getObjectService().createRelationship(getRepositoryId(), - objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), - objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces), - objectFactory.convertAces(removeAces), null); - - if (newId == null) { - return null; - } + private static final Set CREATE_UPDATABILITY = new HashSet(); + static { + CREATE_UPDATABILITY.add(Updatability.ONCREATE); + CREATE_UPDATABILITY.add(Updatability.READWRITE); + } + + private static Log log = LogFactory.getLog(PersistentSessionImpl.class); + + private final ReentrantReadWriteLock fLock = new ReentrantReadWriteLock(); + + /* + * default session context (serializable) + */ + private OperationContext context = DEFAULT_CONTEXT; + + /* + * session parameter (serializable) + */ + private Map parameters = null; + + /* + * CMIS provider (serializable) + */ + private CmisBinding binding = null; + + /* + * Session Locale, determined from session parameter (serializable) + */ + private Locale locale = null; + + /* + * Object cache (serializable) + */ + private Cache cache = null; + + /* + * Lazy loaded repository info. Will be invalid after clear(). Access by + * getter always. (serializable) + */ + private RepositoryInfo repositoryInfo; + + /* + * helper factory (non serializable) + */ + private final ObjectFactory objectFactory = PersistentObjectFactoryImpl.newInstance(this); + + /** + * required for serialization + */ + private static final long serialVersionUID = -4287481628831198383L; + + /** + * Constructor. + */ + public PersistentSessionImpl(Map parameters) { + this.parameters = parameters; + PersistentSessionImpl.log.info("Session Parameters: " + parameters); + + this.locale = this.determineLocale(parameters); + PersistentSessionImpl.log.info("Session Locale: " + this.locale.toString()); + + int cacheSize = this.determineCacheSize(parameters); + + if (cacheSize == -1) { + this.cache = CacheImpl.newInstance(); + } else { + this.cache = CacheImpl.newInstance(cacheSize); + } + PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.getCacheSize()); + } + + private int determineCacheSize(Map parameters) { + int size = -1; + + return size; + } + + private String determineRepositoryId(Map parameters) { + String repositoryId = parameters.get(SessionParameter.REPOSITORY_ID); + // if null then the provider will return a repository id (lazy) + return repositoryId; + } + + private Locale determineLocale(Map parameters) { + Locale locale = null; + + String language = parameters.get(SessionParameter.LOCALE_ISO639_LANGUAGE); + String country = parameters.get(SessionParameter.LOCALE_ISO3166_COUNTRY); + String variant = parameters.get(SessionParameter.LOCALE_VARIANT); + + if (variant != null) { + // all 3 parameter must not be null and valid + locale = new Locale(language, country, variant); + } else { + if (country != null) { + // 2 parameter must not be null and valid + locale = new Locale(language, country); + } else { + if (language != null) { + // 1 parameter must not be null and valid + locale = new Locale(language); + } else { + locale = Locale.getDefault(); + } + } + } + + return locale; + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#clear() + */ + public void clear() { + fLock.writeLock().lock(); + try { + int cacheSize = this.determineCacheSize(this.parameters); + if (cacheSize == -1) { + this.cache = CacheImpl.newInstance(); + } else { + this.cache = CacheImpl.newInstance(cacheSize); + } + PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.getCacheSize()); + + /* + * clear provider cache + */ + getBinding().clearAllCaches(); + } finally { + fLock.writeLock().unlock(); + } + } + + public void save() { + // nop + } + + public void cancel() { + throw new UnsupportedOperationException("cancel"); + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getObjectFactory() + */ + public ObjectFactory getObjectFactory() { + return this.objectFactory; + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getCheckedOutDocs(int) + */ + public PagingIterable getCheckedOutDocs(int itemsPerPage) { + return getCheckedOutDocs(getDefaultContext(), itemsPerPage); + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.opencmis.client.api.Session#getCheckedOutDocs(org.apache. + * opencmis.client.api. OperationContext, int) + */ + public PagingIterable getCheckedOutDocs(OperationContext context, final int itemsPerPage) { + if (itemsPerPage < 1) { + throw new IllegalArgumentException("itemsPerPage must be > 0!"); + } + + final NavigationService navigationService = getBinding().getNavigationService(); + final ObjectFactory objectFactory = getObjectFactory(); + final OperationContext ctxt = new OperationContextImpl(context); + + return new DefaultPagingIterable(new AbstractPageFetch() { + + @Override + protected AbstractPageFetch.PageFetchResult fetchPage(long skipCount) { + + // get all checked out documents + ObjectList checkedOutDocs = navigationService.getCheckedOutDocs(getRepositoryId(), null, ctxt + .getFilterString(), ctxt.getOrderBy(), ctxt.isIncludeAllowableActions(), ctxt + .getIncludeRelationships(), ctxt.getRenditionFilterString(), BigInteger.valueOf(itemsPerPage), + BigInteger.valueOf(skipCount), null); + + // convert objects + List page = new ArrayList(); + if (checkedOutDocs.getObjects() != null) { + for (ObjectData objectData : checkedOutDocs.getObjects()) { + CmisObject doc = objectFactory.convertObject(objectData, ctxt); + if (!(doc instanceof Document)) { + // should not happen... + continue; + } + + page.add((Document) doc); + } + } + + return new AbstractPageFetch.PageFetchResult(page, checkedOutDocs.getNumItems(), + checkedOutDocs.hasMoreItems()) { + }; + } + }); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#getContentChanges(java.lang.String + * , int) + */ + public PagingIterable getContentChanges(String changeLogToken, int itemsPerPage) { + throw new CmisRuntimeException("not implemented"); + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getDefaultContext() + */ + public OperationContext getDefaultContext() { + fLock.readLock().lock(); + try { + return this.context; + } finally { + fLock.readLock().unlock(); + } + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.opencmis.client.api.Session#setDefaultContext(org.apache. + * opencmis.client.api. OperationContext) + */ + public void setDefaultContext(OperationContext context) { + fLock.writeLock().lock(); + try { + this.context = (context == null ? DEFAULT_CONTEXT : context); + } finally { + fLock.writeLock().unlock(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#createOperationContext(java.util + * .Set, boolean, boolean, boolean, + * org.apache.opencmis.commons.enums.IncludeRelationships, java.util.Set, + * boolean, java.lang.String, boolean) + */ + public OperationContext createOperationContext(Set filter, boolean includeAcls, + boolean includeAllowableActions, boolean includePolicies, IncludeRelationships includeRelationships, + Set renditionFilter, boolean includePathSegments, String orderBy, boolean cacheEnabled) { + return new OperationContextImpl(filter, includeAcls, includeAllowableActions, includePolicies, + includeRelationships, renditionFilter, includePathSegments, orderBy, cacheEnabled); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#createObjectId(java.lang.String) + */ + public ObjectId createObjectId(String id) { + return new ObjectIdImpl(id); + } + + public Locale getLocale() { + return this.locale; + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getObject(java.lang.String) + */ + public CmisObject getObject(ObjectId objectId) { + return getObject(objectId, getDefaultContext()); + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getObject(java.lang.String, + * org.apache.opencmis.client.api.OperationContext) + */ + public CmisObject getObject(ObjectId objectId, OperationContext context) { + if ((objectId == null) || (objectId.getId() == null)) { + throw new IllegalArgumentException("Object Id must be set!"); + } + if (context == null) { + throw new IllegalArgumentException("Operation context must be set!"); + } + + CmisObject result = null; + + // ask the cache first + if (context.isCacheEnabled()) { + result = this.cache.getById(objectId.getId(), context.getCacheKey()); + if (result != null) { + return result; + } + } + + // get the object + ObjectData objectData = this.binding.getObjectService().getObject(getRepositoryId(), objectId.getId(), + context.getFilterString(), context.isIncludeAllowableActions(), context.getIncludeRelationships(), + context.getRenditionFilterString(), context.isIncludePolicies(), context.isIncludeAcls(), null); + + result = getObjectFactory().convertObject(objectData, context); + + // put into cache + if (context.isCacheEnabled()) { + this.cache.put(result, context.getCacheKey()); + } + + return result; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#getObjectByPath(java.lang.String) + */ + public CmisObject getObjectByPath(String path) { + return getObjectByPath(path, getDefaultContext()); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#getObjectByPath(java.lang.String, + * org.apache.opencmis.client.api.OperationContext) + */ + public CmisObject getObjectByPath(String path, OperationContext context) { + if (path == null) { + throw new IllegalArgumentException("Path must be set!"); + } + if (context == null) { + throw new IllegalArgumentException("Operation context must be set!"); + } + + CmisObject result = null; + + // ask the cache first + if (context.isCacheEnabled()) { + result = this.cache.getByPath(path, context.getCacheKey()); + if (result != null) { + return result; + } + } + + // get the object + ObjectData objectData = this.binding.getObjectService().getObjectByPath(getRepositoryId(), path, + context.getFilterString(), context.isIncludeAllowableActions(), context.getIncludeRelationships(), + context.getRenditionFilterString(), context.isIncludePolicies(), context.isIncludeAcls(), null); + + result = getObjectFactory().convertObject(objectData, context); + + // put into cache + if (context.isCacheEnabled()) { + this.cache.putPath(path, result, context.getCacheKey()); + } + + return result; + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getRepositoryInfo() + */ + public RepositoryInfo getRepositoryInfo() { + fLock.readLock().lock(); + try { + return this.repositoryInfo; + } finally { + fLock.readLock().unlock(); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getRootFolder() + */ + public Folder getRootFolder() { + return getRootFolder(getDefaultContext()); + } + + /* + * (non-Javadoc) + * + * + * + * + * + * + * + * + * + * @seeorg.apache.opencmis.client.api.Session#getRootFolder(org.apache.opencmis + * .client.api. OperationContext) + */ + public Folder getRootFolder(OperationContext context) { + String rootFolderId = getRepositoryInfo().getRootFolderId(); + + CmisObject rootFolder = getObject(createObjectId(rootFolderId), context); + if (!(rootFolder instanceof Folder)) { + throw new CmisRuntimeException("Root folder object is not a folder!"); + } + + return (Folder) rootFolder; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#getTypeChildren(java.lang.String, + * boolean, int) + */ + public PagingIterable getTypeChildren(final String typeId, final boolean includePropertyDefinitions, + final int itemsPerPage) { + if (itemsPerPage < 1) { + throw new IllegalArgumentException("itemsPerPage must be > 0!"); + } + + final RepositoryService repositoryService = getBinding().getRepositoryService(); + final ObjectFactory objectFactory = this.getObjectFactory(); + + return new DefaultPagingIterable(new AbstractPageFetch() { + + @Override + protected AbstractPageFetch.PageFetchResult fetchPage(long skipCount) { + + // fetch the data + TypeDefinitionList tdl = repositoryService.getTypeChildren( + PersistentSessionImpl.this.getRepositoryId(), typeId, includePropertyDefinitions, BigInteger + .valueOf(itemsPerPage), BigInteger.valueOf(skipCount), null); + + // convert type definitions + List page = new ArrayList(tdl.getList().size()); + for (TypeDefinition typeDefinition : tdl.getList()) { + page.add(objectFactory.convertTypeDefinition(typeDefinition)); + } + + return new AbstractPageFetch.PageFetchResult(page, tdl.getNumItems(), tdl.hasMoreItems()) { + }; + } + }); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#getTypeDefinition(java.lang.String + * ) + */ + public ObjectType getTypeDefinition(String typeId) { + TypeDefinition typeDefinition = getBinding().getRepositoryService().getTypeDefinition(getRepositoryId(), + typeId, null); + return objectFactory.convertTypeDefinition(typeDefinition); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#getTypeDescendants(java.lang.String + * , int, boolean) + */ + public List> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions) { + List descendants = getBinding().getRepositoryService().getTypeDescendants( + getRepositoryId(), typeId, BigInteger.valueOf(depth), includePropertyDefinitions, null); + + return convertTypeDescendants(descendants); + } + + /** + * Converts provider TypeDefinitionContainer to API + * Container. + */ + private List> convertTypeDescendants(List descendantsList) { + List> result = new ArrayList>(); + + for (TypeDefinitionContainer container : descendantsList) { + ObjectType objectType = objectFactory.convertTypeDefinition(container.getTypeDefinition()); + List> children = convertTypeDescendants(container.getChildren()); + + result.add(new ContainerImpl(objectType, children)); + } + + return result; + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#query(java.lang.String, + * boolean, int) + */ + public PagingIterable query(final String statement, final boolean searchAllVersions, + final int itemsPerPage) { + return query(statement, searchAllVersions, getDefaultContext(), itemsPerPage); + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#query(java.lang.String, + * boolean, org.apache.opencmis.client.api.OperationContext, int) + */ + public PagingIterable query(final String statement, final boolean searchAllVersions, + OperationContext context, final int itemsPerPage) { + + if (itemsPerPage < 1) { + throw new IllegalArgumentException("itemsPerPage must be > 0!"); + } + + final DiscoveryService discoveryService = getBinding().getDiscoveryService(); + final ObjectFactory objectFactory = this.getObjectFactory(); + final OperationContext ctxt = new OperationContextImpl(context); + + return new DefaultPagingIterable(new AbstractPageFetch() { + + @Override + protected AbstractPageFetch.PageFetchResult fetchPage(long skipCount) { + + // fetch the data + ObjectList resultList = discoveryService.query(getRepositoryId(), statement, searchAllVersions, ctxt + .isIncludeAllowableActions(), ctxt.getIncludeRelationships(), ctxt.getRenditionFilterString(), + BigInteger.valueOf(itemsPerPage), BigInteger.valueOf(skipCount), null); + + // convert type definitions + List page = new ArrayList(); + if (resultList.getObjects() != null) { + for (ObjectData objectData : resultList.getObjects()) { + if (objectData == null) { + continue; + } + + page.add(objectFactory.convertQueryResult(objectData)); + } + } + + return new AbstractPageFetch.PageFetchResult(page, resultList.getNumItems(), resultList + .hasMoreItems()) { + }; + } + }); + + } + + public String setExtensionContext(String context) { + throw new CmisRuntimeException("not implemented"); + } + + public ExtensionHandler setExtensionHandler(String context, ExtensionHandler extensionHandler) { + throw new CmisRuntimeException("not implemented"); + } + + /** + * Connect session object to the provider. This is the very first call after + * a session is created. + *

+ * In dependency of the parameter set an {@code AtomPub}, a {@code + * WebService} or an {@code InMemory} provider is selected. + */ + public void connect() { + fLock.writeLock().lock(); + try { + this.binding = CmisBindingHelper.createProvider(this.parameters); + + /* get initial repository id from session parameter */ + String repositoryId = this.determineRepositoryId(this.parameters); + if (repositoryId == null) { + throw new IllegalStateException("Repository Id is not set!"); + } + + repositoryInfo = getBinding().getRepositoryService().getRepositoryInfo(repositoryId, null); + } finally { + fLock.writeLock().unlock(); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#getBinding() + */ + public CmisBinding getBinding() { + fLock.readLock().lock(); + try { + return this.binding; + } finally { + fLock.readLock().unlock(); + } + } + + public Cache getCache() { + fLock.readLock().lock(); + try { + return this.cache; + } finally { + fLock.readLock().unlock(); + } + } + + /** + * Returns the repository id. + */ + public String getRepositoryId() { + return getRepositoryInfo().getId(); + } + + // creates + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#createDocument(java.util.Map, + * org.apache.opencmis.client.api.ObjectId, + * org.apache.opencmis.client.api.ContentStream, + * org.apache.opencmis.commons.enums.VersioningState, java.util.List, + * java.util.List, java.util.List) + */ + public ObjectId createDocument(Map properties, ObjectId folderId, ContentStream contentStream, + VersioningState versioningState, List policies, List addAces, List removeAces) { + if ((folderId != null) && (folderId.getId() == null)) { + throw new IllegalArgumentException("Folder Id must be set!"); + } + + String newId = getBinding().getObjectService().createDocument(getRepositoryId(), + objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), + (folderId == null ? null : folderId.getId()), objectFactory.convertContentStream(contentStream), + versioningState, objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces), + objectFactory.convertAces(removeAces), null); + + if (newId == null) { + return null; + } + + return createObjectId(newId); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#createDocumentFromSource(org.apache + * .opencmis.client. api.ObjectId, java.util.Map, + * org.apache.opencmis.client.api.ObjectId, + * org.apache.opencmis.commons.enums.VersioningState, java.util.List, + * java.util.List, java.util.List) + */ + public ObjectId createDocumentFromSource(ObjectId source, Map properties, ObjectId folderId, + VersioningState versioningState, List policies, List addAces, List removeAces) { + if ((folderId != null) && (folderId.getId() == null)) { + throw new IllegalArgumentException("Folder Id must be set!"); + } + + // get the type of the source document + ObjectType type = null; + if (source instanceof CmisObject) { + type = ((CmisObject) source).getBaseType(); + } else { + CmisObject sourceObj = getObject(source); + type = sourceObj.getType(); + } + + if (type.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) { + throw new IllegalArgumentException("Source object must be a document!"); + } + + String newId = getBinding().getObjectService().createDocumentFromSource(getRepositoryId(), source.getId(), + objectFactory.convertProperties(properties, type, CREATE_UPDATABILITY), + (folderId == null ? null : folderId.getId()), versioningState, objectFactory.convertPolicies(policies), + objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); + + if (newId == null) { + return null; + } + + return createObjectId(newId); + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#createFolder(java.util.Map, + * org.apache.opencmis.client.api.ObjectId, java.util.List, java.util.List, + * java.util.List) + */ + public ObjectId createFolder(Map properties, ObjectId folderId, List policies, + List addAces, List removeAces) { + if ((folderId != null) && (folderId.getId() == null)) { + throw new IllegalArgumentException("Folder Id must be set!"); + } + + String newId = getBinding().getObjectService().createFolder(getRepositoryId(), + objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), + (folderId == null ? null : folderId.getId()), objectFactory.convertPolicies(policies), + objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); + + if (newId == null) { + return null; + } + + return createObjectId(newId); + } + + /* + * (non-Javadoc) + * + * @see org.apache.opencmis.client.api.Session#createPolicy(java.util.Map, + * org.apache.opencmis.client.api.ObjectId, java.util.List, java.util.List, + * java.util.List) + */ + public ObjectId createPolicy(Map properties, ObjectId folderId, List policies, + List addAces, List removeAces) { + if ((folderId != null) && (folderId.getId() == null)) { + throw new IllegalArgumentException("Folder Id must be set!"); + } + + String newId = getBinding().getObjectService().createPolicy(getRepositoryId(), + objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), + (folderId == null ? null : folderId.getId()), objectFactory.convertPolicies(policies), + objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); + + if (newId == null) { + return null; + } + + return createObjectId(newId); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.api.Session#createRelationship(java.util.Map, + * java.util.List, java.util.List, java.util.List) + */ + public ObjectId createRelationship(Map properties, List policies, List addAces, + List removeAces) { + String newId = getBinding().getObjectService().createRelationship(getRepositoryId(), + objectFactory.convertProperties(properties, null, CREATE_UPDATABILITY), + objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces), + objectFactory.convertAces(removeAces), null); + + if (newId == null) { + return null; + } - return createObjectId(newId); - } + return createObjectId(newId); + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/DocumentTypeDefinitionImpl.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/DocumentTypeDefinitionImpl.java?rev=937209&r1=937208&r2=937209&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/DocumentTypeDefinitionImpl.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/DocumentTypeDefinitionImpl.java Fri Apr 23 09:28:57 2010 @@ -29,37 +29,37 @@ import org.apache.chemistry.opencmis.com */ public class DocumentTypeDefinitionImpl extends AbstractTypeDefinition implements DocumentTypeDefinition { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private ContentStreamAllowed fContentStreamAllowed; - private Boolean fIsVersionable; + private ContentStreamAllowed fContentStreamAllowed = ContentStreamAllowed.NOTALLOWED; + private Boolean fIsVersionable = Boolean.FALSE; - /* - * (non-Javadoc) - * - * @seeorg.apache.opencmis.client.provider.DocumentTypeDefinitionData# - * getContentStreamAllowed() - */ - public ContentStreamAllowed getContentStreamAllowed() { - return fContentStreamAllowed; - } - - public void setContentStreamAllowed(ContentStreamAllowed contentStreamAllowed) { - fContentStreamAllowed = contentStreamAllowed; - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.opencmis.client.provider.DocumentTypeDefinitionData#isVersionable - * () - */ - public Boolean isVersionable() { - return fIsVersionable; - } - - public void setIsVersionable(Boolean isVersionable) { - fIsVersionable = isVersionable; - } + /* + * (non-Javadoc) + * + * @seeorg.apache.opencmis.client.provider.DocumentTypeDefinitionData# + * getContentStreamAllowed() + */ + public ContentStreamAllowed getContentStreamAllowed() { + return fContentStreamAllowed; + } + + public void setContentStreamAllowed(ContentStreamAllowed contentStreamAllowed) { + fContentStreamAllowed = contentStreamAllowed; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.opencmis.client.provider.DocumentTypeDefinitionData#isVersionable + * () + */ + public Boolean isVersionable() { + return fIsVersionable; + } + + public void setIsVersionable(Boolean isVersionable) { + fIsVersionable = isVersionable; + } } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java?rev=937209&r1=937208&r2=937209&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectIT.java Fri Apr 23 09:28:57 2010 @@ -45,23 +45,6 @@ public class WriteObjectIT extends Abstr String folderName = UUID.randomUUID().toString(); String typeId = FixtureData.FOLDER_TYPE_ID.value(); - /* - * ObjectType ot = this.session.getTypeDefinition(typeId); - * Collection> pdefs = ot.getPropertyDefintions() - * .values(); List> properties = new - * ArrayList>(); Property prop = null; - * - * for (PropertyDefinition pd : pdefs) { try { CmisProperties cmisp = - * CmisProperties.fromValue(pd.getId()); switch (cmisp) { case NAME: - * prop = this.session.getObjectFactory().createProperty(pd, - * folderName); properties.add(prop); break; case OBJECT_TYPE_ID: prop = - * this.session.getObjectFactory().createProperty(pd, typeId); - * properties.add(prop); break; default: break; } } catch (Exception e) - * { // custom property definition } - * - * } - */ - Map properties = new HashMap(); properties.put(PropertyIds.NAME, folderName); properties.put(PropertyIds.OBJECT_TYPE_ID, typeId); @@ -76,26 +59,6 @@ public class WriteObjectIT extends Abstr String folderName = UUID.randomUUID().toString(); String typeId = FixtureData.DOCUMENT_TYPE_ID.value(); - /* - * ObjectType ot = this.session.getTypeDefinition(typeId); - * Collection> pdefs = ot.getPropertyDefintions() - * .values(); List> properties = new - * ArrayList>(); Property prop = null; - * - * for (PropertyDefinition pd : pdefs) { try { CmisProperties cmisp = - * CmisProperties.fromValue(pd.getId()); switch (cmisp) { case NAME: - * prop = this.session.getObjectFactory().createProperty(pd, - * folderName); properties.add(prop); break; case OBJECT_TYPE_ID: prop = - * this.session.getObjectFactory().createProperty(pd, typeId); - * properties.add(prop); break; default: break; } } catch (Exception e) - * { /* custom property definition (note: document type should not have - * further mandatory properties) - */ - /* - * this.log .info( - * "Custom property found but not supported in test case!", e); } } - */ - Map properties = new HashMap(); properties.put(PropertyIds.NAME, folderName); properties.put(PropertyIds.OBJECT_TYPE_ID, typeId); @@ -134,18 +97,6 @@ public class WriteObjectIT extends Abstr String srcContent = this.getContentAsString(srcDocument.getContentStream()); ObjectId parentFolder = session.createObjectId(Fixture.getTestRootId()); - /* - * List> srcProperties = srcDocument.getProperties(); - * assertNotNull(srcProperties); List> dstProperties = - * new ArrayList>(); - * - * for (Property p : srcProperties) { if - * (p.getId().equalsIgnoreCase(CmisProperties.NAME.value())) { // - * change the name String name = UUID.randomUUID().toString(); - * Property pn = this.session.getObjectFactory() - * .createProperty(p.getDefinition(), name); dstProperties.add(pn); - * } else { dstProperties.add(p); } } - */ String name = UUID.randomUUID().toString(); Map properties = new HashMap(); Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectRelationIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectRelationIT.java?rev=937209&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectRelationIT.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectRelationIT.java Fri Apr 23 09:28:57 2010 @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.fit.runtime; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.chemistry.opencmis.client.api.Document; +import org.apache.chemistry.opencmis.client.api.ObjectId; +import org.apache.chemistry.opencmis.client.api.ObjectType; +import org.apache.chemistry.opencmis.client.api.PagingIterable; +import org.apache.chemistry.opencmis.client.api.Relationship; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore // relations not yet supported +public class WriteObjectRelationIT extends AbstractSessionTest { + + @Test + public void createAndLoopRelations() { + String path1 = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME; + Document document1 = (Document) this.session.getObjectByPath(path1); + assertNotNull("Document not found: " + path1, document1); + + String path2 = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT2_NAME; + Document document2 = (Document) this.session.getObjectByPath(path2); + assertNotNull("Document not found: " + path2, document2); + + Map properties = new HashMap(); + properties.put(PropertyIds.OBJECT_TYPE_ID, ObjectType.RELATIONSHIP_BASETYPE_ID); + properties.put(PropertyIds.SOURCE_ID, document1.getId()); + properties.put(PropertyIds.TARGET_ID, document2.getId()); + + ObjectId id = this.session.createRelationship(properties, null, null, null); + + ObjectType ot = document1.getType(); + PagingIterable relations = document1.getRelationships(true, RelationshipDirection.EITHER, ot, this.session.getDefaultContext(), 10); + for (Relationship r : relations) { + assertNotNull(r); + assertEquals(id, r.getId()); + break; + } + } + +} Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectRelationIT.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectVersionIT.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectVersionIT.java?rev=937209&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectVersionIT.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectVersionIT.java Fri Apr 23 09:28:57 2010 @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.fit.runtime; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.apache.chemistry.opencmis.client.api.Document; +import org.apache.chemistry.opencmis.client.api.DocumentType; +import org.apache.chemistry.opencmis.client.api.Folder; +import org.apache.chemistry.opencmis.client.api.ObjectId; +import org.apache.chemistry.opencmis.client.api.PagingIterable; +import org.junit.Test; + +public class WriteObjectVersionIT extends AbstractSessionTest { + @Test + public void checkOutDocs() { + + /* check out one versionable document */ + String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME; + Document document = (Document) this.session.getObjectByPath(path); + assertNotNull("Document not found: " + path, document); + DocumentType dt = (DocumentType) document.getType(); + assertNotNull(dt); + ObjectId id = null; + if (dt.isVersionable()) { + id = document.checkOut(); + } + + /* get all verchecked out docs which should be exactly one or zero */ + Folder f = this.session.getRootFolder(); + assertNotNull(f); + PagingIterable pi = f.getCheckedOutDocs(10); + assertNotNull(pi); + + for (Document d : pi) { + assertNotNull(d); + assertEquals(id, d.getId()); + break; // check only first and only loop entry + } + } + +} Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/WriteObjectVersionIT.java ------------------------------------------------------------------------------ svn:mime-type = text/plain