}
}
} catch (RepositoryException e) {
logger.debug("Error when getting nodetypes", e);
}
GWTJahiaNode n;
// get uuid
String uuid = null;
try {
uuid = node.getIdentifier();
} catch (RepositoryException e) {
logger.debug("Unable to get uuid for node " + node.getName(), e);
}
// get description
String description = "";
try {
if (node.hasProperty("jcr:description")) {
Value dValue = node.getProperty("jcr:description").getValue();
if (dValue != null) {
description = dValue.getString();
}
}
} catch (RepositoryException e) {
logger.debug("Unable to get description property for node " + node.getName(), e);
}
n = new GWTJahiaNode();
n.setUUID(uuid);
n.setName(JCRContentUtils.unescapeLocalNodeName(node.getName()));
try {
if (node.getPath().equals("/")) {
n.setDisplayName("root");
n.setName("root");
} else {
n.setDisplayName(WordUtils.abbreviate(JCRContentUtils.unescapeLocalNodeName(node.getDisplayableName()),70,90,"..."));
}
} catch (Exception e) {
logger.error("Error when getting name", e);
}
n.setNormalizedName(removeDiacritics(n.getName()));
n.setDescription(description);
n.setPath(node.getPath());
n.setUrl(node.getUrl());
n.setNodeTypes(nodeTypes);
n.setInheritedNodeTypes(inheritedTypes);
n.setProviderKey(node.getProvider().getKey());
BitSet bs = node.getPermissionsAsBitSet();
GWTBitSet gwtBs = new GWTBitSet(bs.size());
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
gwtBs.set(i);
}
n.setPermissions(gwtBs);
n.setLockable(node.isLockable());
try {
boolean hasAcl = node.hasNode("j:acl") && node.getNode("j:acl").hasNodes();
n.setHasAcl(hasAcl);
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
try {
String username = node.getSession().getUser().getUsername();
n.setLocked(JCRContentUtils.isLockedAndCannotBeEdited(node));
Map<String, List<String>> infos = node.getLockInfos();
if(!infos.isEmpty()) {
Map.Entry<String, List<String>> stringListEntry = infos.entrySet().iterator().next();
JahiaUser jahiaUser = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(
StringUtils.substringBefore(stringListEntry.getValue().get(0), ":"));
if(jahiaUser==null) {
infos.clear();
infos.put(stringListEntry.getKey(),Arrays.asList("label.locked.by.workflow.process"));
}
}
n.setLockInfos(infos);
if (node.getSession().getLocale() != null) {
String l = node.getSession().getLocale().toString();
n.setCanLock(infos.isEmpty() || !infos.containsKey(l));
n.setCanUnlock(infos.containsKey(null) && infos.get(null).contains(username+":user") && (infos.size() == 1 || infos.containsKey(l) && infos.get(l).contains(username+":user")));
} else {
n.setCanLock(infos.isEmpty());
n.setCanUnlock(infos.containsKey(null) && infos.get(null).contains(username+":user"));
}
} catch (RepositoryException e) {
logger.error("Error when getting lock", e);
}
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);
}
n.setWorkflowInfos(infoMap);
}
} 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.AVAILABLE_WORKKFLOWS)) {
try {
if (node.hasProperty(GWTJahiaNode.AVAILABLE_WORKKFLOWS)) {
final JCRPropertyWrapper property = node.getProperty(GWTJahiaNode.AVAILABLE_WORKKFLOWS);
Value[] values = null;
if (property.isMultiple()) {
values = property.getValues();
} else {
values = new Value[]{property.getValue()};
}
List<String> vals = new LinkedList<String>();
if (values != null) {
for (Value value : values) {
if (value != null) {
vals.add(value.getString());
}
}
}
n.set(GWTJahiaNode.AVAILABLE_WORKKFLOWS, StringUtils.join(vals, ", "));
}
} catch (RepositoryException e) {
logger.error("Cannot get property " + GWTJahiaNode.AVAILABLE_WORKKFLOWS + " on node " + node.getPath());
}
}
if (fields.contains(GWTJahiaNode.PRIMARY_TYPE_LABEL)) {
try {
n.set(GWTJahiaNode.PRIMARY_TYPE_LABEL, node.getPrimaryNodeType().getLabel(node.getSession().getLocale()));
} catch (RepositoryException e) {
logger.error("Cannot get property " + GWTJahiaNode.PRIMARY_TYPE_LABEL + " on node " + node.getPath());
}
}
if (n.isFile() && nodeTypes.contains("jmix:image")) {
fields = new LinkedList<String>(fields);
if (!fields.contains("j:height")) {
fields.add("j:height");
}
if (!fields.contains("j:width")) {
fields.add("j:width");
}
}
if (fields.contains(GWTJahiaNode.SITE_LANGUAGES)) {
try {
n.set(GWTJahiaNode.SITE_LANGUAGES, languages.getLanguages(node.getResolveSite(), node.getSession().getUser(), node.getSession().getLocale()));
} catch (RepositoryException e) {
logger.error("Cannot get sites languages");
}
}
// reference types
try {
String cons = ConstraintsHelper.getConstraints(node);
if (cons != null) {
n.set("referenceTypes", ConstraintsHelper.getReferenceTypes(cons, null));
}
} catch (RepositoryException e) {
logger.error("Cannot get property " + GWTJahiaNode.AVAILABLE_WORKKFLOWS + " on node " + node.getPath());
}
if (fields.contains(GWTJahiaNode.DEFAULT_LANGUAGE)) {
try {
if (node.hasProperty(GWTJahiaNode.DEFAULT_LANGUAGE)) {
Locale locale = LanguageCodeConverters.languageCodeToLocale(node.getProperty(GWTJahiaNode.DEFAULT_LANGUAGE).getString());
n.set(GWTJahiaNode.DEFAULT_LANGUAGE, languages.getCurrentLang(locale));
}
} catch (RepositoryException e) {
logger.error("Cannot get property " + GWTJahiaNode.AVAILABLE_WORKKFLOWS + " on node " + node.getPath());
}
}
if (fields.contains(GWTJahiaNode.HOMEPAGE_PATH) && (node instanceof JCRSiteNode)) {
try {
if (((JCRSiteNode) node).getHome() != null) {
n.set(GWTJahiaNode.HOMEPAGE_PATH, ((JCRSiteNode) node).getHome().getPath());
}
} catch (RepositoryException e) {
logger.error("Cannot get property " + GWTJahiaNode.AVAILABLE_WORKKFLOWS + " on node " + node.getPath());
}
}
// properties
for (String field : fields) {
if (!GWTJahiaNode.RESERVED_FIELDS.contains(field)) {
try {
if (node.hasProperty(field)) {
// n.set(StringUtils.substringAfter(propName, ":"), node.getProperty(propName).getString());
final JCRPropertyWrapper property = node.getProperty(field);
if (property.isMultiple()) {
Value[] values = property.getValues();
List<Object> l = new ArrayList<Object>();
for (Value value : values) {
l.add(getPropertyValue(value, node.getSession()));
}
n.set(field, l);
} else {
Value value = property.getValue();
n.set(field, getPropertyValue(value, node.getSession()));
}
}
} catch (RepositoryException e) {
logger.error("Cannot get property " + field + " on node " + node.getPath());
}
}
}
// versions
if (fields.contains(GWTJahiaNode.VERSIONS) && node.isVersioned()) {
try {
n.setCurrentVersion(node.getBaseVersion().getName());
List<GWTJahiaNodeVersion> gwtJahiaNodeVersions = getVersions(node);
if (gwtJahiaNodeVersions != null && gwtJahiaNodeVersions.size() > 0) {
n.setVersions(gwtJahiaNodeVersions);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
// references
try {
if (node.isNodeType("jmix:nodeReference") && node.hasProperty("j:node")) {
JCRNodeWrapper referencedNode = (JCRNodeWrapper) node.getProperty("j:node").getNode();
n.setReferencedNode(n.getUUID().equals(referencedNode.getIdentifier()) ? n : getGWTJahiaNode(referencedNode));
}
} catch (ItemNotFoundException e) {
logger.debug(e.getMessage(), e);
}
catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
// sort
try {
if (node.getPrimaryNodeType().hasOrderableChildNodes()) {
n.set("hasOrderableChildNodes", Boolean.TRUE);
n.setSortField("index");
} else {
n.setSortField(GWTJahiaNode.NAME);
}
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
// constraints
try {
Set<String> cons = node.getPrimaryNodeType().getUnstructuredChildNodeDefinitions().keySet();
n.setChildConstraints(new HashSet<String>(cons));
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
// WCAG checks
try {
n.setWCAGComplianceCheckEnabled(node.getResolveSite().hasProperty(
SitesSettings.WCAG_COMPLIANCE_CHECKING_ENABLED)
&& node.getResolveSite()
.getProperty(SitesSettings.WCAG_COMPLIANCE_CHECKING_ENABLED)
.getBoolean());
} catch (RepositoryException e) {