Bert Leunis pushed to branch feature/CHANNELMGR-1391 at cms-community / 
hippo-addon-channel-manager


Commits:
32da5efb by Bert Leunis at 2018-03-11T15:48:48+01:00
CHANNELMGR-1391 recognizes the default empty value of a Date property. Sets 
property to this value when no date is filled in.

A Date property has a default value representing an empty property. If such a 
property is read from the backend the frontend field is given an empty string 
so the field appears empty.

When saving a Date field that has no value (which is allowed when it is not 
required), the value for the property is set to the default string representing 
an empty date. This makes that the property is actually created on the document 
node.

- - - - -


3 changed files:

- content-service/pom.xml
- 
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java
- 
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/PrimitiveFieldType.java


Changes:

=====================================
content-service/pom.xml
=====================================
--- a/content-service/pom.xml
+++ b/content-service/pom.xml
@@ -37,6 +37,10 @@
     </dependency>
     <dependency>
       <groupId>org.onehippo.cms7</groupId>
+      <artifactId>hippo-cms-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.onehippo.cms7</groupId>
       <artifactId>hippo-repository-api</artifactId>
     </dependency>
     <dependency>


=====================================
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java
=====================================
--- 
a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java
+++ 
b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java
@@ -15,16 +15,21 @@
  */
 package org.onehippo.cms.channelmanager.content.documenttype.field.type;
 
+import java.util.Calendar;
+
 import javax.jcr.PropertyType;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.jackrabbit.util.ISO8601;
+import org.hippoecm.frontend.model.PropertyValueProvider;
+import org.onehippo.cms.channelmanager.content.document.model.FieldValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class DateFieldType extends PrimitiveFieldType {
 
     private static final Logger log = 
LoggerFactory.getLogger(DateFieldType.class);
-    private static final String DEFAULT_VALUE = StringUtils.EMPTY;
+    private static final String DEFAULT_DISPLAY_VALUE = StringUtils.EMPTY;
 
     public DateFieldType() {
         setType(Type.DATE);
@@ -37,6 +42,29 @@ public class DateFieldType extends PrimitiveFieldType {
 
     @Override
     protected String getDefault() {
-        return DEFAULT_VALUE;
+        return DEFAULT_DISPLAY_VALUE;
+    }
+
+    @Override
+    protected String fieldSpecificConversion(final String input) {
+        if (StringUtils.isBlank(input)) {
+            return PropertyValueProvider.EMPTY_DATE_VALUE;
+        } else {
+            return input;
+        }
+    }
+
+    @Override
+    protected FieldValue getFieldValue(final String value) {
+        if (StringUtils.isBlank(value)) {
+            return new FieldValue(StringUtils.EMPTY);
+        }
+
+        final Calendar calendar = ISO8601.parse(value);
+        if (calendar != null && 
calendar.getTime().equals(PropertyValueProvider.EMPTY_DATE)) {
+            return new FieldValue(StringUtils.EMPTY);
+        }
+
+        return new FieldValue(value);
     }
 }


=====================================
content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/PrimitiveFieldType.java
=====================================
--- 
a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/PrimitiveFieldType.java
+++ 
b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/PrimitiveFieldType.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Hippo B.V. (http://www.onehippo.com)
+ * Copyright 2017-2018 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.
@@ -186,13 +186,17 @@ public abstract class PrimitiveFieldType extends 
AbstractFieldType {
         return true;
     }
 
-    private static void storeProperty(final Collection<FieldValue> values, 
final Property property) throws RepositoryException {
+    protected FieldValue getFieldValue(final String value) {
+        return new FieldValue(value);
+    }
+
+    private void storeProperty(final Collection<FieldValue> values, final 
Property property) throws RepositoryException {
         if (property.isMultiple()) {
             for (final Value v : property.getValues()) {
-                values.add(new FieldValue(v.getString()));
+                values.add(getFieldValue(v.getString()));
             }
         } else {
-            values.add(new FieldValue(property.getString()));
+            values.add(getFieldValue(property.getString()));
         }
     }
 



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/32da5efb8d063678bc05e1584b45746e2bcd8002

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/32da5efb8d063678bc05e1584b45746e2bcd8002
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