public NodePropertyResolver resolverSize = new NodePropertyResolver() {
private static final long serialVersionUID = 1273541660444385276L;
public Object get(Node node) {
ContentData content = (ContentData)node.getProperties().get(ContentModel.PROP_CONTENT);
return (content != null ? new Long(content.getSize()) : 0L);
}
};
SO get the content data from the node. From the content Data extract the size of the file.
Do you know a way to find the version history size of a node?
ReplyDeleteI finally figured it out with a mix of this post and your other post about version history...
ReplyDelete--------------------------
The resulting code :
--------------------------
protected void generateNodeVersionHistorySize(ScriptNode node)
{
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
if(node.getIsContainer()){
this.historyCheckedSpace++;
List childRefs = this.services.getNodeService().getChildAssocs(node.getNodeRef());
for (int i = 0; i < childRefs.size(); i++)
{
// create our Node representation from the NodeRef
ScriptNode child = new ScriptNode(childRefs.get(i).getChildRef(), this.services, scope);
generateNodeVersionHistorySize(child);
}
}else if(node.getIsDocument()){
this.historyCheckedDoc++;
if(node.getNodeRef() != null){
VersionHistory versionHistory = versionService.getVersionHistory(node.getNodeRef());
int versionQty = versionHistory.getAllVersions().size();
historyTotalHistory += versionQty;
historyTotalHistoryWhitoutCurrent += (versionQty - 1);
ContentData contentRef = (ContentData )nodeService.getProperty(node.getNodeRef(), ContentModel.PROP_CONTENT);
long nodeSize = (contentRef != null ? new Long(contentRef.getSize()) : 0L);
long versionSize = 0;
for(Version version : versionHistory.getAllVersions())
{
contentRef = (ContentData )nodeService.getProperty(version.getVersionedNodeRef(), ContentModel.PROP_CONTENT);
versionSize += (contentRef != null ? new Long(contentRef.getSize()) : 0L);
}
historyTotalHistorySize += versionSize;
historyTotalHistorySizeWhitoutCurrent += (versionSize - nodeSize);
}
}else{
this.historyCheckedUnknown++;
if (logger.isDebugEnabled()){
logger.debug("getNodeVersionHistorySize > UnknownNode : " + node.getName() + "(" + node.getId() + ")");
}
}
}
hmmmm Good Charles, Thanks for sharing the code
ReplyDelete