AVMStoreImpl.java

Index Score
org.alfresco.repo.avm
Alfresco

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
SIZESize of the file in bytes
DECL_COMMENTSComments in declarations
RETURNSNumber of return points from functions
INTERFACE_COMPLEXITYInterface complexity
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
OPERANDSNumber of operands
LOCLines of code
COMPARISONSNumber of comparison operators
EXITSProcedure exits
CYCLOMATICCyclomatic complexity
LINESNumber of lines in the source file
PARAMSNumber of formal parameter declarations
EXEC_COMMENTSComments in executable code
BLOCKSNumber of blocks
UNIQUE_OPERANDSNumber of unique operands
LOGICAL_LINESNumber of statements
LINE_COMMENTNumber of line comments
ELOCEffective lines of code
COMMENTSComment lines
PROGRAM_VOCABHalstead program vocabulary
DOC_COMMENTNumber of javadoc comment lines
FUNCTIONSNumber of function declarations
JAVA0233JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0034JAVA0034 Missing braces in if statement
JAVA0117JAVA0117 Missing javadoc: method 'method'
PROGRAM_VOLUMEHalstead program volume
UNIQUE_OPERATORSNumber of unique operators
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
LOOPSNumber of loops
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0068JAVA0068 Modifiers not declared in recommended order
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0145JAVA0145 Tab character used in source file
/* * Copyright (C) 2005-2007 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * As a special exception to the terms and conditions of version 2.0 of * the GPL, you may redistribute this Program in connection with Free/Libre * and Open Source Software ("FLOSS") applications as described in Alfresco's * FLOSS exception. You should have recieved a copy of the text describing * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ package org.alfresco.repo.avm; import java.io.File; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import org.alfresco.model.ContentModel; import org.alfresco.model.WCMModel; import org.alfresco.repo.avm.util.RawServices; import org.alfresco.repo.avm.util.SimplePath; import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.security.permissions.ACLCopyMode; import org.alfresco.repo.domain.QNameDAO; import org.alfresco.repo.domain.QNameEntity; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.avm.AVMBadArgumentException; import org.alfresco.service.cmr.avm.AVMException; import org.alfresco.service.cmr.avm.AVMExistsException; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNotFoundException; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.AVMWrongTypeException; import org.alfresco.service.cmr.avm.VersionDescriptor; import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; import org.alfresco.util.Pair; /** * A Repository contains a current root directory and a list of * root versions. Each root version corresponds to a separate snapshot * operation. * @author britt */ public class AVMStoreImpl implements AVMStore, Serializable { static final long serialVersionUID = -1485972568675732904L; /** * The primary key. */ private long fID; /** * The name of this AVMStore. */ private String fName; /** * The current root directory. */ private DirectoryNode fRoot; /** * The next version id. */ private int fNextVersionID; /** * The version (for concurrency control). */ private long fVers; /** * Acl for this store. */ private DbAccessControlList fACL; /** * The AVMRepository. */ transient private AVMRepository fAVMRepository; /** * Default constructor. */ protected AVMStoreImpl() { fAVMRepository = AVMRepository.GetInstance(); } /** * Make a brand new AVMStore. * @param repo The AVMRepository. * @param name The name of the AVMStore. */ public AVMStoreImpl(AVMRepository repo, String name) { // Make ourselves up and save. fAVMRepository = repo; fName = name; fNextVersionID = 0; fRoot = null; AVMDAOs.Instance().fAVMStoreDAO.save(this); String creator = RawServices.Instance().getAuthenticationComponent().getCurrentUserName(); if (creator == null) { creator = RawServices.Instance().getAuthenticationComponent().getSystemUserName(); } setProperty(ContentModel.PROP_CREATOR, new PropertyValue(null, creator)); setProperty(ContentModel.PROP_CREATED, new PropertyValue(null, new Date(System.currentTimeMillis()))); // Make up the initial version record and save. long time = System.currentTimeMillis(); fRoot = new PlainDirectoryNodeImpl(this); fRoot.setIsRoot(true); AVMDAOs.Instance().fAVMNodeDAO.save(fRoot); VersionRoot versionRoot = new VersionRootImpl(this, fRoot, fNextVersionID, time, creator, "Initial Empty Version.", "Initial Empty Version."); fNextVersionID++; AVMDAOs.Instance().fVersionRootDAO.save(versionRoot); } /** * Setter for hibernate. * @param id The primary key. */ protected void setId(long id) { fID = id; } /** * Get the primary key. * @return The primary key. */ public long getId() { return fID; } /** * Set a new root for this. * @param root */ public void setNewRoot(DirectoryNode root) { fRoot = root; fRoot.setIsRoot(true); } /** * Snapshot this store. This creates a new version record. * @return The version id of the new snapshot. */ @SuppressWarnings("unchecked") public Map<String, Integer> createSnapshot(String tag, String description, Map<String, Integer> snapShotMap) { long rootID = fRoot.getId(); AVMStoreImpl me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(fID); VersionRoot lastVersion = AVMDAOs.Instance().fVersionRootDAO.getMaxVersion(me); List<VersionLayeredNodeEntry> layeredEntries = AVMDAOs.Instance().fVersionLayeredNodeEntryDAO.get(lastVersion); // Is there no need for a snapshot? DirectoryNode root = (DirectoryNode)AVMDAOs.Instance().fAVMNodeDAO.getByID(rootID); if (!root.getIsNew() && layeredEntries.size() == 0) { // So, we set the tag and description fields of the latest version. if (tag != null || description != null) { lastVersion.setTag(tag); lastVersion.setDescription(description); } snapShotMap.put(fName, lastVersion.getVersionID()); return snapShotMap; } snapShotMap.put(fName, me.fNextVersionID); // Force copies on all the layered nodes from last snapshot. for (VersionLayeredNodeEntry entry : layeredEntries) { String path = entry.getPath(); path = path.substring(path.indexOf(':') + 1); Lookup lookup = me.lookup(-1, path, false, false); if (lookup == null) { continue; } if (lookup.getCurrentNode().getType() != AVMNodeType.LAYERED_DIRECTORY && lookup.getCurrentNode().getType() != AVMNodeType.LAYERED_FILE) { continue; } if (lookup.getCurrentNode().getIsNew()) { continue; } fAVMRepository.forceCopy(entry.getPath()); // TODO This leaves the behavior of LayeredFiles not quite // right. /* String parentName[] = AVMNodeConverter.SplitBase(entry.getPath()); parentName[0] = parentName[0].substring(parentName[0].indexOf(':') + 1); lookup = lookupDirectory(-1, parentName[0], true); DirectoryNode parent = (DirectoryNode)lookup.getCurrentNode(); AVMNode child = parent.lookupChild(lookup, parentName[1], false); // TODO For debugging. if (child == null) { System.err.println("Yoiks!"); } // TODO This is funky. Need to look carefully to see that this call // does exactly what's needed. lookup.add(child, parentName[1], false); AVMNode newChild = null; if (child.getType() == AVMNodeType.LAYERED_DIRECTORY) { newChild = child.copy(lookup); } else { newChild = ((LayeredFileNode)child).copyLiterally(lookup); } parent.putChild(parentName[1], newChild); */ } // Clear out the new nodes. List<Long> allLayeredNodeIDs = AVMDAOs.Instance().fAVMNodeDAO.getNewLayeredInStoreIDs(me); AVMDAOs.Instance().fAVMNodeDAO.clearNewInStore(me); AVMDAOs.Instance().fAVMNodeDAO.clear(); List<Long> layeredNodeIDs = new ArrayList<Long>(); for (Long layeredID : allLayeredNodeIDs) { Layered layered = (Layered)AVMDAOs.Instance().fAVMNodeDAO.getByID(layeredID); String indirection = layered.getIndirection(); if (indirection == null) { continue; } layeredNodeIDs.add(layeredID); String storeName = indirection.substring(0, indirection.indexOf(':')); if (!snapShotMap.containsKey(storeName)) { AVMStore store = AVMDAOs.Instance().fAVMStoreDAO.getByName(storeName); if (store == null) { layered.setIndirectionVersion(-1); } else { store.createSnapshot(null, null, snapShotMap); layered = (Layered)AVMDAOs.Instance().fAVMNodeDAO.getByID(layeredID); layered.setIndirectionVersion(snapShotMap.get(storeName)); } } else { layered.setIndirectionVersion(snapShotMap.get(storeName)); } } AVMDAOs.Instance().fAVMNodeDAO.flush(); // Make up a new version record. String user = RawServices.Instance().getAuthenticationComponent().getCurrentUserName(); if (user == null) { user = RawServices.Instance().getAuthenticationComponent().getSystemUserName(); } me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(fID); VersionRoot versionRoot = new VersionRootImpl(me, me.fRoot, me.fNextVersionID++, System.currentTimeMillis(), user, tag, description); // Another embarassing flush needed. AVMDAOs.Instance().fAVMNodeDAO.flush(); AVMDAOs.Instance().fVersionRootDAO.save(versionRoot); for (Long nodeID : layeredNodeIDs) { AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(nodeID); List<String> paths = fAVMRepository.getVersionPaths(versionRoot, node); for (String path : paths) { VersionLayeredNodeEntry entry = new VersionLayeredNodeEntryImpl(versionRoot, path); AVMDAOs.Instance().fVersionLayeredNodeEntryDAO.save(entry); } } return snapShotMap; } /** * Create a new directory. * @param path The path to the containing directory. * @param name The name of the new directory. */ public void createDirectory(String path, String name, List<QName> aspects, Map<QName, PropertyValue> properties) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.ADD_CHILDREN)) { throw new AccessDeniedException("Not allowed to write: " + path); } Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, true); AVMNode child = (temp == null) ? null : temp.getFirst(); if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } DirectoryNode newDir = null; if (lPath.isLayered()) // Creating a directory in a layered context creates // a LayeredDirectoryNode that gets its indirection from // its parent. { newDir = new LayeredDirectoryNodeImpl((String)null, this, null, null, ACLCopyMode.INHERIT); ((LayeredDirectoryNodeImpl)newDir).setPrimaryIndirection(false); ((LayeredDirectoryNodeImpl)newDir).setLayerID(lPath.getTopLayer().getLayerID()); } else { newDir = new PlainDirectoryNodeImpl(this); } // newDir.setVersionID(getNextVersionID()); if (child != null) { newDir.setAncestor(child); } dir.updateModTime(); dir.putChild(name, newDir); if (aspects != null) { // Convert the aspect QNames to entities QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Set<Long> aspectQNameEntityIds = newDir.getAspects(); for (QName aspectQName : aspects) { Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(aspectQName).getId(); aspectQNameEntityIds.add(qnameEntityId); } } if (properties != null) { // Convert the property QNames to entities QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Map<Long, PropertyValue> propertiesByQNameEntityId = new HashMap<Long, PropertyValue>(properties.size() * 2 + 1); for (Map.Entry<QName, PropertyValue> entry : properties.entrySet()) { Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(entry.getKey()).getId(); propertiesByQNameEntityId.put(qnameEntityId, entry.getValue()); } newDir.getProperties().putAll(propertiesByQNameEntityId); } DbAccessControlList acl = dir.getAcl(); newDir.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); } /** * Create a new layered directory. * @param srcPath The target indirection for a layered node. * @param dstPath The containing directory for the new node. * @param name The name of the new node. */ public void createLayeredDirectory(String srcPath, String dstPath, String name) { Lookup lPath = lookupDirectory(-1, dstPath, true); if (lPath == null) { throw new AVMNotFoundException("Path " + dstPath + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, true); AVMNode child = (temp == null) ? null : temp.getFirst(); if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } Long parentAcl = dir.getAcl() == null ? null : dir.getAcl().getId(); LayeredDirectoryNode newDir = new LayeredDirectoryNodeImpl(srcPath, this, null, parentAcl, ACLCopyMode.INHERIT); if (lPath.isLayered()) { // When a layered directory is made inside of a layered context, // it gets its layer id from the topmost layer in its lookup // path. LayeredDirectoryNode top = lPath.getTopLayer(); newDir.setLayerID(top.getLayerID()); } else { // Otherwise we issue a brand new layer id. newDir.setLayerID(fAVMRepository.issueLayerID()); } if (child != null) { newDir.setAncestor(child); } dir.updateModTime(); dir.putChild(name, newDir); // newDir.setVersionID(getNextVersionID()); } /** * Create a new file. * @param path The path to the directory to contain the new file. * @param name The name to give the new file. * initial content. */ public OutputStream createFile(String path, String name) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.ADD_CHILDREN)) { throw new AccessDeniedException("Not allowed to write: " + path); } Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, true); AVMNode child = (temp == null) ? null : temp.getFirst(); if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } PlainFileNodeImpl file = new PlainFileNodeImpl(this); // file.setVersionID(getNextVersionID()); dir.updateModTime(); dir.putChild(name, file); if (child != null) { file.setAncestor(child); } file.setContentData(new ContentData(null, RawServices.Instance().getMimetypeService().guessMimetype(name), -1, "UTF-8")); DbAccessControlList acl = dir.getAcl(); file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); return writer.getContentOutputStream(); } /** * Create a file with the given contents. * @param path The path to the containing directory. * @param name The name to give the new file. * @param data The contents. */ public void createFile(String path, String name, File data, List<QName> aspects, Map<QName, PropertyValue> properties) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.ADD_CHILDREN)) { throw new AccessDeniedException("Not allowed to write: " + path); } Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, true); AVMNode child = (temp == null) ? null : temp.getFirst(); if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } PlainFileNodeImpl file = new PlainFileNodeImpl(this); // file.setVersionID(getNextVersionID()); dir.updateModTime(); dir.putChild(name, file); if (child != null) { file.setAncestor(child); } file.setContentData(new ContentData(null, RawServices.Instance().getMimetypeService().guessMimetype(name), -1, "UTF-8")); if (aspects != null) { // Convert the aspect QNames to entities QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Set<Long> aspectQNameEntityIds = file.getAspects(); for (QName aspectQName : aspects) { Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(aspectQName).getId(); aspectQNameEntityIds.add(qnameEntityId); } } if (properties != null) { // Convert the property QNames to entities QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Map<Long, PropertyValue> propertiesByQNameEntityId = new HashMap<Long, PropertyValue>(properties.size() * 2 + 1); for (Map.Entry<QName, PropertyValue> entry : properties.entrySet()) { Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(entry.getKey()).getId(); propertiesByQNameEntityId.put(qnameEntityId, entry.getValue()); } file.getProperties().putAll(propertiesByQNameEntityId); } DbAccessControlList acl = dir.getAcl(); file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); // Yet another flush. AVMDAOs.Instance().fAVMNodeDAO.flush(); ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); writer.putContent(data); } /** * Create a new layered file. * @param srcPath The target indirection for the layered file. * @param dstPath The path to the directory to contain the new file. * @param name The name of the new file. */ public void createLayeredFile(String srcPath, String dstPath, String name) { Lookup lPath = lookupDirectory(-1, dstPath, true); if (lPath == null) { throw new AVMNotFoundException("Path " + dstPath + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.ADD_CHILDREN)) { throw new AccessDeniedException("Not allowed to write: " + dstPath); } Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, true); AVMNode child = (temp == null) ? null : temp.getFirst(); if (child != null && child.getType() != AVMNodeType.DELETED_NODE) { throw new AVMExistsException("Child exists: " + name); } // TODO Reexamine decision to not check validity of srcPath. LayeredFileNodeImpl newFile = new LayeredFileNodeImpl(srcPath, this, null); if (child != null) { newFile.setAncestor(child); } dir.updateModTime(); dir.putChild(name, newFile); DbAccessControlList acl = dir.getAcl(); newFile.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); // newFile.setVersionID(getNextVersionID()); } /** * Get an input stream from a file. * @param version The version id to look under. * @param path The path to the file. * @return An InputStream. */ public InputStream getInputStream(int version, String path) { ContentReader reader = getContentReader(version, path); if (reader == null) { // TODO This is wrong, wrong, wrong. Do something about it // sooner rather than later. throw new AVMNotFoundException(path + " has no content."); } return reader.getContentInputStream(); } /** * Get a ContentReader from a file. * @param version The version to look under. * @param path The path to the file. * @return A ContentReader. */ public ContentReader getContentReader(int version, String path) { NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path); return RawServices.Instance().getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT); } /** * Get a ContentWriter to a file. * @param path The path to the file. * @return A ContentWriter. */ public ContentWriter createContentWriter(String path) { NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path); ContentWriter writer = RawServices.Instance().getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true); return writer; } /** * Get a listing from a directory. * @param version The version to look under. * @param path The path to the directory. * @return A List of FolderEntries. */ public SortedMap<String, AVMNodeDescriptor> getListing(int version, String path, boolean includeDeleted) { Lookup lPath = lookupDirectory(version, path, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.READ_CHILDREN)) { throw new AccessDeniedException("Not allowed to read: " + path); } Map<String, AVMNode> listing = dir.getListing(lPath, includeDeleted); return translateListing(listing, lPath); } /** * Get the list of nodes directly contained in a directory. * @param version The version to look under. * @param path The path to the directory. * @return A Map of names to descriptors. */ public SortedMap<String, AVMNodeDescriptor> getListingDirect(int version, String path, boolean includeDeleted) { Lookup lPath = lookupDirectory(version, path, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.READ_CHILDREN)) { throw new AccessDeniedException("Not allowed to read: " + path); } if (lPath.isLayered() && dir.getType() != AVMNodeType.LAYERED_DIRECTORY) { return new TreeMap<String, AVMNodeDescriptor>(); } Map<String, AVMNode> listing = dir.getListingDirect(lPath, includeDeleted); return translateListing(listing, lPath); } /** * Helper to convert an internal representation of a directory listing * to an external representation. * @param listing The internal listing, a Map of names to nodes. * @param lPath The Lookup for the directory. * @return A Map of names to descriptors. */ private SortedMap<String, AVMNodeDescriptor> translateListing(Map<String, AVMNode> listing, Lookup lPath) { SortedMap<String, AVMNodeDescriptor> results = new TreeMap<String, AVMNodeDescriptor>(String.CASE_INSENSITIVE_ORDER); for (String name : listing.keySet()) { // TODO consider doing this at a lower level. AVMNode child = AVMNodeUnwrapper.Unwrap(listing.get(name)); AVMNodeDescriptor desc = child.getDescriptor(lPath, name); results.put(name, desc); } return results; } /** * Get the names of the deleted nodes in a directory. * @param version The version to look under. * @param path The path to the directory. * @return A List of names. */ public List<String> getDeleted(int version, String path) { Lookup lPath = lookupDirectory(version, path, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.READ_CHILDREN)) { throw new AccessDeniedException("Not allowed to read: " + path); } List<String> deleted = dir.getDeletedNames(); return deleted; } /** * Get an output stream to a file. * @param path The path to the file. * @return An OutputStream. */ public OutputStream getOutputStream(String path) { ContentWriter writer = createContentWriter(path); return writer.getContentOutputStream(); } /** * Remove a node and everything underneath it. * @param path The path to the containing directory. * @param name The name of the node to remove. */ public void removeNode(String path, String name) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(this, dir, PermissionService.DELETE_CHILDREN)) { throw new AVMNotFoundException("Not allowed to write: " + path); } if (dir.lookupChild(lPath, name, false) == null) { throw new AVMNotFoundException("Does not exist: " + name); } dir.removeChild(lPath, name); dir.updateModTime(); } /** * Allow a name which has been deleted to be visible through that layer. * @param dirPath The path to the containing directory. * @param name The name to uncover. */ public void uncover(String dirPath, String name) { Lookup lPath = lookup(-1, dirPath, true, false); if (lPath == null) { throw new AVMNotFoundException("Path " + dirPath + " not found."); } AVMNode node = lPath.getCurrentNode(); if (node.getType() != AVMNodeType.LAYERED_DIRECTORY) { throw new AVMWrongTypeException("Not a layered directory: " + dirPath); } if (!fAVMRepository.can(this, node, PermissionService.DELETE_CHILDREN)) { throw new AccessDeniedException("Not allowed to write: " + dirPath); } ((LayeredDirectoryNode)node).uncover(lPath, name); node.updateModTime(); } // TODO This is problematic. As time goes on this returns // larger and larger data sets. Perhaps what we should do is // provide methods for getting versions by date range, n most // recent etc. /** * Get the set of all extant versions for this AVMStore. * @return A Set of version ids. */ @SuppressWarnings("unchecked") public List<VersionDescriptor> getVersions() { List<VersionRoot> versions = AVMDAOs.Instance().fVersionRootDAO.getAllInAVMStore(this); List<VersionDescriptor> descs = new ArrayList<VersionDescriptor>(); for (VersionRoot vr : versions) { VersionDescriptor desc = new VersionDescriptor(fName, vr.getVersionID(), vr.getCreator(), vr.getCreateDate(), vr.getTag(), vr.getDescription()); descs.add(desc); } return descs; } /** * Get the versions between the given dates (inclusive). From or * to may be null but not both. * @param from The earliest date. * @param to The latest date. * @return The Set of matching version IDs. */ @SuppressWarnings("unchecked") public List<VersionDescriptor> getVersions(Date from, Date to) { List<VersionRoot> versions = AVMDAOs.Instance().fVersionRootDAO.getByDates(this, from, to); List<VersionDescriptor> descs = new ArrayList<VersionDescriptor>(); for (VersionRoot vr : versions) { VersionDescriptor desc = new VersionDescriptor(fName, vr.getVersionID(), vr.getCreator(), vr.getCreateDate(), vr.getTag(), vr.getDescription()); descs.add(desc); } return descs; } /** * Get the AVMRepository. * @return The AVMRepository */ public AVMRepository getAVMRepository() { return fAVMRepository; } /** * Lookup up a path. * @param version The version to look in. * @param path The path to look up. * @param write Whether this is in the context of a write. * @return A Lookup object. */ public Lookup lookup(int version, String path, boolean write, boolean includeDeleted) { SimplePath sPath = new SimplePath(path); return RawServices.Instance().getLookupCache().lookup(this, version, sPath, write, includeDeleted); } /** * Get the root node descriptor. * @param version The version to get. * @return The descriptor. */ public AVMNodeDescriptor getRoot(int version) { AVMNode root = null; if (version < 0) { root = fRoot; } else { root = AVMDAOs.Instance().fAVMNodeDAO.getAVMStoreRoot(this, version); } if (!fAVMRepository.can(this, root, PermissionService.READ_CHILDREN)) { throw new AccessDeniedException("Not allowed to read: " + fName + "@" + version); } return root.getDescriptor(fName + ":", "", null, -1); } /** * Lookup a node and insist that it is a directory. * @param version The version to look under. * @param path The path to the directory. * @param write Whether this is in a write context. * @return A Lookup object. */ public Lookup lookupDirectory(int version, String path, boolean write) { // Just do a regular lookup and assert that the last element // is a directory. Lookup lPath = lookup(version, path, write, false); if (lPath == null) { return null; } if (lPath.getCurrentNode().getType() != AVMNodeType.PLAIN_DIRECTORY && lPath.getCurrentNode().getType() != AVMNodeType.LAYERED_DIRECTORY) { return null; } return lPath; } /** * Get the effective indirection path for a layered node. * @param version The version to look under. * @param path The path to the node. * @return The effective indirection. */ public String getIndirectionPath(int version, String path) { Lookup lPath = lookup(version, path, false, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } if (!lPath.isLayered()) { return null; } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.READ_PROPERTIES)) { throw new AccessDeniedException("Not allowed to read: " + path); } if (node.getType() == AVMNodeType.LAYERED_DIRECTORY) { LayeredDirectoryNode dir = (LayeredDirectoryNode)node; return dir.getUnderlying(lPath); } else if (node.getType() == AVMNodeType.LAYERED_FILE) { LayeredFileNode file = (LayeredFileNode)node; return file.getUnderlying(lPath); } return lPath.getIndirectionPath(); } /** * Make the indicated node a primary indirection. * @param path The path to the node. */ public void makePrimary(String path) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!lPath.isLayered()) { throw new AVMException("Not in a layered context: " + path); } if (!fAVMRepository.can(this, dir, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } dir.turnPrimary(lPath); dir.updateModTime(); } /** * Change the indirection of a layered directory. * @param path The path to the layered directory. * @param target The target indirection to set. */ public void retargetLayeredDirectory(String path, String target) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!lPath.isLayered()) { throw new AVMException("Not in a layered context: " + path); } if (!fAVMRepository.can(this, dir, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } dir.retarget(lPath, target); dir.updateModTime(); } /** * Set the name of this AVMStore. * @param name */ public void setName(String name) { fName = name; } /** * Get the name of this AVMStore. * @return The name. */ public String getName() { return fName; } /* (non-Javadoc) * @see org.alfresco.repo.avm.AVMStore#getAcl() */ public DbAccessControlList getStoreAcl() { return fACL; } public void setStoreAcl(DbAccessControlList acl) { fACL = acl; } /** * Set the next version id. * @param nextVersionID */ protected void setNextVersionID(int nextVersionID) { fNextVersionID = nextVersionID; } /** * Get the next version id. * @return The next version id. */ public int getNextVersionID() { return fNextVersionID; } /** * This gets the last extant version id. */ public int getLastVersionID() { Integer lastVersionId = AVMDAOs.Instance().fVersionRootDAO.getMaxVersionID(this); if (lastVersionId == null) { return 0; } else { return lastVersionId.intValue(); } } /** * Set the root directory. Hibernate. * @param root */ protected void setRoot(DirectoryNode root) { fRoot = root; } /** * Get the root directory. * @return The root directory. */ public DirectoryNode getRoot() { return fRoot; } /** * Set the version (for concurrency control). Hibernate. * @param vers */ protected void setVers(long vers) { fVers = vers; } /** * Get the version (for concurrency control). Hibernate. * @return The version. */ protected long getVers() { return fVers; } /** * Equals override. * @param obj * @return Equality. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof AVMStore)) { return false; } return fID == ((AVMStore)obj).getId(); } /** * Get a hash code. * @return The hash code. */ @Override public int hashCode() { return (int)fID; } /** * Purge all nodes reachable only via this version and repostory. * @param version */ @SuppressWarnings("unchecked") public void purgeVersion(int version) { if (version == 0) { throw new AVMBadArgumentException("Cannot purge initial version"); } VersionRoot vRoot = AVMDAOs.Instance().fVersionRootDAO.getByVersionID(this, version); if (vRoot == null) { throw new AVMNotFoundException("Version not found."); } AVMDAOs.Instance().fVersionLayeredNodeEntryDAO.delete(vRoot); AVMNode root = vRoot.getRoot(); if (!fAVMRepository.can(null, root, PermissionService.DELETE_CHILDREN)) { throw new AccessDeniedException("Not allowed to purge: " + fName + "@" + version); } root.setIsRoot(false); AVMDAOs.Instance().fAVMNodeDAO.update(root); AVMDAOs.Instance().fVersionRootDAO.delete(vRoot); if (root.equals(fRoot)) { // We have to set a new current root. // TODO More hibernate goofiness to compensate for: fSuper.getSession().flush(); vRoot = AVMDAOs.Instance().fVersionRootDAO.getMaxVersion(this); fRoot = vRoot.getRoot(); AVMDAOs.Instance().fAVMStoreDAO.update(this); } } // TODO permissions? /** * Get the descriptor for this. * @return An AVMStoreDescriptor */ public AVMStoreDescriptor getDescriptor() { // Get the creator ensuring that nulls are not hit PropertyValue creatorValue = getProperty(ContentModel.PROP_CREATOR); String creator = creatorValue == null ? "system" : (String) creatorValue.getValue(DataTypeDefinition.TEXT); creator = (creator == null) ? "system" : creator; // Get the created date ensuring that nulls are not hit PropertyValue createdValue = getProperty(ContentModel.PROP_CREATED); Date created = createdValue == null ? (new Date()) : (Date) createdValue.getValue(DataTypeDefinition.DATE); created = (created == null) ? (new Date()) : created; return new AVMStoreDescriptor(fName, creator, created.getTime()); } /** * Set the opacity of a layered directory. An opaque directory hides * what is pointed at by its indirection. * @param path The path to the layered directory. * @param opacity True is opaque; false is not. */ public void setOpacity(String path, boolean opacity) { Lookup lPath = lookup(-1, path, true, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!(node instanceof LayeredDirectoryNode)) { throw new AVMWrongTypeException("Not a LayeredDirectoryNode."); } if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } ((LayeredDirectoryNode)node).setOpacity(opacity); node.updateModTime(); } // TODO Does it make sense to set properties on DeletedNodes? /** * Set a property on a node. * @param path The path to the node. * @param name The name of the property. * @param value The value to set. */ public void setNodeProperty(String path, QName name, PropertyValue value) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getOrCreateQNameEntity(name); node.setProperty(qnameEntity.getId(), value); node.setGuid(GUID.generate()); } /** * Set a collection of properties on a node. * @param path The path to the node. * @param properties The Map of QNames to PropertyValues. */ public void setNodeProperties(String path, Map<QName, PropertyValue> properties) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } if (properties != null) { // Convert the property QNames to entities QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Map<Long, PropertyValue> propertiesByQNameEntityId = new HashMap<Long, PropertyValue>(properties.size() * 2 + 1); for (Map.Entry<QName, PropertyValue> entry : properties.entrySet()) { Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(entry.getKey()).getId(); propertiesByQNameEntityId.put(qnameEntityId, entry.getValue()); } node.addProperties(propertiesByQNameEntityId); } node.setGuid(GUID.generate()); } /** * Get a property by name. * @param version The version to lookup. * @param path The path to the node. * @param name The name of the property. * @return A PropertyValue or null if not found. */ public PropertyValue getNodeProperty(int version, String path, QName name) { Lookup lPath = lookup(version, path, false, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.READ_PROPERTIES)) { throw new AccessDeniedException("Not allowed to read: " + path); } // Convert the QName QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; QNameEntity qnameEntity = qnameDAO.getOrCreateQNameEntity(name); if (qnameEntity == null) { // No such QName return null; } else { PropertyValue prop = node.getProperty(qnameEntity.getId()); return prop; } } /** * Get all the properties associated with a node. * @param version The version to lookup. * @param path The path to the node. * @return A Map of QNames to PropertyValues. */ public Map<QName, PropertyValue> getNodeProperties(int version, String path) { Lookup lPath = lookup(version, path, false, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.READ_PROPERTIES)) { throw new AccessDeniedException("Not allowed to read: " + path); } Map<Long, PropertyValue> props = node.getProperties(); // Convert to QNames QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; @SuppressWarnings("unchecked") Map<QName, PropertyValue> convertedProps = (Map<QName, PropertyValue>) qnameDAO.convertIdMapToQNameMap(props); return convertedProps; } /** * Delete a single property from a node. * @param path The path to the node. * @param name The name of the property. */ public void deleteNodeProperty(String path, QName name) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } node.setGuid(GUID.generate()); // convert the QName QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getQNameEntity(name); if (qnameEntity == null) { // No such property } else { node.deleteProperty(qnameEntity.getId()); } } /** * Delete all properties from a node. * @param path The path to the node. */ public void deleteNodeProperties(String path) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } node.setGuid(GUID.generate()); node.deleteProperties(); } /** * Set a property on this store. Replaces if property already exists. * @param name The QName of the property. * @param value The actual PropertyValue. */ public void setProperty(QName name, PropertyValue value) { QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getOrCreateQNameEntity(name); AVMStoreProperty prop = new AVMStorePropertyImpl(); prop.setStore(this); prop.setName(qnameEntity); prop.setValue(value); AVMDAOs.Instance().fAVMStorePropertyDAO.save(prop); } /** * Set a group of properties on this store. Replaces any property that exists. * @param properties A Map of QNames to PropertyValues to set. */ public void setProperties(Map<QName, PropertyValue> properties) { for (QName name : properties.keySet()) { setProperty(name, properties.get(name)); } } /** * Get a property by name. * @param name The QName of the property to fetch. * @return The PropertyValue or null if non-existent. */ public PropertyValue getProperty(QName name) { AVMStoreProperty prop = AVMDAOs.Instance().fAVMStorePropertyDAO.get(this, name); if (prop == null) { return null; } return prop.getValue(); } /** * Get all the properties associated with this node. * @return A Map of the properties. */ public Map<QName, PropertyValue> getProperties() { List<AVMStoreProperty> props = AVMDAOs.Instance().fAVMStorePropertyDAO.get(this); Map<QName, PropertyValue> retVal = new HashMap<QName, PropertyValue>(); for (AVMStoreProperty prop : props) { retVal.put(prop.getName().getQName(), prop.getValue()); } return retVal; } /** * Delete a property. * @param name The name of the property to delete. */ public void deleteProperty(QName name) { AVMDAOs.Instance().fAVMStorePropertyDAO.delete(this, name); } /** * Get the ContentData on a file. * @param version The version to look under. * @param path The path to the file. * @return The ContentData corresponding to the file. */ public ContentData getContentDataForRead(int version, String path) { Lookup lPath = lookup(version, path, false, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!(node instanceof FileNode)) { throw new AVMWrongTypeException("File Expected."); } if (!fAVMRepository.can(this, node, PermissionService.READ_CONTENT)) { throw new AccessDeniedException("Not allowed to read: " + path); } ContentData content = ((FileNode)node).getContentData(lPath); // AVMDAOs.Instance().fAVMNodeDAO.flush(); // AVMDAOs.Instance().fAVMNodeDAO.evict(node); return content; } /** * Get the ContentData on a file for writing. * @param path The path to the file. * @return The ContentData corresponding to the file. */ public ContentData getContentDataForWrite(String path) { Lookup lPath = lookup(-1, path, true, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!(node instanceof FileNode)) { throw new AVMWrongTypeException("File Expected."); } if (!fAVMRepository.can(this, node, PermissionService.WRITE_CONTENT)) { throw new AccessDeniedException("Not allowed to write content: " + path); } // TODO Set modifier. node.updateModTime(); node.setGuid(GUID.generate()); ContentData content = ((FileNode)node).getContentData(lPath); // AVMDAOs.Instance().fAVMNodeDAO.flush(); // AVMDAOs.Instance().fAVMNodeDAO.evict(node); return content; } // Not doing permission checking because it will already have been done // at the getContentDataForWrite point. /** * Set the ContentData for a file. * @param path The path to the file. * @param data The ContentData to set. */ public void setContentData(String path, ContentData data) { Lookup lPath = lookup(-1, path, true, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!(node instanceof FileNode)) { throw new AVMWrongTypeException("File Expected."); } ((FileNode)node).setContentData(data); } /** * Set meta data, aspects, properties, acls, from another node. * @param path The path to the node to set metadata on. * @param from The node to get the metadata from. */ public void setMetaDataFrom(String path, AVMNode from) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path not found: " + path); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write properties: " + path); } node.copyMetaDataFrom(from, node.getAcl() == null ? null : node.getAcl().getInheritsFrom()); node.setGuid(GUID.generate()); } /** * Add an aspect to a node. * @param path The path to the node. * @param aspectName The name of the aspect. */ public void addAspect(String path, QName aspectName) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write: " + path); } // Convert the aspect QNames to entities QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(aspectName).getId(); // Convert the node.getAspects().add(qnameEntityId); node.setGuid(GUID.generate()); } /** * Get all aspects on a given 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 Set<QName> getAspects(int version, String path) { Lookup lPath = lookup(version, path, false, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.READ_PROPERTIES)) { throw new AccessDeniedException("Not allowed to read properties: " + path); } Set<Long> aspects = node.getAspects(); QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; Set<QName> aspectQNames = qnameDAO.convertIdsToQNames(aspects); return aspectQNames; } /** * Remove an aspect and all 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) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write properties: " + path); } QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; // Get the persistent ID for the QName and remove from the set QNameEntity qnameEntity = qnameDAO.getQNameEntity(aspectName); if (qnameEntity != null) { node.getAspects().remove(qnameEntity.getId()); } AspectDefinition def = RawServices.Instance().getDictionaryService().getAspect(aspectName); Map<QName, PropertyDefinition> properties = def.getProperties(); for (QName name : properties.keySet()) { QNameEntity propertyQNameEntity = qnameDAO.getQNameEntity(name); node.getProperties().remove(propertyQNameEntity.getId()); } node.setGuid(GUID.generate()); } /** * Does a given node have a given aspect. * @param version The version to look under. * @param path The path to the node. * @param aspectName The name of the aspect. * @return Whether the node has the aspect. */ public boolean hasAspect(int version, String path, QName aspectName) { Lookup lPath = lookup(version, path, false, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.READ_PROPERTIES)) { throw new AccessDeniedException("Not allowed to read properties: " + path); } QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; // Get the persistent ID for the QName and remove from the set QNameEntity qnameEntity = qnameDAO.getQNameEntity(aspectName); if (qnameEntity != null) { return node.getAspects().contains(qnameEntity.getId()); } else { return false; } } /** * Set the ACL on a node. * @param path The path to the node. * @param acl The ACL to set. */ public void setACL(String path, DbAccessControlList acl) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.CHANGE_PERMISSIONS)) { throw new AccessDeniedException("Not allowed to change permissions: " + path); } node.setAcl(acl); node.setGuid(GUID.generate()); } /** * Get the ACL on a node. * @param version The version to look under. * @param path The path to the node. * @return The ACL. */ public DbAccessControlList getACL(int version, String path) { Lookup lPath = lookup(version, path, false, false); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } if (!fAVMRepository.can(this, lPath.getCurrentNode(), PermissionService.READ_PERMISSIONS)) { throw new AccessDeniedException("Not allowed to read permissions: " + path + " in "+getName()); } return lPath.getCurrentNode().getAcl(); } /** * Link a node intro a directory, directly. * @param parentPath The path to the directory. * @param name The name to give the parent. * @param toLink The node to link. */ public void link(String parentPath, String name, AVMNodeDescriptor toLink) { Lookup lPath = lookupDirectory(-1, parentPath, true); if (lPath == null) { throw new AVMNotFoundException("Path " + parentPath + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(null, dir, PermissionService.ADD_CHILDREN)) { throw new AccessDeniedException("Not allowed to add children: " + parentPath); } dir.link(lPath, name, toLink); } /** * Revert a head path to a given version. This works by cloning * the version to revert to, and then linking that new version into head. * The reverted version will have the previous head version as ancestor. * @param path The path to the parent directory. * @param name The name of the node to revert. * @param toRevertTo The descriptor of the version to revert to. */ public void revert(String path, String name, AVMNodeDescriptor toRevertTo) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) { throw new AVMNotFoundException("Path " + path + " not found."); } DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); if (!fAVMRepository.can(null, dir, PermissionService.DELETE_CHILDREN) || !fAVMRepository.can(null, dir, PermissionService.ADD_CHILDREN)) { throw new AccessDeniedException("Not allowed to revert: " + path); } Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, true); AVMNode child = (temp == null) ? null : temp.getFirst(); if (child == null) { throw new AVMNotFoundException("Node not found: " + name); } AVMNode revertNode = AVMDAOs.Instance().fAVMNodeDAO.getByID(toRevertTo.getId()); if (revertNode == null) { throw new AVMNotFoundException(toRevertTo.toString()); } AVMNode toLink = revertNode.copy(lPath); dir.putChild(name, toLink); toLink.changeAncestor(child); toLink.setVersionID(child.getVersionID() + 1); // TODO This really shouldn't be here. Leaking layers. QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; QNameEntity revertedQNameEntity = qnameDAO.getOrCreateQNameEntity(WCMModel.ASPECT_REVERTED); toLink.getAspects().add(revertedQNameEntity.getId()); PropertyValue value = new PropertyValue(null, toRevertTo.getId()); QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getOrCreateQNameEntity(WCMModel.PROP_REVERTED_ID); toLink.setProperty(qnameEntity.getId(), value); } /* (non-Javadoc) * @see org.alfresco.repo.avm.AVMStore#setGuid(java.lang.String, java.lang.String) */ public void setGuid(String path, String guid) { Lookup lPath = lookup(-1, path, true, true); if (lPath == null) { throw new AVMNotFoundException("Path not found: " + path); } AVMNode node = lPath.getCurrentNode(); if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write properties: " + path); } node.setGuid(guid); } /* (non-Javadoc) * @see org.alfresco.repo.avm.AVMStore#setEncoding(java.lang.String, java.lang.String) */ public void setEncoding(String path, String encoding) { Lookup lPath = lookup(-1, path, true, false); if (lPath == null) { throw new AVMNotFoundException("Path not found: " + path); } AVMNode node = lPath.getCurrentNode(); if (node.getType() != AVMNodeType.PLAIN_FILE) { throw new AVMWrongTypeException("Not a File: " + path); } if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write properties: " + path); } PlainFileNode file = (PlainFileNode)node; file.setEncoding(encoding); } /* (non-Javadoc) * @see org.alfresco.repo.avm.AVMStore#setMimeType(java.lang.String, java.lang.String) */ public void setMimeType(String path, String mimeType) { Lookup lPath = lookup(-1, path, true, false); if (lPath == null) { throw new AVMNotFoundException("Path not found: " + path); } AVMNode node = lPath.getCurrentNode(); if (node.getType() != AVMNodeType.PLAIN_FILE) { throw new AVMWrongTypeException("Not a File: " + path); } if (!fAVMRepository.can(this, node, PermissionService.WRITE_PROPERTIES)) { throw new AccessDeniedException("Not allowed to write properties: " + path); } PlainFileNode file = (PlainFileNode)node; file.setMimeType(mimeType); } }

The table below shows all metrics for AVMStoreImpl.java.

MetricValueDescription
BLOCKS224.00Number of blocks
BLOCK_COMMENT59.00Number of block comment lines
COMMENTS487.00Comment lines
COMMENT_DENSITY 0.61Comment density
COMPARISONS169.00Number of comparison operators
CYCLOMATIC227.00Cyclomatic complexity
DECL_COMMENTS84.00Comments in declarations
DOC_COMMENT368.00Number of javadoc comment lines
ELOC801.00Effective lines of code
EXEC_COMMENTS44.00Comments in executable code
EXITS175.00Procedure exits
FUNCTIONS72.00Number of function declarations
HALSTEAD_DIFFICULTY96.13Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY303.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 1.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 2.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 0.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 1.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1824.00Number of lines in the source file
LINE_COMMENT60.00Number of line comments
LOC1251.00Lines of code
LOGICAL_LINES525.00Number of statements
LOOPS 0.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS3028.00Number of operands
OPERATORS5579.00Number of operators
PARAMS118.00Number of formal parameter declarations
PROGRAM_LENGTH8607.00Halstead program length
PROGRAM_VOCAB804.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS185.00Number of return points from functions
SIZE67765.00Size of the file in bytes
UNIQUE_OPERANDS756.00Number of unique operands
UNIQUE_OPERATORS48.00Number of unique operators
WHITESPACE86.00Number of whitespace lines