Skip to content

Commit

Permalink
Improved: PicklistStatusHistory doesn't follow history entity status …
Browse files Browse the repository at this point in the history
…pattern

(OFBIZ-11182)
The entity PicklistStatusHistory record each status change realized on picklist.

It can't be convert to entity-auto easily because PicklistStatusHistory's fields pattern
doesn't follow same entities like ShipmentStatus and PartyStatus.

To solve this issue, I deprecate PicklistStatusHistory and move it to OldPicklistStatusHistory
and replace it by new entity PicklistStatus that can use natively with entityauto.

I added a new migration service migrateOldPicklistStatusHistoryToPickListStatus to forward all 
picklist status history to new entity.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1866558 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
nmalin committed Sep 7, 2019
1 parent 70969b2 commit 1e5c621
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
27 changes: 26 additions & 1 deletion applications/datamodel/entitydef/shipment-entitymodel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ under the License.
<key-map field-name="lastModifiedByUserLogin" rel-field-name="userLoginId"/>
</relation>
</entity>
<entity entity-name="PicklistStatusHistory"
<entity entity-name="OldPicklistStatusHistory" table-name="PICKLIST_STATUS_HISTORY"
package-name="org.apache.ofbiz.shipment.picklist"
title="Picklist Status History">
<description>Deprecated since branch release: PicklistStatus instead</description>
<field name="picklistId" type="id"></field>
<field name="changeDate" type="date-time"></field>
<field name="changeUserLoginId" type="id-vlong"></field>
Expand All @@ -338,6 +339,30 @@ under the License.
</relation>
</entity>

<entity entity-name="PicklistStatus"
package-name="org.apache.ofbiz.shipment.picklist"
title="Picklist Status History">
<field name="picklistId" type="id"/>
<field name="statusDate" type="date-time"/>
<field name="changeByUserLoginId" type="id-vlong"/>
<field name="statusId" type="id"/>
<field name="statusIdTo" type="id"/>
<prim-key field="picklistId"/>
<prim-key field="statusDate"/>
<relation type="one" fk-name="PCKLST_STST_PKLT" rel-entity-name="Picklist">
<key-map field-name="picklistId"/>
</relation>
<relation type="one" fk-name="PCKLST_STST_CUL" title="Change" rel-entity-name="UserLogin">
<key-map field-name="changeByUserLoginId" rel-field-name="userLoginId"/>
</relation>
<relation type="one" fk-name="PCKLST_STST_FSI" rel-entity-name="StatusItem">
<key-map field-name="statusId"/>
</relation>
<relation type="one" fk-name="PCKLST_STST_TSI" title="To" rel-entity-name="StatusItem">
<key-map field-name="statusIdTo" rel-field-name="statusId"/>
</relation>
</entity>

<!-- ========================================================= -->
<!-- org.apache.ofbiz.shipment.receipt -->
<!-- ========================================================= -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/

import org.apache.ofbiz.entity.GenericValue

/*
* Migrate all element present on entity OldPicklistStatusHistory to entity PickListStatus
* Update service for Deprecate since: branch release
*/
def migrateOldPicklistStatusHistoryToPickListStatus() {
List<GenericValue> oldPicklistStatusHistories = delegator.findAll("OldPicklistStatusHistory", false)
oldPicklistStatusHistories.each {
GenericValue picklistStatus = makeValue("PicklistStatus")
picklistStatus.statusId = it.statusId
picklistStatus.statusIdTo = it.statusIdTo
picklistStatus.picklistId = it.picklistId
picklistStatus.changeByUserLoginId = it.changeUserLoginId
picklistStatus.statusDate = it.changeDate
picklistStatus.create()
it.remove()
}
return success()
}
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,12 @@ under the License.
</if-empty>
<check-errors/>

