mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-02 17:35:18 +00:00
Added accessors for node history. Added those to console.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
6fff182633
commit
c892c5a4b5
@ -296,6 +296,48 @@ public class AVMInteractiveConsole
|
||||
System.out.println("Owner: " + desc.getOwner());
|
||||
System.out.println("Mod Time: " + new Date(desc.getModDate()));
|
||||
}
|
||||
else if (command[0].equals("history"))
|
||||
{
|
||||
if (command.length != 4)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
AVMNodeDescriptor desc = fService.lookup(Integer.parseInt(command[2]), command[1]);
|
||||
List<AVMNodeDescriptor> history = fService.getHistory(desc, Integer.parseInt(command[3]));
|
||||
for (AVMNodeDescriptor node : history)
|
||||
{
|
||||
System.out.println(node);
|
||||
System.out.println("Version: " + desc.getVersionID());
|
||||
System.out.println("Owner: " + desc.getOwner());
|
||||
System.out.println("Mod Time: " + new Date(desc.getModDate()));
|
||||
}
|
||||
}
|
||||
else if (command[0].equals("catver"))
|
||||
{
|
||||
if (command.length != 4)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
AVMNodeDescriptor desc = fService.lookup(Integer.parseInt(command[2]), command[1]);
|
||||
List<AVMNodeDescriptor> history = fService.getHistory(desc, Integer.parseInt(command[3]));
|
||||
if (history.size() == 0)
|
||||
{
|
||||
System.err.println("No history found.");
|
||||
continue;
|
||||
}
|
||||
BufferedReader reader =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(
|
||||
fService.getFileInputStream(history.get(history.size() - 1))));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
System.out.println(line);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
else if (command[0].equals("exit"))
|
||||
{
|
||||
done = true;
|
||||
|
@ -42,6 +42,13 @@ public interface AVMService
|
||||
*/
|
||||
public InputStream getFileInputStream(int version, String path);
|
||||
|
||||
/**
|
||||
* Get an input stream from a particular version of a file.
|
||||
* @param desc The node descriptor pointing at the node.
|
||||
* @return The InputStream.
|
||||
*/
|
||||
public InputStream getFileInputStream(AVMNodeDescriptor desc);
|
||||
|
||||
/**
|
||||
* Get an output stream to a file node. The file must already exist.
|
||||
* @param path The simple absolute path to the file node.
|
||||
@ -248,4 +255,12 @@ public interface AVMService
|
||||
* @param path The full path.
|
||||
*/
|
||||
public void makePrimary(String path);
|
||||
|
||||
/**
|
||||
* Get a list of all the ancestor versions of a node.
|
||||
* @param desc The version of a node to find ancestors for.
|
||||
* @param count How many. -1 means all.
|
||||
* @return A List of ancestors starting with the most recent.
|
||||
*/
|
||||
public List<AVMNodeDescriptor> getHistory(AVMNodeDescriptor desc, int count);
|
||||
}
|
||||
|
@ -160,6 +160,32 @@ public class AVMServiceImpl implements AVMService
|
||||
return doit.in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an InputStream from a particular version of a file.
|
||||
* @param desc The node descriptor.
|
||||
* @return The InputStream.
|
||||
*/
|
||||
public InputStream getFileInputStream(final AVMNodeDescriptor desc)
|
||||
{
|
||||
if (desc == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal null argument.");
|
||||
}
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public InputStream in = null;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.setSession(session);
|
||||
in = fSuperRepository.getInputStream(desc);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit, false);
|
||||
return doit.in;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getFileOutputStream(java.lang.String)
|
||||
*/
|
||||
@ -781,4 +807,31 @@ public class AVMServiceImpl implements AVMService
|
||||
fTransaction.perform(doit, false);
|
||||
return doit.root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the history of a node.
|
||||
* @param desc The node to get history from.
|
||||
* @param count The number of ancestors to fallow back. -1 means all.
|
||||
* @return A List of ancestors most recent first.
|
||||
*/
|
||||
public List<AVMNodeDescriptor> getHistory(final AVMNodeDescriptor desc, final int count)
|
||||
{
|
||||
if (desc == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null descriptor.");
|
||||
}
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public List<AVMNodeDescriptor> history;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.setSession(session);
|
||||
history = fSuperRepository.getHistory(desc, count);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit, false);
|
||||
return doit.history;
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,9 @@ interface FileNode extends AVMNode
|
||||
{
|
||||
/**
|
||||
* Get the content object associated with this node, for reading.
|
||||
* @param version The version to get in.
|
||||
* @return A FileContent object.
|
||||
*/
|
||||
public FileContent getContentForRead(Repository repo);
|
||||
public FileContent getContentForRead();
|
||||
|
||||
/**
|
||||
* Get the content object for writing. This will do COW
|
||||
|
@ -78,7 +78,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
|
||||
}
|
||||
// This is a mildly dirty trick. We use getContentForRead so as not to startle
|
||||
// the ultimate destination content into copying itself prematurely.
|
||||
FileContent content = ((FileNode)indirect).getContentForRead(lPath.getRepository());
|
||||
FileContent content = ((FileNode)indirect).getContentForRead();
|
||||
PlainFileNodeImpl newMe = new PlainFileNodeImpl(content, lPath.getRepository(), getBasicAttributes());
|
||||
newMe.setAncestor(this);
|
||||
return newMe;
|
||||
@ -98,9 +98,9 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
|
||||
* @param repo The Repository.
|
||||
* @return A FileContent object.
|
||||
*/
|
||||
public FileContent getContentForRead(Repository repo)
|
||||
public FileContent getContentForRead()
|
||||
{
|
||||
Lookup lookup = repo.getSuperRepository().lookup(-1, fIndirection);
|
||||
Lookup lookup = SuperRepository.GetInstance().lookup(-1, fIndirection);
|
||||
AVMNode node = lookup.getCurrentNode();
|
||||
if (node.getType() != AVMNodeType.LAYERED_FILE &&
|
||||
node.getType() != AVMNodeType.PLAIN_FILE)
|
||||
@ -108,7 +108,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
|
||||
throw new AVMException("Missing Link.");
|
||||
}
|
||||
FileNode file = (FileNode)node;
|
||||
return file.getContentForRead(repo);
|
||||
return file.getContentForRead();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +107,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
|
||||
/**
|
||||
* Get content for reading.
|
||||
*/
|
||||
public FileContent getContentForRead(Repository repo)
|
||||
public FileContent getContentForRead()
|
||||
{
|
||||
return fContent;
|
||||
}
|
||||
@ -157,8 +157,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
|
||||
null,
|
||||
false,
|
||||
-1,
|
||||
getContentForRead(
|
||||
lPath.getRepository())
|
||||
getContentForRead()
|
||||
.getLength(lPath.getRepository().getSuperRepository()));
|
||||
}
|
||||
|
||||
@ -186,8 +185,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
|
||||
null,
|
||||
false,
|
||||
-1,
|
||||
getContentForRead(
|
||||
getRepository())
|
||||
getContentForRead()
|
||||
.getLength(getRepository().getSuperRepository()));
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ class RepositoryImpl implements Repository, Serializable
|
||||
throw new AVMExistsException("Not a file: " + path + " r " + version);
|
||||
}
|
||||
FileNode file = (FileNode)node;
|
||||
FileContent content = file.getContentForRead(this);
|
||||
FileContent content = file.getContentForRead();
|
||||
return content.getInputStream(fSuper);
|
||||
}
|
||||
|
||||
@ -328,10 +328,10 @@ class RepositoryImpl implements Repository, Serializable
|
||||
throw new AVMException("Access denied: " + path);
|
||||
}
|
||||
Lookup lPath = lookup(version, path);
|
||||
if (write)
|
||||
{
|
||||
// if (write)
|
||||
// {
|
||||
// lPath.acquireLocks();
|
||||
}
|
||||
// }
|
||||
AVMNode node = lPath.getCurrentNode();
|
||||
if (node.getType() != AVMNodeType.PLAIN_FILE &&
|
||||
node.getType() != AVMNodeType.LAYERED_FILE)
|
||||
@ -347,7 +347,7 @@ class RepositoryImpl implements Repository, Serializable
|
||||
}
|
||||
else
|
||||
{
|
||||
content = file.getContentForRead(this);
|
||||
content = file.getContentForRead();
|
||||
}
|
||||
return content.getRandomAccess(fSuper, access);
|
||||
}
|
||||
@ -759,6 +759,10 @@ class RepositoryImpl implements Repository, Serializable
|
||||
query.setInteger("version", version);
|
||||
VersionRoot vRoot = (VersionRoot)query.uniqueResult();
|
||||
AVMNode root = vRoot.getRoot();
|
||||
if (root == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Version not found.");
|
||||
}
|
||||
root.setIsRoot(false);
|
||||
fSuper.getSession().delete(vRoot);
|
||||
if (root.equals(fRoot))
|
||||
|
@ -20,6 +20,7 @@ package org.alfresco.repo.avm;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -508,6 +509,28 @@ class SuperRepository
|
||||
return repo.getInputStream(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an InputStream from a given version of a file.
|
||||
* @param desc The node descriptor.
|
||||
* @return The InputStream.
|
||||
*/
|
||||
public InputStream getInputStream(AVMNodeDescriptor desc)
|
||||
{
|
||||
fLookupCount.set(1);
|
||||
AVMNode node = (AVMNode)fSession.get().get(AVMNodeImpl.class, desc.getId());
|
||||
if (node == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Not found.");
|
||||
}
|
||||
if (node.getType() != AVMNodeType.PLAIN_FILE &&
|
||||
node.getType() != AVMNodeType.LAYERED_FILE)
|
||||
{
|
||||
throw new AVMWrongTypeException("Not a file.");
|
||||
}
|
||||
FileNode file = (FileNode)node;
|
||||
return file.getContentForRead().getInputStream(SuperRepository.GetInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a listing of a directory.
|
||||
* @param version The version to look under.
|
||||
@ -780,6 +803,36 @@ class SuperRepository
|
||||
rep.retargetLayeredDirectory(pathParts[1], target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the history chain for a node.
|
||||
* @param desc The node to get history of.
|
||||
* @param count The maximum number of ancestors to traverse. Negative means all.
|
||||
* @return A List of ancestors.
|
||||
*/
|
||||
public List<AVMNodeDescriptor> getHistory(AVMNodeDescriptor desc, int count)
|
||||
{
|
||||
AVMNode node = (AVMNode)fSession.get().get(AVMNodeImpl.class, desc.getId());
|
||||
if (node == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Not found.");
|
||||
}
|
||||
if (count < 0)
|
||||
{
|
||||
count = Integer.MAX_VALUE;
|
||||
}
|
||||
List<AVMNodeDescriptor> history = new ArrayList<AVMNodeDescriptor>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
node = node.getAncestor();
|
||||
if (node == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
history.add(node.getDescriptor("UNKNOWN", "UNKNOWN", "UNKNOWN"));
|
||||
}
|
||||
return history;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the single instance of SuperRepository.
|
||||
* @return
|
||||
|
Loading…
x
Reference in New Issue
Block a user