/* * Copyright (C) 2006 Alfresco, Inc. * * Licensed under the Mozilla Public License version 1.1 * with a permitted attribution clause. You may obtain a * copy of the License at * * http://www.alfresco.org/legal/license.txt * * 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.alfresco.service.cmr.avm; import java.io.InputStream; import java.io.OutputStream; import java.util.Date; import java.util.List; import java.util.Map; import java.util.SortedMap; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; /** * This is the service interface for the [Alfresco|Addled|Advanced|Aleatoric|Apotheosed|Awful] * Versioning Model. It specifies methods that are close in functionality to the underlying * implementation, and is intended as both a first class Alfresco service and an * aid in creating new implementations of existing services. * Paths are of the form storename:/foo/bar/baz. * @author britt */ public interface AVMService { /** * Get an InputStream for a file node. * @param version The version id to look in. * @param path The simple absolute path to the file node. * @return An InputStream for the designated file. * @throws AVMNotFoundException If path is not found. * @throws AVMWrongTypeException If path contains a non-terminal * component that is not a Directory of if it does not point at a file. */ public InputStream getFileInputStream(int version, String path); /** * Get an output stream to a file node. The file must already exist. * @param path The simple absolute path to the file node. * @throws AVMNotFoundException If path is not found. * @throws AVMWrongTypeException If path contains a non-terminal * component that is not a directory, or if it is not pointing to a file. */ public OutputStream getFileOutputStream(String path); /** * Get a listing of a Folder by name. * @param version The version id to look in. * @param path The simple absolute path to the file node. * @return A Map of names to descriptors. * @throws AVMNotFoundException If path is not found. * @throws AVMWrongTypeException If path contains a non-terminal * component that is not a directory, or if path is not pointing * at a directory. */ public SortedMap getDirectoryListing(int version, String path); /** * Get a listing of a Folder by name, with the option of seeing * Deleted Nodes. * @param version The version id to look in. * @param path The simple absolute path to the file node. * @param includeDeleted Whether to see Deleted Nodes. * @return A Map of names to descriptors. * @throws AVMNotFoundException If path is not found. * @throws AVMWrongTypeException If path contains a non-terminal * component that is not a directory, or if path is not pointing * at a directory. */ public SortedMap getDirectoryListing(int version, String path, boolean includeDeleted); /** * Get the listing of nodes contained directly in a directory. This is the * same as getDirectoryListing for PlainDirectories, but returns only those that * are directly contained in a layered directory. * @param version The version to look up. * @param path The full path to get listing for. * @return A Map of names to descriptors. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains any non-directory * elements. */ public SortedMap getDirectoryListingDirect(int version, String path); /** * Get the listing of nodes contained directly in a directory. This is the * same as getDirectoryListing for PlainDirectories, but returns only those that * are directly contained in a layered directory. This has the option of * seeing Deleted Nodes. * @param version The version to look up. * @param path The full path to get listing for. * @param includeDeleted Whether to see Deleted Nodes. * @return A Map of names to descriptors. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains any non-directory * elements. */ public SortedMap getDirectoryListingDirect(int version, String path, boolean includeDeleted); /** * Get a listing of all the directly contained children of a directory. * @param dir The directory descriptor. * @param includeDeleted Whether to include deleted children. * @return A Map of Strings to descriptors. */ public SortedMap getDirectoryListingDirect(AVMNodeDescriptor dir, boolean includeDeleted); /** * Get a directory listing from a node descriptor. * @param dir The directory node descriptor. * @return A Map of names to node descriptors. * @throws AVMNotFoundException If the descriptor is stale. * @throws AVMWrongTypeException If the descriptor does not point at * a directory. */ public SortedMap getDirectoryListing(AVMNodeDescriptor dir); /** * Get a directory listing from a node descriptor, with the option of * seeing deleted nodes. * @param dir The directory node descriptor. * @param includeDeleted Whether to see Deleted Nodes. * @return A Map of names to node descriptors. * @throws AVMNotFoundException If the descriptor is stale. * @throws AVMWrongTypeException If the descriptor does not point at a directory. */ public SortedMap getDirectoryListing(AVMNodeDescriptor dir, boolean includeDeleted); /** * Get the names of nodes that have been deleted in a directory. * @param version The version to look under. * @param path The path of the directory. * @return A List of names. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains any elements * that are not directories. */ public List getDeleted(int version, String path); /** * Create a new File. Fails if the file already exists. * @param path The simple absolute path to the parent. * @param name The name to give the file. * @throws AVMNotFound If path is non existent. * @throws AVMExists If name already exists. * @throws AVMWrongType If some component of path is not * a directory. */ public OutputStream createFile(String path, String name); /** * Create a new File. Guarantees that the entire contents of the * input stream will be loaded atomically. * @param path The path to the parent directory. * @param name The name for the new file. * @param in An input stream with data for the file. * @throws AVMNotFound If path is non existent. * @throws AVMExists If name already exists. * @throws AVMWrongType If some component of path is not * a directory. */ public void createFile(String path, String name, InputStream in); /** * Create a new directory. * @param path The simple absolute path to the parent. * @param name The name to give the folder. * @throws AVMNotFound If path is non existent. * @throws AVMExists If name already exists. * @throws AVMWrongType If some component of path is not * a directory. */ public void createDirectory(String path, String name); /** * Create a new layered file. * @param targetPath The simple absolute path that the new file will point at. * @param parent The simple absolute path to the parent. * @param name The name to give the new file. * @throws AVMNotFound If parent is non existent. * @throws AVMExists If name already exists. * @throws AVMWrongType If some component of parent is not * a directory. */ public void createLayeredFile(String targetPath, String parent, String name); /** * Create a new layered directory. * @param targetPath The simple absolute path that the new folder will point at. * @param parent The simple absolute path to the parent. * @param name The name to give the new folder. * @throws AVMNotFound If parent is non existent. * @throws AVMExists If name already exists. * @throws AVMWrongType If some component of parent is not * a directory. */ public void createLayeredDirectory(String targetPath, String parent, String name); /** * Retarget a layered directory. * @param path Path to the layered directory. * @param target The new target to aim at. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * component that is not a directory or if it does not point at a retargetable * directory. */ public void retargetLayeredDirectory(String path, String target); /** * Create a new AVMStore. All AVMStores are top level in a hierarchical * sense. * @param name The name to give the AVMStore. * @throws AVMExistsException If name is an already existing store. */ public void createAVMStore(String name); /** * Create a branch from a given version and path. * @param version The version number from which to make the branch. * @param srcPath The path to the node to branch from. * @param dstPath The path to the directory to contain the * new branch. * @param name The name to give the new branch. * @throws AVMNotFoundException If either srcPath or * dstPath does not exist. * @throws AVMExistsException If name already exists. * @throws AVMWrongTypeException If srcPath or dstPath * contains a non-terminal element that is not a directory. */ public void createBranch(int version, String srcPath, String dstPath, String name); /** * Remove a child from its parent. * @param parent The simple absolute path to the parent directory. * @param name The name of the child to remove. * @throws AVMNotFoundException If parent or name * does not exist. * @throws AVMWrongTypeException If parent contains a non-terminal * element that is not a directory. */ public void removeNode(String parent, String name); /** * Remove a node from by its full path. * @param path The full path to the node to remove. */ public void removeNode(String path); /** * Rename a node. * @param srcParent The simple absolute path to the parent folder. * @param srcName The name of the node in the src Folder. * @param dstParent The simple absolute path to the destination folder. * @param dstName The name that the node will have in the destination folder. * @throws AVMNotFoundException If srcParent, * srcName, or dstParent do not exist. * @throws AVMExistsException If dstName already exists. * @throws AVMWrongTypeException If srcParent or * dstParent contain non-terminal elements that are not directories * or if either do not point at directories. */ public void rename(String srcParent, String srcName, String dstParent, String dstName); /** * Uncover a name in a layered directory. That is, if the layered * directory has a deleted entry of the given name remove that * name from the deleted list. * @param dirPath The path to the layered directory. * @param name The name to uncover. * @throws AVMNotFoundException If dirPath does not exist. * @throws AVMWrongTypeExceptiont If dirPath contains a non-terminal * element that is not a directory. */ public void uncover(String dirPath, String name); /** * Get the latest version id of the AVMStore. * @param storeName The name of the AVMStore. * @return The latest version id of the AVMStore. * @throws AVMNotFoundException If storeName does not exist. */ public int getLatestVersionID(String storeName); /** * Get the latest snapshot id of a store. * @param storeName The store name. * @return The id of the latest extant version of the store. * @throws AVMNotFoundException If storeName does not exist. */ public int getLatestSnapshotID(String storeName); /** * Snapshot the given AVMStores. When this is called everything that has been added, * deleted, or modified since the last time this function was called, is marked * as needing to be copied, so that further modifications will trigger copy on write * semantics. * @param stores The names of the AVMStores to snapshot. * @return A List of the version ids of the newly created snapshots. * @throws AVMNotFoundException If any of the stores do not exist. */ public List createSnapshot(List stores); /** * Snapshot the given AVMStore. * @param store The name of the AVMStore to snapshot. * @param tag The short description. * @param description The thick description. * @throws AVMNotFoundException If store does not exist. */ public int createSnapshot(String store, String tag, String description); /** * Get the set of versions in an AVMStore * @param name The name of the AVMStore. * @return A Set of version IDs * @throws AVMNotFoundException If name does not exist. */ public List getAVMStoreVersions(String name); /** * Get AVMStore version descriptors by creation date. Either from or * to can be null but not both. * @param name The name of the AVMStore. * @param from Earliest date of version to include. * @param to Latest date of version to include. * @return The Set of version IDs that match. * @throws AVMNotFoundException If name does not exist. */ public List getAVMStoreVersions(String name, Date from, Date to); /** * Get the descriptors of all AVMStores. * @return A List of all AVMStores. */ public List getAVMStores(); /** * Get (and create if necessary) the system store. This store houses things * like workflow packages. * @return The descriptor. */ public AVMStoreDescriptor getAVMSystemStore(); /** * Get a descriptor for an AVMStore. * @param name The AVMStore's name. * @return A Descriptor. * @throws AVMNotFoundException If name does not exist. */ public AVMStoreDescriptor getAVMStore(String name); /** * Get the specified root of an AVMStore. * @param version The version to look up. * @param name The name of the AVMStore. * @return A descriptor for the specified root. * @throws AVMNotFoundException If name does not exist or * if version does not exist. */ public AVMNodeDescriptor getAVMStoreRoot(int version, String name); /** * Lookup a node by version ids and path. * @param version The version id to look under. * @param path The simple absolute path to the parent directory. * @return An AVMNodeDescriptor. * @throws AVMNotFoundException If path does not exist or * if version does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public AVMNodeDescriptor lookup(int version, String path); /** * Lookup a node by version ids and path, with the option of * seeing Deleted Nodes. * @param version The version id to look under. * @param path The simple absolute path to the parent directory. * @param includeDeleted Whether to see Deleted Nodes. * @return An AVMNodeDescriptor. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public AVMNodeDescriptor lookup(int version, String path, boolean includeDeleted); /** * Lookup a node from a directory node. * @param dir The descriptor for the directory node. * @param name The name to lookup. * @return The descriptor for the child. * @throws AVMWrongTypeException If dir does not refer to a directory. */ public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name); /** * Lookup a node from a directory node, with the option of seeing * Deleted Nodes. * @param dir The descriptor for the directory node. * @param name The name to lookup. * @param includeDeleted Whether to see Deleted Nodes. * @return The descriptor for the child. * @throws AVMWrongTypeException If dir does not refer to a directory. */ public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name, boolean includeDeleted); /** * Get a list of all paths that a given node has. * @param desc The node descriptor to get paths for. * @return A List of version, path Pairs. */ public List> getPaths(AVMNodeDescriptor desc); /** * Get all paths that a given node has that are in the head version. * @param desc The node descriptor to get paths for. * @return A List of version, path Pairs. */ public List> getHeadPaths(AVMNodeDescriptor desc); /** * Get all paths to a node starting at the HEAD version of a store. * @param desc The node descriptor. * @param store The store. * @return A List of all paths meeting the criteria. */ public List> getPathsInStoreHead(AVMNodeDescriptor desc, String store); /** * Get the indirection path for a node in a layered context. * @param version The version number to get. * @param path The path to the node of interest. * @return The indirection path, or null if the path is not in a layered context. * @throws AVMNotFoundException If path does not exist or * if version does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory or if it does not refer to a layered * node. */ public String getIndirectionPath(int version, String path); /** * Purge an AVMStore. This is a complete wipe of an AVMStore. * @param name The name of the AVMStore. * @throws AVMNotFoundException If name does not exist. */ public void purgeAVMStore(String name); /** * Purge a version from an AVMStore. Deletes everything that lives in * the given version only. * @param version The version to purge. * @param name The name of the AVMStore from which to purge it. * @throws AVMNotFoundException If name or version * do not exist. */ public void purgeVersion(int version, String name); /** * Make a directory into a primary indirection node. * @param path The full path. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory or if it refers to a node that can't be made * primary. */ public void makePrimary(String path); /** * Get a list of all the ancestor versions of a node. * @param desc The version of a node to find ancestors for. * @param count How many. -1 means all. * @return A List of ancestors starting with the most recent. * @throws AVMNotFoundException If desc is dangling. */ public List getHistory(AVMNodeDescriptor desc, int count); /** * Set the opacity of a layered directory. An opaque layered directory * hides the contents of its indirection. * @param path The path to the layered directory. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory or if it refers to a node that cannot have * its opacity set. */ public void setOpacity(String path, boolean opacity); /** * Get the common ancestor of two nodes if one exists. * @param left The first node. * @param right The second node. * @return The common ancestor. There are four possible results. Null means * that there is no common ancestor. Left returned means that left is strictly * an ancestor of right. Right returned means that right is strictly an * ancestor of left. Any other non null return is the common ancestor and * indicates that left and right are in conflict. * @throws AVMNotFoundException If left or right * do not exist. */ public AVMNodeDescriptor getCommonAncestor(AVMNodeDescriptor left, AVMNodeDescriptor right); /** * Get layering information about a path. * @param version The version to look under. * @param path The full AVM path. * @return A LayeringDescriptor. * @throws AVMNotFoundException If path or version * do not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public LayeringDescriptor getLayeringInfo(int version, String path); /** * Set a property on a node. * @param path The path to the node to set the property on. * @param name The QName of the property. * @param value The property to set. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public void setNodeProperty(String path, QName name, PropertyValue value); /** * Set a collection of properties on a node. * @param path The path to the node. * @param properties The Map of properties to set. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public void setNodeProperties(String path, Map properties); /** * Get a property of a node by QName. * @param version The version to look under. * @param path The path to the node. * @param name The QName. * @return The PropertyValue or null if it doesn't exist. * @throws AVMNotFoundException If path or version * do not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public PropertyValue getNodeProperty(int version, String path, QName name); /** * Get all the properties associated with a node. * @param version The version to look under. * @param path The path to the node. * @return A Map of QNames to PropertyValues. * @throws AVMNotFoundException If path or version * do not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public Map getNodeProperties(int version, String path); /** * Delete a property. * @param path The path to the node. * @param name The QName of the property to delete. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path contains a non-terminal * element that is not a directory. */ public void deleteNodeProperty(String path, QName name); /** * Delete all the properties attached to an AVM node. * @param path The path to the node. */ public void deleteNodeProperties(String path); /** * Set a property on a store. If the property exists it will be overwritten. * @param store The store to set the property on. * @param name The name of the property. * @param value The value of the property. * @throws AVMNotFoundException If store * does not exist. */ public void setStoreProperty(String store, QName name, PropertyValue value); /** * Set a group of properties on a store. Existing properties will be overwritten. * @param store The name of the store. * @param props A Map of the properties to set. * @throws AVMNotFoundException If store * does not exist. */ public void setStoreProperties(String store, Map props); /** * Get a property from a store. * @param store The name of the store. * @param name The name of the property. * @return A PropertyValue or null if non-existent. * @throws AVMNotFoundException If store * does not exist. */ public PropertyValue getStoreProperty(String store, QName name); /** * Get all the properties associated with a store. * @param store The name of the store. * @return A Map of the stores properties. * @throws AVMNotFoundException If store * does not exist. */ public Map getStoreProperties(String store); /** * Queries a given store for properties with keys that match a given pattern. * @param store The name of the store. * @param keyPattern The sql 'like' pattern, inserted into a QName. * @return A Map of the matching key value pairs. */ public Map queryStorePropertyKey(String store, QName keyPattern); /** * Queries all AVM stores for properties with keys that matcha given pattern. * @param keyPattern The sql 'like' pattern, inserted into a QName. * @return A Map of store names to Maps of property key value pairs that match * the pattern. */ public Map> queryStoresPropertyKeys(QName keyPattern); /** * Delete a property on a store by name. * @param store The name of the store. * @param name The name of the property to delete. * @throws AVMNotFoundException If store * does not exist. */ public void deleteStoreProperty(String store, QName name); /** * Get the ContentData for a node. Only applies to a file. * @param version The version to look under. * @param path The path to the node. * @return The ContentData object. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path does not * point to a file. */ public ContentData getContentDataForRead(int version, String path); /** * Get the ContentData for a node. * @param path The path to the node. * @return The ContentData object. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path does not point * to a file. */ public ContentData getContentDataForWrite(String path); /** * Set the content data on a file. * @param path The path to the file. * @param data The ContentData to set. * @throws AVMNotFoundException If path does not exist. * @throws AVMWrongTypeException If path does not point * to a file. */ public void setContentData(String path, ContentData data); /** * Set all metadata on a node from another node. Aspects, properties, ACLs. * @param path The path to the node to set. * @param from The descriptor for the node to get metadata from. */ public void setMetaDataFrom(String path, AVMNodeDescriptor from); /** * Add an aspect to an AVM node. * @param path The path to the node. * @param aspectName The QName of the aspect. * @throws AVMNotFoundException If path does not exist. * @throws AVMExistsException If the aspect already exists. */ public void addAspect(String path, QName aspectName); /** * Get all the aspects on an AVM node. * @param version The version to look under. * @param path The path to the node. * @return A List of the QNames of the aspects. */ public List getAspects(int version, String path); /** * Remove an aspect and its properties from a node. * @param path The path to the node. * @param aspectName The name of the aspect. */ public void removeAspect(String path, QName aspectName); /** * Does a node have a particular aspect. * @param version The version to look under. * @param path The path to the node. * @param aspectName The aspect name to check. * @return Whether the given node has the given aspect. */ public boolean hasAspect(int version, String path, QName aspectName); /** * This inserts a node into a parent directly. * @param parentPath The path to the parent directory. * @param name The name to give the node. * @param toLink A descriptor for the node to insert. */ public void link(String parentPath, String name, AVMNodeDescriptor toLink); /** * Force copy on write of a path. * @param path The path to force. */ public AVMNodeDescriptor forceCopy(String path); /** * Copy (possibly recursively) the source into the destination * directory. * @param srcVersion The version of the source. * @param srcPath The path to the source. * @param dstPath The destination directory. * @param name The name to give the destination. */ public void copy(int srcVersion, String srcPath, String dstPath, String name); }