}
n.setThumbnailsMap(new HashMap<String, String>());
n.setVersioned(node.isVersioned());
n.setLanguageCode(node.getLanguage());
try {
JCRSiteNode site = node.getResolveSite();
if (site != null) {
n.setSiteUUID(site.getUUID());
n.setAclContext("site:" + site.getName());
n.setSiteKey(site.getSiteKey());
} else {
n.setAclContext("sharedOnly");
}
} catch (RepositoryException e) {
logger.error("Error when getting sitekey", e);
}
if (node.isFile()) {
n.setSize(node.getFileContent().getContentLength());
}
n.setFile(node.isFile());
n.setIsShared(false);
try {
if (node.isNodeType("mix:shareable") && node.getSharedSet().getSize() > 1) {
n.setIsShared(true);
}
} catch (RepositoryException e) {
logger.error("Error when getting shares", e);
}
try {
n.setReference(node.isNodeType("jmix:nodeReference"));
} catch (RepositoryException e1) {
logger.error("Error checking node type", e1);
}
if (fields.contains(GWTJahiaNode.CHILDREN_INFO)) {
boolean hasChildren = false;
if (node instanceof JCRMountPointNode) {
hasChildren = true;
} else if (!node.isFile()) {
try {
final NodeIterator nodesIterator = node.getNodes();
if (nodesIterator.hasNext()) {
hasChildren = true;
}
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
}
n.setHasChildren(hasChildren);
}
if (fields.contains(GWTJahiaNode.TAGS)) {
try {
if (node.hasProperty("j:tags")) {
StringBuilder b = new StringBuilder();
Value[] values = node.getProperty("j:tags").getValues();
for (Value value : values) {
Node tag = ((JCRValueWrapper) value).getNode();
if (tag != null) {
b.append(", ");
b.append(tag.getName());
}
}
if (b.length() > 0) {
n.setTags(b.substring(2));
}
}
} catch (RepositoryException e) {
logger.error("Error when getting tags", e);
}
}
if (node.isPortlet()) {
n.setPortlet(true);
}
// icons
if (fields.contains(GWTJahiaNode.ICON)) {
try {
n.setIcon(JCRContentUtils.getIcon(node));
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
}
// thumbnails
List<String> names = node.getThumbnails();
if (names.contains("thumbnail")) {
n.setPreview(node.getThumbnailUrl("thumbnail"));
n.setDisplayable(true);
}
for (String name : names) {
n.getThumbnailsMap().put(name, node.getThumbnailUrl(name));
}
//count
if (fields.contains(GWTJahiaNode.COUNT)) {
try {
n.set("count", JCRContentUtils.size(node.getWeakReferences()));
} catch (RepositoryException e) {
logger.warn("Unable to count node references for node");
}
}
if (fields.contains(GWTJahiaNode.PUBLICATION_INFO)) {
try {
n.setAggregatedPublicationInfos(publication.getAggregatedPublicationInfosByLanguage(node.getIdentifier(),
Collections.singleton(node.getSession().getLocale().toString()), node.getSession()));
} catch (UnsupportedRepositoryOperationException e) {
// do nothing
logger.debug(e.getMessage());
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
} catch (GWTJahiaServiceException e) {
logger.error(e.getMessage(), e);
}
}
if (fields.contains(GWTJahiaNode.PUBLICATION_INFOS)) {
try {
JCRSiteNode siteNode = node.getResolveSite();
if (siteNode != null) {
JCRSessionWrapper session = node.getSession();
n.setAggregatedPublicationInfos(publication.getAggregatedPublicationInfosByLanguage(node.getIdentifier(),
siteNode.getLanguages(), session));
n.setFullPublicationInfos(publication.getFullPublicationInfosByLanguage(Arrays.asList(node.getIdentifier()), siteNode.getLanguages(),
session, false));
}
} catch (UnsupportedRepositoryOperationException e) {
// do nothing
logger.debug(e.getMessage());
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
} catch (GWTJahiaServiceException e) {
logger.error(e.getMessage(), e);
}
}
if (fields.contains(GWTJahiaNode.WORKFLOW_INFO) || fields.contains(GWTJahiaNode.PUBLICATION_INFO)) {
try {
n.setWorkflowInfo(
workflow.getWorkflowInfo(n.getPath(), node.getSession(), node.getSession().getLocale()));
} catch (UnsupportedRepositoryOperationException e) {
// do nothing
logger.debug(e.getMessage());
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
} catch (GWTJahiaServiceException e) {
logger.error(e.getMessage(), e);
}
}
if (fields.contains(GWTJahiaNode.WORKFLOW_INFOS)) {
try {
JCRSiteNode node1 = node.getResolveSite();
if (node1 != null) {
Map<String, GWTJahiaWorkflowInfo> infoMap = new HashMap<String, GWTJahiaWorkflowInfo>();
JCRSessionWrapper session = node.getSession();
for (String code : node1.getLanguages()) {
Locale locale = LanguageCodeConverters.languageCodeToLocale(code);
JCRSessionWrapper localeSession =
sessionFactory.getCurrentUserSession(session.getWorkspace().getName(), locale);
GWTJahiaWorkflowInfo info = workflow.getWorkflowInfo(n.getPath(), localeSession, locale);
infoMap.put(code, info);