}
private GWTJahiaPublicationInfo convert(OrderedMap all, PublicationInfoNode root, List<String> mainPaths,
WorkflowRule lastRule, PublicationInfoNode node, List<PublicationInfo> references,
JCRSessionWrapper currentUserSession, String language) {
GWTJahiaPublicationInfo gwtInfo = new GWTJahiaPublicationInfo(node.getUuid(), node.getStatus(), node.isCanPublish(language));
try {
JCRNodeWrapper jcrNode;
if (node.getStatus() == PublicationInfo.DELETED) {
JCRSessionWrapper liveSession = JCRTemplate.getInstance().getSessionFactory().getCurrentUserSession("live", currentUserSession.getLocale(), currentUserSession.getFallbackLocale());
jcrNode = liveSession.getNodeByUUID(node.getUuid());
} else {
jcrNode = currentUserSession.getNodeByUUID(node.getUuid());
if (lastRule == null || jcrNode.hasNode(WorkflowService.WORKFLOWRULES_NODE_NAME)) {
WorkflowRule rule = workflowService.getWorkflowRuleForAction(jcrNode, null, "publish", null);
if (rule != null) {
if (!rule.equals(lastRule)) {
if (workflowService.getWorkflowRuleForAction(jcrNode, currentUserSession.getUser() , "publish", null) != null) {
lastRule = rule;
} else {
lastRule = null;
}
}
}
}
}
if (jcrNode.hasProperty("jcr:title")) {
gwtInfo.setTitle(jcrNode.getProperty("jcr:title").getString());
} else {
gwtInfo.setTitle(jcrNode.getName());
}
gwtInfo.setNodetype(jcrNode.getPrimaryNodeType().getLabel(currentUserSession.getLocale()));
} catch (RepositoryException e1) {
gwtInfo.setTitle(node.getPath());
}
String mainPath = root.getPath();
gwtInfo.setMainPath(mainPath);
gwtInfo.setMainUUID(root.getUuid());
gwtInfo.setLanguage(language);
if (!mainPaths.contains(mainPath)) {
mainPaths.add(mainPath);
}
gwtInfo.setMainPathIndex(mainPaths.indexOf(mainPath));
Map<String, GWTJahiaPublicationInfo> gwtInfos = new HashMap<String, GWTJahiaPublicationInfo>();
gwtInfos.put(node.getPath(), gwtInfo);
List<String> refUuids = new ArrayList<String>();
if (node.isLocked() ) {
// gwtInfo.setLocked(true);
}
all.put(node.getUuid(), gwtInfo);
if (lastRule != null) {
gwtInfo.setWorkflowGroup(language + lastRule.getDefinitionPath());
gwtInfo.setWorkflowDefinition(lastRule.getProviderKey()+":"+lastRule.getWorkflowDefinitionKey());
} else {
gwtInfo.setWorkflowGroup("no-workflow");
}
for (PublicationInfoNode sub : node.getChildren()) {
if (sub.getPath().contains("/j:translation_"+language)) {
String key = StringUtils.substringBeforeLast(sub.getPath(), "/j:translation");
GWTJahiaPublicationInfo lastPub = gwtInfos.get(key);
if (lastPub != null) {
if (sub.getStatus() > lastPub.getStatus()) {
lastPub.setStatus(sub.getStatus());
}
if (lastPub.getStatus() == GWTJahiaPublicationInfo.UNPUBLISHED && sub.getStatus() != GWTJahiaPublicationInfo.UNPUBLISHED) {
lastPub.setStatus(sub.getStatus());
}
if (sub.isLocked()) {
gwtInfo.setLocked(true);
}
lastPub.setI18NUuid(sub.getUuid());
}
// references.addAll(sub.getReferences());
for (PublicationInfo pi : sub.getReferences()) {
if (!refUuids.contains(pi.getRoot().getUuid()) && !all.containsKey(pi.getRoot().getUuid())) {
refUuids.add(pi.getRoot().getUuid() );