我正在尝试重构此代码以使其更清洁并使用更好的 OOP 实践。此方法采用一堆单选框/复选框和文本框响应并在数据库表中更新它们,然后在另一个数据库表中更新检查表本身。
我觉得这种方法正在尝试做很多事情。但是我需要确定其他方法和类使用的一些东西,例如是否存在缺陷(单选值 = 2),是否推进工作流(在 processUpdateCheckbox 中确定的高级工作流布尔值),接下来根据状态向谁发送电子邮件currentActionItem 和advanceWorkflow 布尔值,以及持久化响应。
setFormFeedback 也不属于这里,因为该方法是从另一个处理表单数据的 Servlet 调用的,并且该消息丢失了。
非常感谢任何有助于重构的帮助。
public ChecklistInstance updateYesNoNAChecklistTogles(HttpServletRequest request, ChecklistInstance ci) throws DAOException {
String work_item_class_id = request.getParameter("work_item_class_id");
String work_action_class_id = request.getParameter("work_action_class_id");
String paramName;
String attribute_id;
String radioValue;
String textValue;
String strStatus = "1";
String strStoredNo = "";
Date dateNow = new Date();
YesNoNAAnswerDAO ynnDao = new YesNoNAAnswerDAO();
ChecklistInstanceDAO ciDao = new ChecklistInstanceDAO();
WorkflowInstanceWorkItemAction currentActionItem = new WorkflowInstanceWorkItemAction();
currentActionItem.setWork_item_class_id(work_item_class_id);
currentActionItem.setWork_action_class_id(work_action_class_id);
// Put the form check list responses into a list
List answer_attribute_list = new ArrayList();
java.util.Enumeration enum2 = request.getParameterNames();
while (enum2.hasMoreElements()) {
paramName = (String) enum2.nextElement();
boolean isNewQ = paramName.startsWith("qID_");
if (isNewQ) {
attribute_id = paramName.replaceAll("qID_", "");
YesNoNAAnswer clr = new YesNoNAAnswer();
if (request.getParameter("radio_" + attribute_id) != null) {
radioValue = request.getParameter("radio_" + attribute_id);
} else {
radioValue = "0";
}
if (request.getParameter("textbox_" + attribute_id) != null) {
textValue = request.getParameter("textbox_" + attribute_id);
} else {
textValue = "";
}
if (request.getParameter("check_" + attribute_id) != null) {
radioValue = request.getParameter("check_" + attribute_id);
} else {
// checkValue = "";
}
if ("0".equals(radioValue) || "2".equals(radioValue)) {
strStatus = "0";
}
strStoredNo = request.getParameter("stored_" + attribute_id);
if ("2".equals(radioValue) && !"yes".equals(strStoredNo)) {
deficiencyFound = true;
}
clr.setWorkflow_instance_id(ci.getWorkflow_instance_id());
clr.setWfi_work_item_action_id(ci.getWfi_work_item_action_id());
clr.setFail_reason(textValue);
clr.setAttribute_id(attribute_id);
clr.setToggle_value(radioValue);
answer_attribute_list.add(clr);
}
}
ci.setChecklist_state(strStatus);
ci.setLast_update(dateNow);
ci.setAdditional_info(FormUtil.getFieldValue(request, FIELD_ADDITIONAL_INFO));
processUpdateCheckbox(request, ci, currentActionItem);
// Update the base check list
ciDao.updateInstance(ci, authenticatedUser);
// Update the check list question responses
ynnDao.updateToggles(answer_attribute_list, authenticatedUser);
// update the work flow
WorkflowInstanceDAO wfiDao = new WorkflowInstanceDAO();
WorkflowInstanceForm wfiForm = new WorkflowInstanceForm(wfiDao, authenticatedUser);
WorkflowInstance wfi = (WorkflowInstance) wfiForm.view(ci.getWorkflow_instance_id(), authenticatedUser);
wfiForm.updateWorkFlowInstance(wfi, currentActionItem);
setFormFeedback("You have successfully updated the checklist.");
triggerUpdateEmail(request, ci, wfi, currentActionItem);
return ci;
}