Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryNavigationServiceImpl.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryNavigationServiceImpl.java?rev=936938&r1=936937&r2=936938&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryNavigationServiceImpl.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryNavigationServiceImpl.java Thu Apr 22 16:27:57 2010 @@ -64,345 +64,345 @@ import org.apache.commons.logging.LogFac public class InMemoryNavigationServiceImpl extends InMemoryAbstractServiceImpl implements CmisNavigationService { - private static Log LOG = LogFactory.getLog(InMemoryNavigationServiceImpl.class); + private static Log LOG = LogFactory.getLog(InMemoryNavigationServiceImpl.class); - AtomLinkInfoProvider fAtomLinkProvider; + AtomLinkInfoProvider fAtomLinkProvider; - public InMemoryNavigationServiceImpl(StoreManager storeManager) { - super(storeManager); - fAtomLinkProvider = new AtomLinkInfoProvider(fStoreManager); - } - - public ObjectList getCheckedOutDocs(CallContext context, String repositoryId, String folderId, String filter, - String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, - String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension, - ObjectInfoHolder objectInfos) { - - ObjectListImpl res = new ObjectListImpl(); - List<ObjectData> odList = new ArrayList<ObjectData>(); - - LOG.debug("start getCheckedOutDocs()"); - if (null != folderId) - checkStandardParameters(repositoryId, folderId); - else - checkRepositoryId(repositoryId); - - String user = context.getUsername(); - if (null == folderId) { - List<VersionedDocument> checkedOuts = fStoreManager.getObjectStore(repositoryId).getCheckedOutDocuments( - orderBy); - for (VersionedDocument checkedOut : checkedOuts) { - ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, checkedOut, filter, user, - includeAllowableActions, includeRelationships, renditionFilter, false, false, extension); - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, checkedOut, objectInfos); - odList.add(od); - } - } else { - ObjectInFolderList children = getChildrenIntern(repositoryId, folderId, filter, orderBy, - includeAllowableActions, includeRelationships, renditionFilter, false, -1, -1, false, objectInfos, - user); - for (ObjectInFolderData child : children.getObjects()) { - ObjectData obj = child.getObject(); - StoredObject so = fStoreManager.getObjectStore(repositoryId).getObjectById(obj.getId()); - LOG.info("Checked out: children:" + obj.getId()); - if (so instanceof DocumentVersion && ((DocumentVersion) so).getParentDocument().isCheckedOut()) { - odList.add(obj); - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); - } - } - } - res.setObjects(odList); - res.setNumItems(BigInteger.valueOf(odList.size())); - - LOG.debug("end getCheckedOutDocs()"); - return res; - } - - public ObjectInFolderList getChildren(CallContext context, String repositoryId, String folderId, String filter, - String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, - String renditionFilter, Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, - ExtensionsData extension, ObjectInfoHolder objectInfos) { - - LOG.debug("start getChildren()"); - - checkStandardParameters(repositoryId, folderId); - - int maxItemsInt = maxItems == null ? -1 : maxItems.intValue(); - int skipCountInt = skipCount == null ? -1 : skipCount.intValue(); - String user = context.getUsername(); - ObjectInFolderList res = getChildrenIntern(repositoryId, folderId, filter, orderBy, includeAllowableActions, - includeRelationships, renditionFilter, includePathSegment, maxItemsInt, skipCountInt, false, - objectInfos, user); - LOG.debug("stop getChildren()"); - return res; - } - - public List<ObjectInFolderContainer> getDescendants(CallContext context, String repositoryId, String folderId, - BigInteger depth, String filter, Boolean includeAllowableActions, - IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, - ExtensionsData extension, ObjectInfoHolder objectInfos) { - - LOG.debug("start getDescendants()"); - - checkStandardParameters(repositoryId, folderId); - - int levels; - if (depth == null) - levels = 2; // one of the recommended defaults (should it be - // -1?) - else if (depth.intValue() == 0) - throw new CmisInvalidArgumentException("A zero depth is not allowed for getDescendants()."); - else - levels = depth.intValue(); - - int level = 0; - String user = context.getUsername(); - List<ObjectInFolderContainer> result = getDescendantsIntern(repositoryId, folderId, filter, - includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, level, levels, - false, objectInfos, user); - - LOG.debug("stop getDescendants()"); - return result; - } - - public ObjectData getFolderParent(CallContext context, String repositoryId, String folderId, String filter, - ExtensionsData extension, ObjectInfoHolder objectInfos) { - - LOG.debug("start getFolderParent()"); - - StoredObject so = checkStandardParameters(repositoryId, folderId); - - Folder folder = null; - if (so instanceof Folder) - folder = (Folder) so; - else - throw new CmisInvalidArgumentException("Can't get folder parent, id does not refer to a folder: " - + folderId); - - ObjectData res = getFolderParentIntern(repositoryId, folder, filter, objectInfos); - - // To be able to provide all Atom links in the response we need - // additional information: - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); - - LOG.debug("stop getFolderParent()"); - return res; - } - - public List<ObjectInFolderContainer> getFolderTree(CallContext context, String repositoryId, String folderId, - BigInteger depth, String filter, Boolean includeAllowableActions, - IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, - ExtensionsData extension, ObjectInfoHolder objectInfos) { - - LOG.debug("start getFolderTree()"); - - checkStandardParameters(repositoryId, folderId); - - if (depth != null && depth.intValue() == 0) - throw new CmisInvalidArgumentException("A zero depth is not allowed for getFolderTree()."); - - int levels = depth == null ? 2 : depth.intValue(); - int level = 0; - String user = context.getUsername(); - List<ObjectInFolderContainer> result = getDescendantsIntern(repositoryId, folderId, filter, - includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, level, levels, - true, objectInfos, user); - - LOG.debug("stop getFolderTree()"); - return result; - } - - public List<ObjectParentData> getObjectParents(CallContext context, String repositoryId, String objectId, - String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, - String renditionFilter, Boolean includeRelativePathSegment, ExtensionsData extension, - ObjectInfoHolder objectInfos) { - - LOG.debug("start getObjectParents()"); - - StoredObject so = checkStandardParameters(repositoryId, objectId); - - // for now we have only folders that have a parent and the in-memory - // provider only has one - // parent for each object (no multi-filing) - List<ObjectParentData> result = null; - - Filing spo = null; - if (so instanceof Filing) - spo = (Filing) so; - else - throw new CmisInvalidArgumentException( - "Can't get object parent, id does not refer to a folder or document: " + objectId); - - result = getObjectParentsIntern(repositoryId, spo, filter, objectInfos); - - // To be able to provide all Atom links in the response we need - // additional information: - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); - - LOG.debug("stop getObjectParents()"); - return result; - } - - // private helpers - - private ObjectInFolderList getChildrenIntern(String repositoryId, String folderId, String filter, String orderBy, - Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, - Boolean includePathSegments, int maxItems, int skipCount, boolean folderOnly, ObjectInfoHolder objectInfos, - String user) { - - ObjectInFolderListImpl result = new ObjectInFolderListImpl(); - List<ObjectInFolderData> folderList = new ArrayList<ObjectInFolderData>(); - ObjectStore fs = fStoreManager.getObjectStore(repositoryId); - StoredObject so = fs.getObjectById(folderId); - Folder folder = null; - - if (so == null) - throw new CmisObjectNotFoundException("Unknown object id: " + folderId); - - if (so instanceof Folder) - folder = (Folder) so; - else - return null; // it is a document and has no children - - List<? extends StoredObject> children = folderOnly ? folder.getFolderChildren(maxItems, skipCount) : folder - .getChildren(maxItems, skipCount); - - List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter); - - for (StoredObject spo : children) { - ObjectInFolderDataImpl oifd = new ObjectInFolderDataImpl(); - ObjectDataImpl objectData = new ObjectDataImpl(); - if (includePathSegments != null && includePathSegments) - oifd.setPathSegment(spo.getName()); - if (includeAllowableActions != null && includeAllowableActions) { - AllowableActions allowableActions = DataObjectCreator.fillAllowableActions(fs, spo, user); - objectData.setAllowableActions(allowableActions); - } - if (includeRelationships != null && includeRelationships != IncludeRelationships.NONE) { - objectData.setRelationships(null /* f.getRelationships() */); - } - if (renditionFilter != null && renditionFilter.length() > 0) { - objectData.setRelationships(null /* - * f.getRenditions(renditionFilter - * ) - */); - } - - Properties props = PropertyCreationHelper.getPropertiesFromObject(repositoryId, spo, fStoreManager, - requestedIds); - objectData.setProperties(props); - - oifd.setObject(objectData); - folderList.add(oifd); - // add additional information for Atom - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, spo, objectInfos); - - } - result.setObjects(folderList); - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); - return result; - } - - private List<ObjectInFolderContainer> getDescendantsIntern(String repositoryId, String folderId, String filter, - Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, - Boolean includePathSegments, int level, int maxLevels, boolean folderOnly, ObjectInfoHolder objectInfos, - String user) { - - // log.info("getDescendantsIntern: " + folderId + ", in level " + level - // + ", max levels " + maxLevels); - - List<ObjectInFolderContainer> childrenOfFolderId = null; - if (maxLevels == -1 || level < maxLevels) { - String orderBy = PropertyIds.NAME; - ObjectInFolderList children = getChildrenIntern(repositoryId, folderId, filter, orderBy, - includeAllowableActions, includeRelationships, renditionFilter, includePathSegments, 1000, 0, - folderOnly, objectInfos, user); - - childrenOfFolderId = new ArrayList<ObjectInFolderContainer>(); - if (null != children) { - - for (ObjectInFolderData child : children.getObjects()) { - ObjectInFolderContainerImpl oifc = new ObjectInFolderContainerImpl(); - String childId = child.getObject().getId(); - List<ObjectInFolderContainer> subChildren = getDescendantsIntern(repositoryId, childId, filter, - includeAllowableActions, includeRelationships, renditionFilter, includePathSegments, - level + 1, maxLevels, folderOnly, objectInfos, user); - - oifc.setObject(child); - if (null != subChildren) - oifc.setChildren(subChildren); - childrenOfFolderId.add(oifc); - } - } - } - return childrenOfFolderId; - } - - private List<ObjectParentData> getObjectParentsIntern(String repositoryId, Filing sop, String filter, - ObjectInfoHolder objectInfos) { - - List<ObjectParentData> result = null; - if (sop instanceof SingleFiling) { - ObjectData parent = getFolderParentIntern(repositoryId, (SingleFiling) sop, filter, objectInfos); - if (null != parent) { - ObjectParentDataImpl parentData = new ObjectParentDataImpl(); - parentData.setObject(parent); - String path = ((SingleFiling) sop).getPath(); - int beginIndex = path.lastIndexOf(Filing.PATH_SEPARATOR) + 1; // Note - // : - // if - // / - // not - // found - // results in 0 - String relPathSeg = path.substring(beginIndex, path.length()); - parentData.setRelativePathSegment(relPathSeg); - result = Collections.singletonList((ObjectParentData) parentData); - } else - result = Collections.emptyList(); - } else if (sop instanceof MultiFiling) { - result = new ArrayList<ObjectParentData>(); - MultiFiling multiParentObj = (MultiFiling) sop; - List<Folder> parents = multiParentObj.getParents(); - if (null != parents) - for (Folder parent : parents) { - ObjectParentDataImpl parentData = new ObjectParentDataImpl(); - ObjectDataImpl objData = new ObjectDataImpl(); - copyFilteredProperties(repositoryId, parent, filter, objData); - parentData.setObject(objData); - parentData.setRelativePathSegment(multiParentObj.getPathSegment()); - result.add(parentData); - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, parent, objectInfos); - } - } - return result; - } - - private ObjectData getFolderParentIntern(String repositoryId, SingleFiling sop, String filter, - ObjectInfoHolder objectInfos) { - - ObjectDataImpl parent = new ObjectDataImpl(); - - Folder parentFolder = sop.getParent(); - - if (null == parentFolder) { - if (sop instanceof Children) // a folder without a parent - throw new CmisInvalidArgumentException("Cannot get parent of a root folder"); - else - return null; // an unfiled document - } - - copyFilteredProperties(repositoryId, parentFolder, filter, parent); - fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, parentFolder, objectInfos); - - return parent; - } - - void copyFilteredProperties(String repositoryId, StoredObject so, String filter, ObjectDataImpl objData) { - List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter); - Properties props = PropertyCreationHelper - .getPropertiesFromObject(repositoryId, so, fStoreManager, requestedIds); - objData.setProperties(props); - } + public InMemoryNavigationServiceImpl(StoreManager storeManager) { + super(storeManager); + fAtomLinkProvider = new AtomLinkInfoProvider(fStoreManager); + } + + public ObjectList getCheckedOutDocs(CallContext context, String repositoryId, String folderId, String filter, + String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, + String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension, + ObjectInfoHolder objectInfos) { + + ObjectListImpl res = new ObjectListImpl(); + List<ObjectData> odList = new ArrayList<ObjectData>(); + + LOG.debug("start getCheckedOutDocs()"); + if (null != folderId) + checkStandardParameters(repositoryId, folderId); + else + checkRepositoryId(repositoryId); + + String user = context.getUsername(); + if (null == folderId) { + List<VersionedDocument> checkedOuts = fStoreManager.getObjectStore(repositoryId).getCheckedOutDocuments( + orderBy); + for (VersionedDocument checkedOut : checkedOuts) { + ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, checkedOut, filter, user, + includeAllowableActions, includeRelationships, renditionFilter, false, false, extension); + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, checkedOut, objectInfos); + odList.add(od); + } + } else { + ObjectInFolderList children = getChildrenIntern(repositoryId, folderId, filter, orderBy, + includeAllowableActions, includeRelationships, renditionFilter, false, -1, -1, false, objectInfos, + user); + for (ObjectInFolderData child : children.getObjects()) { + ObjectData obj = child.getObject(); + StoredObject so = fStoreManager.getObjectStore(repositoryId).getObjectById(obj.getId()); + LOG.info("Checked out: children:" + obj.getId()); + if (so instanceof DocumentVersion && ((DocumentVersion) so).getParentDocument().isCheckedOut()) { + odList.add(obj); + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); + } + } + } + res.setObjects(odList); + res.setNumItems(BigInteger.valueOf(odList.size())); + + LOG.debug("end getCheckedOutDocs()"); + return res; + } + + public ObjectInFolderList getChildren(CallContext context, String repositoryId, String folderId, String filter, + String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, + String renditionFilter, Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, + ExtensionsData extension, ObjectInfoHolder objectInfos) { + + LOG.debug("start getChildren()"); + + checkStandardParameters(repositoryId, folderId); + + int maxItemsInt = maxItems == null ? -1 : maxItems.intValue(); + int skipCountInt = skipCount == null ? -1 : skipCount.intValue(); + String user = context.getUsername(); + ObjectInFolderList res = getChildrenIntern(repositoryId, folderId, filter, orderBy, includeAllowableActions, + includeRelationships, renditionFilter, includePathSegment, maxItemsInt, skipCountInt, false, + objectInfos, user); + LOG.debug("stop getChildren()"); + return res; + } + + public List<ObjectInFolderContainer> getDescendants(CallContext context, String repositoryId, String folderId, + BigInteger depth, String filter, Boolean includeAllowableActions, + IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, + ExtensionsData extension, ObjectInfoHolder objectInfos) { + + LOG.debug("start getDescendants()"); + + checkStandardParameters(repositoryId, folderId); + + int levels; + if (depth == null) + levels = 2; // one of the recommended defaults (should it be + // -1?) + else if (depth.intValue() == 0) + throw new CmisInvalidArgumentException("A zero depth is not allowed for getDescendants()."); + else + levels = depth.intValue(); + + int level = 0; + String user = context.getUsername(); + List<ObjectInFolderContainer> result = getDescendantsIntern(repositoryId, folderId, filter, + includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, level, levels, + false, objectInfos, user); + + LOG.debug("stop getDescendants()"); + return result; + } + + public ObjectData getFolderParent(CallContext context, String repositoryId, String folderId, String filter, + ExtensionsData extension, ObjectInfoHolder objectInfos) { + + LOG.debug("start getFolderParent()"); + + StoredObject so = checkStandardParameters(repositoryId, folderId); + + Folder folder = null; + if (so instanceof Folder) + folder = (Folder) so; + else + throw new CmisInvalidArgumentException("Can't get folder parent, id does not refer to a folder: " + + folderId); + + ObjectData res = getFolderParentIntern(repositoryId, folder, filter, objectInfos); + + // To be able to provide all Atom links in the response we need + // additional information: + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); + + LOG.debug("stop getFolderParent()"); + return res; + } + + public List<ObjectInFolderContainer> getFolderTree(CallContext context, String repositoryId, String folderId, + BigInteger depth, String filter, Boolean includeAllowableActions, + IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, + ExtensionsData extension, ObjectInfoHolder objectInfos) { + + LOG.debug("start getFolderTree()"); + + checkStandardParameters(repositoryId, folderId); + + if (depth != null && depth.intValue() == 0) + throw new CmisInvalidArgumentException("A zero depth is not allowed for getFolderTree()."); + + int levels = depth == null ? 2 : depth.intValue(); + int level = 0; + String user = context.getUsername(); + List<ObjectInFolderContainer> result = getDescendantsIntern(repositoryId, folderId, filter, + includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, level, levels, + true, objectInfos, user); + + LOG.debug("stop getFolderTree()"); + return result; + } + + public List<ObjectParentData> getObjectParents(CallContext context, String repositoryId, String objectId, + String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, + String renditionFilter, Boolean includeRelativePathSegment, ExtensionsData extension, + ObjectInfoHolder objectInfos) { + + LOG.debug("start getObjectParents()"); + + StoredObject so = checkStandardParameters(repositoryId, objectId); + + // for now we have only folders that have a parent and the in-memory + // provider only has one + // parent for each object (no multi-filing) + List<ObjectParentData> result = null; + + Filing spo = null; + if (so instanceof Filing) + spo = (Filing) so; + else + throw new CmisInvalidArgumentException( + "Can't get object parent, id does not refer to a folder or document: " + objectId); + + result = getObjectParentsIntern(repositoryId, spo, filter, objectInfos); + + // To be able to provide all Atom links in the response we need + // additional information: + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); + + LOG.debug("stop getObjectParents()"); + return result; + } + + // private helpers + + private ObjectInFolderList getChildrenIntern(String repositoryId, String folderId, String filter, String orderBy, + Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, + Boolean includePathSegments, int maxItems, int skipCount, boolean folderOnly, ObjectInfoHolder objectInfos, + String user) { + + ObjectInFolderListImpl result = new ObjectInFolderListImpl(); + List<ObjectInFolderData> folderList = new ArrayList<ObjectInFolderData>(); + ObjectStore fs = fStoreManager.getObjectStore(repositoryId); + StoredObject so = fs.getObjectById(folderId); + Folder folder = null; + + if (so == null) + throw new CmisObjectNotFoundException("Unknown object id: " + folderId); + + if (so instanceof Folder) + folder = (Folder) so; + else + return null; // it is a document and has no children + + List<? extends StoredObject> children = folderOnly ? folder.getFolderChildren(maxItems, skipCount) : folder + .getChildren(maxItems, skipCount); + + List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter); + + for (StoredObject spo : children) { + ObjectInFolderDataImpl oifd = new ObjectInFolderDataImpl(); + ObjectDataImpl objectData = new ObjectDataImpl(); + if (includePathSegments != null && includePathSegments) + oifd.setPathSegment(spo.getName()); + if (includeAllowableActions != null && includeAllowableActions) { + AllowableActions allowableActions = DataObjectCreator.fillAllowableActions(fs, spo, user); + objectData.setAllowableActions(allowableActions); + } + if (includeRelationships != null && includeRelationships != IncludeRelationships.NONE) { + objectData.setRelationships(null /* f.getRelationships() */); + } + if (renditionFilter != null && renditionFilter.length() > 0) { + objectData.setRelationships(null /* + * f.getRenditions(renditionFilter + * ) + */); + } + + Properties props = PropertyCreationHelper.getPropertiesFromObject(repositoryId, spo, fStoreManager, + requestedIds); + objectData.setProperties(props); + + oifd.setObject(objectData); + folderList.add(oifd); + // add additional information for Atom + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, spo, objectInfos); + + } + result.setObjects(folderList); + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos); + return result; + } + + private List<ObjectInFolderContainer> getDescendantsIntern(String repositoryId, String folderId, String filter, + Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, + Boolean includePathSegments, int level, int maxLevels, boolean folderOnly, ObjectInfoHolder objectInfos, + String user) { + + // log.info("getDescendantsIntern: " + folderId + ", in level " + level + // + ", max levels " + maxLevels); + + List<ObjectInFolderContainer> childrenOfFolderId = null; + if (maxLevels == -1 || level < maxLevels) { + String orderBy = PropertyIds.NAME; + ObjectInFolderList children = getChildrenIntern(repositoryId, folderId, filter, orderBy, + includeAllowableActions, includeRelationships, renditionFilter, includePathSegments, 1000, 0, + folderOnly, objectInfos, user); + + childrenOfFolderId = new ArrayList<ObjectInFolderContainer>(); + if (null != children) { + + for (ObjectInFolderData child : children.getObjects()) { + ObjectInFolderContainerImpl oifc = new ObjectInFolderContainerImpl(); + String childId = child.getObject().getId(); + List<ObjectInFolderContainer> subChildren = getDescendantsIntern(repositoryId, childId, filter, + includeAllowableActions, includeRelationships, renditionFilter, includePathSegments, + level + 1, maxLevels, folderOnly, objectInfos, user); + + oifc.setObject(child); + if (null != subChildren) + oifc.setChildren(subChildren); + childrenOfFolderId.add(oifc); + } + } + } + return childrenOfFolderId; + } + + private List<ObjectParentData> getObjectParentsIntern(String repositoryId, Filing sop, String filter, + ObjectInfoHolder objectInfos) { + + List<ObjectParentData> result = null; + if (sop instanceof SingleFiling) { + ObjectData parent = getFolderParentIntern(repositoryId, (SingleFiling) sop, filter, objectInfos); + if (null != parent) { + ObjectParentDataImpl parentData = new ObjectParentDataImpl(); + parentData.setObject(parent); + String path = ((SingleFiling) sop).getPath(); + int beginIndex = path.lastIndexOf(Filing.PATH_SEPARATOR) + 1; // Note + // : + // if + // / + // not + // found + // results in 0 + String relPathSeg = path.substring(beginIndex, path.length()); + parentData.setRelativePathSegment(relPathSeg); + result = Collections.singletonList((ObjectParentData) parentData); + } else + result = Collections.emptyList(); + } else if (sop instanceof MultiFiling) { + result = new ArrayList<ObjectParentData>(); + MultiFiling multiParentObj = (MultiFiling) sop; + List<Folder> parents = multiParentObj.getParents(); + if (null != parents) + for (Folder parent : parents) { + ObjectParentDataImpl parentData = new ObjectParentDataImpl(); + ObjectDataImpl objData = new ObjectDataImpl(); + copyFilteredProperties(repositoryId, parent, filter, objData); + parentData.setObject(objData); + parentData.setRelativePathSegment(multiParentObj.getPathSegment()); + result.add(parentData); + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, parent, objectInfos); + } + } + return result; + } + + private ObjectData getFolderParentIntern(String repositoryId, SingleFiling sop, String filter, + ObjectInfoHolder objectInfos) { + + ObjectDataImpl parent = new ObjectDataImpl(); + + Folder parentFolder = sop.getParent(); + + if (null == parentFolder) { + if (sop instanceof Children) // a folder without a parent + throw new CmisInvalidArgumentException("Cannot get parent of a root folder"); + else + return null; // an unfiled document + } + + copyFilteredProperties(repositoryId, parentFolder, filter, parent); + fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, parentFolder, objectInfos); + + return parent; + } + + void copyFilteredProperties(String repositoryId, StoredObject so, String filter, ObjectDataImpl objData) { + List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter); + Properties props = PropertyCreationHelper + .getPropertiesFromObject(repositoryId, so, fStoreManager, requestedIds); + objData.setProperties(props); + } }
