svn commit: r1864215 - in /ofbiz/ofbiz-framework/trunk/applications/party: servicedef/services_upgrade.xml src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1864215 - in /ofbiz/ofbiz-framework/trunk/applications/party: servicedef/services_upgrade.xml src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java

Pawan Verma-2
Author: pawan
Date: Fri Aug  2 10:36:33 2019
New Revision: 1864215

URL: http://svn.apache.org/viewvc?rev=1864215&view=rev
Log:
[Implemented]: Provide a service for moving data for marital status field (from boolean to enum)
[OFBIZ-10977]
Migrate Person's marital status from indicator to enumeration
Since revision 1858261(27 April 2019) field oldMaritalStatus of Person has been deprecated.
This service can be used to upgrade existing data of oldMaritalStatus field to the new maritalStatusEnumId
field of Person Entity.
[Thanks]: Suraj Khurana for your contribution and Jacques Le Roux for the review.

Added:
    ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml   (with props)
    ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java   (with props)

Added: ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml?rev=1864215&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml (added)
+++ ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml Fri Aug  2 10:36:33 2019
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/services.xsd">
+    <description>Party Component Services</description>
+    <vendor>OFBiz</vendor>
+    <version>1.0</version>
+
+
+    <service name="migrateMaritalStatusFromIndicatorToEnum" engine="java"
+         location="org.apache.ofbiz.party.party.UpgradeServices" invoke="migrateMaritalStatusFromIndicatorToEnum">
+        <description>
+            Migrate Person's marital status from indicator to enumeration
+            Since revision 1858261(27 April 2019) field oldMaritalStatus of Person has been deprecated.
+            This service can be used to upgrade existing data of oldMaritalStatus field to the new maritalStatusEnumId
+            field of Person Entity.
+        </description>
+    </service>
+</services>

Propchange: ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/applications/party/servicedef/services_upgrade.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java?rev=1864215&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java (added)
+++ ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java Fri Aug  2 10:36:33 2019
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.ofbiz.party.party;
+
+import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericEntityException;
+import org.apache.ofbiz.entity.GenericValue;
+import org.apache.ofbiz.entity.condition.EntityCondition;
+import org.apache.ofbiz.entity.condition.EntityOperator;
+import org.apache.ofbiz.entity.util.EntityQuery;
+import org.apache.ofbiz.service.DispatchContext;
+import org.apache.ofbiz.service.ServiceUtil;
+
+import java.util.List;
+import java.util.Map;
+
+public class UpgradeServices {
+
+    public static final String module = UpgradeServices.class.getName();
+
+    public static Map<String, Object> migrateMaritalStatusFromIndicatorToEnum(DispatchContext dctx, Map<String, Object> context) {
+        Delegator delegator = dctx.getDelegator();
+        try {
+            List<GenericValue> persons = EntityQuery.use(delegator).from("Person")
+                    .where(EntityCondition.makeCondition("oldMaritalStatus", EntityOperator.NOT_EQUAL, null)).queryList();
+            for (GenericValue person : persons) {
+                person.put("maritalStatusEnumId", "Y".equalsIgnoreCase(person.getString("oldMaritalStatus")) ? "MARRIED" : "SINGLE");
+                person.store();
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+}

Propchange: ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/party/UpgradeServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain