Skip to content
Permalink
Browse files
Fixed: No functional change, correct checkstyle issues on GenericWebE…
…vent.java
  • Loading branch information
nmalin committed Jan 29, 2020
1 parent 8902637 commit fac12a4e6fbcd6892dffa2a75ed83f6bed19a424
Showing with 73 additions and 37 deletions.
  1. +73 −37 framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
@@ -65,25 +65,31 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
entityName = (String) request.getAttribute("entityName");
}
if (UtilValidate.isEmpty(entityName)) {
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.entity_name_not_specified", locale) + ".";
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.entity_name_not_specified", locale) + ".";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[GenericWebEvent.updateGeneric] The entityName was not specified, but is required.", module);
Debug.logWarning("[GenericWebEvent.updateGeneric] The entityName was not specified,"
+ " but is required.", module);
return "error";
}

Security security = (Security) request.getAttribute("security");
Delegator delegator = (Delegator) request.getAttribute("delegator");

if (security == null) {
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource,"genericWebEvent.security_object_not_found", locale) + ".";
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.security_object_not_found", locale) + ".";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[updateGeneric] The security object was not found in the request, please check the control servlet init.", module);
Debug.logWarning("[updateGeneric] The security object was not found in the request,"
+ " please check the control servlet init.", module);
return "error";
}
if (delegator == null) {
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.delegator_object_not_found", locale) + ".";
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.delegator_object_not_found", locale) + ".";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[updateGeneric] The delegator object was not found in the request, please check the control servlet init.", module);
Debug.logWarning("[updateGeneric] The delegator object was not found in the request,"
+ " please check the control servlet init.", module);
return "error";
}

@@ -109,25 +115,33 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
}

if (UtilValidate.isEmpty(updateMode)) {
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.update_mode_not_specified", locale) + ".";
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.update_mode_not_specified", locale) + ".";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[updateGeneric] Update Mode was not specified, but is required; entityName: " + entityName, module);
Debug.logWarning("[updateGeneric] Update Mode was not specified, but is required;"
+ "entityName: " + entityName, module);
return "error";
}

// check permissions before moving on...
if (!security.hasEntityPermission("ENTITY_DATA", "_" + updateMode, request.getSession()) &&
!security.hasEntityPermission(entity.getPlainTableName(), "_" + updateMode, request.getSession())) {
Map<String, String> messageMap = UtilMisc.toMap("updateMode", updateMode, "entityName", entity.getEntityName(), "entityPlainTableName", entity.getPlainTableName());
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.not_sufficient_permissions_01", messageMap, locale);
errMsg += UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.not_sufficient_permissions_02", messageMap, locale) + ".";
String plainTableName = entity.getPlainTableName();
if (!security.hasEntityPermission("ENTITY_DATA", "_" + updateMode, request.getSession())
&& !security.hasEntityPermission(plainTableName, "_" + updateMode, request.getSession())) {
Map<String, String> messageMap = UtilMisc.toMap(
"updateMode", updateMode,
"entityName", entity.getEntityName(),
"entityPlainTableName", plainTableName);
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.not_sufficient_permissions_01", messageMap, locale);
errMsg += UtilProperties.getMessage(err_resource,
"genericWebEvent.not_sufficient_permissions_02", messageMap, locale) + ".";

request.setAttribute("_ERROR_MESSAGE_", errMsg);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
// not really successful, but error return through ERROR_MESSAGE, so quietly fail
return "error";
}

GenericValue findByEntity = delegator.makeValue(entityName);
GenericValue findByEntity = delegator.makeValue(entityName, pkFields);

// get the primary key parameters...
String errMsgPk = "";
@@ -142,7 +156,8 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
Map<String, String> messageMap = UtilMisc.toMap("fieldType", field.getType());
errMsg += UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.fatal_error_param", messageMap, locale) + ".";
errMsg += UtilProperties.getMessage(err_resource,
"genericWebEvent.fatal_error_param", messageMap, locale) + ".";
}

