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



##########
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:
       Hmm good point, I think that was an oversight as I was having difficulty 
building in this one case -- happy to revert them back.

##########
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:
       agree, I try to avoid hard-coding too.  Thanks for catching that.




-- 
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