Commits

Christian Junk committed 087ba08

Fixed bug which was preventing update of properties.

Comments (0)

Files changed (6)

Propertyset-grailsPlugins.iml

     <content url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/hibernate-2.1.1">
       <sourceFolder url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/hibernate-2.1.1/grails-app/i18n" isTestSource="false" />
     </content>
-    <content url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/release-2.0.3">
-      <sourceFolder url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/release-2.0.3/src/java" isTestSource="false" />
-      <sourceFolder url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/release-2.0.3/src/groovy" isTestSource="false" />
+    <content url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/release-2.0.4">
+      <sourceFolder url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/release-2.0.4/src/java" isTestSource="false" />
+      <sourceFolder url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/release-2.0.4/src/groovy" isTestSource="false" />
     </content>
     <content url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/rest-client-builder-1.0.2">
       <sourceFolder url="file://$USER_HOME$/.grails/2.1.1/projects/propertyset/plugins/rest-client-builder-1.0.2/src/groovy" isTestSource="false" />

PropertysetGrailsPlugin.groovy

 class PropertysetGrailsPlugin {
     // the plugin version
-    def version = "1.0.1"
+    def version = "1.0.7"
     // the version or versions of Grails the plugin is designed for
     def grailsVersion = "2.1 > *"
     // the other plugins this plugin depends on

grails-app/domain/com/opensymphony/module/propertyset/PropertyNumber.groovy

 
 class PropertyNumber {
 
-    static belongsTo = [propertyEntry : PropertyEntry]
+    PropertyEntry propertyEntry
 
     Long propertyValue
 
-<plugin name='propertyset' version='1.0.1' grailsVersion='2.1 &gt; *'>
+<plugin name='propertyset' version='1.0.7' grailsVersion='2.1 &gt; *'>
   <author>Christian Junk</author>
   <authorEmail>christian@christianjunk.de</authorEmail>
   <title>Propertyset Plugin</title>
   </repositories>
   <dependencies>
     <runtime>
+      <dependency group='org.apache.xmlbeans' name='xmlbeans' version='2.3.0' />
       <dependency group='org.grails.plugins' name='cloud-support' version='1.0.8' />
-      <dependency group='org.apache.xmlbeans' name='xmlbeans' version='2.3.0' />
     </runtime>
   </dependencies>
   <plugins />

src/groovy/com/opensymphony/module/propertyset/gorm/GroovyPropertySet.groovy

         switch (type)
         {
             case BOOLEAN:
-                def numberVal = new PropertyNumber()
-                numberVal.setPropertyValue( ((Boolean) value).booleanValue() ? 1 : 0 )
-                item.setNumberVal(  numberVal )
+                PropertyNumber propertyNumber = item.getNumberVal()
 
+                if (propertyNumber == null) {
+                    def numberVal = new PropertyNumber()
+                    numberVal.setPropertyValue( ((Boolean) value).booleanValue() ? 1 : 0 )
+                    item.setNumberVal( numberVal )
+                }
+                else {
+                    propertyNumber.setPropertyValue( ((Boolean) value).booleanValue() ? 1 : 0 )
+                }
                 break;
 
             case DOUBLE:
-                def decimalVal = new PropertyDecimal()
-                decimalVal.setPropertyValue( ((Double) value).doubleValue() )
-                item.setDecimalVal( decimalVal )
+                PropertyDecimal propertyDecimal = item.getDecimalVal()
 
+                if (propertyDecimal == null) {
+                    def decimalVal = new PropertyDecimal()
+                    decimalVal.setPropertyValue( ((Double) value).doubleValue() )
+                    item.setDecimalVal( decimalVal )
+                }
+                else {
+                    propertyDecimal.setPropertyValue( ((Double) value).doubleValue() )
+                }
                 break;
 
             case STRING:
-                def stringVal = new PropertyString()
-                stringVal.setPropertyValue( (String) value )
-                item.setStringVal( stringVal )
+                PropertyString propertyString = item.getStringVal()
+
+                if (propertyString == null) {
+                    def stringVal = new PropertyString()
+                    stringVal.setPropertyValue( (String) value )
+                    item.setStringVal( stringVal )
+                }
+                else {
+                    propertyString.setPropertyValue( (String) value )
+                }
                 break;
 
             case TEXT:
+                PropertyText propertyText = item.getTextVal()
 
-                def textVal = new PropertyText()
-                textVal.setPropertyValue( (String) value )
-                item.setTextVal( textVal )
-
+                if (propertyText == null) {
+                    def textVal = new PropertyText()
+                    textVal.setPropertyValue( (String) value )
+                    item.setTextVal( textVal )
+                }
+                else {
+                    propertyText.setPropertyValue( (String) value )
+                }
                 break;
 
             case LONG:
-                def numberVal = new PropertyNumber()
-                numberVal.setPropertyValue( ((Long) value).longValue() )
-                item.setNumberVal(  numberVal )
 
+                PropertyNumber propertyNumber = item.numberVal
+
+                if (propertyNumber == null) {
+                    def numberVal = new PropertyNumber()
+                    numberVal.setPropertyValue( ((Long) value).longValue() )
+                    item.setNumberVal(  numberVal )
+                }
+                else {
+                    propertyNumber.setPropertyValue( ((Long) value).longValue() )
+                }
                 break;
 
             case INT:
-                def numberVal = new PropertyNumber()
-                numberVal.setPropertyValue( ((Integer) value).intValue() )
-                item.setNumberVal(  numberVal )
+                PropertyNumber propertyNumber = item.numberVal
 
+                if (propertyNumber == null) {
+                    def numberVal = new PropertyNumber()
+                    numberVal.setPropertyValue( ((Long) value).longValue() )
+                    item.setNumberVal(  numberVal )
+                }
+                else {
+                    propertyNumber.setPropertyValue( ((Long) value).longValue() )
+                }
                 break;
 
             case DATE:
-                def dateVal = new PropertyDate()
-                dateVal.setPropertyValue( (Date) value )
-                item.setDateVal( dateVal )
+                PropertyDate propertyDate = item.dateVal
 
+                if (propertyDate == null) {
+                    def dateVal = new PropertyDate()
+                    dateVal.setPropertyValue( (Date) value )
+                    item.setDateVal( dateVal )
+                }
+                else {
+                    propertyDate.setPropertyValue( (Date) value )
+                }
                 break;
 
             default:
 
         item.setPropertyType(type);
 
-        item.save(failOnError: true)
+        item.save(failOnError: true, flush: true)
     }
 
     @Override
                 return  item.getNumberVal().getPropertyValue().intValue()
 
             case DATE:
-                return item.getDateVal();
+                return item.getDateVal().getPropertyValue();
         }
 
         throw new PropertyException("type " + type + " not supported");
 
     void remove(String key) {
         def item =  PropertyEntry.findByEntityIdAndEntityNameAndPropertyKey(entityId, entityName, key)
-        item.delete( flush: true )
+        item.delete( failOnError: true, flush: true )
     }
 
     void remove() {

test/integration/com/opensymphony/module/propertyset/PropertyEntryTests.groovy

 import org.junit.Before
 import org.junit.Test
 import org.codehaus.groovy.grails.compiler.injection.GrailsAwareClassLoader
+import com.opensymphony.module.propertyset.gorm.GroovyPropertySet
 
-class PropertyEntryTests {
+class PropertyEntryTests extends GroovyTestCase {
+
+    static transactional = false
 
     @Before
     void setUp() {
         PropertySet ps = PropertySetManager.getInstance("gorm", args, new GrailsAwareClassLoader(getClass().getClassLoader()))
         ps.setInt( "proxy", 8080 )
     }
+
+    @Test
+    void testMe() {
+        def args = [entityId:2, entityName:"propertyset.test"]
+        PropertySet grailsPropertySet = new GroovyPropertySet();
+        grailsPropertySet.init(new HashMap(), args);
+        grailsPropertySet.setDate("test", new Date())
+    }
 }