Kevin Roast ed48e2c4c9 Merged BRANCHES/DEV/V4.1-BUG-FIX to HEAD
41929: ALF-12202: Solr Port display wrong labels on Edit form
          - Added solr.help.field.solr.port and solr.help.field.solr.port.ssl messages
   41940: Fix for ALF-16086 SOLR tracking does not include transformation status etc (error in header name)
   41958: Merged V4.1 to V4.1-BUG-FIX (RECORD ONLY)
            39973: Merged BRANCHES/DEV/V4.1-BUG-FIX to BRANCHES/V4.1: merged for KR => ALF-13404 (and CLOUD-438)
               39953: Refactored "Content I'm Editing" dashlet from synchronous (slowing down user dashboard initial display) to asynchronous client-side rendering.
            39976: Merged BRANCHES/DEV/V4.1-BUG-FIX to BRANCHES/DEV/V3.4-BUG-FIX: (record-only) - for KR (to ignore the hand merge of the dashlet changes from V3.4)
               39953: Refactored "Content I'm Editing" dashlet from synchronous (slowing down user dashboard initial display) to asynchronous client-side rendering. (ALF-13404)
            41129: ALF-15782: Merged V4.1-BUG-FIX to V4.1
               41032: Fix for ALF-15753	Infinite loop during Solr ACL indexing when ACL Changeset batch is empty
   41986: Merged PATCHES/V4.1.1 to V4.1-BUG-FIX
            41983: Merged V4.1 to PATCHES/V4.1.1
               41982: Merged DEV to V4.1
                  41962: ALF-16029: TransactionCleanupTest throws constraint violations
                     Use overrided deleteNodesByCommitTime() method in DAO for MSSQL. 
                  41977: ALF-16029: TransactionCleanupTest throws constraint violations.
                     Change delete_NodePropsByTxnCommitTime statement to be common for all DB dialects.
            41985: Merged V4.1 to PATCHES/V4.1.1 (RECORD ONLY)
               41129: ALF-15782: Merged V4.1-BUG-FIX to V4.1
                  41032: Fix for ALF-15753	Infinite loop during Solr ACL indexing when ACL Changeset batch is empty
               41654: Fix for ALF-15965 - hand merged back from rev 41653
               41968: Merged PATCHES/V4.1.1 to V4.1 (4.1.1)
   42045: Refactor of recent change to always release opLock on close.   Code needs to move out of the transactional layers to LegacyFileStateDriver.
   42052: Fix for ALF-952
          Merged BRANCHES/DEV to BRANCHES/DEV/V4.1-BUG-FIX
             41829: akovalchuk ALF-952: Message "Password must be between 3 and 256 characters in length" incorrect
                Configuration of max password length is now being picked up from ClientConfig (which reads it from password-max-length element of web-client-config.xml) and validated on backend using LoginBean.validatePassword method.
                Maximum password length is set to 255. Field "confirm" is checked only for exact matching to the field "password" at validation phase using LoginBean.validateMatch.
                Tenant username check now is made at validation phase together with other username validations in CreateUserWizard.validateUsername.
   42056: Merged HEAD to V4.1-BUG-FIX (RECORD ONLY)
            ALF-15987: merged Visio support in HEAD to V4.1-BUG-FIX.
   42111: SPANISH: Translation updates based on EN r41902, Fixes: ALF-15359, ALF-15682, ALF-15926
   42112: ITALIAN: Translation updates based on EN r41902, Fixes: ALF-15359, ALF-15682, ALF-15926
   42113: JAPANESE: Translation updates based on EN r41902, Fixes: ALF-15359, ALF-15682, ALF-15926
   42115: ALL LANGUAGES: Standardises on 24 hour display for all non-English languages. Fixes: ALF-15992 and related to ALF-13712
   42129: ALF-16098: Activiti upgrade to 5.10 (RECORD ONLY)
   42136: Last SOLR side update for ALF-14861 SOLR to scale for non-admin users in 100k sites and a subgroup of each of 1000 independent groupings with 1000 subgroups
   42137: ALF-16132 - Problems with Versionable onUpdate Policy execution and JLan exception handling
          fixed third sub issue.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42145 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-09-28 13:18:09 +00:00

