Extend entity JCR types.
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 31 Oct 2020 08:52:37 +0000 (09:52 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 31 Oct 2020 08:52:37 +0000 (09:52 +0100)
org.argeo.entity.api/src/org/argeo/entity/EntityJcrUtils.java [new file with mode: 0644]
org.argeo.entity.api/src/org/argeo/entity/EntityNames.java
org.argeo.entity.api/src/org/argeo/entity/EntityType.java [new file with mode: 0644]
org.argeo.entity.api/src/org/argeo/entity/EntityTypes.java
org.argeo.entity.api/src/org/argeo/entity/entity.cnd
org.argeo.entity.core/src/org/argeo/entity/core/JcrEntityDefinition.java

diff --git a/org.argeo.entity.api/src/org/argeo/entity/EntityJcrUtils.java b/org.argeo.entity.api/src/org/argeo/entity/EntityJcrUtils.java
new file mode 100644 (file)
index 0000000..f32c182
--- /dev/null
@@ -0,0 +1,60 @@
+package org.argeo.entity;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/** JCR utilities around the entity concepts. */
+public class EntityJcrUtils {
+       /**
+        * The name of a node which will be serialized as XML text, as per section 7.3.1
+        * of the JCR 2.0 specifications.
+        */
+       public final static String JCR_XMLTEXT = "jcr:xmltext";
+
+       /**
+        * The name of a property which will be serialized as XML text, as per section
+        * 7.3.1 of the JCR 2.0 specifications.
+        */
+       public final static String JCR_XMLCHARACTERS = "jcr:xmlcharacters";
+
+       /*
+        * XML
+        */
+       /**
+        * Set both as a property and as a subnode which will be exported as an XML
+        * element.
+        */
+
+//     public static void setAttrAndElem(Node node, String name, String value) {
+//             Jcr.set(node, name, value);
+//             setElem(node, name, value);
+//     }
+       /**
+        * Set as a subnode which will be exported as an XML element.
+        */
+       public static String getXmlValue(Node node, String name) {
+               try {
+                       if (!node.hasNode(name))
+                               throw new IllegalArgumentException("No XML text named " + name);
+                       return node.getNode(name).getNode(JCR_XMLTEXT).getProperty(JCR_XMLCHARACTERS).getString();
+               } catch (RepositoryException e) {
+                       throw new IllegalStateException("Cannot get " + name + " as XML text", e);
+               }
+       }
+
+       /**
+        * Set as a subnode which will be exported as an XML element.
+        */
+       public static void setXmlValue(Node node, String name, String value) {
+               try {
+                       if (node.hasNode(name))
+                               node.getNode(name).getNode(JCR_XMLTEXT).setProperty(JCR_XMLCHARACTERS, value);
+                       else
+                               node.addNode(name, EntityType.xmlvalue.qualified()).addNode(JCR_XMLTEXT, EntityType.xmltext.qualified())
+                                               .setProperty(JCR_XMLCHARACTERS, value);
+               } catch (RepositoryException e) {
+                       throw new IllegalStateException("Cannot set " + name + " as XML text", e);
+               }
+       }
+
+}
index 973947199ff3a6e62804a69f77279a7f00e56073..b28e71df35c1699fb2d14cde8c04d206cac24486 100644 (file)
@@ -4,13 +4,20 @@ import org.argeo.naming.LdapAttrs;
 
 /** Constants used to name entity structures. */
 public interface EntityNames {
-       final String ENTITY_DEFINITIONS_PATH = "/entity:entityDefinitions";
+       final String ENTITY_DEFINITIONS_PATH = "/entity";
+       final String TYPOLOGIES_PATH = "/class";
+
+       /** Administrative units. */
+       final String ADM = "adm";
 
        final String ENTITY_TYPE = "entity:type";
        final String ENTITY_UID = "entity:uid";
+       final String ENTITY_NAME = "entity:name";
 
        // GENERIC CONCEPTS
-       /** The date which is clearly relevant for this entity. */
+       /** The language which is relevant. */
+       final String XML_LANG = "xml:lang";
+       /** The date which is relevant. */
        final String ENTITY_DATE = "entity:date";
        final String ENTITY_RELATED_TO = "entity:relatedTo";
 
@@ -21,4 +28,10 @@ public interface EntityNames {
        final String SURNAME = LdapAttrs.sn.property();
        final String EMAIL = LdapAttrs.mail.property();
 
+       final String OU = LdapAttrs.ou.property();
+
+       // WGS84
+       final String GEO_LAT = "geo:lat";
+       final String GEO_LONG = "geo:long";
+       final String GEO_ALT = "geo:alt";
 }
diff --git a/org.argeo.entity.api/src/org/argeo/entity/EntityType.java b/org.argeo.entity.api/src/org/argeo/entity/EntityType.java
new file mode 100644 (file)
index 0000000..7fc86a3
--- /dev/null
@@ -0,0 +1,34 @@
+package org.argeo.entity;
+
+import org.argeo.naming.QualifiedName;
+
+/** Types related to entities. */
+public enum EntityType implements QualifiedName {
+       // entity
+       entity, definition,
+       // xml
+       xmlvalue,xmltext,
+       // typology
+       typology, term
+       // ldap
+       , person;
+
+       @Override
+       public String getPrefix() {
+               return prefix();
+       }
+
+       public static String prefix() {
+               return "entity";
+       }
+
+       @Override
+       public String getNamespace() {
+               return namespace();
+       }
+
+       public static String namespace() {
+               return "http://www.argeo.org/ns/entity";
+       }
+
+}
index f4b3e5e59eb2c16885777336caf98ad3959c437e..ef35147212647f16a2b89aa8ad88ee59bc4cd5dd 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.entity;
 
 /** Types related to entities. */
+@Deprecated
 public interface EntityTypes {
        final static String ENTITY_ENTITY = "entity:entity";
        final static String ENTITY_DEFINITION = "entity:definition";
index 67116cd69ca88a05a9dd225c006930b8d87792cb..1ef20a7604a670f553b33148225bc87e4ed4a19a 100644 (file)
@@ -1,28 +1,75 @@
 <ldap = 'http://www.argeo.org/ns/ldap'>
 <entity = 'http://www.argeo.org/ns/entity'>
 
-[entity:entity] > mix:title, mix:created, mix:lastModified, mix:referenceable
+// standard namespaces
+<xsd = "http://www.w3.org/2001/XMLSchema">
+<h = "http://www.w3.org/1999/xhtml">
+<xforms = "http://www.w3.org/2002/xforms">
+
+// see https://www.w3.org/2003/01/geo/
+<geo = 'http://www.w3.org/2003/01/geo/wgs84_pos#'>
+
+
+[entity:entity] > mix:created, mix:referenceable
 mixin
 //- entity:uid (String) m // an implementation dependent UID for each entity
 //- entity:type (String) // the type of this entity
 
-[entity:definition] > entity:composite, mix:title, mix:created, mix:lastModified, mix:referenceable
-mixin
+//
+// ENTITY DEFINITION
+//
+[entity:definition] > entity:composite, mix:created, mix:referenceable
+//- entity:type (String) multiple
 
 [entity:part]
-mixin
 
 [entity:reference]
-mixin
 
 [entity:composite]
-mixin
 orderable
-+ * (entity:part)
-+ * (entity:reference)
-+ * (entity:composite)
+//+ * (entity:part)
+//+ * (entity:reference)
+//+ * (entity:composite)
+
+//
+// TYPOLOGY
+//
+[entity:term]
+orderable
++ * (entity:term) *
+
+[entity:typology] > mix:referenceable, mix:created
+orderable
++ * (entity:term) *
+
+//
+// XML
+//
+[entity:xmlvalue] > mix:language
+- *
++ jcr:xmltext (entity:xmltext)
+
+[entity:xmltext]
+ - jcr:xmlcharacters (String) mandatory
+
+//
+// HTML
+//
+[h:head]
++ h:title (entity:xmlvalue)
++ h:base (entity:xmlvalue)
++ h:style (entity:xmlvalue) multiple
++ h:meta (entity:xmlvalue) multiple
++ h:link (entity:xmlvalue) multiple
++ h:script (entity:xmlvalue) multiple
+
+[h:html]
++ h:head (h:head)
++ h:body (nt:unstructured)
 
 // LDAP-LIKE ENTITIES
 // A real person
 [entity:person] > entity:entity
 mixin
+- ldap:sn (String)
+- ldap:givenName (String)
index 15fb812c0567505fef6c80ee9a9b228bb444780e..f76eb63fa96491b4df5874f246ff896de56cdfa1 100644 (file)
@@ -32,8 +32,8 @@ public class JcrEntityDefinition implements EntityDefinition {
                        defaultEditoryId = properties.get(EntityConstants.DEFAULT_EDITORY_ID);
                        String definitionPath = EntityNames.ENTITY_DEFINITIONS_PATH + '/' + type;
                        if (!adminSession.itemExists(definitionPath)) {
-                               Node entityDefinition = JcrUtils.mkdirs(adminSession, definitionPath);
-                               entityDefinition.addMixin(EntityTypes.ENTITY_DEFINITION);
+                               Node entityDefinition = JcrUtils.mkdirs(adminSession, definitionPath, EntityTypes.ENTITY_DEFINITION);
+//                             entityDefinition.addMixin(EntityTypes.ENTITY_DEFINITION);
                                adminSession.save();
                        }
                        initJcr(adminSession);