String fval = request.getParameter(field.getName());
@@ -151,7 +166,7 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
findByEntity.setString(field.getName(), fval);
} catch (Exception e) {
Map<String, String> messageMap = UtilMisc.toMap("fval", fval);
errMsg = errMsg + "<li>" + field.getColName() + UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.conversion_failed", messageMap, locale) + type.getJavaType() + ".";
errMsg = errMsg + "<li>" + field.getColName() + UtilProperties.getMessage(err_resource, "genericWebEvent.conversion_failed", messageMap, locale) + type.getJavaType() + ".";
Debug.logWarning("[updateGeneric] " + field.getColName() + " conversion failed: \"" + fval + "\" is not a valid " + type.getJavaType() + "; entityName: " + entityName, module);
}
}
@@ -168,10 +183,12 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
// Delete actual main entity last, just in case database is set up to do a cascading delete, caches won't get cleared
try {
delegator.removeByPrimaryKey(findByEntity.getPrimaryKey());
String confirmMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.delete_succeeded", locale) ;
String confirmMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.delete_succeeded", locale);
request.setAttribute("_EVENT_MESSAGE_", confirmMsg);
} catch (GenericEntityException e) {
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.delete_failed", locale) + ": " + e.toString();
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.delete_failed", locale) + ": " + e.toString();
Debug.logWarning(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
@@ -192,7 +209,8 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
Map<String, String> messageMap = UtilMisc.toMap("fieldType", field.getType());
errMsgNonPk += UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.fatal_error_param", messageMap, locale) + ".";
errMsgNonPk += UtilProperties.getMessage(err_resource,
"genericWebEvent.fatal_error_param", messageMap, locale) + ".";
}

String fval = request.getParameter(field.getName());
@@ -201,9 +219,11 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
findByEntity.setString(field.getName(), fval);
} catch (Exception e) {
Map<String, String> messageMap = UtilMisc.toMap("fval", fval);
errMsgNonPk += field.getColName() + UtilProperties.getMessage(GenericWebEvent.err_resource,
errMsgNonPk += field.getColName() + UtilProperties.getMessage(err_resource,
"genericWebEvent.conversion_failed", messageMap, locale) + type.getJavaType() + ".";
Debug.logWarning("[updateGeneric] " + field.getColName() + " conversion failed: \"" + fval + "\" is not a valid " + type.getJavaType() + "; entityName: " + entityName, module);
Debug.logWarning("[updateGeneric] " + field.getColName()
+ " conversion failed: \"" + fval + "\" is not a valid "
+ type.getJavaType() + "; entityName: " + entityName, module);
}
} else {
findByEntity.set(field.getName(), null);
@@ -221,17 +241,22 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
GenericValue tempEntity = null;

try {
tempEntity = EntityQuery.use(delegator).from(findByEntity.getEntityName()).where(findByEntity.getPrimaryKey()).queryOne();
tempEntity = EntityQuery.use(delegator)
.from(findByEntity.getEntityName())
.where(findByEntity.getPrimaryKey())
.queryOne();
} catch (GenericEntityException e) {
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.create_failed_by_check", locale) + ": " + e.toString();
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.create_failed_by_check", locale) + ": " + e.toString();
Debug.logWarning(e, errMsg, module);

request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
if (tempEntity != null) {
Map<String, String> messageMap = UtilMisc.toMap("primaryKey", findByEntity.getPrimaryKey().toString());
String errMsg = "[updateGeneric] " + entity.getEntityName() + UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.already_exists_pk", messageMap, locale)+ ".";
String errMsg = "[updateGeneric] " + entity.getEntityName() + UtilProperties.getMessage(err_resource,
"genericWebEvent.already_exists_pk", messageMap, locale) + ".";
Debug.logWarning(errMsg, module);
}
}
@@ -243,7 +268,7 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
ModelField field = fieldIter.next();

for (String curValidate : field.getValidators()) {
Class<?>[] paramTypes = { String.class };
Class<?>[] paramTypes = {String.class};
Object[] params = new Object[] {findByEntity.get(field.getName()).toString()};

String className = "org.apache.ofbiz.base.util.UtilValidate";
@@ -259,15 +284,17 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
ClassLoader loader = Thread.currentThread().getContextClassLoader();
valClass = loader.loadClass(className);
} catch (ClassNotFoundException cnfe) {
Debug.logError("[updateGeneric] Could not find validation class: " + className + "; ignoring.", module);
Debug.logError("[updateGeneric] Could not find validation class: " + className
+ "; ignoring.", module);
continue;
}
Method valMethod;

try {
valMethod = valClass.getMethod(methodName, paramTypes);
} catch (NoSuchMethodException cnfe) {
Debug.logError("[updateGeneric] Could not find validation method: " + methodName + " of class " + className + "; ignoring.", module);
Debug.logError("[updateGeneric] Could not find validation method: " + methodName
+ " of class " + className + "; ignoring.", module);
continue;
}

@@ -276,7 +303,8 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
try {
resultBool = (Boolean) valMethod.invoke(null, params);
} catch (Exception e) {
Debug.logError("[updateGeneric] Could not access validation method: " + methodName + " of class " + className + "; returning true.", module);
Debug.logError("[updateGeneric] Could not access validation method: " + methodName
+ " of class " + className + "; returning true.", module);
resultBool = Boolean.TRUE;
}

@@ -288,10 +316,11 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
msgField = valClass.getField(curValidate + "Msg");
message = (String) msgField.get(null);
} catch (Exception e) {
Debug.logError("[updateGeneric] Could not find validation message field: " + curValidate + "Msg of class " + className + "; returning generic validation failure message.", module);
message = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.validation_failed", locale) + ".";
Debug.logError("[updateGeneric] Could not find validation message field: " + curValidate
+ "Msg of class " + className + "; returning generic validation failure message.", module);
message = UtilProperties.getMessage(err_resource, "genericWebEvent.validation_failed", locale) + ".";
}
errMsgParam += field.getColName() + " " + curValidate + " " + UtilProperties.getMessage(GenericWebEvent.err_resource,
errMsgParam += field.getColName() + " " + curValidate + " " + UtilProperties.getMessage(err_resource,
"genericWebEvent.failed", locale) + ": " + message;

Debug.logWarning("[updateGeneric] " + field.getColName() + " " + curValidate + " failed: " + message, module);
@@ -300,7 +329,8 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
}

