klcodanr commented on a change in pull request #73:
URL: https://github.com/apache/sling-whiteboard/pull/73#discussion_r605163744



##########
File path: 
SlingModelPersist/src/main/java/org/apache/sling/models/persistor/ModelPersistor.java
##########
@@ -18,10 +18,10 @@
  */
 package org.apache.sling.models.persistor;
 
+import com.drew.lang.annotations.NotNull;

Review comment:
       @badvision  any particular reason for changing annotation types? A 
number of other projects use the Jetbrains annotations, so it'd be better to be 
consistent

##########
File path: 
SlingModelPersist/src/main/java/org/apache/sling/models/persistor/impl/ModelPersistorImpl.java
##########
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.models.persistor.impl;
 
+import com.drew.lang.annotations.NotNull;

Review comment:
       Same comment re:annotation

##########
File path: 
SlingModelPersist/src/main/java/org/apache/sling/models/persistor/impl/ResourceTypeKey.java
##########
@@ -50,22 +52,34 @@ public static ResourceTypeKey fromObject(Object obj) {
             return NODE_TYPE_FOR_CLASS.get(obj.getClass());
         }
 
+        String nodeType = getNodeType(obj);
         Model modelAnnotation = obj.getClass().getAnnotation(Model.class);
-        String primaryType = (String) getAnnotatedValue(obj, 
ResourceType.class);
+        String resourceType = (String) getAnnotatedValue(obj, 
ResourceType.class);
+
         // Use the model annotation for resource type as needed
-        if (primaryType == null
+        if (resourceType == null
                 && modelAnnotation != null
                 && modelAnnotation.resourceType() != null
-                && modelAnnotation.resourceType().length == 1) {
-            primaryType = modelAnnotation.resourceType()[0];
+                && modelAnnotation.resourceType().length >= 1) {
+            resourceType = modelAnnotation.resourceType()[0];
         }
-        String childType = (String) getAnnotatedValue(obj, ChildType.class);
-        if (primaryType != null) {
-            ResourceTypeKey key = new ResourceTypeKey(primaryType, childType);
+
+        if (nodeType != null || resourceType != null) {
+            ResourceTypeKey key = new ResourceTypeKey(nodeType, resourceType);
             NODE_TYPE_FOR_CLASS.put(obj.getClass(), key);
             return key;
         } else {
             return ResourceTypeKey.NT_UNSTRUCTURED;
         }
     }
+
+    private static String getNodeType(Object obj) throws 
IllegalArgumentException, IllegalAccessException {
+        for (Field f : obj.getClass().getDeclaredFields()) {
+            Named namedAnnotation = f.getAnnotation(Named.class);
+            if (namedAnnotation != null && 
namedAnnotation.value().equals("jcr:primaryType")) {

Review comment:
       Probably should use: 
http://jackrabbit.apache.org/api/2.20/org/apache/jackrabbit/JcrConstants.html#JCR_PRIMARYTYPE




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to