From 6b66f008d1baa6cb54b3b16220572cfd572670f1 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 7 Jun 2021 10:29:06 +0200 Subject: [PATCH] Manage mixin supertypes. --- .../src/org/argeo/suite/ui/SuiteApp.java | 67 +++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java index 63a09f1..c0dbc57 100644 --- a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java +++ b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java @@ -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 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) -- 2.30.2