<make-value entity-name="PicklistStatusHistory" value-field="newStatusValue"/>
<make-value entity-name="PicklistStatus" value-field="newStatusValue"/>
<set from-field="parameters.picklistId" field="newStatusValue.picklistId"/>
<set from-field="lookedUpValue.statusId" field="newStatusValue.statusId"/>
<set from-field="parameters.statusId" field="newStatusValue.statusIdTo"/>
<now-timestamp field="newStatusValue.changeDate"/>
<set from-field="userLogin.userLoginId" field="newStatusValue.changeUserLoginId"/>
<now-timestamp field="newStatusValue.statusDate"/>
<set from-field="userLogin.userLoginId" field="newStatusValue.changeByUserLoginId"/>
<create-value value-field="newStatusValue"/>
</if-compare-field>
</if-not-empty>
Expand Down Expand Up @@ -1352,7 +1352,7 @@ under the License.
</iterate>

<clear-field field="picklistStatusHistoryInfoList"/>
<get-related value-field="picklist" relation-name="PicklistStatusHistory" list="picklistStatusHistoryList"/>
<get-related value-field="picklist" relation-name="PicklistStatus" list="picklistStatusHistoryList"/>
<iterate list="picklistStatusHistoryList" entry="picklistStatusHistory">
<clear-field field="picklistStatusHistoryInfo"/>
<get-related-one value-field="picklistStatusHistory" relation-name="StatusItem" to-value-field="picklistStatusHistoryInfo.statusItem" use-cache="true"/>
Expand Down
1 change: 1 addition & 0 deletions applications/product/ofbiz-component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ under the License.
<service-resource type="model" loader="main" location="servicedef/services_config.xml"/>
<service-resource type="model" loader="main" location="servicedef/services_cost.xml"/>
<service-resource type="model" loader="main" location="servicedef/services_uom.xml"/>
<service-resource type="model" loader="main" location="servicedef/services_upgrade.xml"/>
<service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
<service-resource type="eca" loader="main" location="servicedef/secas_shipment.xml"/>
<service-resource type="group" loader="main" location="servicedef/groups.xml"/>
Expand Down
9 changes: 9 additions & 0 deletions applications/product/servicedef/services_picklist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ under the License.
<permission-service service-name="facilityPermissionCheck" main-action="DELETE"/>
<auto-attributes include="pk" mode="IN" optional="false"/>
</service>
<service name="createPicklistStatus" default-entity-name="PicklistStatus" engine="entity-auto" invoke="create" auth="true">
<description>Create Picklist status History</description>
<permission-service service-name="facilityPermissionCheck" main-action="CREATE"/>
<auto-attributes include="pk" mode="IN" optional="false"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>
<override name="statusId" optional="false"/>
<override name="statusIdTo" optional="false"/>
<override name="statusDate" optional="true"/>
</service>

<!-- PicklistBin -->
<service name="createPicklistBin" default-entity-name="PicklistBin" engine="simple"
Expand Down
31 changes: 31 additions & 0 deletions applications/product/servicedef/services_upgrade.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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>Migration services on product component</description>
<vendor>OFBiz</vendor>
<version>1.0</version>

<service name="migrateOldPicklistStatusHistoryToPickListStatus" engine="groovy"
location="component://product/groovyScripts/shipment/picklist/PicklistServices.groovy" invoke="migrateOldPicklistStatusHistoryToPickListStatus" auth="true">
<description>Migration service to convert entries from OldPicklistStatusHistory to new Entity PickListStatus</description>
</service>
</services>
4 changes: 2 additions & 2 deletions applications/product/template/facility/PicklistManage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ under the License.
<div style="margin-left: 15px;">
<span class="label">${uiLabelMap.CommonStatus}</span> ${uiLabelMap.CommonChange} ${uiLabelMap.CommonFrom} ${picklistStatusHistoryInfo.statusItem.get("description",locale)}
${uiLabelMap.CommonTo} ${picklistStatusHistoryInfo.statusItemTo.description}
${uiLabelMap.CommonOn} ${picklistStatusHistoryInfo.picklistStatusHistory.changeDate}
${uiLabelMap.CommonBy} ${picklistStatusHistoryInfo.picklistStatusHistory.changeUserLoginId}
${uiLabelMap.CommonOn} ${picklistStatusHistoryInfo.picklistStatusHistory.statusDate}
${uiLabelMap.CommonBy} ${picklistStatusHistoryInfo.picklistStatusHistory.changeByUserLoginId}
</div>
</#list>
<hr />
Expand Down

0 comments on commit 1e5c621

Please sign in to comment.