if (errMsgParam.length() > 0) {
errMsgParam = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.following_error_occurred", locale) + errMsgParam;
errMsgParam = UtilProperties.getMessage(err_resource,
"genericWebEvent.following_error_occurred", locale) + errMsgParam;
request.setAttribute("_ERROR_MESSAGE_", errMsgParam);
return "error";
}
@@ -310,7 +340,9 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
delegator.create(findByEntity.getEntityName(), findByEntity.getAllFields());
} catch (GenericEntityException e) {
Map<String, String> messageMap = UtilMisc.toMap("entityName", entity.getEntityName());
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.creation_param_failed", messageMap, locale)+ ": " + findByEntity.toString() + ": " + e.toString();
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.creation_param_failed", messageMap, locale)
+ ": " + findByEntity.toString() + ": " + e.toString();
Debug.logWarning(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
@@ -322,17 +354,21 @@ public static String updateGeneric(HttpServletRequest request, HttpServletRespon
value.store();
} catch (GenericEntityException e) {
Map<String, String> messageMap = UtilMisc.toMap("entityName", entity.getEntityName());
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.update_of_param_failed", messageMap, locale)+ ": " + value.toString() + ": " + e.toString();
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.update_of_param_failed", messageMap, locale)
+ ": " + value.toString() + ": " + e.toString();
Debug.logWarning(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
} else {
Map<String, String> messageMap = UtilMisc.toMap("updateMode", updateMode);
String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.update_of_param_failed", messageMap, locale)+ ".";
String errMsg = UtilProperties.getMessage(err_resource,
"genericWebEvent.update_of_param_failed", messageMap, locale) + ".";

request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("updateGeneric: Update Mode specified (" + updateMode + ") was not valid for entity: " + findByEntity.toString(), module);
Debug.logWarning("updateGeneric: Update Mode specified (" + updateMode + ") was not valid for entity: "
+ findByEntity.toString(), module);
return "error";
}

0 comments on commit fac12a4

Please sign in to comment.