X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.ui%2Fsrc%2Forg%2Fargeo%2Fapp%2Fui%2FSuiteApp.java;h=3777b2ecda03557afa810dd561b32f5d0935ba3d;hb=99a029d144e7aab7f8b5a9ac3a2c4383cae4a6f5;hp=9bfec26ba989f5428c13f40689900a8af47c0f70;hpb=8317c50a86ebb2d50add224816e3dd6103e36150;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java b/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java index 9bfec26..3777b2e 100644 --- a/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java +++ b/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java @@ -1,6 +1,7 @@ package org.argeo.app.ui; import static org.argeo.api.cms.CmsView.CMS_VIEW_UID_PROPERTY; +import static org.argeo.cms.acr.ContentUtils.SLASH; import java.util.Collections; import java.util.HashMap; @@ -14,16 +15,12 @@ import java.util.TreeMap; import java.util.TreeSet; import javax.jcr.Node; -import javax.jcr.Repository; import javax.jcr.RepositoryException; -import javax.jcr.Session; import javax.jcr.nodetype.NodeType; -import javax.naming.InvalidNameException; -import javax.naming.ldap.LdapName; +import javax.xml.namespace.QName; import org.argeo.api.acr.Content; import org.argeo.api.acr.ContentRepository; -import org.argeo.api.acr.ContentSession; import org.argeo.api.acr.spi.ProvidedSession; import org.argeo.api.cms.CmsConstants; import org.argeo.api.cms.CmsLog; @@ -40,16 +37,16 @@ import org.argeo.cms.AbstractCmsApp; import org.argeo.cms.CmsUserManager; import org.argeo.cms.LocaleUtils; import org.argeo.cms.Localized; +import org.argeo.cms.acr.CmsContentRepository; import org.argeo.cms.jcr.CmsJcrUtils; import org.argeo.cms.jcr.acr.JcrContent; -import org.argeo.cms.jcr.acr.JcrContentProvider; import org.argeo.cms.swt.CmsSwtUtils; import org.argeo.cms.swt.dialogs.CmsFeedback; import org.argeo.cms.ui.CmsUiProvider; import org.argeo.cms.ux.CmsUxUtils; import org.argeo.eclipse.ui.specific.UiContext; -import org.argeo.jcr.Jcr; import org.argeo.jcr.JcrException; +import org.argeo.osgi.useradmin.UserDirectory; import org.argeo.util.LangUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; @@ -99,10 +96,10 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { // ACR private ContentRepository contentRepository; - private JcrContentProvider jcrContentProvider; +// private JcrContentProvider jcrContentProvider; // JCR - private Repository repository; +// private Repository repository; public void init(Map properties) { if (log.isDebugEnabled()) @@ -192,7 +189,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { throw new IllegalStateException("UI name should not be null"); CmsView cmsView = CmsSwtUtils.getCmsView(ui); - ContentSession contentSession = CmsUxUtils.getContentSession(contentRepository, cmsView); + ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository, cmsView); CmsUiProvider headerUiProvider = findUiProvider(headerPid); CmsUiProvider footerUiProvider = findUiProvider(footerPid); @@ -231,16 +228,18 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { ui.setUserDir(userDir); // ui.initSessions(getRepository(), publicBasePath); } else { - Session adminSession = null; - try { - adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), null); - Node userDirNode = SuiteUtils.getOrCreateCmsSessionNode(adminSession, cmsSession); - Content userDir = contentSession.get(CmsConstants.SYS_WORKSPACE + userDirNode.getPath()); - ui.setUserDir(userDir); -// ui.initSessions(getRepository(), userDirNode.getPath()); - } finally { - Jcr.logout(adminSession); - } +// Session adminSession = null; +// try { +// adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), null); +// Node userDirNode = SuiteUtils.getOrCreateCmsSessionNode(adminSession, cmsSession); +// Content userDir = contentSession.get(CmsConstants.SYS_WORKSPACE + userDirNode.getPath()); +// ui.setUserDir(userDir); +//// ui.initSessions(getRepository(), userDirNode.getPath()); +// } finally { +// Jcr.logout(adminSession); +// } + Content userDir = contentSession.getSessionRunDir(); + ui.setUserDir(userDir); } } initLocale(cmsSession); @@ -297,63 +296,79 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { private T findByType(Map> byType, Content content) { if (content == null) throw new IllegalArgumentException("A node should be provided"); - - if(content instanceof JcrContent) { - Node context = ((JcrContent)content).getJcrNode(); - try { - // mixins - Set types = new TreeSet<>(); - for (NodeType mixinType : context.getMixinNodeTypes()) { - String mixinTypeName = mixinType.getName(); - if (byType.containsKey(mixinTypeName)) { - types.add(mixinTypeName); + + if (content instanceof JcrContent) { + Node context = ((JcrContent) content).getJcrNode(); + try { + // mixins + Set types = new TreeSet<>(); + for (NodeType mixinType : context.getMixinNodeTypes()) { + String mixinTypeName = mixinType.getName(); + if (byType.containsKey(mixinTypeName)) { + types.add(mixinTypeName); + } + for (NodeType superType : mixinType.getDeclaredSupertypes()) { + if (byType.containsKey(superType.getName())) { + types.add(superType.getName()); + } + } } - for (NodeType superType : mixinType.getDeclaredSupertypes()) { + // primary node type + NodeType primaryType = context.getPrimaryNodeType(); + String primaryTypeName = primaryType.getName(); + if (byType.containsKey(primaryTypeName)) { + types.add(primaryTypeName); + } + for (NodeType superType : primaryType.getDeclaredSupertypes()) { if (byType.containsKey(superType.getName())) { types.add(superType.getName()); } } - } - // primary node type - NodeType primaryType = context.getPrimaryNodeType(); - String primaryTypeName = primaryType.getName(); - if (byType.containsKey(primaryTypeName)) { - types.add(primaryTypeName); - } - for (NodeType superType : primaryType.getDeclaredSupertypes()) { - if (byType.containsKey(superType.getName())) { - types.add(superType.getName()); - } - } - // entity type - if (context.isNodeType(EntityType.entity.get())) { - if (context.hasProperty(EntityNames.ENTITY_TYPE)) { - String entityTypeName = context.getProperty(EntityNames.ENTITY_TYPE).getString(); - if (byType.containsKey(entityTypeName)) { - types.add(entityTypeName); + // entity type + if (context.isNodeType(EntityType.entity.get())) { + if (context.hasProperty(EntityNames.ENTITY_TYPE)) { + String entityTypeName = context.getProperty(EntityNames.ENTITY_TYPE).getString(); + if (byType.containsKey(entityTypeName)) { + types.add(entityTypeName); + } } } - } // if (context.getPath().equals("/")) {// root node // types.add("nt:folder"); // } - if (CmsJcrUtils.isUserHome(context) && byType.containsKey("nt:folder")) {// home node - types.add("nt:folder"); + if (CmsJcrUtils.isUserHome(context) && byType.containsKey("nt:folder")) {// home node + types.add("nt:folder"); + } + + if (types.size() == 0) + throw new IllegalArgumentException( + "No type found for " + context + " (" + listTypes(context) + ")"); + String type = types.iterator().next(); + if (!byType.containsKey(type)) + throw new IllegalArgumentException("No component found for " + context + " with type " + type); + return byType.get(type).get(); + } catch (RepositoryException e) { + throw new IllegalStateException(e); } + } else { + + List objectClasses = content.getTypes(); + Set types = new TreeSet<>(); + for (QName cc : objectClasses) { + String type = cc.getPrefix() + ":" + cc.getLocalPart(); + if (byType.containsKey(type)) + types.add(type); + } if (types.size() == 0) - throw new IllegalArgumentException("No type found for " + context + " (" + listTypes(context) + ")"); + throw new IllegalArgumentException("No type found for " + content + " (" + objectClasses + ")"); String type = types.iterator().next(); if (!byType.containsKey(type)) - throw new IllegalArgumentException("No component found for " + context + " with type " + type); + throw new IllegalArgumentException("No component found for " + content + " with type " + type); return byType.get(type).get(); - } catch (RepositoryException e) { - throw new IllegalStateException(e); - } - - }else { - throw new UnsupportedOperationException("Content "+content.getClass().getName()+" is not supported."); + // throw new UnsupportedOperationException("Content " + + // content.getClass().getName() + " is not supported."); } } @@ -425,7 +440,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { if (state == null || !state.startsWith("/")) return null; - String path=state; + String path = state; // String path = state.substring(1); // String workspace; // if (path.equals("")) { @@ -542,8 +557,8 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository, ui.getCmsView()); - String path = get(event,SuiteEvent.CONTENT_PATH); - + String path = get(event, SuiteEvent.CONTENT_PATH); + // String nodePath = get(event, SuiteEvent.NODE_PATH); if (path != null && path.equals(HOME_STATE)) return ui.getUserDir(); @@ -560,15 +575,16 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { User user = cmsUserManager.getUser(username); if (user == null) return null; - LdapName userDn; - try { - userDn = new LdapName(user.getName()); - } catch (InvalidNameException e) { - throw new IllegalArgumentException("Badly formatted username", e); - } - String userNodePath = SuiteUtils.getUserNodePath(userDn); + node = SuiteUtils.roleToContent(cmsUserManager, contentSession, user); +// LdapName userDn; +// try { +// userDn = new LdapName(user.getName()); +// } catch (InvalidNameException e) { +// throw new IllegalArgumentException("Badly formatted username", e); +// } +// String userNodePath = SuiteUtils.getUserNodePath(userDn); // FIXME deal with home path - return null; +// return null; // if (Jcr.itemExists(session, userNodePath)) // node = Jcr.getNode(session, userNodePath); // else { @@ -674,13 +690,13 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { this.cmsUserManager = cmsUserManager; } - protected Repository getRepository() { - return repository; - } - - public void setRepository(Repository repository) { - this.repository = repository; - } +// protected Repository getRepository() { +// return repository; +// } +// +// public void setRepository(Repository repository) { +// this.repository = repository; +// } protected ContentRepository getContentRepository() { return contentRepository; @@ -690,8 +706,8 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { this.contentRepository = contentRepository; } - public void setJcrContentProvider(JcrContentProvider jcrContentProvider) { - this.jcrContentProvider = jcrContentProvider; - } +// public void setJcrContentProvider(JcrContentProvider jcrContentProvider) { +// this.jcrContentProvider = jcrContentProvider; +// } }