Woonsan Ko pushed to branch feature/spaplus at cms-community / 
hippo-site-toolkit


Commits:
10713706 by Woonsan Ko at 2018-03-13T13:10:33-04:00
HSTTWO-4268: fixing model collection and removing unused lines and updating 
json serializing details

- - - - -


3 changed files:

- 
components/core/src/main/java/org/hippoecm/hst/core/pagemodel/container/PageModelAggregationValve.java
- 
components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/AggregatedPageModel.java
- 
components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/ComponentWindowModel.java


Changes:

=====================================
components/core/src/main/java/org/hippoecm/hst/core/pagemodel/container/PageModelAggregationValve.java
=====================================
--- 
a/components/core/src/main/java/org/hippoecm/hst/core/pagemodel/container/PageModelAggregationValve.java
+++ 
b/components/core/src/main/java/org/hippoecm/hst/core/pagemodel/container/PageModelAggregationValve.java
@@ -69,11 +69,6 @@ public class PageModelAggregationValve extends 
AggregationValve {
     private static final String PAGE_MODEL_ATTR_NAME = 
PageModelAggregationValve.class.getName() + ".pageModel";
 
     /**
-     * Page definition ID metadata name.
-     */
-    private static final String DEFINITION_ID_METADATA = "definitionId";
-
-    /**
      * Content JSON Pointer prefix.
      */
     private static final String CONTENT_JSON_POINTER_PREFIX = "/content/";
@@ -192,10 +187,6 @@ public class PageModelAggregationValve extends 
AggregationValve {
     protected AggregatedPageModel createAggregatedPageModel(final 
HstComponentWindow[] sortedComponentWindows,
             final Map<HstComponentWindow, HstRequest> requestMap,
             final Map<HstComponentWindow, HstResponse> responseMap) throws 
ContainerException {
-        final HstRequestContext requestContext = RequestContextProvider.get();
-        final String componentRenderingWindowReferenceNamespace = 
requestContext.getBaseURL()
-                .getComponentRenderingWindowReferenceNamespace();
-
         // root component (page component) is the first item in the 
sortedComponentWindows.
         final HstComponentWindow rootWindow = sortedComponentWindows[0];
         final String id = rootWindow.getReferenceNamespace();
@@ -233,9 +224,10 @@ public class PageModelAggregationValve extends 
AggregationValve {
 
                     decorateContentMetadata(hstRequest, hstResponse, bean, 
wrapperBeanModel);
 
-
                     currentComponentWindowModel
                             .putModel(name, new 
ReferenceMetadataBaseModel(CONTENT_JSON_POINTER_PREFIX + 
jsonPointerRepresentationId));
+                } else {
+                    currentComponentWindowModel.putModel(name, model);
                 }
             }
         }


=====================================
components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/AggregatedPageModel.java
=====================================
--- 
a/components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/AggregatedPageModel.java
+++ 
b/components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/AggregatedPageModel.java
@@ -19,6 +19,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonInclude;
@@ -50,8 +51,12 @@ public class AggregatedPageModel extends 
IdentifiableLinkableMetadataBaseModel {
 
     private void populateFlattened(final ComponentWindowModel model) {
         flattened.put(model.getId(), model);
-        for (ComponentWindowModel child : model.getComponents()) {
-            populateFlattened(child);
+
+        final Set<ComponentWindowModel> components = model.getComponents();
+        if (components != null) {
+            for (ComponentWindowModel child : components) {
+                populateFlattened(child);
+            }
         }
     }
 


=====================================
components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/ComponentWindowModel.java
=====================================
--- 
a/components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/ComponentWindowModel.java
+++ 
b/components/core/src/main/java/org/hippoecm/hst/core/pagemodel/model/ComponentWindowModel.java
@@ -26,7 +26,6 @@ import org.hippoecm.hst.core.container.HstComponentWindow;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.annotation.JsonProperty;
 
 /**
  * Component window model representation.
@@ -34,21 +33,26 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 public class ComponentWindowModel extends 
IdentifiableLinkableMetadataBaseModel {
 
     private final String name;
-    private final String clazz;
+    private final String componentClass;
     private final String type;
     private String label;
-    private Map<String, ReferenceMetadataBaseModel> models;
+    private Map<String, Object> models;
     private Set<ComponentWindowModel> components;
 
-
     public ComponentWindowModel(final HstComponentWindow window) {
         super(window.getReferenceNamespace());
         name = window.getName();
-        clazz = window.getComponentName();
+        componentClass = window.getComponentName();
         type = window.getComponentInfo().getComponentType().toString();
-        components = new HashSet<>();
-        for (HstComponentWindow child : window.getChildWindowMap().values()) {
-            components.add(new ComponentWindowModel(child));
+
+        final Map<String, HstComponentWindow> childComponentWindows = 
window.getChildWindowMap();
+
+        if (!childComponentWindows.isEmpty()) {
+            components = new HashSet<>();
+
+            for (HstComponentWindow child : childComponentWindows.values()) {
+                components.add(new ComponentWindowModel(child));
+            }
         }
     }
 
@@ -62,9 +66,8 @@ public class ComponentWindowModel extends 
IdentifiableLinkableMetadataBaseModel 
     /**
      * @return the component's type name. i.e component class' FQCN.
      */
-    @JsonProperty("class")
-    public String getClazz() {
-        return clazz;
+    public String getComponentClass() {
+        return componentClass;
     }
 
     /**
@@ -91,11 +94,11 @@ public class ComponentWindowModel extends 
IdentifiableLinkableMetadataBaseModel 
      * @return
      */
     @JsonInclude(Include.NON_NULL)
-    public Map<String, ReferenceMetadataBaseModel> getModels() {
+    public Map<String, Object> getModels() {
         return models;
     }
 
-    public void putModel(String name, ReferenceMetadataBaseModel model) {
+    public void putModel(String name, Object model) {
         if (models == null) {
             models = new LinkedHashMap<>();
         }
@@ -103,6 +106,7 @@ public class ComponentWindowModel extends 
IdentifiableLinkableMetadataBaseModel 
         models.put(name, model);
     }
 
+    @JsonInclude(Include.NON_NULL)
     public Set<ComponentWindowModel> getComponents() {
         return components;
     }



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/10713706e1ac396cfe3ba84246ecba41155493f2

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/10713706e1ac396cfe3ba84246ecba41155493f2
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to