From a98d91d5da93f6fe4eab5cbc721937c3c884491c Mon Sep 17 00:00:00 2001 From: Marco Risaliti Date: Sat, 20 Sep 2008 21:26:16 +0000 Subject: [PATCH] Convert a bsh script to groovy. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@697423 13f79535-47bb-0310-9956-ffa450edef68 --- .../{editMaint.bsh => EditMaint.groovy} | 19 ++--- .../assetmaint/PrintFixedAssetMaint.groovy | 71 ++++++++++++++++ .../assetmaint/printFixedAssetMaint.bsh | 73 ---------------- .../actions/workeffort/EditWorkEfforts.bsh | 84 ------------------- .../actions/workeffort/EditWorkEfforts.groovy | 84 +++++++++++++++++++ assetmaint/widget/AssetmaintScreens.xml | 6 +- 6 files changed, 167 insertions(+), 170 deletions(-) rename assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/{editMaint.bsh => EditMaint.groovy} (65%) create mode 100644 assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/PrintFixedAssetMaint.groovy delete mode 100644 assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/printFixedAssetMaint.bsh delete mode 100644 assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.bsh create mode 100644 assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.groovy diff --git a/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/editMaint.bsh b/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/EditMaint.groovy similarity index 65% rename from assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/editMaint.bsh rename to assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/EditMaint.groovy index 8b6780269..e33cfd2e1 100644 --- a/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/editMaint.bsh +++ b/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/EditMaint.groovy @@ -17,22 +17,21 @@ * under the License. */ -import org.ofbiz.base.util.*; import org.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; import org.ofbiz.entity.util.*; // This is a small script to set things up when the EditFixedAssetMaint // screen is called from one of the WorkEffort calendar screens. // The URL coming from WorkEffort does not contain the maintHistSeqId parameter, // so this script will look it up using the workEffortId parameter. +maintHistSeqId = parameters.maintHistSeqId; +workEffortId = parameters.workEffortId; -String maintHistSeqId = parameters.get("maintHistSeqId"); -String workEffortId = parameters.get("workEffortId"); - -if (UtilValidate.isEmpty(maintHistSeqId) && UtilValidate.isNotEmpty(workEffortId)) { - GenericValue fixedAssetMaint = EntityUtil.getFirst(delegator.findByAnd("FixedAssetMaint", UtilMisc.toMap("scheduleWorkEffortId", workEffortId))); - if (fixedAssetMaint != null) { - parameters.put("fixedAssetId", fixedAssetMaint.get("fixedAssetId")); - parameters.put("maintHistSeqId", fixedAssetMaint.get("maintHistSeqId")); +if (!maintHistSeqId && workEffortId) { + fixedAssetMaint = EntityUtil.getFirst(delegator.findList("FixedAssetMaint", EntityCondition.makeCondition([scheduleWorkEffortId : workEffortId]), null, null, null, false)); + if (fixedAssetMaint) { + parameters.fixedAssetId = fixedAssetMaint.fixedAssetId; + parameters.maintHistSeqId = fixedAssetMaint.maintHistSeqId; } -} +} \ No newline at end of file diff --git a/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/PrintFixedAssetMaint.groovy b/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/PrintFixedAssetMaint.groovy new file mode 100644 index 000000000..5641b8d96 --- /dev/null +++ b/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/PrintFixedAssetMaint.groovy @@ -0,0 +1,71 @@ +/** +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.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; + +facility = fixedAsset.getRelatedOne("LocatedAtFacility"); +context.locatedAtFacility = facility; + +fixedAssetIdents = delegator.findList("FixedAssetIdent", EntityCondition.makeCondition([fixedAssetId : fixedAssetId]), null, null, null, false); +fixedAssetIdentValue = ""; +if (fixedAssetIdents) { + fixedAssetIdents.each { ident -> + fixedAssetIdentValue = fixedAssetIdentValue + " " + ident.idValue; + } +} +context.fixedAssetIdentValue = fixedAssetIdentValue; + +status = fixedAssetMaint.getRelatedOne("StatusItem"); +if (status) { + context.statusItemDesc = status.description; +} +//context.put("fixedAssetMaint",fixedAssetMaint); + +intervalUom = fixedAssetMaint.getRelatedOne("IntervalUom"); +if (intervalUom) { + context.intervalUomDesc = intervalUom.description; +} + +instanceOfProductId = fixedAsset.instanceOfProductId; +productMaintSeqId = fixedAssetMaint.productMaintSeqId; +if (productMaintSeqId) { + productMaint = delegator.findOne("ProductMaint", [productId : instanceOfProductId, productMaintSeqId : productMaintSeqId], false); + context.productMaintName = productMaint.maintName; +} + +productMaintTypeId = fixedAssetMaint.productMaintTypeId; +if (productMaintTypeId) { + productMaintType = delegator.findOne("ProductMaintType", [productMaintTypeId : productMaintTypeId], false); + if (productMaintType) { + productMaintTypeDesc = productMaintType.description; + context.productMaintTypeDesc = productMaintTypeDesc; + } +} + +intervalMeterTypeId = fixedAssetMaint.intervalMeterTypeId; +productMeterTypeDesc = ""; +if (intervalMeterTypeId) { + productMeterType = delegator.findOne("ProductMeterType", [productMeterTypeId : intervalMeterTypeId], false); + productMeterTypeDesc = productMeterType.description; +} +context.productMeterTypeDesc = productMeterTypeDesc; + +scheduleWorkEffort = fixedAssetMaint.getRelatedOne("ScheduleWorkEffort"); +context.scheduleWorkEffort = scheduleWorkEffort; \ No newline at end of file diff --git a/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/printFixedAssetMaint.bsh b/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/printFixedAssetMaint.bsh deleted file mode 100644 index 4583590d2..000000000 --- a/assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/printFixedAssetMaint.bsh +++ /dev/null @@ -1,73 +0,0 @@ -/** -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.ofbiz.base.util.UtilMisc; - - -facility = fixedAsset.getRelatedOne("LocatedAtFacility"); -context.put("locatedAtFacility", facility); - -List fixedAssetIdents = delegator.findByAnd("FixedAssetIdent", UtilMisc.toMap("fixedAssetId",fixedAssetId)); -fixedAssetIdentValue = ""; -if (fixedAssetIdents !=null) { - iter = fixedAssetIdents.iterator(); - while (iter.hasNext()) { - ident = iter.next(); - fixedAssetIdentValue = fixedAssetIdentValue + " " + ident.get("idValue"); - } -} -context.put("fixedAssetIdentValue",fixedAssetIdentValue); - -status = fixedAssetMaint.getRelatedOne("StatusItem"); -if (status !=null) { - context.put("statusItemDesc",status.getString("description")); -} -//context.put("fixedAssetMaint",fixedAssetMaint); - -intervalUom = fixedAssetMaint.getRelatedOne("IntervalUom"); -if (intervalUom!=null) { - context.put("intervalUomDesc",intervalUom.getString("description")); -} - -instanceOfProductId = fixedAsset.get("instanceOfProductId"); -productMaintSeqId = fixedAssetMaint.get("productMaintSeqId"); -if (productMaintSeqId != null && !productMaintSeqId.equals("")) { - productMaint = delegator.findByPrimaryKey("ProductMaint", UtilMisc.toMap("productId", instanceOfProductId,"productMaintSeqId",productMaintSeqId)); - context.put("productMaintName",productMaint.get("maintName")); -} - -productMaintTypeId = fixedAssetMaint.get("productMaintTypeId"); -if (productMaintTypeId!= null && !productMaintTypeId.equals("")) { - productMaintType = delegator.findByPrimaryKey("ProductMaintType", UtilMisc.toMap("productMaintTypeId", productMaintTypeId)); - if (productMaintType != null) { - productMaintTypeDesc = productMaintType.get("description"); - context.put("productMaintTypeDesc",productMaintTypeDesc); - } -} - -intervalMeterTypeId = fixedAssetMaint.get("intervalMeterTypeId"); -productMeterTypeDesc = ""; -if (intervalMeterTypeId!= null && !intervalMeterTypeId.equals("")) { - productMeterType = delegator.findByPrimaryKey("ProductMeterType", UtilMisc.toMap("productMeterTypeId", intervalMeterTypeId)); - productMeterTypeDesc = productMeterType.get("description"); -} -context.put("productMeterTypeDesc",productMeterTypeDesc); - -scheduleWorkEffort = fixedAssetMaint.getRelatedOne("ScheduleWorkEffort"); -context.put("scheduleWorkEffort",scheduleWorkEffort); diff --git a/assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.bsh b/assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.bsh deleted file mode 100644 index 25a997d8b..000000000 --- a/assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.bsh +++ /dev/null @@ -1,84 +0,0 @@ -/* - 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 java.util.*; - -import org.ofbiz.base.util.*; -import org.ofbiz.entity.*; -import org.ofbiz.entity.condition.*; -import org.ofbiz.entity.util.*; - -maintHistSeqId = context.get("maintHistSeqId"); -fixedAssetId = context.get("fixedAssetId"); -workEffortId = context.get("workEffortId"); - -if (maintHistSeqId == null) { - maintHistSeqId = parameters.get("maintHistSeqId"); -} -if (fixedAssetId == null) { - fixedAssetId = parameters.get("fixedAssetId"); -} -if (workEffortId == null) { - workEffortId = parameters.get("workEffortId"); -} - -fixedAssetMaint = null; -workEffort = null; -fixedAsset = null; -rootWorkEffortId = null; - -if (workEffortId != null) { - workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId)); - if (workEffort != null) { - if (fixedAssetId == null) { - fixedAssetId = workEffort.get("fixedAssetId"); - } - // If this is a child workeffort, locate the "root" workeffort - parentWorkEffort = EntityUtil.getFirst(delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdTo", workEffortId))); - while (parentWorkEffort != null) { - rootWorkEffortId = parentWorkEffort.get("workEffortIdFrom"); - parentWorkEffort = EntityUtil.getFirst(delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdTo", rootWorkEffortId))); - } - } -} - -if (rootWorkEffortId == null) { - rootWorkEffortId = workEffortId; -} - -if (rootWorkEffortId != null) { - fixedAssetMaint = EntityUtil.getFirst(delegator.findByAnd("FixedAssetMaint", UtilMisc.toMap("scheduleWorkEffortId", rootWorkEffortId))); - if (fixedAssetMaint != null) { - maintHistSeqId = fixedAssetMaint.get("maintHistSeqId"); - if (fixedAssetId == null) { - fixedAssetId = fixedAssetMaint.get("fixedAssetId"); - } - } -} - -if (fixedAssetId != null) { - fixedAsset = delegator.findByPrimaryKey("FixedAsset", UtilMisc.toMap("fixedAssetId", fixedAssetId)); -} - -context.put("fixedAssetMaint", fixedAssetMaint); -context.put("workEffort", workEffort); -context.put("fixedAsset", fixedAsset); -context.put("maintHistSeqId", maintHistSeqId); -context.put("fixedAssetId", fixedAssetId); -context.put("workEffortId", workEffortId); diff --git a/assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.groovy b/assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.groovy new file mode 100644 index 000000000..65650ab7e --- /dev/null +++ b/assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.groovy @@ -0,0 +1,84 @@ +/* + 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 java.util.*; + +import org.ofbiz.base.util.*; +import org.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; +import org.ofbiz.entity.util.*; + +maintHistSeqId = context.maintHistSeqId; +fixedAssetId = context.fixedAssetId; +workEffortId = context.workEffortId; + +if (!maintHistSeqId) { + maintHistSeqId = parameters.maintHistSeqId; +} +if (!fixedAssetId) { + fixedAssetId = parameters.fixedAssetId; +} +if (!workEffortId) { + workEffortId = parameters.workEffortId; +} + +fixedAssetMaint = null; +workEffort = null; +fixedAsset = null; +rootWorkEffortId = null; + +if (workEffortId) { + workEffort = delegator.findOne("WorkEffort", [workEffortId : workEffortId], false); + if (workEffort) { + if (!fixedAssetId) { + fixedAssetId = workEffort.fixedAssetId; + } + // If this is a child workeffort, locate the "root" workeffort + parentWorkEffort = EntityUtil.getFirst(delegator.findList("WorkEffortAssoc", EntityCondition.makeCondition([workEffortIdTo : workEffortId]), null, null, null, false)); + while (parentWorkEffort) { + rootWorkEffortId = parentWorkEffort.workEffortIdFrom; + parentWorkEffort = EntityUtil.getFirst(delegator.findList("WorkEffortAssoc", EntityCondition.makeCondition([workEffortIdTo : rootWorkEffortId]), null, null, null, false)); + } + } +} + +if (!rootWorkEffortId) { + rootWorkEffortId = workEffortId; +} + +if (rootWorkEffortId) { + fixedAssetMaint = EntityUtil.getFirst(delegator.findList("FixedAssetMaint", EntityCondition.makeCondition([scheduleWorkEffortId : rootWorkEffortId]), null, null, null, false)); + if (fixedAssetMaint) { + maintHistSeqId = fixedAssetMaint.maintHistSeqId; + if (!fixedAssetId) { + fixedAssetId = fixedAssetMaint.fixedAssetId; + } + } +} + +if (fixedAssetId) { + fixedAsset = delegator.findOne("FixedAsset", [fixedAssetId : fixedAssetId], false); +} + +context.fixedAssetMaint = fixedAssetMaint; +context.workEffort = workEffort; +context.fixedAsset = fixedAsset; +context.maintHistSeqId = maintHistSeqId; +context.fixedAssetId = fixedAssetId; +context.workEffortId = workEffortId; \ No newline at end of file diff --git a/assetmaint/widget/AssetmaintScreens.xml b/assetmaint/widget/AssetmaintScreens.xml index 69fb0bc69..6797866d1 100644 --- a/assetmaint/widget/AssetmaintScreens.xml +++ b/assetmaint/widget/AssetmaintScreens.xml @@ -92,7 +92,7 @@
-