From: Mathieu Baudier Date: Sat, 31 Oct 2020 08:52:37 +0000 (+0100) Subject: Extend entity JCR types. X-Git-Tag: argeo-suite-2.1.16~48 X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=commitdiff_plain;h=04cafe75836841a6c845b8dbc0cc80998442f78f Extend entity JCR types. --- 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 index 0000000..f32c182 --- /dev/null +++ b/org.argeo.entity.api/src/org/argeo/entity/EntityJcrUtils.java @@ -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); + } + } + +} diff --git a/org.argeo.entity.api/src/org/argeo/entity/EntityNames.java b/org.argeo.entity.api/src/org/argeo/entity/EntityNames.java index 9739471..b28e71d 100644 --- a/org.argeo.entity.api/src/org/argeo/entity/EntityNames.java +++ b/org.argeo.entity.api/src/org/argeo/entity/EntityNames.java @@ -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 index 0000000..7fc86a3 --- /dev/null +++ b/org.argeo.entity.api/src/org/argeo/entity/EntityType.java @@ -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"; + } + +} diff --git a/org.argeo.entity.api/src/org/argeo/entity/EntityTypes.java b/org.argeo.entity.api/src/org/argeo/entity/EntityTypes.java index f4b3e5e..ef35147 100644 --- a/org.argeo.entity.api/src/org/argeo/entity/EntityTypes.java +++ b/org.argeo.entity.api/src/org/argeo/entity/EntityTypes.java @@ -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"; diff --git a/org.argeo.entity.api/src/org/argeo/entity/entity.cnd b/org.argeo.entity.api/src/org/argeo/entity/entity.cnd index 67116cd..1ef20a7 100644 --- a/org.argeo.entity.api/src/org/argeo/entity/entity.cnd +++ b/org.argeo.entity.api/src/org/argeo/entity/entity.cnd @@ -1,28 +1,75 @@ -[entity:entity] > mix:title, mix:created, mix:lastModified, mix:referenceable +// standard namespaces + + + + +// see https://www.w3.org/2003/01/geo/ + + + +[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) diff --git a/org.argeo.entity.core/src/org/argeo/entity/core/JcrEntityDefinition.java b/org.argeo.entity.core/src/org/argeo/entity/core/JcrEntityDefinition.java index 15fb812..f76eb63 100644 --- a/org.argeo.entity.core/src/org/argeo/entity/core/JcrEntityDefinition.java +++ b/org.argeo.entity.core/src/org/argeo/entity/core/JcrEntityDefinition.java @@ -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);