Convert a bsh script to groovy.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@697423 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Marco Risaliti
2008-09-20 21:26:16 +00:00
parent d890f62312
commit a98d91d5da
6 changed files with 167 additions and 170 deletions
@@ -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;
}
}
}
@@ -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;
@@ -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);
@@ -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);
@@ -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;
+3 -3
View File
@@ -92,7 +92,7 @@
<section>
<actions>
<set field="titleProperty" value="PageTitleEditFixedAssetMaintenance"/>
<script location="component://assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/editMaint.bsh"/>
<script location="component://assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/EditMaint.groovy"/>
<set field="fixedAssetId" from-field="parameters.fixedAssetId"/>
<set field="maintHistSeqId" from-field="parameters.maintHistSeqId"/>
<entity-one entity-name="FixedAsset" value-name="fixedAsset"/>
@@ -138,7 +138,7 @@
<actions>
<set field="titleProperty" value="PageTitleEditWorkEffort"/>
<set field="tabButtonItemFixedAssetMaint" value="EditWorkEfforts"/>
<script location="component://assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.bsh"/>
<script location="component://assetmaint/webapp/assetmaint/WEB-INF/actions/workeffort/EditWorkEfforts.groovy"/>
<set field="fixedAssetId" from-field="parameters.fixedAssetId"/>
</actions>
<widgets>
@@ -307,7 +307,7 @@
<condition-expr field-name="workEffortId" env-name="workEffortId"/>
<order-by field-name="noteId"/>
</entity-condition>
<script location="component://assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/printFixedAssetMaint.bsh"/>
<script location="component://assetmaint/webapp/assetmaint/WEB-INF/actions/assetmaint/PrintFixedAssetMaint.groovy"/>
</actions>
<widgets>
<decorator-screen name="GlobalFoDecorator" location="component://common/widget/CommonScreens.xml">