mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added a method to AVMService and its dependent services to get an InputStream
directly from a node descriptor. It's a minor optimization for a few use scenarios. It's also convenient for accessing content of historical file versions directly. Another CLT, to list the versions of a store. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4496 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -175,6 +175,9 @@
|
|||||||
<property name="lookupCache">
|
<property name="lookupCache">
|
||||||
<ref bean="lookupCache"/>
|
<ref bean="lookupCache"/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="contentStore">
|
||||||
|
<ref bean="fileContentStore"/>
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- A Local implementation of the Remote AVM interface. -->
|
<!-- A Local implementation of the Remote AVM interface. -->
|
||||||
|
@@ -42,10 +42,17 @@ public interface AVMRemote
|
|||||||
* to a server side input stream.
|
* to a server side input stream.
|
||||||
* @param version The version to look under.
|
* @param version The version to look under.
|
||||||
* @param path The path to the file.
|
* @param path The path to the file.
|
||||||
* @return A handle.
|
* @return An InputStream.
|
||||||
*/
|
*/
|
||||||
public InputStream getFileInputStream(int version, String path);
|
public InputStream getFileInputStream(int version, String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an InputStream from a descriptor directly.
|
||||||
|
* @param desc The descriptor.
|
||||||
|
* @return An InputStream.
|
||||||
|
*/
|
||||||
|
public InputStream getFileInputStream(AVMNodeDescriptor desc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an opaque handle to a server side output stream.
|
* Get an opaque handle to a server side output stream.
|
||||||
* @param path The path to the existing file.
|
* @param path The path to the existing file.
|
||||||
@@ -182,7 +189,7 @@ public interface AVMRemote
|
|||||||
* @param store The name of the AVMStore to snapshot.
|
* @param store The name of the AVMStore to snapshot.
|
||||||
* @return The version id of the new snapshot.
|
* @return The version id of the new snapshot.
|
||||||
*/
|
*/
|
||||||
public int createSnapshot(String store);
|
public int createSnapshot(String store, String label, String comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a List of all versions in a given store.
|
* Get a List of all versions in a given store.
|
||||||
|
@@ -97,9 +97,9 @@ public class AVMRemoteLocal implements AVMRemote
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.avm.AVMRemote#createSnapshot(java.lang.String)
|
* @see org.alfresco.repo.avm.AVMRemote#createSnapshot(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public int createSnapshot(String store)
|
public int createSnapshot(String store, String label, String comment)
|
||||||
{
|
{
|
||||||
return fService.createSnapshot(store, null, null);
|
return fService.createSnapshot(store, label, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -219,6 +219,14 @@ public class AVMRemoteLocal implements AVMRemote
|
|||||||
return fService.getFileInputStream(version, path);
|
return fService.getFileInputStream(version, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.avm.AVMRemote#getFileInputStream(org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||||
|
*/
|
||||||
|
public InputStream getFileInputStream(AVMNodeDescriptor desc)
|
||||||
|
{
|
||||||
|
return fService.getFileInputStream(desc);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.avm.AVMRemote#getFileOutputStream(java.lang.String)
|
* @see org.alfresco.repo.avm.AVMRemote#getFileOutputStream(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@@ -31,6 +31,14 @@ public interface AVMRemoteTransport
|
|||||||
*/
|
*/
|
||||||
public String getInputHandle(String ticket, int version, String path);
|
public String getInputHandle(String ticket, int version, String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an input handle from a descriptor.
|
||||||
|
* @param ticket The authentication ticket.
|
||||||
|
* @param desc The descriptor.
|
||||||
|
* @return An input handle.
|
||||||
|
*/
|
||||||
|
public String getInputHandle(String ticket, AVMNodeDescriptor desc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a chunk of data from a handle.
|
* Read a chunk of data from a handle.
|
||||||
* @param handle The opaque input stream handle.
|
* @param handle The opaque input stream handle.
|
||||||
@@ -199,7 +207,7 @@ public interface AVMRemoteTransport
|
|||||||
* @param store The name of the AVMStore to snapshot.
|
* @param store The name of the AVMStore to snapshot.
|
||||||
* @return The version id of the new snapshot.
|
* @return The version id of the new snapshot.
|
||||||
*/
|
*/
|
||||||
public int createSnapshot(String ticket, String store);
|
public int createSnapshot(String ticket, String store, String label, String comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a List of all versions in a given store.
|
* Get a List of all versions in a given store.
|
||||||
|
@@ -250,6 +250,23 @@ public class AVMRemoteTransportService implements AVMRemoteTransport, Runnable
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.avm.AVMRemoteTransport#getInputHandle(java.lang.String, org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||||
|
*/
|
||||||
|
public String getInputHandle(String ticket, AVMNodeDescriptor desc)
|
||||||
|
{
|
||||||
|
fAuthService.validate(ticket);
|
||||||
|
InputStream in = fAVMService.getFileInputStream(desc);
|
||||||
|
String handle = GUID.generate();
|
||||||
|
synchronized (this)
|
||||||
|
{
|
||||||
|
fInputStreams.put(handle, in);
|
||||||
|
fInputLastAccessTimes.put(handle, System.currentTimeMillis());
|
||||||
|
fInputBusy.put(handle, false);
|
||||||
|
}
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a chunk of data from a handle.
|
* Read a chunk of data from a handle.
|
||||||
* @param handle The opaque input stream handle.
|
* @param handle The opaque input stream handle.
|
||||||
@@ -611,10 +628,10 @@ public class AVMRemoteTransportService implements AVMRemoteTransport, Runnable
|
|||||||
* @param store The name of the AVMStore to snapshot.
|
* @param store The name of the AVMStore to snapshot.
|
||||||
* @return The version id of the new snapshot.
|
* @return The version id of the new snapshot.
|
||||||
*/
|
*/
|
||||||
public int createSnapshot(String ticket, String store)
|
public int createSnapshot(String ticket, String store, String label, String comment)
|
||||||
{
|
{
|
||||||
fAuthService.validate(ticket);
|
fAuthService.validate(ticket);
|
||||||
return fAVMService.createSnapshot(store, null, null);
|
return fAVMService.createSnapshot(store, label, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,6 +27,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
|
|
||||||
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.domain.DbAccessControlList;
|
import org.alfresco.repo.domain.DbAccessControlList;
|
||||||
import org.alfresco.repo.domain.PropertyValue;
|
import org.alfresco.repo.domain.PropertyValue;
|
||||||
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
|
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
|
||||||
@@ -41,6 +42,7 @@ import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
|||||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
@@ -75,6 +77,11 @@ public class AVMRepository
|
|||||||
*/
|
*/
|
||||||
private Issuer fLayerIssuer;
|
private Issuer fLayerIssuer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the ContentStoreImpl
|
||||||
|
*/
|
||||||
|
private ContentStore fContentStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Lookup Cache instance.
|
* The Lookup Cache instance.
|
||||||
*/
|
*/
|
||||||
@@ -107,6 +114,14 @@ public class AVMRepository
|
|||||||
fLayerIssuer = layerIssuer;
|
fLayerIssuer = layerIssuer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the ContentService.
|
||||||
|
*/
|
||||||
|
public void setContentStore(ContentStore store)
|
||||||
|
{
|
||||||
|
fContentStore = store;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Lookup Cache instance.
|
* Set the Lookup Cache instance.
|
||||||
* @param cache The instance to set.
|
* @param cache The instance to set.
|
||||||
@@ -798,6 +813,23 @@ public class AVMRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream(AVMNodeDescriptor desc)
|
||||||
|
{
|
||||||
|
AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(desc.getId());
|
||||||
|
if (!(node instanceof FileNode))
|
||||||
|
{
|
||||||
|
throw new AVMWrongTypeException(desc + " is not a File.");
|
||||||
|
}
|
||||||
|
FileNode file = (FileNode)node;
|
||||||
|
ContentData data = file.getContentData(null);
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
throw new AVMException(desc + " has no content.");
|
||||||
|
}
|
||||||
|
ContentReader reader = fContentStore.getReader(data.getContentUrl());
|
||||||
|
return reader.getContentInputStream();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a listing of a directory.
|
* Get a listing of a directory.
|
||||||
* @param version The version to look under.
|
* @param version The version to look under.
|
||||||
|
@@ -108,6 +108,21 @@ public class AVMServiceImpl implements AVMService
|
|||||||
return fAVMRepository.getInputStream(version, path);
|
return fAVMRepository.getInputStream(version, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an InputStream from a descriptor.
|
||||||
|
* @param desc The descriptor.
|
||||||
|
* @return An InputStream.
|
||||||
|
* @throws AVMNotFoundException
|
||||||
|
*/
|
||||||
|
public InputStream getFileInputStream(AVMNodeDescriptor desc)
|
||||||
|
{
|
||||||
|
if (desc == null)
|
||||||
|
{
|
||||||
|
throw new AVMBadArgumentException("Illegal Null Argument.");
|
||||||
|
}
|
||||||
|
return fAVMRepository.getInputStream(desc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an output stream to a file. Triggers versioning.
|
* Get an output stream to a file. Triggers versioning.
|
||||||
*/
|
*/
|
||||||
|
@@ -247,6 +247,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
|
|||||||
throw new AVMException("Should not be called.");
|
throw new AVMException("Should not be called.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO The lPath argument is unnecessary.
|
||||||
/**
|
/**
|
||||||
* Get the ContentData for this file.
|
* Get the ContentData for this file.
|
||||||
* @return The ContentData object for this file.
|
* @return The ContentData object for this file.
|
||||||
|
@@ -50,7 +50,7 @@ public class AVMCopyOut extends AVMCltBase
|
|||||||
AVMNodeDescriptor desc = fAVMRemote.lookup(version, path);
|
AVMNodeDescriptor desc = fAVMRemote.lookup(version, path);
|
||||||
if (flags.containsKey("-r"))
|
if (flags.containsKey("-r"))
|
||||||
{
|
{
|
||||||
recursiveCopy(version, desc, args.get(1));
|
recursiveCopy(desc, args.get(1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (desc == null)
|
if (desc == null)
|
||||||
@@ -105,7 +105,7 @@ public class AVMCopyOut extends AVMCltBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recursiveCopy(int version, AVMNodeDescriptor src, String dst)
|
private void recursiveCopy(AVMNodeDescriptor src, String dst)
|
||||||
{
|
{
|
||||||
String newDst = dst + File.separator + src.getName();
|
String newDst = dst + File.separator + src.getName();
|
||||||
if (fVerbose)
|
if (fVerbose)
|
||||||
@@ -119,13 +119,13 @@ public class AVMCopyOut extends AVMCltBase
|
|||||||
Map<String, AVMNodeDescriptor> listing = fAVMRemote.getDirectoryListing(src);
|
Map<String, AVMNodeDescriptor> listing = fAVMRemote.getDirectoryListing(src);
|
||||||
for (AVMNodeDescriptor child : listing.values())
|
for (AVMNodeDescriptor child : listing.values())
|
||||||
{
|
{
|
||||||
recursiveCopy(version, child, newDst);
|
recursiveCopy(child, newDst);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InputStream in = fAVMRemote.getFileInputStream(version, src.getPath());
|
InputStream in = fAVMRemote.getFileInputStream(src);
|
||||||
OutputStream out = new FileOutputStream(newDst);
|
OutputStream out = new FileOutputStream(newDst);
|
||||||
copyStream(in, out);
|
copyStream(in, out);
|
||||||
}
|
}
|
||||||
|
39
source/java/org/alfresco/repo/avm/clt/AVMLsVersions.java
Normal file
39
source/java/org/alfresco/repo/avm/clt/AVMLsVersions.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.avm.clt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all versions of a given store.
|
||||||
|
* @author britt
|
||||||
|
*/
|
||||||
|
public class AVMLsVersions extends AVMCltBase
|
||||||
|
{
|
||||||
|
private static Object [] flagDefs = { };
|
||||||
|
|
||||||
|
private static String USAGE = "usage: AVMLsVersion storename";
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||||
|
{
|
||||||
|
List<VersionDescriptor> versions = fAVMRemote.getAVMStoreVersions(args.get(0));
|
||||||
|
for (VersionDescriptor version : versions)
|
||||||
|
{
|
||||||
|
System.out.println(version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
AVMLsVersions me = new AVMLsVersions();
|
||||||
|
me.exec(args, flagDefs, 1, USAGE);
|
||||||
|
}
|
||||||
|
}
|
@@ -101,9 +101,9 @@ public class AVMRemoteImpl implements AVMRemote
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.avm.AVMRemote#createSnapshot(java.lang.String)
|
* @see org.alfresco.repo.avm.AVMRemote#createSnapshot(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public int createSnapshot(String store)
|
public int createSnapshot(String store, String label, String comment)
|
||||||
{
|
{
|
||||||
return fTransport.createSnapshot(ClientTicketHolder.GetTicket(), store);
|
return fTransport.createSnapshot(ClientTicketHolder.GetTicket(), store, label, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -224,6 +224,15 @@ public class AVMRemoteImpl implements AVMRemote
|
|||||||
fTransport);
|
fTransport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.avm.AVMRemote#getFileInputStream(org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||||
|
*/
|
||||||
|
public InputStream getFileInputStream(AVMNodeDescriptor desc)
|
||||||
|
{
|
||||||
|
return new AVMRemoteInputStream(fTransport.getInputHandle(ClientTicketHolder.GetTicket(), desc),
|
||||||
|
fTransport);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.avm.AVMRemote#getFileOutputStream(java.lang.String)
|
* @see org.alfresco.repo.avm.AVMRemote#getFileOutputStream(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@@ -14,7 +14,7 @@ public class AVMSnapshot extends AVMCltBase
|
|||||||
{
|
{
|
||||||
private static Object [] flagDefs = { };
|
private static Object [] flagDefs = { };
|
||||||
|
|
||||||
private static String USAGE = "usage: AVMSnapshot storename";
|
private static String USAGE = "usage: AVMSnapshot storename label comment";
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||||
@@ -22,7 +22,7 @@ public class AVMSnapshot extends AVMCltBase
|
|||||||
@Override
|
@Override
|
||||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||||
{
|
{
|
||||||
fAVMRemote.createSnapshot(args.get(0));
|
fAVMRemote.createSnapshot(args.get(0), args.get(1), args.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +31,6 @@ public class AVMSnapshot extends AVMCltBase
|
|||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
AVMSnapshot me = new AVMSnapshot();
|
AVMSnapshot me = new AVMSnapshot();
|
||||||
me.exec(args, flagDefs, 1, USAGE);
|
me.exec(args, flagDefs, 3, USAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,14 @@ public interface AVMService
|
|||||||
*/
|
*/
|
||||||
public InputStream getFileInputStream(int version, String path);
|
public InputStream getFileInputStream(int version, String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an InputStream from a descriptor.
|
||||||
|
* @param desc The descriptor.
|
||||||
|
* @return An InputStream.
|
||||||
|
* @throws AVMNotFoundException
|
||||||
|
*/
|
||||||
|
public InputStream getFileInputStream(AVMNodeDescriptor desc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an output stream to a file node. The file must already exist.
|
* Get an output stream to a file node. The file must already exist.
|
||||||
* @param path The simple absolute path to the file node.
|
* @param path The simple absolute path to the file node.
|
||||||
|
Reference in New Issue
Block a user