Mathijs den Burger pushed to branch feature/visual-editing-psp1-CHANNELMGR-935 
at cms-community / hippo-addon-channel-manager


Commits:
3023d06d by Mathijs den Burger at 2016-10-18T14:34:39+02:00
CHANNELMGR-935 Retrieve parent level once to simplify code

- - - - -
de67e11d by Mathijs den Burger at 2016-10-18T14:46:58+02:00
CHANNELMGR-935 Prevent NPE when field is not multiple

- - - - -


3 changed files:

- 
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/DocumentTypesServiceImpl.java
- 
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldType.java
- + 
content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldTypeTest.java


Changes:

=====================================
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/DocumentTypesServiceImpl.java
=====================================
--- 
a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/DocumentTypesServiceImpl.java
+++ 
b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/DocumentTypesServiceImpl.java
@@ -87,10 +87,10 @@ public class DocumentTypesServiceImpl implements 
DocumentTypesService {
             final int level = parentContext.getLevel() + 1;
             final ContentTypeContext context = 
ContentTypeContext.createDocumentTypeContext(id, userSession, locale, level);
 
-            if (parentContext.getLevel() < MAX_NESTING_LEVEL) {
+            if (level <= MAX_NESTING_LEVEL) {
                 populateFields(fields, context, docType);
             } else {
-                log.info("Ignoring fields of {}-level-deep nested compound, 
nesting maximum reached", MAX_NESTING_LEVEL);
+                log.info("Ignoring fields of {}-level-deep nested compound, 
nesting maximum reached", level);
             }
         } catch (RepositoryException e) {
             log.warn("Failed to retrieve user session", e);


=====================================
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldType.java
=====================================
--- 
a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldType.java
+++ 
b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldType.java
@@ -108,7 +108,7 @@ public class FieldType {
     }
 
     public Boolean isMultiple() {
-        return multiple;
+        return multiple != null && multiple;
     }
 
     public void setMultiple(final boolean multiple) {


=====================================
content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldTypeTest.java
=====================================
--- /dev/null
+++ 
b/content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/FieldTypeTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 Hippo B.V. (http://www.onehippo.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onehippo.cms.channelmanager.content.documenttype.field.type;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class FieldTypeTest {
+
+    @Test
+    public void isMultiple() {
+        final FieldType fieldType = new FieldType();
+        fieldType.setMultiple(true);
+        assertTrue(fieldType.isMultiple());
+    }
+
+    @Test
+    public void isNotMultiple() {
+        final FieldType fieldType = new FieldType();
+        assertFalse(fieldType.isMultiple());
+    }
+}
\ No newline at end of file



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/8171b59208b0f2e2a260a71947dca7cccbc699f7...de67e11d5d88f60510e0b1b2ead407720d069523
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to