From 18894e6dc0fa7cba5dcd3dd93a23bdcaa5a61785 Mon Sep 17 00:00:00 2001 From: Deepak Dixit Date: Tue, 16 May 2017 17:36:32 +0000 Subject: [PATCH] Improved: Inconsistent String Comparisons, Applied plugins groovy patch from jira issue. (OFBIZ-9254) I found an inconsistency in the code for string comparison statusId.equals("PRUN_COMPLETED") whereas it should be written as "PRUN_COMPLETED".equals(statusId) cause the former can throw NullPointerException if the variable found to be NULL. Thanks Devanshu Vyas for your contribution. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk@1795344 13f79535-47bb-0310-9956-ffa450edef68 --- .../catalog/MiniProductSummary.groovy | 4 +- .../groovyScripts/forum/HtmlAreaPrep.groovy | 2 +- ecommerce/groovyScripts/forum/PermPrep.groovy | 2 +- .../groovyScripts/order/BillSettings.groovy | 2 +- .../groovyScripts/order/OrderStatus.groovy | 2 +- .../order/PaymentInformation.groovy | 2 +- .../order/QuickAnonCustSettings.groovy | 2 +- .../groovyScripts/order/ShipSettings.groovy | 2 +- .../groovyScripts/EditWeekTimesheet.groovy | 16 ++--- projectmgr/groovyScripts/GanttChart.groovy | 4 +- .../groovyScripts/ProjectBilling.groovy | 2 +- .../groovyScripts/ProjectIsBillable.groovy | 4 +- .../groovyScripts/AddResourceTaskParty.groovy | 2 +- .../groovyScripts/EditDailyHourReport.groovy | 60 +++++++++---------- scrum/groovyScripts/EditWeekTimesheet.groovy | 16 ++--- scrum/groovyScripts/ProductBilling.groovy | 2 +- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/ecommerce/groovyScripts/catalog/MiniProductSummary.groovy b/ecommerce/groovyScripts/catalog/MiniProductSummary.groovy index 45a61c1b2..1eb069cb0 100644 --- a/ecommerce/groovyScripts/catalog/MiniProductSummary.groovy +++ b/ecommerce/groovyScripts/catalog/MiniProductSummary.groovy @@ -55,7 +55,7 @@ if (miniProduct && productStoreId && prodCatalogId ) { // returns: isSale, price, orderItemPriceInfos context.priceResult = priceResult // Check if Price has to be displayed with tax - if (productStore.get("showPricesWithVatTax").equals("Y")) { + if ("Y".equals(productStore.get("showPricesWithVatTax"))) { Map priceMap = runService('calcTaxForDisplay', ["basePrice": priceResult.get("price"), "locale": locale, "productId": optProductId, "productStoreId": productStoreId]) context.price = priceMap.get("priceWithTax") } else { @@ -68,7 +68,7 @@ if (miniProduct && productStoreId && prodCatalogId ) { if (configWrapper) { configWrapper.setDefaultConfig() // Check if Config Price has to be displayed with tax - if (productStore.get("showPricesWithVatTax").equals("Y")) { + if ("Y".equals(productStore.get("showPricesWithVatTax"))) { BigDecimal totalPriceNoTax = configWrapper.getTotalPrice() Map totalPriceMap = runService('calcTaxForDisplay', ["basePrice": totalPriceNoTax, "locale": locale, "productId": optProductId, "productStoreId": productStoreId]) context.totalPrice = totalPriceMap.get("priceWithTax") diff --git a/ecommerce/groovyScripts/forum/HtmlAreaPrep.groovy b/ecommerce/groovyScripts/forum/HtmlAreaPrep.groovy index 4be9ac6d2..7d736ea45 100644 --- a/ecommerce/groovyScripts/forum/HtmlAreaPrep.groovy +++ b/ecommerce/groovyScripts/forum/HtmlAreaPrep.groovy @@ -36,6 +36,6 @@ import javax.servlet.http.* contentIdTo = parameters.contentIdTo -if (!contentIdTo || !contentIdTo.equals("TEMPLATE_MASTER")) { +if (!contentIdTo || !"TEMPLATE_MASTER".equals(contentIdTo)) { context.dynamicPrimaryHTMLField = "textData" } diff --git a/ecommerce/groovyScripts/forum/PermPrep.groovy b/ecommerce/groovyScripts/forum/PermPrep.groovy index 3b2cf4207..5ffdb1afc 100644 --- a/ecommerce/groovyScripts/forum/PermPrep.groovy +++ b/ecommerce/groovyScripts/forum/PermPrep.groovy @@ -69,7 +69,7 @@ if ("add".equals(mode)) { } } -if (permissionType.equals("complex")) { +if ("complex".equals(permissionType)) { mapIn = [:] mapIn.userLogin = userLogin targetOperationList = StringUtil.split(targetOperation, "|") diff --git a/ecommerce/groovyScripts/order/BillSettings.groovy b/ecommerce/groovyScripts/order/BillSettings.groovy index 57fa17a8c..b286dae07 100644 --- a/ecommerce/groovyScripts/order/BillSettings.groovy +++ b/ecommerce/groovyScripts/order/BillSettings.groovy @@ -39,7 +39,7 @@ context.partyId = partyId // nuke the event messages request.removeAttribute("_EVENT_MESSAGE_") -if (partyId && !partyId.equals("_NA_")) { +if (partyId && !"_NA_".equals(partyId)) { party = from("Party").where("partyId", partyId).queryOne() person = party.getRelatedOne("Person", false) context.party = party diff --git a/ecommerce/groovyScripts/order/OrderStatus.groovy b/ecommerce/groovyScripts/order/OrderStatus.groovy index f6c183013..d41f014cb 100644 --- a/ecommerce/groovyScripts/order/OrderStatus.groovy +++ b/ecommerce/groovyScripts/order/OrderStatus.groovy @@ -176,7 +176,7 @@ if (orderHeader) { ritems = oitem.getRelated("ReturnItem", null, null, false) ritems.each { ritem -> rh = ritem.getRelatedOne("ReturnHeader", false) - if (!rh.statusId.equals("RETURN_CANCELLED")) { + if (!"RETURN_CANCELLED".equals(rh.statusId)) { returned += ritem.returnQuantity } } diff --git a/ecommerce/groovyScripts/order/PaymentInformation.groovy b/ecommerce/groovyScripts/order/PaymentInformation.groovy index 25cbc48cc..35c5831f7 100644 --- a/ecommerce/groovyScripts/order/PaymentInformation.groovy +++ b/ecommerce/groovyScripts/order/PaymentInformation.groovy @@ -35,7 +35,7 @@ if (!partyId) { } context.partyId = partyId -if (partyId && !partyId.equals("_NA_")) { +if (partyId && !"_NA_".equals(partyId)) { party = from("Party").where("partyId", partyId).queryOne() person = party.getRelatedOne("Person", false) context.party = party diff --git a/ecommerce/groovyScripts/order/QuickAnonCustSettings.groovy b/ecommerce/groovyScripts/order/QuickAnonCustSettings.groovy index a8e97bfd8..dfda3f820 100644 --- a/ecommerce/groovyScripts/order/QuickAnonCustSettings.groovy +++ b/ecommerce/groovyScripts/order/QuickAnonCustSettings.groovy @@ -89,7 +89,7 @@ context.cart = cart // nuke the event messages request.removeAttribute("_EVENT_MESSAGE_") -if (cartPartyId && !cartPartyId.equals("_NA_")) { +if (cartPartyId && !"_NA_".equals(cartPartyId)) { cartParty = from("Party").where("partyId", cartPartyId).queryOne() if (cartParty) { cartPerson = cartParty.getRelatedOne("Person", false) diff --git a/ecommerce/groovyScripts/order/ShipSettings.groovy b/ecommerce/groovyScripts/order/ShipSettings.groovy index 7a8d96f24..f5db109eb 100644 --- a/ecommerce/groovyScripts/order/ShipSettings.groovy +++ b/ecommerce/groovyScripts/order/ShipSettings.groovy @@ -31,7 +31,7 @@ context.cart = cart // nuke the event messages request.removeAttribute("_EVENT_MESSAGE_") -if (partyId && !partyId.equals("_NA_")) { +if (partyId && !"_NA_".equals(partyId)) { party = from("Party").where("partyId", partyId).queryOne() person = party.getRelatedOne("Person", false) context.party = party diff --git a/projectmgr/groovyScripts/EditWeekTimesheet.groovy b/projectmgr/groovyScripts/EditWeekTimesheet.groovy index 74c2f18b9..bd1b54793 100644 --- a/projectmgr/groovyScripts/EditWeekTimesheet.groovy +++ b/projectmgr/groovyScripts/EditWeekTimesheet.groovy @@ -145,13 +145,13 @@ while (te.hasNext()) { dayNumber = "d" + (timeEntry.fromDate.getTime() - timesheet.fromDate.getTime()) / (24*60*60*1000) hours = timeEntry.hours.doubleValue() entry.put(String.valueOf(dayNumber), hours) - if (dayNumber.equals("d0")) day0Total += hours - if (dayNumber.equals("d1")) day1Total += hours - if (dayNumber.equals("d2")) day2Total += hours - if (dayNumber.equals("d3")) day3Total += hours - if (dayNumber.equals("d4")) day4Total += hours - if (dayNumber.equals("d5")) day5Total += hours - if (dayNumber.equals("d6")) day6Total += hours + if ("d0".equals(dayNumber)) day0Total += hours + if ("d1".equals(dayNumber)) day1Total += hours + if ("d2".equals(dayNumber)) day2Total += hours + if ("d3".equals(dayNumber)) day3Total += hours + if ("d4".equals(dayNumber)) day4Total += hours + if ("d5".equals(dayNumber)) day5Total += hours + if ("d6".equals(dayNumber)) day6Total += hours taskTotal += hours } entry.rateTypeId = timeEntry.rateTypeId @@ -163,7 +163,7 @@ if (timeEntry) { } // add empty lines if timesheet not completed -if (!timesheet.statusId.equals("TIMESHEET_COMPLETED")) { +if (!"TIMESHEET_COMPLETED".equals(timesheet.statusId)) { for (c=0; c < 3; c++) { // add empty lines entries.add(["timesheetId" : timesheet.timesheetId]) } diff --git a/projectmgr/groovyScripts/GanttChart.groovy b/projectmgr/groovyScripts/GanttChart.groovy index a58362611..24a8a85b4 100644 --- a/projectmgr/groovyScripts/GanttChart.groovy +++ b/projectmgr/groovyScripts/GanttChart.groovy @@ -73,13 +73,13 @@ if (phases) { taskInfo = resultTaskInfo.taskInfo taskInfo.taskNr = task.workEffortId taskInfo.phaseNr = phase.phaseId - if (taskInfo.plannedHours && !taskInfo.currentStatusId.equals("PTS_COMPLETED") && taskInfo.plannedHours > taskInfo.actualHours) { + if (taskInfo.plannedHours && !"PTS_COMPLETED".equals(taskInfo.currentStatusId) && taskInfo.plannedHours > taskInfo.actualHours) { taskInfo.resource = taskInfo.plannedHours + " Hrs" } else { taskInfo.resource = taskInfo.actualHours + " Hrs" } Double duration = resultTaskInfo.plannedHours - if (taskInfo.currentStatusId.equals("PTS_COMPLETED")) { + if ("PTS_COMPLETED".equals(taskInfo.currentStatusId)) { taskInfo.completion = 100 } else { if (taskInfo.actualHours && taskInfo.plannedHours) { diff --git a/projectmgr/groovyScripts/ProjectBilling.groovy b/projectmgr/groovyScripts/ProjectBilling.groovy index ab03660ef..78d411af4 100644 --- a/projectmgr/groovyScripts/ProjectBilling.groovy +++ b/projectmgr/groovyScripts/ProjectBilling.groovy @@ -40,7 +40,7 @@ entryIterator = from("ProjectPhaseTaskAndTimeEntryTimeSheet") .queryIterator() while (entryItem = entryIterator.next()) { invoice = entryItem.getRelatedOne("Invoice", false) - if (invoice.getString("statusId").equals("INVOICE_IN_PROCESS")) { + if ("INVOICE_IN_PROCESS".equals(invoice.getString("statusId"))) { context.partyIdFrom = invoice.partyIdFrom context.partyId = invoice.partyId context.invoiceId = invoice.invoiceId diff --git a/projectmgr/groovyScripts/ProjectIsBillable.groovy b/projectmgr/groovyScripts/ProjectIsBillable.groovy index 7054e621c..1bde14a42 100644 --- a/projectmgr/groovyScripts/ProjectIsBillable.groovy +++ b/projectmgr/groovyScripts/ProjectIsBillable.groovy @@ -22,10 +22,10 @@ projectMembers = from("WorkEffortPartyAssignment").where("workEffortId", context toPartyId = null fromPartyId = null projectMembers.each {member -> - if (member.roleTypeId.equals("INTERNAL_ORGANIZATIO")) { + if ("INTERNAL_ORGANIZATIO".equals(member.roleTypeId)) { fromPartyId = member.partyId } - if (member.roleTypeId.equals("CLIENT_BILLING")) { + if ("CLIENT_BILLING".equals(member.roleTypeId)) { toPartyId = member.partyId } if (fromPartyId && toPartyId && fromPartyId.equals(toPartyId)) { diff --git a/scrum/groovyScripts/AddResourceTaskParty.groovy b/scrum/groovyScripts/AddResourceTaskParty.groovy index 382108bb5..730015023 100644 --- a/scrum/groovyScripts/AddResourceTaskParty.groovy +++ b/scrum/groovyScripts/AddResourceTaskParty.groovy @@ -46,7 +46,7 @@ userLoginId = userLogin.partyId } else { custRequestTypeId = projectAndTaskMap.custRequestTypeId backlogStatusId = projectAndTaskMap.backlogStatusId - if (custRequestTypeId.equals("RF_SCRUM_MEETINGS") && backlogStatusId.equals("CRQ_REVIEWED")) { + if ("RF_SCRUM_MEETINGS".equals(custRequestTypeId) && "CRQ_REVIEWED".equals(backlogStatusId)) { projectSprintBacklogAndTaskList.add(projectAndTaskMap) } } diff --git a/scrum/groovyScripts/EditDailyHourReport.groovy b/scrum/groovyScripts/EditDailyHourReport.groovy index 32d833d71..c25392f4f 100644 --- a/scrum/groovyScripts/EditDailyHourReport.groovy +++ b/scrum/groovyScripts/EditDailyHourReport.groovy @@ -182,26 +182,26 @@ while (te.hasNext()) { dayNumber = "d" + (timeEntry.fromDate.getTime() - timesheet.fromDate.getTime()) / (24*60*60*1000) hours = timeEntry.hours.doubleValue() entry.put(String.valueOf(dayNumber), hours) - if (dayNumber.equals("d0")) day0Total += hours - if (dayNumber.equals("d1")) day1Total += hours - if (dayNumber.equals("d2")) day2Total += hours - if (dayNumber.equals("d3")) day3Total += hours - if (dayNumber.equals("d4")) day4Total += hours - if (dayNumber.equals("d5")) day5Total += hours - if (dayNumber.equals("d6")) day6Total += hours + if ("d0".equals(dayNumber)) day0Total += hours + if ("d1".equals(dayNumber)) day1Total += hours + if ("d2".equals(dayNumber)) day2Total += hours + if ("d3".equals(dayNumber)) day3Total += hours + if ("d4".equals(dayNumber)) day4Total += hours + if ("d5".equals(dayNumber)) day5Total += hours + if ("d6".equals(dayNumber)) day6Total += hours taskTotal += hours } if (timeEntry.planHours) { dayNumber = "pd" + (timeEntry.fromDate.getTime() - timesheet.fromDate.getTime()) / (24*60*60*1000) planHours = timeEntry.planHours.doubleValue() entry.put(String.valueOf(dayNumber), planHours) - if (dayNumber.equals("pd0")) pDay0Total += planHours - if (dayNumber.equals("pd1")) pDay1Total += planHours - if (dayNumber.equals("pd2")) pDay2Total += planHours - if (dayNumber.equals("pd3")) pDay3Total += planHours - if (dayNumber.equals("pd4")) pDay4Total += planHours - if (dayNumber.equals("pd5")) pDay5Total += planHours - if (dayNumber.equals("pd6")) pDay6Total += planHours + if ("pd0".equals(dayNumber)) pDay0Total += planHours + if ("pd1".equals(dayNumber)) pDay1Total += planHours + if ("pd2".equals(dayNumber)) pDay2Total += planHours + if ("pd3".equals(dayNumber)) pDay3Total += planHours + if ("pd4".equals(dayNumber)) pDay4Total += planHours + if ("pd5".equals(dayNumber)) pDay5Total += planHours + if ("pd6".equals(dayNumber)) pDay6Total += planHours planTotal += planHours } @@ -265,13 +265,13 @@ while ((emplLeaveMap = emplLeave.next())) { ["userLogin": parameters.userLogin, "partyId": emplLeaveEntry.partyId, "leaveTypeId": emplLeaveEntry.leaveTypeId, "fromDate": emplLeaveEntry.fromDate]) leaveHours = resultHours.hours.doubleValue() leaveEntry.put(String.valueOf(leaveDayNumber), leaveHours) - if (leaveDayNumber.equals("d0")) day0Total += leaveHours - if (leaveDayNumber.equals("d1")) day1Total += leaveHours - if (leaveDayNumber.equals("d2")) day2Total += leaveHours - if (leaveDayNumber.equals("d3")) day3Total += leaveHours - if (leaveDayNumber.equals("d4")) day4Total += leaveHours - if (leaveDayNumber.equals("d5")) day5Total += leaveHours - if (leaveDayNumber.equals("d6")) day6Total += leaveHours + if ("d0".equals(leaveDayNumber)) day0Total += leaveHours + if ("d1".equals(leaveDayNumber)) day1Total += leaveHours + if ("d2".equals(leaveDayNumber)) day2Total += leaveHours + if ("d3".equals(leaveDayNumber)) day3Total += leaveHours + if ("d4".equals(leaveDayNumber)) day4Total += leaveHours + if ("d5".equals(leaveDayNumber)) day5Total += leaveHours + if ("d6".equals(leaveDayNumber)) day6Total += leaveHours leaveTaskTotal += leaveHours } if (resultHours.hours) { @@ -280,13 +280,13 @@ while ((emplLeaveMap = emplLeave.next())) { ["userLogin": parameters.userLogin, "partyId": emplLeaveEntry.partyId, "leaveTypeId": emplLeaveEntry.leaveTypeId, "fromDate": emplLeaveEntry.fromDate]) leavePlanHours = resultPlanHours.hours.doubleValue() leaveEntry.put(String.valueOf(leavePlanDay), leavePlanHours) - if (leavePlanDay.equals("pd0")) pDay0Total += leavePlanHours - if (leavePlanDay.equals("pd1")) pDay1Total += leavePlanHours - if (leavePlanDay.equals("pd2")) pDay2Total += leavePlanHours - if (leavePlanDay.equals("pd3")) pDay3Total += leavePlanHours - if (leavePlanDay.equals("pd4")) pDay4Total += leavePlanHours - if (leavePlanDay.equals("pd5")) pDay5Total += leavePlanHours - if (leavePlanDay.equals("pd6")) pDay6Total += leavePlanHours + if ("pd0".equals(leavePlanDay)) pDay0Total += leavePlanHours + if ("pd1".equals(leavePlanDay)) pDay1Total += leavePlanHours + if ("pd2".equals(leavePlanDay)) pDay2Total += leavePlanHours + if ("pd3".equals(leavePlanDay)) pDay3Total += leavePlanHours + if ("pd4".equals(leavePlanDay)) pDay4Total += leavePlanHours + if ("pd5".equals(leavePlanDay)) pDay5Total += leavePlanHours + if ("pd6".equals(leavePlanDay)) pDay6Total += leavePlanHours leavePlanTotal += leavePlanHours } leaveEntry.rateTypeId = "STANDARD" @@ -303,7 +303,7 @@ if (emplLeaveEntry) { } // add empty lines if timesheet not completed -if (!timesheet.statusId.equals("TIMESHEET_COMPLETED")) { +if (!"TIMESHEET_COMPLETED".equals(timesheet.statusId)) { for (c=0; c < 3; c++) { // add empty lines entries.add(["timesheetId" : timesheet.timesheetId]) } @@ -393,7 +393,7 @@ userLoginId = userLogin.partyId if (partyAssignmentTaskMap) { custRequestTypeId = projectAndTaskMap.custRequestTypeId backlogStatusId = projectAndTaskMap.backlogStatusId - if (custRequestTypeId.equals("RF_SCRUM_MEETINGS") && backlogStatusId.equals("CRQ_REVIEWED")) { + if ("RF_SCRUM_MEETINGS".equals(custRequestTypeId) && "CRQ_REVIEWED".equals(backlogStatusId)) { projectSprintBacklogAndTaskList.add(projectAndTaskMap) } } else { diff --git a/scrum/groovyScripts/EditWeekTimesheet.groovy b/scrum/groovyScripts/EditWeekTimesheet.groovy index fa5d7b718..9c2d38d8c 100644 --- a/scrum/groovyScripts/EditWeekTimesheet.groovy +++ b/scrum/groovyScripts/EditWeekTimesheet.groovy @@ -148,13 +148,13 @@ while (te.hasNext()) { dayNumber = "d" + (timeEntry.fromDate.getTime() - timesheet.fromDate.getTime()) / (24*60*60*1000) hours = timeEntry.hours.doubleValue() entry.put(String.valueOf(dayNumber), hours) - if (dayNumber.equals("d0")) day0Total += hours - if (dayNumber.equals("d1")) day1Total += hours - if (dayNumber.equals("d2")) day2Total += hours - if (dayNumber.equals("d3")) day3Total += hours - if (dayNumber.equals("d4")) day4Total += hours - if (dayNumber.equals("d5")) day5Total += hours - if (dayNumber.equals("d6")) day6Total += hours + if ("d0".equals(dayNumber)) day0Total += hours + if ("d1".equals(dayNumber)) day1Total += hours + if ("d2".equals(dayNumber)) day2Total += hours + if ("d3".equals(dayNumber)) day3Total += hours + if ("d4".equals(dayNumber)) day4Total += hours + if ("d5".equals(dayNumber)) day5Total += hours + if ("d6".equals(dayNumber)) day6Total += hours taskTotal += hours } entry.rateTypeId = timeEntry.rateTypeId @@ -166,7 +166,7 @@ if (timeEntry) { } // add empty lines if timesheet not completed -if (!timesheet.statusId.equals("TIMESHEET_COMPLETED")) { +if (!"TIMESHEET_COMPLETED".equals(timesheet.statusId)) { for (c=0; c < 3; c++) { // add empty lines entries.add(["timesheetId" : timesheet.timesheetId]) } diff --git a/scrum/groovyScripts/ProductBilling.groovy b/scrum/groovyScripts/ProductBilling.groovy index 0ddcbf55b..eda26802a 100644 --- a/scrum/groovyScripts/ProductBilling.groovy +++ b/scrum/groovyScripts/ProductBilling.groovy @@ -35,7 +35,7 @@ entryExprs = entryIterator = from("ProjectSprintBacklogTaskAndTimeEntryTimeSheet").where(entryExprs).orderBy("-fromDate").queryIterator() while (entryItem = entryIterator.next()) { invoice = entryItem.getRelatedOne("Invoice", false) - if (invoice.getString("statusId").equals("INVOICE_IN_PROCESS")) { + if ("INVOICE_IN_PROCESS".equals(invoice.getString("statusId"))) { context.partyIdFrom = invoice.partyIdFrom context.partyId = invoice.partyId context.invoiceId = invoice.invoiceId