Interface SynchronizationCollection
- All Superinterfaces:
Folder
,HierarchyItem
This specification defines an extension to Web Distributed Authoring and Versioning (WebDAV)
that allows efficient synchronization of he contents of a WebDAV collection.
-
Method Summary
Methods inherited from interface com.ithit.webdav.server.Folder
createFile, createFolder, getChildren
Methods inherited from interface com.ithit.webdav.server.HierarchyItem
copyTo, delete, getCreated, getModified, getName, getPath, getProperties, getPropertyNames, moveTo, updateProperties
-
Method Details
-
getChanges
Changes getChanges(List<Property> propNames, String syncToken, boolean deep, Long limit) throws ServerException Returns a list of changes that correspond to a synchronization request.- Parameters:
propNames
- List of properties to retrieve with the children. They will be queried by the engine later.syncToken
- The synchronization token provided by the server and returned by the client.deep
- Indicates the "scope" of the synchronization report request, false - immediate children and true - all children at any depth.limit
- Limits the number of member URLs in a response.- Returns:
- Changes details for the folder.
The code below is part of Collection Synchronization sample provided with the SDK.@Override public Changes getChanges(List<Property> propNames, String syncToken, boolean deep, Long limit) throws ServerException { DavChanges changes = new DavChanges(); Long syncUsn = null; Long maxUsn = 0L; if (!StringUtil.isNullOrEmpty(syncToken)) { syncUsn = Long.parseLong(syncToken); } List<Pair<HierarchyItemImpl, Long>> children = new ArrayList<>(); try (Stream<Path> stream = Files.walk(Paths.get(getFullPath().toString()), deep ? Integer.MAX_VALUE : 1)) { for (String path : stream.map(Path::toString).collect(Collectors.toSet())) { String childPath = StringUtil.trimEnd(getPath(), "/") + "/" + StringUtil.trimStart(path.substring(getFullPath().toString().length()).replace(java.io.File.separator, "/"), "/"); HierarchyItemImpl child = FolderImpl.getFolder(childPath, getEngine()); if (child == null) { child = FileImpl.getFile(childPath, getEngine()); } if (child != null) { children.add(new ImmutablePair<>(child, FileSystemExtension.getUsn(path))); } } } catch (IOException ex) { throw new ServerException(ex); } if (limit != null && limit == 0) { maxUsn = children.stream().mapToLong(Pair::getValue).max().orElse(0); } else { for (Pair<HierarchyItemImpl, Long> item : children.stream().sorted(Comparator.comparingLong(Pair::getValue)).collect(Collectors.toCollection(LinkedHashSet::new))) { // Don't include deleted files/folders when syncToken is empty, because this is full sync. if (!(item.getLeft().getChangeType() == Change.DELETED && StringUtil.isNullOrEmpty(syncToken))) { maxUsn = item.getValue(); if (syncUsn == null || item.getValue() > syncUsn) { changes.add(item.getLeft()); } if (limit != null && limit <= changes.size()) { changes.setMoreResults(true); break; } } } } changes.setNewSyncToken(maxUsn.toString()); return changes; }
- Throws:
ServerException
-