Manage mixin supertypes.
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 7 Jun 2021 08:29:06 +0000 (10:29 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 7 Jun 2021 08:29:06 +0000 (10:29 +0200)
core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java

index 63a09f1b7290671d4664471d0b57b46699a1a295..c0dbc575f46168064c5df9d9f15c53a85351f9ec 100644 (file)
@@ -37,6 +37,7 @@ import org.argeo.entity.EntityConstants;
 import org.argeo.entity.EntityNames;
 import org.argeo.entity.EntityType;
 import org.argeo.jcr.Jcr;
+import org.argeo.jcr.JcrException;
 import org.argeo.suite.RankedObject;
 import org.argeo.suite.SuiteUtils;
 import org.argeo.util.LangUtils;
@@ -176,7 +177,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                                CmsSession cmsSession = cmsView.getCmsSession();
                                if (ui.getUserDir() == null) {
                                        // FIXME NPE on CMSSession when logging in from anonymous
-                                       if (cmsSession==null || cmsView.isAnonymous()) {
+                                       if (cmsSession == null || cmsView.isAnonymous()) {
                                                assert publicBasePath != null;
                                                ui.initSessions(getRepository(), publicBasePath);
                                        } else {
@@ -245,31 +246,34 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                try {
                        // mixins
                        Set<String> types = new TreeSet<>();
-                       for (NodeType nodeType : context.getMixinNodeTypes()) {
-                               String typeName = nodeType.getName();
-                               if (byType.containsKey(typeName)) {
-                                       types.add(typeName);
+                       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());
+                                       }
                                }
                        }
                        // primary node type
-                       {
-                               NodeType nodeType = context.getPrimaryNodeType();
-                               String typeName = nodeType.getName();
-                               if (byType.containsKey(typeName)) {
-                                       types.add(typeName);
-                               }
-                               for (NodeType mixin : nodeType.getDeclaredSupertypes()) {
-                                       if (byType.containsKey(mixin.getName())) {
-                                               types.add(mixin.getName());
-                                       }
+                       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 typeName = context.getProperty(EntityNames.ENTITY_TYPE).getString();
-                                       if (byType.containsKey(typeName)) {
-                                               types.add(typeName);
+                                       String entityTypeName = context.getProperty(EntityNames.ENTITY_TYPE).getString();
+                                       if (byType.containsKey(entityTypeName)) {
+                                               types.add(entityTypeName);
                                        }
                                }
                        }
@@ -282,7 +286,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                        }
 
                        if (types.size() == 0)
-                               throw new IllegalArgumentException("No type found for " + context);
+                               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);
@@ -292,6 +296,31 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                }
        }
 
+       private static String listTypes(Node context) {
+               try {
+                       StringBuilder sb = new StringBuilder();
+                       sb.append(context.getPrimaryNodeType().getName());
+                       for (NodeType superType : context.getPrimaryNodeType().getDeclaredSupertypes()) {
+                               sb.append(' ');
+                               sb.append(superType.getName());
+                       }
+
+                       for (NodeType nodeType : context.getMixinNodeTypes()) {
+                               sb.append(' ');
+                               sb.append(nodeType.getName());
+                               if (nodeType.getName().equals(EntityType.entity.get()))
+                                       sb.append('/').append(context.getProperty(EntityNames.ENTITY_TYPE).getString());
+                               for (NodeType superType : nodeType.getDeclaredSupertypes()) {
+                                       sb.append(' ');
+                                       sb.append(superType.getName());
+                               }
+                       }
+                       return sb.toString();
+               } catch (RepositoryException e) {
+                       throw new JcrException(e);
+               }
+       }
+
        @Override
        public void setState(Composite parent, String state) {
                if (state == null)