Skip to content

Commit

Permalink
try to get workflow state
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Dec 27, 2015
1 parent e233870 commit 5d27d96
Showing 1 changed file with 32 additions and 1 deletion.
Expand Up @@ -140,6 +140,8 @@ private StringBuilder getContentXMLOfFileSystemDirectory(String path) throws Exc

/**
* Get yarep collection listing as XML
* @param path Path of directory/collection
* @return listing of child nodes of directory/collection as XML
*/
private StringBuilder getContentXMLOfYarepNode(String path) throws Exception {
Repository repo = getRealm().getRepository();
Expand Down Expand Up @@ -184,7 +186,15 @@ private StringBuilder getContentXMLOfYarepNode(String path) throws Exception {
lastModified = df.format(children[i].getLastModified());
log.warn("DEBUG: File last modified (formatted): " + lastModified);
}
sb.append("<dir:file path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\" lastModified=\"" + children[i].getLastModified() + "\" date=\"" + lastModified + "\" size=\"" + children[i].getSize() + "\"/>");
sb.append("<dir:file");
sb.append(" path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\" lastModified=\"" + children[i].getLastModified() + "\" date=\"" + lastModified + "\" size=\"" + children[i].getSize() + "\"");
String workflowState = getWorkflowState(children[i]);
if (workflowState != null) {
sb.append(" workflow-state=\"" + workflowState + "\"");
} else {
log.warn("DEBUG: Node '" + children[i].getPath() + "' has no workflow state set.");
}
sb.append("/>");
} else if (children[i].isCollection()) {
sb.append("<dir:directory path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\"/>");
} else {
Expand All @@ -202,6 +212,27 @@ private StringBuilder getContentXMLOfYarepNode(String path) throws Exception {
return sb;
}

/**
* Get workflow state if available
* @param node Node which might has a workflow state
* @return workflow state associated with node if available and null otherwise
*/
private String getWorkflowState(Node node) throws Exception {
if (org.wyona.commons.clazz.ClazzUtil.implementsInterface(node, "org.wyona.yarep.core.attributes.VersionableV1")) {
java.util.Iterator<org.wyona.yarep.core.Revision> revisions = ((org.wyona.yarep.core.attributes.VersionableV1) node).getRevisions(false);
if (revisions != null && revisions.hasNext()) {
String revisionName = ((org.wyona.yarep.core.Revision) revisions.next()).getRevisionName();
return org.wyona.yanel.core.workflow.WorkflowHelper.getWorkflowState(node, revisionName);
} else {
log.warn("Node '" + node.getPath() + "' has no revisions.");
return null;
}
} else {
log.warn("Node implementation is not VersionableV1");
return null;
}
}

/**
* @see org.wyona.yanel.impl.resources.BasicXMLResource#getXMLView(String, InputStream)
*/
Expand Down

0 comments on commit 5d27d96

Please sign in to comment.