527 lines
18 KiB
Java

/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.filesys.repo;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import org.alfresco.filesys.alfresco.ExtendedDiskInterface;
import org.alfresco.filesys.config.ServerConfigurationBean;
import org.alfresco.jlan.server.SrvSession;
import org.alfresco.jlan.server.core.DeviceContext;
import org.alfresco.jlan.server.core.DeviceContextException;
import org.alfresco.jlan.server.filesys.FileAccessToken;
import org.alfresco.jlan.server.filesys.FileInfo;
import org.alfresco.jlan.server.filesys.FileOpenParams;
import org.alfresco.jlan.server.filesys.FileStatus;
import org.alfresco.jlan.server.filesys.NetworkFile;
import org.alfresco.jlan.server.filesys.SearchContext;
import org.alfresco.jlan.server.filesys.TreeConnection;
import org.alfresco.jlan.server.filesys.cache.FileState;
import org.alfresco.jlan.server.filesys.cache.FileStateCache;
import org.alfresco.jlan.server.filesys.cache.NetworkFileStateInterface;
import org.alfresco.jlan.server.filesys.pseudo.PseudoFile;
import org.alfresco.jlan.server.locking.OpLockInterface;
import org.alfresco.jlan.server.locking.OpLockManager;
import org.alfresco.jlan.smb.SharingMode;
import org.alfresco.model.ContentModel;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.config.ConfigElement;
/**
* The Legacy file state driver is used to update JLAN's file state cache.
* <p>
* This class decorates an ExtendedDiskInterface with odds and ends to keep JLan happy.
* <p>
* In particular this implementation cannot contain any code that requires access to the
* alfresco repository.
*
*/
public class LegacyFileStateDriver implements ExtendedDiskInterface
{
private ExtendedDiskInterface diskInterface;
public void init()
{
PropertyCheck.mandatory(this, "diskInterface", diskInterface);
}
private static final Log logger = LogFactory.getLog(LegacyFileStateDriver.class);
@Override
public void treeOpened(SrvSession sess, TreeConnection tree)
{
diskInterface.treeOpened(sess, tree);
}
@Override
public void treeClosed(SrvSession sess, TreeConnection tree)
{
diskInterface.treeClosed(sess, tree);
}
@Override
public NetworkFile createFile(SrvSession sess, TreeConnection tree,
FileOpenParams params) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
FileAccessToken token = null;
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
token = cache.grantFileAccess(params, fstate, FileStatus.NotExist);
if(logger.isDebugEnabled())
{
logger.debug("create file created lock token:" + token);
}
}
try
{
NetworkFile newFile = diskInterface.createFile(sess, tree, params);
newFile.setAccessToken(token);
if(tctx.hasStateCache())
{
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
// Indicate that the file is open
fstate.setFileStatus(newFile.isDirectory()? FileStatus.DirectoryExists : FileStatus.FileExists);
long allocationSize = params.getAllocationSize();
if(allocationSize > 0)
{
fstate.setAllocationSize(allocationSize);
fstate.setFileSize(allocationSize);
}
if (newFile instanceof NodeRefNetworkFile)
{
NodeRefNetworkFile x = (NodeRefNetworkFile)newFile;
x.setFileState(fstate);
}
if (newFile instanceof TempNetworkFile)
{
TempNetworkFile x = (TempNetworkFile)newFile;
x.setFileState(fstate);
}
}
if (newFile instanceof NodeRefNetworkFile)
{
NodeRefNetworkFile x = (NodeRefNetworkFile)newFile;
x.setProcessId( params.getProcessId());
x.setAccessToken(token);
}
if (newFile instanceof TempNetworkFile)
{
TempNetworkFile x = (TempNetworkFile)newFile;
x.setAccessToken(token);
}
return newFile;
}
catch(IOException ie)
{
if(logger.isDebugEnabled())
{
logger.debug("create file exception caught", ie);
}
if(tctx.hasStateCache() && token != null)
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), false);
if(fstate != null && token != null)
{
if(logger.isDebugEnabled())
{
logger.debug("create file release lock token:" + token);
}
cache.releaseFileAccess(fstate, token);
}
}
throw ie;
}
}
@Override
public NetworkFile openFile(SrvSession sess, TreeConnection tree,
FileOpenParams params) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
String path = params.getPath();
FileAccessToken token = null;
if(tctx.hasStateCache())
{
if(!params.isDirectory())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), true);
token = cache.grantFileAccess(params, fstate, FileStatus.Unknown);
if(logger.isDebugEnabled())
{
logger.debug("open file created lock token:" + token);
}
}
}
try
{
NetworkFile openFile = diskInterface.openFile(sess, tree, params);
openFile.setAccessToken(token);
FileState fstate = null;
if(tctx.hasStateCache())
{
fstate = tctx.getStateCache().findFileState( path, true);
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
// Access date time is read/write time not open time
// fstate.updateAccessDateTime();
fstate.setFileSize(openFile.getFileSize());
fstate.updateChangeDateTime(openFile.getModifyDate());
fstate.updateModifyDateTime(openFile.getModifyDate());
}
if (openFile instanceof ContentNetworkFile)
{
ContentNetworkFile x = (ContentNetworkFile)openFile;
x.setProcessId( params.getProcessId());
if(fstate != null)
{
x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists);
}
}
else if (openFile instanceof TempNetworkFile)
{
TempNetworkFile x = (TempNetworkFile)openFile;
if(fstate != null)
{
x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists);
}
}
else if (openFile instanceof AlfrescoFolder)
{
AlfrescoFolder x = (AlfrescoFolder)openFile;
if(fstate != null)
{
x.setFileState(fstate);
fstate.setFileStatus(FileStatus.DirectoryExists);
}
}
else if (openFile instanceof NetworkFile)
{
NetworkFile x = (NetworkFile)openFile;
if(fstate != null)
{
// NetworkFile does not have setFileState
//x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists);
}
}
return openFile;
}
catch(IOException ie)
{
if(logger.isDebugEnabled())
{
logger.debug("open file exception caught", ie);
}
if(tctx.hasStateCache() && token != null)
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState( params.getPath(), false);
if(fstate != null)
{
if(logger.isDebugEnabled())
{
logger.debug("open file release lock token:" + token);
}
cache.releaseFileAccess(fstate, token);
}
}
throw ie;
}
}
@Override
public void closeFile(SrvSession sess, TreeConnection tree,
NetworkFile param) throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
if(logger.isDebugEnabled())
{
logger.debug("closeFile:" + param.getFullName() + ", accessToken:" + param.getAccessToken());
}
try
{
if ( param.hasOpLock()) {
// Release the oplock
OpLockInterface flIface = (OpLockInterface) this;
OpLockManager oplockMgr = flIface.getOpLockManager(sess, tree);
oplockMgr.releaseOpLock( param.getOpLock().getPath());
// DEBUG
if ( logger.isDebugEnabled())
logger.debug("Released oplock for closed file, file=" + param.getFullName());
}
diskInterface.closeFile(sess, tree, param);
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( param.getFullName(), true);
if(fstate != null && param.getAccessToken() != null)
{
FileAccessToken token = param.getAccessToken();
if(logger.isDebugEnabled() && token != null)
{
logger.debug("close file, release access token:" + token);
}
cache.releaseFileAccess(fstate, token);
}
if(fstate.getOpenCount() == 0 )
{
logger.debug("fstate OpenCount == 0, reset in-flight state");
fstate.setAllocationSize(-1);
fstate.setFileSize(-1);
fstate.updateChangeDateTime(0);
fstate.updateModifyDateTime(0);
}
}
}
catch(IOException ie)
{
if(logger.isDebugEnabled())
{
logger.debug("close file exception caught", ie);
}
throw ie;
}
}
@Override
public void registerContext(DeviceContext ctx) throws DeviceContextException
{
diskInterface.registerContext(ctx);
}
public void setDiskInterface(ExtendedDiskInterface diskInterface)
{
this.diskInterface = diskInterface;
}
public ExtendedDiskInterface getDiskInterface()
{
return diskInterface;
}
@Override
public void createDirectory(SrvSession sess, TreeConnection tree,
FileOpenParams params) throws IOException
{
diskInterface.createDirectory(sess, tree, params);
}
@Override
public void deleteDirectory(SrvSession sess, TreeConnection tree, String dir)
throws IOException
{
diskInterface.deleteDirectory(sess, tree, dir);
}
@Override
public void deleteFile(SrvSession sess, TreeConnection tree, String name)
throws IOException
{
ContentContext tctx = (ContentContext) tree.getContext();
diskInterface.deleteFile(sess, tree, name);
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( name, false);
if(fstate != null)
{
fstate.setFileStatus(FileStatus.NotExist);
fstate.setOpenCount(0);
}
}
}
@Override
public int fileExists(SrvSession sess, TreeConnection tree, String name)
{
return diskInterface.fileExists(sess, tree, name);
}
@Override
public void flushFile(SrvSession sess, TreeConnection tree, NetworkFile file)
throws IOException
{
diskInterface.flushFile(sess, tree, file);
}
@Override
public FileInfo getFileInformation(SrvSession sess, TreeConnection tree,
String name) throws IOException
{
return diskInterface.getFileInformation(sess, tree, name);
}
@Override
public boolean isReadOnly(SrvSession sess, DeviceContext ctx)
throws IOException
{
return diskInterface.isReadOnly(sess, ctx);
}
@Override
public int readFile(SrvSession sess, TreeConnection tree, NetworkFile file,
byte[] buf, int bufPos, int siz, long filePos) throws IOException
{
return diskInterface.readFile(sess, tree, file, buf, bufPos, siz, filePos);
}
@Override
public void renameFile(SrvSession sess, TreeConnection tree,
String oldName, String newName) throws IOException
{
diskInterface.renameFile(sess, tree, oldName, newName);
}
@Override
public long seekFile(SrvSession sess, TreeConnection tree,
NetworkFile file, long pos, int typ) throws IOException
{
return diskInterface.seekFile(sess, tree, file, pos, typ);
}
@Override
public void setFileInformation(SrvSession sess, TreeConnection tree,
String name, FileInfo info) throws IOException
{
diskInterface.setFileInformation(sess, tree, name, info);
ContentContext tctx = (ContentContext) tree.getContext();
if(tctx.hasStateCache())
{
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( name, true);
// if ( info.hasSetFlag(FileInfo.SetCreationDate))
// {
// if ( logger.isDebugEnabled())
// {
// logger.debug("Set creation date in file state cache" + name + ", " + info.getCreationDateTime());
// }
// Date createDate = new Date( info.getCreationDateTime());
// fstate.u(createDate.getTime());
// }
if ( info.hasSetFlag(FileInfo.SetModifyDate))
{
if ( logger.isDebugEnabled())
{
logger.debug("Set modification date in file state cache" + name + ", " + info.getModifyDateTime());
}
Date modifyDate = new Date( info.getModifyDateTime());
fstate.updateModifyDateTime(modifyDate.getTime());
}
}
}
@Override
public SearchContext startSearch(SrvSession sess, TreeConnection tree,
String searchPath, int attrib) throws FileNotFoundException
{
InFlightCorrector t = new InFlightCorrectorImpl(tree);
SearchContext ctx = diskInterface.startSearch(sess, tree, searchPath, attrib);
if(ctx instanceof InFlightCorrectable)
{
InFlightCorrectable thingable = (InFlightCorrectable)ctx;
thingable.setInFlightCorrector(t);
}
return ctx;
}
@Override
public void truncateFile(SrvSession sess, TreeConnection tree,
NetworkFile file, long siz) throws IOException
{
diskInterface.truncateFile(sess, tree, file, siz);
}
@Override
public int writeFile(SrvSession sess, TreeConnection tree,
NetworkFile file, byte[] buf, int bufoff, int siz, long fileoff)
throws IOException
{
return diskInterface.writeFile(sess, tree, file, buf, bufoff, siz, fileoff);
}
@Override
public DeviceContext createContext(String shareName, ConfigElement args)
throws DeviceContextException
{
return diskInterface.createContext(shareName, args);
}
}