Author: lektran
Date: Mon Aug 2 10:47:26 2010
New Revision: 981446
URL: http://svn.apache.org/viewvc?rev=981446&view=rev
Log:
Copied CommonWorkers.hasParentType(...) over to EntityTypeUtil and deprecated
the method.
Modified:
ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java
Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java?rev=981446&r1=981445&r2=981446&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java
(original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java Mon
Aug 2 10:47:26 2010
@@ -33,6 +33,7 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityTypeUtil;
/**
* Common Workers
@@ -146,26 +147,11 @@ public class CommonWorkers {
* @param parentTypeField Field in Type entity which stores the parent
type.
* @param parentType Value of the parent type against which check is
performed.
* @return boolean value based on the check results.
+ *
+ * @deprecated Moved to {...@link
org.ofbiz.entity.util.EntityTypeUtil#hasParentType(Delegator, String, String,
String, String, String) EntityTypeUtil}
*/
+ @Deprecated
public static boolean hasParentType(Delegator delegator, String
entityName, String primaryKey, String childType, String parentTypeField, String
parentType) {
- GenericValue childTypeValue = null;
- try {
- childTypeValue = delegator.findOne(entityName,
UtilMisc.toMap(primaryKey, childType), true);
- } catch (GenericEntityException e) {
- Debug.logError("Error finding "+entityName+" record for type
"+childType, module);
- }
- if (childTypeValue != null) {
- if (parentType.equals(childTypeValue.getString(primaryKey)))
return true;
-
- if (childTypeValue.getString(parentTypeField) != null) {
- if
(parentType.equals(childTypeValue.getString(parentTypeField))) {
- return true;
- } else {
- return hasParentType(delegator, entityName, primaryKey,
childTypeValue.getString(parentTypeField), parentTypeField, parentType);
- }
- }
- }
-
- return false;
+ return EntityTypeUtil.hasParentType(delegator, entityName, primaryKey,
childType, parentTypeField, parentType);
}
}
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java?rev=981446&r1=981445&r2=981446&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java
(original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java
Mon Aug 2 10:47:26 2010
@@ -23,6 +23,8 @@ import java.util.Collection;
import java.util.List;
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
@@ -115,4 +117,38 @@ public class EntityTypeUtil {
return isType(getParentType(thisType), targetType);
}
}
+
+ /**
+ * A generic method to be used on Type enities, e.g. ProductType. Recurse
to the root level in the type hierarchy
+ * and checks if the specified type childType has parentType as its parent
somewhere in the hierarchy.
+ *
+ * @param delegator The Delegator object.
+ * @param entityName Name of the Type entity on which check is
performed.
+ * @param primaryKey Primary Key field of the Type entity.
+ * @param childType Type value for which the check is performed.
+ * @param parentTypeField Field in Type entity which stores the parent
type.
+ * @param parentType Value of the parent type against which check is
performed.
+ * @return boolean value based on the check results.
+ */
+ public static boolean hasParentType(Delegator delegator, String
entityName, String primaryKey, String childType, String parentTypeField, String
parentType) {
+ GenericValue childTypeValue = null;
+ try {
+ childTypeValue = delegator.findOne(entityName,
UtilMisc.toMap(primaryKey, childType), true);
+ } catch (GenericEntityException e) {
+ Debug.logError("Error finding "+entityName+" record for type
"+childType, module);
+ }
+ if (childTypeValue != null) {
+ if (parentType.equals(childTypeValue.getString(primaryKey)))
return true;
+
+ if (childTypeValue.getString(parentTypeField) != null) {
+ if
(parentType.equals(childTypeValue.getString(parentTypeField))) {
+ return true;
+ } else {
+ return hasParentType(delegator, entityName, primaryKey,
childTypeValue.getString(parentTypeField), parentTypeField, parentType);
+ }
+ }
+ }
+
+ return false;
+ }
}