Author: doogie
Date: Fri Mar 27 16:56:29 2009 New Revision: 759233 URL: http://svn.apache.org/viewvc?rev=759233&view=rev Log: Fix lines that *only* have whitespace. Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityServiceFactory.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityWatchServices.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/cache/EntityCacheServices.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncServices.java Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java Fri Mar 27 16:56:29 2009 @@ -41,14 +41,14 @@ public static Set<String> getEntityNamesByGroup(String entityGroupId, GenericDelegator delegator, boolean requireStampFields) throws GenericEntityException { Set<String> entityNames = FastSet.newInstance(); - + List<GenericValue> entitySyncGroupIncludes = delegator.findByAnd("EntityGroupEntry", UtilMisc.toMap("entityGroupId", entityGroupId)); - + List<ModelEntity> modelEntities = getModelEntitiesFromRecords(entitySyncGroupIncludes, delegator, requireStampFields); for (ModelEntity modelEntity: modelEntities) { entityNames.add(modelEntity.getEntityName()); } - + return entityNames; } @@ -57,17 +57,17 @@ for (String entityName: delegator.getModelReader().getEntityNames()) { ModelEntity modelEntity = delegator.getModelEntity(entityName); - + // if view-entity, throw it out if (modelEntity instanceof ModelViewEntity) { continue; } - + // if it doesn't have either or both of the two update stamp fields, throw it out if (requireStampFields && (!modelEntity.isField(ModelEntity.STAMP_FIELD) || !modelEntity.isField(ModelEntity.STAMP_TX_FIELD))) { continue; } - + // if there are no includes records, always include; otherwise check each one to make sure at least one matches if (entityGroupEntryValues.size() == 0) { entityModelToUseList.add(modelEntity); @@ -88,7 +88,7 @@ } else if (modelEntity.getPackageName().startsWith(entityOrPackage)) { matches = true; } - + if (matches) { if ("ESIA_INCLUDE".equals(entitySyncInclude.getString("applEnumId"))) { matchesInclude = true; @@ -100,7 +100,7 @@ } } } - + if (matchesAlways || (matchesInclude && !matchesExclude)) { // make sure this log message is not checked in uncommented: //Debug.log("In runEntitySync adding [" + modelEntity.getEntityName() + "] to list of Entities to sync", module); @@ -108,7 +108,7 @@ } } } - + return entityModelToUseList; } } Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityServiceFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityServiceFactory.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityServiceFactory.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityServiceFactory.java Fri Mar 27 16:56:29 2009 @@ -34,7 +34,7 @@ LocalDispatcher dispatcher = GenericDispatcher.getLocalDispatcher("entity-" + delegator.getDelegatorName(), delegator); return dispatcher; } - + public static DispatchContext getDispatchContext(GenericDelegator delegator) { LocalDispatcher dispatcher = getLocalDispatcher(delegator); if (dispatcher == null) return null; Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityWatchServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityWatchServices.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityWatchServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityWatchServices.java Fri Mar 27 16:56:29 2009 @@ -55,11 +55,11 @@ public static Map watchEntity(DispatchContext dctx, Map context) { GenericValue newValue = (GenericValue) context.get("newValue"); String fieldName = (String) context.get("fieldName"); - + if (newValue == null) { return ServiceUtil.returnSuccess(); } - + GenericValue currentValue = null; try { currentValue = dctx.getDelegator().findOne(newValue.getEntityName(), newValue.getPrimaryKey(), false); @@ -67,7 +67,7 @@ String errMsg = "Error finding currentValue for primary key [" + newValue.getPrimaryKey() + "]: " + e.toString(); Debug.logError(e, errMsg, module); } - + if (currentValue != null) { if (UtilValidate.isNotEmpty(fieldName)) { // just watch the field @@ -83,7 +83,7 @@ changed = true; } } - + if (changed) { String errMsg = "Watching entity [" + currentValue.getEntityName() + "] field [" + fieldName + "] value changed from [" + currentFieldValue + "] to [" + newFieldValue + "] for pk [" + newValue.getPrimaryKey() + "]"; Debug.log(new Exception(errMsg), errMsg, module); @@ -107,7 +107,7 @@ Debug.log(new Exception(errMsg), errMsg, module); } } - + return ServiceUtil.returnSuccess(); } } Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/cache/EntityCacheServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/cache/EntityCacheServices.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/cache/EntityCacheServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/cache/EntityCacheServices.java Fri Mar 27 16:56:29 2009 @@ -39,7 +39,7 @@ * Entity Engine Cache Services */ public class EntityCacheServices implements DistributedCacheClear { - + public static final String module = EntityCacheServices.class.getName(); protected GenericDelegator delegator = null; @@ -53,7 +53,7 @@ this.dispatcher = EntityServiceFactory.getLocalDispatcher(delegator); this.userLoginId = userLoginId; } - + public GenericValue getAuthUserLogin() { GenericValue userLogin = null; try { @@ -76,7 +76,7 @@ Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module); return; } - + try { this.dispatcher.runAsync("distributedClearCacheLineByValue", UtilMisc.toMap("value", value, "userLogin", userLogin), false); } catch (GenericServiceException e) { @@ -96,7 +96,7 @@ Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module); return; } - + try { this.dispatcher.runAsync("distributedClearCacheLineByDummyPK", UtilMisc.toMap("dummyPK", dummyPK, "userLogin", userLogin), false); } catch (GenericServiceException e) { @@ -116,14 +116,14 @@ Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module); return; } - + try { this.dispatcher.runAsync("distributedClearCacheLineByCondition", UtilMisc.toMap("entityName", entityName, "condition", condition, "userLogin", userLogin), false); } catch (GenericServiceException e) { Debug.logError(e, "Error running the distributedClearCacheLineByCondition service", module); } } - + public void distributedClearCacheLine(GenericPK primaryKey) { // Debug.logInfo("running distributedClearCacheLine for primaryKey: " + primaryKey, module); if (this.dispatcher == null) { @@ -136,7 +136,7 @@ Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module); return; } - + try { this.dispatcher.runAsync("distributedClearCacheLineByPrimaryKey", UtilMisc.toMap("primaryKey", primaryKey, "userLogin", userLogin), false); } catch (GenericServiceException e) { @@ -155,14 +155,14 @@ Debug.logWarning("The userLogin for distributed cache clear was not found with userLoginId [" + userLoginId + "], not clearing remote caches.", module); return; } - + try { this.dispatcher.runAsync("distributedClearAllEntityCaches", UtilMisc.toMap("userLogin", userLogin), false); } catch (GenericServiceException e) { Debug.logError(e, "Error running the distributedClearAllCaches service", module); } } - + /** * Clear All Entity Caches Service *@param ctx The DispatchContext that this service is operating in @@ -174,12 +174,12 @@ Boolean distributeBool = (Boolean) context.get("distribute"); boolean distribute = false; if (distributeBool != null) distribute = distributeBool.booleanValue(); - + delegator.clearAllCaches(distribute); - + return ServiceUtil.returnSuccess(); } - + /** * Clear Cache Line Service: one of the following context parameters is required: value, dummyPK or primaryKey *@param ctx The DispatchContext that this service is operating in Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java Fri Mar 27 16:56:29 2009 @@ -95,7 +95,7 @@ } argument = argument.substring(subIdx); } - + // parse the arguments String argumentName; String argumentVal; @@ -145,7 +145,7 @@ Debug.log("-help ................ display this information", module); System.exit(1); } - + // special case if (this.readers == null && (!this.files.isEmpty() || this.directory != null)) { this.readers = "none"; @@ -244,7 +244,7 @@ NumberFormat changedFormat = NumberFormat.getIntegerInstance(); changedFormat.setMinimumIntegerDigits(5); changedFormat.setGroupingUsed(false); - + List<Object> errorMessages = FastList.newInstance(); List<String> infoMessages = FastList.newInstance(); int totalRowsChanged = 0; @@ -275,7 +275,7 @@ Debug.logImportant(message, module); } } - + if (errorMessages.size() > 0) { Debug.logImportant("The following errors occured in the data load:", module); for (Object message: errorMessages) { @@ -284,7 +284,7 @@ } Debug.logImportant("=-=-=-=-=-=-= Finished the data load with " + totalRowsChanged + " rows changed.", module); - + return true; } Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java Fri Mar 27 16:56:29 2009 @@ -415,17 +415,17 @@ // step 8 - checkdb Debug.logImportant("Running DB check with add missing enabled", module); dbUtil.checkDb(modelEntities, messages, true); - + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("messages", messages); return result; } - + public static Map<String, Object> unwrapByteWrappers(DispatchContext dctx, Map<String, Object> context) { GenericDelegator delegator = dctx.getDelegator(); String entityName = (String) context.get("entityName"); String fieldName = (String) context.get("fieldName"); - + EntityListIterator eli = null; try { eli = delegator.find(entityName, null, null, null, null, null); @@ -451,7 +451,7 @@ } } } - + return ServiceUtil.returnSuccess(); } } Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java Fri Mar 27 16:56:29 2009 @@ -51,7 +51,7 @@ this.delegatorName = delegator.getDelegatorName(); this.entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(this.delegatorName); this.dctx = EntityServiceFactory.getDispatchContext(delegator); - + //preload the cache EntityEcaUtil.getEntityEcaCache(this.entityEcaReaderName); } @@ -72,11 +72,11 @@ List<EntityEcaRule> rules = eventMap.get(event); //Debug.logInfo("Handler.evalRules for entity " + value.getEntityName() + ", event " + event + ", num rules=" + (rules == null ? 0 : rules.size()), module); - + if (rules == null || rules.size() == 0) { return; } - + if (!rules.isEmpty() && Debug.verboseOn()) Debug.logVerbose("Running ECA (" + event + ").", module); Set<String> actionsRun = new TreeSet<String>(); for (EntityEcaRule eca: rules) { Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java Fri Mar 27 16:56:29 2009 @@ -66,7 +66,7 @@ public void runAction(DispatchContext dctx, Map<String, ? extends Object> context, GenericEntity newValue) throws GenericEntityException { Map<String, Object> actionResult = null; - + try { // pull out context parameters needed for this service. Map<String, Object> actionContext = dctx.getModelService(serviceName).makeValid(context, ModelService.IN_PARAM); @@ -74,7 +74,7 @@ if (valueAttr != null && valueAttr.length() > 0) { actionContext.put(valueAttr, newValue); } - + //Debug.logInfo("Running Entity ECA action service " + this.serviceName + " triggered by entity: " + value.getEntityName(), module); //Debug.logInfo("Running Entity ECA action service " + this.serviceName + "; value=" + value + "; actionContext=" + actionContext, module); Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java Fri Mar 27 16:56:29 2009 @@ -34,7 +34,7 @@ * EntityEcaCondition */ public class EntityEcaCondition implements java.io.Serializable { - + public static final String module = EntityEcaCondition.class.getName(); protected String lhsValueName, rhsValueName; Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java Fri Mar 27 16:56:29 2009 @@ -95,7 +95,7 @@ if (!"any".equals(this.operationName) && this.operationName.indexOf(currentOperation) == -1) { return; } - + Map<String, Object> context = FastMap.newInstance(); context.putAll(value); Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java Fri Mar 27 16:56:29 2009 @@ -70,7 +70,7 @@ protected PermissionConditionGetter permissionConditionGetter; protected RelatedRoleGetter relatedRoleGetter; protected AuxiliaryValueGetter auxiliaryValueGetter; - + public EntityPermissionChecker(Element element) { this.entityNameExdr = FlexibleStringExpander.getInstance(element.getAttribute("entity-name")); this.entityIdExdr = FlexibleStringExpander.getInstance(element.getAttribute("entity-id")); @@ -106,7 +106,7 @@ } public boolean runPermissionCheck(Map<String, ?> context) { - + boolean passed = false; String idString = entityIdExdr.expandString(context); List<String> entityIdList = null; @@ -128,7 +128,7 @@ } delegator = (GenericDelegator)request.getAttribute("delegator"); } - + if (auxiliaryValueGetter != null) auxiliaryValueGetter.clearList(); if (relatedRoleGetter != null) relatedRoleGetter.clearList(); try { @@ -172,7 +172,7 @@ String privilegeEnumId) { return checkPermission(content, statusList, userLogin, passedPurposes, targetOperations, passedRoles, delegator, security, entityAction, privilegeEnumId, null); } - + public static Map<String, Object> checkPermission(GenericValue content, List<String> statusList, GenericValue userLogin, List<String> passedPurposes, List<String> targetOperations, List<String> passedRoles, @@ -207,11 +207,11 @@ } return results; } - - + + public static boolean checkPermissionMethod(GenericDelegator delegator, GenericValue userLogin, List<String> targetOperationList, String entityName, List<? extends Object> entityIdList, List<String> purposeList, List<String> roleList, String privilegeEnumId) throws GenericEntityException { boolean passed = false; - + String lcEntityName = entityName.toLowerCase(); String userLoginId = null; String partyId = null; @@ -230,22 +230,22 @@ boolean hasStatusField = false; if (modelEntity.getField("statusId") != null) hasStatusField = true; - + boolean hasPrivilegeField = false; if (modelEntity.getField("privilegeEnumId") != null) hasPrivilegeField = true; - + List<GenericValue> operationEntities = null; ModelEntity modelOperationEntity = delegator.getModelEntity(entityName + "PurposeOperation"); if (modelOperationEntity == null) { modelOperationEntity = delegator.getModelEntity(entityName + "Operation"); } - + if (modelOperationEntity == null) { Debug.logError("No operation entity found for " + entityName, module); throw new RuntimeException("No operation entity found for " + entityName); } - + boolean hasPurposeOp = false; if (modelOperationEntity.getField(lcEntityName + "PurposeTypeId") != null) hasPurposeOp = true; @@ -255,7 +255,7 @@ boolean hasPrivilegeOp = false; if (modelOperationEntity.getField("privilegeEnumId") != null) hasPrivilegeOp = true; - + // Get all the condition operations that could apply, rather than having to go thru // entire table each time. //List condList = FastList.newInstance(); @@ -265,18 +265,18 @@ // condList.add(EntityCondition.makeCondition(lcEntityName + "OperationId", op)); //} //EntityCondition opCond = EntityCondition.makeCondition(condList, EntityOperator.OR); - + EntityCondition opCond = EntityCondition.makeCondition(lcEntityName + "OperationId", EntityOperator.IN, targetOperationList); - + List<GenericValue> targetOperationEntityList = delegator.findList(modelOperationEntity.getEntityName(), opCond, null, null, null, true); Map<String, GenericValue> entities = FastMap.newInstance(); String pkFieldName = modelEntity.getFirstPkFieldName(); - + //TODO: privilegeEnumId test /* if (hasPrivilegeOp && hasPrivilegeField) { int privilegeEnumSeq = -1; - + if ( UtilValidate.isNotEmpty(privilegeEnumId)) { GenericValue privEnum = delegator.findByPrimaryKeyCache("Enumeration", UtilMisc.toMap("enumId", privilegeEnumId)); if (privEnum != null) { @@ -293,7 +293,7 @@ while (iter.hasNext()) { GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, iter.next(), entities); if (entity == null) continue; - + String entityId = entity.getString(pkFieldName); String targetPrivilegeEnumId = entity.getString("privilegeEnumId"); if (UtilValidate.isNotEmpty(targetPrivilegeEnumId)) { @@ -315,7 +315,7 @@ } } */ - + // check permission for each id in passed list until success. // Note that "quickCheck" id come first in the list // Check with no roles or purposes on the chance that the permission fields contain _NA_ s. @@ -327,41 +327,41 @@ for (Object id: entityIdList) { GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, id, entities); if (entity == null) continue; - + String statusId = null; if (hasStatusOp && hasStatusField) { statusId = entity.getString("statusId"); } - + int privilegeEnumSeq = -1; if (hasPrivilegeOp && hasPrivilegeField) { privilegeEnumId = entity.getString("privilegeEnumId"); privilegeEnumSeq = getPrivilegeEnumSeq(delegator, privilegeEnumId); } - + passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId); if (passed) { break; } } - + if (passed) { return true; } - + if (hasPurposeOp) { // Check with just purposes next. for (Object id: entityIdList) { GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, id, entities); if (entity == null) continue; - + String entityId = entity.getString(pkFieldName); purposeList = getRelatedPurposes(entity, null); String statusId = null; if (hasStatusOp && hasStatusField) { statusId = entity.getString("statusId"); } - + if (purposeList.size() > 0) { passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId); } @@ -371,11 +371,11 @@ purposes.put(entityId, purposeList); } } - + if (passed) return true; - + if (userLogin == null) return false; - + // Check with roles. for (Object id: entityIdList) { GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, id, entities); @@ -389,7 +389,7 @@ } else { purposeList = tmpPurposeList; } - + List<String> tmpRoleList = getUserRoles(entity, userLogin, delegator); if (roleList != null ) { if (tmpRoleList != null) { @@ -398,42 +398,42 @@ } else { roleList = tmpRoleList; } - + String statusId = null; if (hasStatusOp && hasStatusField) { statusId = entity.getString("statusId"); } - + passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId); if (passed) { break; } roles.put(entityId, roleList); } - + if (passed) return true; - + // Follow ownedEntityIds if (modelEntity.getField("owner" + entityName + "Id") != null) { for (Object id: entityIdList) { GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, id, entities); if (entity == null) continue; - + String entityId = entity.getString(pkFieldName); List<String> ownedContentIdList = FastList.newInstance(); getEntityOwners(delegator, entity, ownedContentIdList, "Content", "ownerContentId"); - + List<String> ownedContentRoleIds = getUserRolesFromList(delegator, ownedContentIdList, partyId, "contentId", "partyId", "roleTypeId", "ContentRole"); String statusId = null; if (hasStatusOp && hasStatusField) { statusId = entity.getString("statusId"); } - + purposeList = purposes.get(entityId); passed = hasMatch(entityName, targetOperationEntityList, ownedContentRoleIds, hasPurposeOp, purposeList, hasStatusOp, statusId); if (passed) break; - + /* String ownedEntityId = entity.getString("owner" + entityName + "Id"); GenericValue ownedEntity = delegator.findByPrimaryKeyCache(entityName,UtilMisc.toMap(pkFieldName, ownedEntityId)); @@ -444,12 +444,12 @@ //purposeList = (List)purposes.get(entityId); //purposeList = getRelatedPurposes(ownedEntity, purposeList); roleList = getUserRoles(ownedEntity, userLogin, delegator); - + String statusId = null; if (hasStatusOp && hasStatusField) { statusId = entity.getString("statusId"); } - + passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId); if (passed) break; @@ -467,8 +467,8 @@ */ } } - - + + /* seems like repeat // Check parents iter = entityIdList.iterator(); @@ -477,7 +477,7 @@ GenericValue entity = (GenericValue)entities.get(entityId); purposeList = (List)purposes.get(entityId); roleList = getUserRoles(entity, userLogin, delegator); - + String statusId = null; if (hasStatusOp && hasStatusField) { statusId = entity.getString("statusId"); @@ -486,35 +486,35 @@ if (hasPrivilegeOp && hasPrivilegeField) { targetPrivilegeEnumId = entity.getString("privilegeEnumId"); } - + passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId); if (passed) break; alreadyCheckedIds.add(entityId); } */ - + return passed; } public static boolean checkPermissionMethod(GenericDelegator delegator, String partyId, String entityName, List<? extends Object> entityIdList, AuxiliaryValueGetter auxiliaryValueGetter, RelatedRoleGetter relatedRoleGetter, PermissionConditionGetter permissionConditionGetter) throws GenericEntityException { - + permissionConditionGetter.init(delegator); if (Debug.verboseOn()) Debug.logVerbose(permissionConditionGetter.dumpAsText(), module); boolean passed = false; - + boolean checkAncestors = false; boolean hasRoleOperation = checkHasRoleOperations(partyId, permissionConditionGetter, delegator); if ( hasRoleOperation ) { return true; } ModelEntity modelEntity = delegator.getModelEntity(entityName); - + if (relatedRoleGetter != null) { if (UtilValidate.isNotEmpty(partyId)) { relatedRoleGetter.setList(UtilMisc.toList("LOGGEDIN")); } } - + // check permission for each id in passed list until success. // Note that "quickCheck" id come first in the list // Check with no roles or purposes on the chance that the permission fields contain _NA_ s. @@ -531,7 +531,7 @@ } //if (Debug.infoOn()) Debug.logInfo(entityIdString, module); } - + List alreadyCheckedIds = FastList.newInstance(); Map<String, GenericValue> entities = FastMap.newInstance(); //List purposeList = null; @@ -545,11 +545,11 @@ break; } } - + if (passed) { return true; } - + if (auxiliaryValueGetter != null) { //if (Debug.infoOn()) Debug.logInfo(auxiliaryValueGetter.dumpAsText(), module); // Check with just purposes next. @@ -558,18 +558,18 @@ if (entity == null) continue; checkAncestors = false; passed = hasMatch(entity, permissionConditionGetter, relatedRoleGetter, auxiliaryValueGetter, partyId, checkAncestors); - + if (passed) { break; } } } - + if (passed) return true; - + // TODO: need to return some information here about why it failed if (partyId == null) return false; - + // Check with roles. if (relatedRoleGetter != null) { for (Object id: entityIdList) { @@ -577,59 +577,59 @@ if (entity == null) continue; checkAncestors = false; passed = hasMatch(entity, permissionConditionGetter, relatedRoleGetter, auxiliaryValueGetter, partyId, checkAncestors); - + if (passed) { break; } } } - + if (passed) return true; - + if (relatedRoleGetter != null) { for (Object id: entityIdList) { GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, id, entities); if (entity == null) continue; checkAncestors = true; passed = hasMatch(entity, permissionConditionGetter, relatedRoleGetter, auxiliaryValueGetter, partyId, checkAncestors); - + if (passed) { break; } } } - - + + return passed; } - - + + public static GenericValue getNextEntity(GenericDelegator delegator, String entityName, String pkFieldName, Object obj, Map<String, GenericValue> entities) throws GenericEntityException { GenericValue entity = null; if (obj instanceof String) { String entityId = (String)obj; if (entities != null) entity = entities.get(entityId); - + if (entity == null) entity = delegator.findByPrimaryKeyCache(entityName,UtilMisc.toMap(pkFieldName, entityId)); } else if (obj instanceof GenericValue) { entity = (GenericValue)obj; } return entity; } - + public static boolean checkHasRoleOperations(String partyId, PermissionConditionGetter permissionConditionGetter , GenericDelegator delegator) { List<String> targetOperations = permissionConditionGetter.getOperationList(); return checkHasRoleOperations(partyId, targetOperations, delegator); } - + public static boolean checkHasRoleOperations(String partyId, List<String> targetOperations, GenericDelegator delegator) { //if (Debug.infoOn()) Debug.logInfo("targetOperations:" + targetOperations, module); //if (Debug.infoOn()) Debug.logInfo("userLoginId:" + userLoginId, module); if (targetOperations == null) return false; - + if (partyId != null && targetOperations.contains("HAS_USER_ROLE")) return true; - + boolean hasRoleOperation = false; boolean hasNeed = false; List<String> newHasRoleList = FastList.newInstance(); @@ -646,7 +646,7 @@ } } } - + if (hasNeed) { try { if (UtilValidate.isNotEmpty(partyId)) { @@ -670,7 +670,7 @@ } return hasRoleOperation; } - + public static boolean hasMatch(String entityName, List<GenericValue> targetOperations, List<String> roles, boolean hasPurposeOp, List<String> purposes, boolean hasStatusOp, String targStatusId) { boolean isMatch = false; int targPrivilegeSeq = 0; @@ -691,24 +691,24 @@ //if (hasPrivilegeOp) //testPrivilegeEnumId = (String)targetOp.get("privilegeEnumId"); //int testPrivilegeSeq = 0; - + boolean purposesCond = ( !hasPurposeOp || (purposes != null && purposes.contains(testContentPurposeTypeId) ) || testContentPurposeTypeId.equals("_NA_") ); boolean statusCond = ( !hasStatusOp || testStatusId.equals("_NA_") || (targStatusId != null && targStatusId.equals(testStatusId) ) ); //boolean privilegeCond = ( !hasPrivilegeOp || testPrivilegeEnumId.equals("_NA_") || testPrivilegeSeq <= targPrivilegeSeq || testPrivilegeEnumId.equals(targPrivilegeEnumId) ); boolean roleCond = ( testRoleTypeId.equals("_NA_") || (roles != null && roles.contains(testRoleTypeId) ) ); - - + + if (purposesCond && statusCond && roleCond) { - + isMatch = true; break; } } return isMatch; } - + public static boolean hasMatch(GenericValue entity, PermissionConditionGetter permissionConditionGetter, RelatedRoleGetter relatedRoleGetter, AuxiliaryValueGetter auxiliaryValueGetter, String partyId, boolean checkAncestors) throws GenericEntityException { - + ModelEntity modelEntity = entity.getModelEntity(); GenericDelegator delegator = entity.getDelegator(); String pkFieldName = modelEntity.getFirstPkFieldName(); @@ -736,22 +736,22 @@ } else { if (Debug.verboseOn()) Debug.logVerbose("NO ROLE GETTER", module); } - + String targStatusId = null; if (modelEntity.getField("statusId") != null) { targStatusId = entity.getString("statusId"); } if (Debug.verboseOn()) Debug.logVerbose("STATUS:" + targStatusId, module); - + while (permissionConditionGetter.getNext() ) { String roleConditionId = permissionConditionGetter.getRoleValue(); String auxiliaryConditionId = permissionConditionGetter.getAuxiliaryValue(); String statusConditionId = permissionConditionGetter.getStatusValue(); - + boolean auxiliaryCond = ( auxiliaryConditionId == null || auxiliaryConditionId.equals("_NA_") || (auxiliaryValueList != null && auxiliaryValueList.contains(auxiliaryConditionId) ) ); boolean statusCond = ( statusConditionId == null || statusConditionId.equals("_NA_") || (targStatusId != null && targStatusId.equals(statusConditionId) ) ); boolean roleCond = ( roleConditionId == null || roleConditionId.equals("_NA_") || (roleValueList != null && roleValueList.contains(roleConditionId) ) ); - + if (auxiliaryCond && statusCond && roleCond) { if (Debug.verboseOn()) Debug.logVerbose("MATCHED: role:" + roleConditionId + " status:" + statusConditionId + " aux:" + auxiliaryConditionId, module); isMatch = true; @@ -760,14 +760,14 @@ } return isMatch; } - + /** * getRelatedPurposes */ public static List<String> getRelatedPurposes(GenericValue entity, List<String> passedPurposes) { - + if (entity == null) return passedPurposes; - + List<String> purposeIds = null; if (passedPurposes == null) { purposeIds = FastList.newInstance( ); @@ -775,10 +775,10 @@ purposeIds = FastList.newInstance( ); purposeIds.addAll( passedPurposes ); } - + String entityName = entity.getEntityName(); String lcEntityName = entityName.toLowerCase(); - + List<GenericValue> purposes = null; try { purposes = entity.getRelatedCache(entityName + "Purpose"); @@ -786,16 +786,16 @@ Debug.logError(e, "No associated purposes found. ", module); return purposeIds; } - + for (GenericValue val: purposes) { purposeIds.add((String) val.get(lcEntityName + "PurposeTypeId")); } - - + + return purposeIds; } - - + + /** * getUserRoles * Queries for the ContentRoles associated with a Content entity @@ -803,13 +803,13 @@ * Follows group parties to see if the user is a member. */ public static List<String> getUserRoles(GenericValue entity, GenericValue userLogin, GenericDelegator delegator) throws GenericEntityException { - + String entityName = entity.getEntityName(); List<String> roles = FastList.newInstance(); if (entity == null) return roles; // TODO: Need to use ContentManagementWorker.getAuthorContent first - - + + roles.remove("OWNER"); // always test with the owner of the current content if ( entity.get("createdByUserLogin") != null && userLogin != null) { String userLoginId = (String)userLogin.get("userLoginId"); @@ -820,7 +820,7 @@ //if (Debug.infoOn()) Debug.logInfo("in getUserRoles, passedRoles(0):" + passedRoles, null); } } - + String partyId = (String)userLogin.get("partyId"); List<GenericValue> relatedRoles = null; List<GenericValue> tmpRelatedRoles = entity.getRelatedCache(entityName + "Role"); @@ -842,7 +842,7 @@ partyTypeId = (String)party.get("partyTypeId"); if ( partyTypeId != null && partyTypeId.equals("PARTY_GROUP") ) { Map<String, Object> map = FastMap.newInstance(); - + // At some point from/thru date will need to be added map.put("partyIdFrom", partyId); map.put("partyIdTo", targPartyId); @@ -859,8 +859,8 @@ } return roles; } - - + + /** * Tests to see if the user belongs to a group */ @@ -872,7 +872,7 @@ String roleTypeIdTo = "PERMISSION_GROUP"; Timestamp fromDate = UtilDateTime.nowTimestamp(); Timestamp thruDate = UtilDateTime.getDayStart(UtilDateTime.nowTimestamp(), 1); - + if (partyRelationshipValues.get("roleTypeIdFrom") != null ) { roleTypeIdFrom = (String)partyRelationshipValues.get("roleTypeIdFrom") ; } @@ -885,22 +885,22 @@ if (partyRelationshipValues.get("thruDate") != null ) { thruDate = (Timestamp)partyRelationshipValues.get("thruDate") ; } - + EntityExpr partyFromExpr = EntityCondition.makeCondition("partyIdFrom", partyIdFrom); EntityExpr partyToExpr = EntityCondition.makeCondition("partyIdTo", partyIdTo); - + EntityExpr relationExpr = EntityCondition.makeCondition("partyRelationshipTypeId", "CONTENT_PERMISSION"); //EntityExpr roleTypeIdFromExpr = EntityCondition.makeCondition("roleTypeIdFrom", "CONTENT_PERMISSION_GROUP_MEMBER"); //EntityExpr roleTypeIdToExpr = EntityCondition.makeCondition("roleTypeIdTo", "CONTENT_PERMISSION_GROUP"); EntityExpr fromExpr = EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, fromDate); EntityCondition thruCond = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("thruDate", null), EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, thruDate)), EntityOperator.OR); - + // This method is simplified to make it work, these conditions need to be added back in. //List joinList = UtilMisc.toList(fromExpr, thruCond, partyFromExpr, partyToExpr, relationExpr); List<? extends EntityCondition> joinList = UtilMisc.toList( partyFromExpr, partyToExpr); EntityCondition condition = EntityCondition.makeCondition(joinList); - + List<GenericValue> partyRelationships = null; try { partyRelationships = delegator.findList("PartyRelationship", condition, null, null, null, false); @@ -911,13 +911,13 @@ if (partyRelationships.size() > 0) { isMember = true; } - + return isMember; } - - + + public interface PermissionConditionGetter { - + public boolean getNext(); public String getRoleValue(); public String getOperationValue(); @@ -932,9 +932,9 @@ public String dumpAsText(); public void clearList(); } - + public static class StdPermissionConditionGetter implements PermissionConditionGetter { - + protected List<GenericValue> entityList; protected List<String> operationList; protected ListIterator<GenericValue> iter; @@ -945,9 +945,9 @@ protected String privilegeFieldName; protected String auxiliaryFieldName; protected String entityName; - + public StdPermissionConditionGetter () { - + this.operationFieldName = "contentOperationId"; this.roleFieldName = "roleTypeId"; this.statusFieldName = "statusId"; @@ -955,9 +955,9 @@ this.auxiliaryFieldName = "contentPurposeTypeId"; this.entityName = "ContentPurposeOperation"; } - + public StdPermissionConditionGetter ( String entityName, String operationFieldName, String roleFieldName, String statusFieldName, String auxiliaryFieldName, String privilegeFieldName) { - + this.operationFieldName = operationFieldName; this.roleFieldName = roleFieldName ; this.statusFieldName = statusFieldName ; @@ -965,7 +965,7 @@ this.auxiliaryFieldName = auxiliaryFieldName ; this.entityName = entityName; } - + public StdPermissionConditionGetter ( Element getterElement) { this.operationFieldName = getterElement.getAttribute("operation-field-name"); this.roleFieldName = getterElement.getAttribute("role-field-name"); @@ -974,7 +974,7 @@ this.auxiliaryFieldName = getterElement.getAttribute("auxiliary-field-name"); this.entityName = getterElement.getAttribute("entity-name"); } - + public boolean getNext() { boolean hasNext = false; if (iter != null && iter.hasNext()) { @@ -983,23 +983,23 @@ } return hasNext; } - + public String getRoleValue() { return this.currentValue.getString(this.roleFieldName); } - + public String getOperationValue() { return this.currentValue.getString(this.operationFieldName); } public String getStatusValue() { return this.currentValue.getString(this.statusFieldName); - + } public int getPrivilegeValue() throws GenericEntityException { int privilegeEnumSeq = -1; String privilegeEnumId = null; GenericDelegator delegator = currentValue.getDelegator(); - + if (UtilValidate.isNotEmpty(privilegeFieldName)) { privilegeEnumId = currentValue.getString(this.privilegeFieldName); } @@ -1015,51 +1015,51 @@ } } return privilegeEnumSeq; - + } - + public String getAuxiliaryValue() { return this.currentValue.getString(this.auxiliaryFieldName); } - + public void setOperationList(String operationIdString) { - + this.operationList = null; if (UtilValidate.isNotEmpty(operationIdString)) { this.operationList = StringUtil.split(operationIdString, "|"); } } - + public void setOperationList(List<String> operationList) { this.operationList = operationList; } - + public List<String> getOperationList() { return this.operationList; } - + public void clearList() { this.entityList = FastList.newInstance(); } - + public void init( GenericDelegator delegator) throws GenericEntityException { EntityCondition opCond = EntityCondition.makeCondition(operationFieldName, EntityOperator.IN, this.operationList); this.entityList = delegator.findList(this.entityName, opCond, null, null, null, true); } - + public void restart() { this.iter = null; if (this.entityList != null) { this.iter = this.entityList.listIterator(); } } - + public String dumpAsText() { List<String> fieldNames = UtilMisc.toList("roleFieldName", "auxiliaryFieldName", "statusFieldName"); Map<String, Integer> widths = UtilMisc.toMap("roleFieldName", Integer.valueOf(24), "auxiliaryFieldName", Integer.valueOf(24), "statusFieldName", Integer.valueOf(24)); StringBuilder buf = new StringBuilder(); Integer wid = null; - + buf.append("Dump for "); buf.append(this.entityName); buf.append(" ops:"); @@ -1090,7 +1090,7 @@ for (int i=0; i < (wid.intValue() - contentOperationId.length()); i++) buf.append("^"); buf.append(" "); */ - + String roleTypeId = contentPurposeOperation.getString(this.roleFieldName); if (UtilValidate.isEmpty(roleTypeId)) { roleTypeId = ""; @@ -1099,7 +1099,7 @@ buf.append(roleTypeId); for (int i=0; i < (wid.intValue() - roleTypeId.length()); i++) buf.append("^"); buf.append(" "); - + String auxiliaryFieldValue = contentPurposeOperation.getString(this.auxiliaryFieldName); if (UtilValidate.isEmpty(auxiliaryFieldValue)) { auxiliaryFieldValue = ""; @@ -1108,7 +1108,7 @@ buf.append(auxiliaryFieldValue); for (int i=0; i < (wid.intValue() - auxiliaryFieldValue.length()); i++) buf.append("^"); buf.append(" "); - + String statusId = contentPurposeOperation.getString(this.statusFieldName); if (UtilValidate.isEmpty(statusId)) { statusId = ""; @@ -1119,63 +1119,63 @@ for (int i=0; i < (wid.intValue() - statusId.length()); i++) buf.append(" "); */ buf.append(" "); - + buf.append("\n"); } } return buf.toString(); } } - + public interface AuxiliaryValueGetter { public void init(GenericDelegator delegator, String entityId) throws GenericEntityException; public List<String> getList(); public void clearList(); public String dumpAsText(); } - + public static class StdAuxiliaryValueGetter implements AuxiliaryValueGetter { - + protected List<String> entityList = FastList.newInstance(); protected String auxiliaryFieldName; protected String entityName; protected String entityIdName; - + public StdAuxiliaryValueGetter () { - + this.auxiliaryFieldName = "contentPurposeTypeId"; this.entityName = "ContentPurpose"; this.entityIdName = "contentId"; } - + public StdAuxiliaryValueGetter ( String entityName, String auxiliaryFieldName, String entityIdName) { - + this.auxiliaryFieldName = auxiliaryFieldName ; this.entityName = entityName; this.entityIdName = entityIdName; } - + public StdAuxiliaryValueGetter ( Element getterElement) { - + this.auxiliaryFieldName = getterElement.getAttribute("auxiliary-field-name"); this.entityName = getterElement.getAttribute("entity-name"); this.entityIdName = getterElement.getAttribute("entity-id-name"); } - + public List<String> getList() { return entityList; } - + public void clearList() { this.entityList = FastList.newInstance(); } - + public void setList(List<String> lst) { this.entityList = lst; } - + public void init(GenericDelegator delegator, String entityId) throws GenericEntityException { - + if (this.entityList == null) { this.entityList = FastList.newInstance(); } @@ -1187,7 +1187,7 @@ this.entityList.add(entity.getString(this.auxiliaryFieldName)); } } - + public String dumpAsText() { StringBuilder buf = new StringBuilder(); buf.append("AUXILIARY: "); @@ -1200,7 +1200,7 @@ return buf.toString(); } } - + public interface RelatedRoleGetter { public void init(GenericDelegator delegator, String entityId, String partyId, GenericValue entity) throws GenericEntityException; public void initWithAncestors(GenericDelegator delegator, GenericValue entity, String partyId) throws GenericEntityException; @@ -1210,9 +1210,9 @@ public String dumpAsText(); public boolean isOwner(GenericValue entity, String targetPartyId); } - + public static class StdRelatedRoleGetter implements RelatedRoleGetter { - + protected List<String> roleIdList = FastList.newInstance(); protected String roleTypeFieldName; protected String partyFieldName; @@ -1220,9 +1220,9 @@ protected String roleEntityIdName; protected String roleEntityName; protected String ownerEntityFieldName; - + public StdRelatedRoleGetter () { - + this.roleTypeFieldName = "roleTypeId"; this.partyFieldName = "partyId"; this.ownerEntityFieldName = "ownerContentId"; @@ -1230,9 +1230,9 @@ this.roleEntityName = "ContentRole"; this.roleEntityIdName = "contentId"; } - + public StdRelatedRoleGetter ( String entityName, String roleTypeFieldName, String roleEntityIdName, String partyFieldName, String ownerEntityFieldName, String roleEntityName) { - + this.roleTypeFieldName = roleTypeFieldName ; this.partyFieldName = partyFieldName ; this.ownerEntityFieldName = ownerEntityFieldName ; @@ -1240,9 +1240,9 @@ this.roleEntityName = roleEntityName; this.roleEntityIdName = roleEntityIdName; } - + public StdRelatedRoleGetter ( Element getterElement) { - + this.roleTypeFieldName = getterElement.getAttribute("role-type-field-name"); this.partyFieldName = getterElement.getAttribute("party-field-name"); this.ownerEntityFieldName = getterElement.getAttribute("owner-entity-field-name"); @@ -1250,21 +1250,21 @@ this.roleEntityName = getterElement.getAttribute("role-entity-name"); this.roleEntityIdName = getterElement.getAttribute("entity-id-name"); } - + public List<String> getList() { return this.roleIdList; } - + public void clearList() { this.roleIdList = FastList.newInstance(); } - + public void setList(List<String> lst) { this.roleIdList = lst; } - + public void init(GenericDelegator delegator, String entityId, String partyId, GenericValue entity) throws GenericEntityException { - + List<String> lst = getUserRolesFromList(delegator, UtilMisc.toList(entityId), partyId, this.roleEntityIdName, this.partyFieldName, this.roleTypeFieldName, this.roleEntityName); this.roleIdList.addAll(lst); @@ -1272,9 +1272,9 @@ this.roleIdList.add("OWNER"); } } - + public void initWithAncestors(GenericDelegator delegator, GenericValue entity, String partyId) throws GenericEntityException { - + List<String> ownedContentIdList = FastList.newInstance(); getEntityOwners(delegator, entity, ownedContentIdList, this.entityName, this.ownerEntityFieldName); if (ownedContentIdList.size() > 0) { @@ -1282,7 +1282,7 @@ this.roleIdList.addAll(lst); } } - + public boolean isOwner( GenericValue entity, String targetPartyId) { boolean isOwner = false; if (entity == null || targetPartyId == null) { @@ -1307,12 +1307,12 @@ } } catch (GenericEntityException e) { Debug.logInfo(e.getMessage() + " Returning false for 'isOwner'.", module); - + } } return isOwner; } - + public String dumpAsText() { StringBuilder buf = new StringBuilder(); buf.append("ROLES: "); @@ -1327,7 +1327,7 @@ } public static List<String> getUserRolesFromList(GenericDelegator delegator, List<String> idList, String partyId, String entityIdFieldName, String partyIdFieldName, String roleTypeIdFieldName, String entityName) throws GenericEntityException { - + EntityExpr expr = EntityCondition.makeCondition(entityIdFieldName, EntityOperator.IN, idList); EntityExpr expr2 = EntityCondition.makeCondition(partyIdFieldName, partyId); EntityConditionList condList = EntityCondition.makeCondition(UtilMisc.toList(expr, expr2)); @@ -1359,7 +1359,7 @@ public static int getPrivilegeEnumSeq(GenericDelegator delegator, String privilegeEnumId) throws GenericEntityException { int privilegeEnumSeq = -1; - + if ( UtilValidate.isNotEmpty(privilegeEnumId)) { GenericValue privEnum = delegator.findByPrimaryKeyCache("Enumeration", UtilMisc.toMap("enumId", privilegeEnumId)); if (privEnum != null) { Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java?rev=759233&r1=759232&r2=759233&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java Fri Mar 27 16:56:29 2009 @@ -64,9 +64,9 @@ * Entity Engine Sync Services */ public class EntitySyncContext { - + public static final String module = EntitySyncContext.class.getName(); - + // set default split to 10 seconds, ie try not to get too much data moving over at once public static final long defaultSyncSplitMillis = 10000; @@ -91,13 +91,13 @@ public String targetServiceName; public String targetDelegatorName; - + public Timestamp syncEndStamp; public long offlineSyncSplitMillis = defaultOfflineSyncSplitMillis; public long syncSplitMillis = defaultSyncSplitMillis; public long syncEndBufferMillis = defaultSyncEndBufferMillis; public long maxRunningNoUpdateMillis = defaultMaxRunningNoUpdateMillis; - + public Timestamp lastSuccessfulSynchTime; public List<ModelEntity> entityModelToUseList; public Set<String> entityNameToUseSet; @@ -113,7 +113,7 @@ public Timestamp nextCreateTxTime = null; public Timestamp nextUpdateTxTime = null; public Timestamp nextRemoveTxTime = null; - + // this is the other part of the history PK, leave null until we create the history object public Timestamp startDate = null; @@ -153,7 +153,7 @@ this.userLogin = (GenericValue) context.get("userLogin"); - + this.entitySyncId = (String) context.get("entitySyncId"); Debug.logInfo("Creating EntitySyncContext with entitySyncId=" + entitySyncId, module); @@ -172,7 +172,7 @@ targetServiceName = entitySync.getString("targetServiceName"); targetDelegatorName = entitySync.getString("targetDelegatorName"); - + // make the last time to sync X minutes before the current time so that if this machines clock is up to that amount of time //ahead of another machine writing to the DB it will still work fine and not lose any data syncEndStamp = new Timestamp(System.currentTimeMillis() - syncEndBufferMillis); @@ -185,11 +185,11 @@ this.lastSuccessfulSynchTime = entitySync.getTimestamp("lastSuccessfulSynchTime"); this.entityModelToUseList = this.makeEntityModelToUseList(); this.entityNameToUseSet = this.makeEntityNameToUseSet(); - + // set start and end times for the first/current pass this.currentRunStartTime = getCurrentRunStartTime(lastSuccessfulSynchTime, entityModelToUseList, delegator); this.setCurrentRunEndTime(); - + // this is mostly for the pull side... will always be null for at the beginning of a push process, to be filled in later this.startDate = (Timestamp) context.get("startDate"); } catch (GenericEntityException e) { @@ -207,7 +207,7 @@ throw new SyncDataErrorException("Unable to commit transaction", e); } } - + /** * To see if it is running check: * - in the running status @@ -221,7 +221,7 @@ if (!isInRunning) { return false; } - + Timestamp esLastUpdated = this.entitySync.getTimestamp(ModelEntity.STAMP_FIELD); if (esLastUpdated == null) { // shouldn't ever happen, but just in case; assume is running if we don't know when it was last updated @@ -234,18 +234,18 @@ // it has been longer than the maxRunningNoUpdateMillis, so don't consider it running return false; } - + return true; } - + public boolean hasMoreTimeToSync() { return currentRunStartTime.before(syncEndStamp); } - + protected void setCurrentRunEndTime() { this.currentRunEndTime = getNextRunEndTime(); } - + protected Timestamp getNextRunEndTime() { long syncSplit = this.isOfflineSync ? offlineSyncSplitMillis : syncSplitMillis; Timestamp nextRunEndTime = new Timestamp(this.currentRunStartTime.getTime() + syncSplit); @@ -254,7 +254,7 @@ } return nextRunEndTime; } - + public void advanceRunTimes() { this.currentRunStartTime = this.currentRunEndTime; this.setCurrentRunEndTime(); @@ -263,7 +263,7 @@ public void setSplitStartTime() { this.splitStartTime = System.currentTimeMillis(); } - + protected static long getSyncSplitMillis(GenericValue entitySync) { long splitMillis = defaultSyncSplitMillis; Long syncSplitMillis = entitySync.getLong("syncSplitMillis"); @@ -290,7 +290,7 @@ } return syncEndBufferMillis; } - + protected static long getMaxRunningNoUpdateMillis(GenericValue entitySync) { long maxRunningNoUpdateMillis = defaultMaxRunningNoUpdateMillis; Long maxRunningNoUpdateMillisLong = entitySync.getLong("maxRunningNoUpdateMillis"); @@ -299,7 +299,7 @@ } return maxRunningNoUpdateMillis; } - + /** create history record, target service should run in own tx */ public void createInitialHistory() throws SyncDataErrorException, SyncServiceErrorException { String errorMsg = "Not running EntitySync [" + entitySyncId + "], could not create EntitySyncHistory"; @@ -313,20 +313,20 @@ throw new SyncServiceErrorException(errorMsg, e); } } - + public ArrayList<GenericValue> assembleValuesToCreate() throws SyncDataErrorException { // first grab all values inserted in the date range, then get the updates (leaving out all values inserted in the data range) ArrayList<GenericValue> valuesToCreate = new ArrayList<GenericValue>(); // make it an ArrayList to easily merge in sorted lists - + if (this.nextCreateTxTime != null && (this.nextCreateTxTime.equals(currentRunEndTime) || this.nextCreateTxTime.after(currentRunEndTime))) { // this means that for all entities in this pack we found on the last pass that there would be nothing for this one, so just return nothing... return valuesToCreate; } //Debug.logInfo("Getting values to create; currentRunStartTime=" + currentRunStartTime + ", currentRunEndTime=" + currentRunEndTime, module); - + int entitiesSkippedForKnownNext = 0; - + // iterate through entities, get all records with tx stamp in the current time range, put all in a single list for (ModelEntity modelEntity: entityModelToUseList) { int insertBefore = 0; @@ -367,16 +367,16 @@ valuesPerEntity++; } eli.close(); - + // definately remove this message and related data gathering //long preCount = delegator.findCountByCondition(modelEntity.getEntityName(), findValCondition, null); //long entityTotalCount = delegator.findCountByCondition(modelEntity.getEntityName(), null, null); //if (entityTotalCount > 0 || preCount > 0 || valuesPerEntity > 0) Debug.logInfo("Got " + valuesPerEntity + "/" + preCount + "/" + entityTotalCount + " values for entity " + modelEntity.getEntityName(), module); - + // if we didn't find anything for this entity, find the next value's Timestamp and keep track of it if (valuesPerEntity == 0) { Timestamp startCheckStamp = new Timestamp(System.currentTimeMillis() - syncEndBufferMillis); - + EntityCondition findNextCondition = EntityCondition.makeCondition( EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null), EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunEndTime)); @@ -404,7 +404,7 @@ } catch (GenericEntityException e) { try { TransactionUtil.rollback(beganTransaction, "Entity Engine error in assembleValuesToCreate", e); - + } catch (GenericTransactionException e2) { Debug.logWarning(e2, "Unable to call rollback()", module); } @@ -428,7 +428,7 @@ if (entitiesSkippedForKnownNext > 0) { if (Debug.infoOn()) Debug.logInfo("In assembleValuesToCreate skipped [" + entitiesSkippedForKnownNext + "/" + entityModelToUseList + "] entities for the time period ending at [" + currentRunEndTime + "] because of next known create times", module); } - + // TEST SECTION: leave false for normal use boolean logValues = false; if (logValues && valuesToCreate.size() > 0) { @@ -443,7 +443,7 @@ } Debug.logInfo(toCreateInfo.toString(), module); } - + return valuesToCreate; } @@ -457,13 +457,13 @@ } // Debug.logInfo("Getting values to store; currentRunStartTime=" + currentRunStartTime + ", currentRunEndTime=" + currentRunEndTime, module); - + int entitiesSkippedForKnownNext = 0; - + // iterate through entities, get all records with tx stamp in the current time range, put all in a single list for (ModelEntity modelEntity: entityModelToUseList) { int insertBefore = 0; - + // first test to see if we know that there are no records for this entity in this time period... Timestamp knownNextUpdateTime = this.nextEntityUpdateTxTime.get(modelEntity.getEntityName()); if (knownNextUpdateTime != null && (knownNextUpdateTime.equals(currentRunEndTime) || knownNextUpdateTime.after(currentRunEndTime))) { @@ -504,7 +504,7 @@ valuesPerEntity++; } eli.close(); - + // definately remove this message and related data gathering //long preCount = delegator.findCountByCondition(modelEntity.getEntityName(), findValCondition, null); //long entityTotalCount = delegator.findCountByCondition(modelEntity.getEntityName(), null, null); @@ -513,7 +513,7 @@ // if we didn't find anything for this entity, find the next value's Timestamp and keep track of it if (valuesPerEntity == 0) { Timestamp startCheckStamp = new Timestamp(System.currentTimeMillis() - syncEndBufferMillis); - + EntityCondition findNextCondition = EntityCondition.makeCondition( EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null), EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunEndTime), @@ -566,7 +566,7 @@ if (entitiesSkippedForKnownNext > 0) { if (Debug.infoOn()) Debug.logInfo("In assembleValuesToStore skipped [" + entitiesSkippedForKnownNext + "/" + entityModelToUseList + "] entities for the time period ending at [" + currentRunEndTime + "] because of next known update times", module); } - + // TEST SECTION: leave false for normal use boolean logValues = false; if (logValues && valuesToStore.size() > 0) { @@ -581,7 +581,7 @@ } Debug.logInfo(toStoreInfo.toString(), module); } - + return valuesToStore; } @@ -633,7 +633,7 @@ Debug.logError(e, errorMsg, module); throw new SyncDataErrorException(errorMsg, e); } - + // set the stamp fields for future reference pkToRemove.set(ModelEntity.STAMP_TX_FIELD, entitySyncRemove.get(ModelEntity.STAMP_TX_FIELD)); pkToRemove.set(ModelEntity.STAMP_FIELD, entitySyncRemove.get(ModelEntity.STAMP_FIELD)); @@ -696,10 +696,10 @@ } Debug.logInfo(toRemoveInfo.toString(), module); } - + return keysToRemove; } - + public void saveResultsReportedFromDataStore() throws SyncDataErrorException, SyncServiceErrorException { try { long runningTimeMillis = System.currentTimeMillis() - startDate.getTime(); @@ -712,7 +712,7 @@ if (splitTotalTime > this.perSplitMaxMillis) { this.perSplitMaxMillis = splitTotalTime; } - + // start the timer for the next split setSplitStartTime(); @@ -758,13 +758,13 @@ updateHistoryMap.put("perSplitMaxItems", Long.valueOf(perSplitMaxItems)); updateHistoryMap.put("userLogin", userLogin); Map<String, Object> updateEsHistRunResult = dispatcher.runSync("updateEntitySyncHistory", updateHistoryMap); - + // now we have updated EntitySync and EntitySyncHistory, check both ops for errors... if (ServiceUtil.isError(updateEsRunResult)) { String errorMsg = "Error running EntitySync [" + entitySyncId + "], update of EntitySync record with lastSuccessfulSynchTime failed."; throw new SyncDataErrorException(errorMsg, null, null, updateEsRunResult, null); } - + if (ServiceUtil.isError(updateEsHistRunResult)) { String errorMsg = "Error running EntitySync [" + entitySyncId + "], update of EntitySyncHistory (startDate:[" + startDate + "]) record with lastSuccessfulSynchTime and result stats failed."; throw new SyncDataErrorException(errorMsg, null, null, updateEsHistRunResult, null); @@ -773,7 +773,7 @@ throw new SyncServiceErrorException("Error saving results reported from data store", e); } } - + public void saveFinalSyncResults() throws SyncDataErrorException, SyncServiceErrorException { String newStatusId = "ESR_COMPLETE"; if (this.isOfflineSync && totalRowsExported > 0) { @@ -791,7 +791,7 @@ } catch (GenericServiceException e) { throw new SyncServiceErrorException(esErrMsg, e); } - + // if nothing moved over, remove the history record, otherwise store status long totalRows = totalRowsToCreate + totalRowsToStore + totalRowsToRemove; if (totalRows == 0) { @@ -817,7 +817,7 @@ throw new SyncServiceErrorException(eshCompleteErrMsg, e); } } - + if (Debug.infoOn()) Debug.logInfo("Finished saveFinalSyncResults [" + entitySyncId + "]: totalRows=" + totalRows + ", totalRowsToCreate=" + totalRowsToCreate + ", totalRowsToStore=" + totalRowsToStore + ", totalRowsToRemove=" + totalRowsToRemove, module); } @@ -828,7 +828,7 @@ } return entityNameToUseSet; } - + /** prepare a list of all entities we want to synchronize: remove all view-entities and all entities that don't match the patterns attached to this EntitySync */ protected List<ModelEntity> makeEntityModelToUseList() throws GenericEntityException { List<GenericValue> entitySyncIncludes = entitySync.getRelated("EntitySyncInclude"); @@ -837,7 +837,7 @@ entitySyncIncludes.addAll(entitySyncGroupIncludes); List<ModelEntity> entityModelToUseList = EntityGroupUtil.getModelEntitiesFromRecords(entitySyncIncludes, delegator, true); - + if (Debug.infoOn()) Debug.logInfo("In makeEntityModelToUseList for EntitySync with ID [" + entitySync.get("entitySyncId") + "] syncing " + entityModelToUseList.size() + " entities", module); return entityModelToUseList; } @@ -895,12 +895,12 @@ if (UtilValidate.isEmpty(targetServiceName)) { throw new SyncAbortException("Not running EntitySync [" + entitySyncId + "], no targetServiceName is specified, where do we send the data?"); } - + // check to see if this sync is already running, if so return error if (this.isEntitySyncRunning()) { throw new SyncAbortException("Not running EntitySync [" + entitySyncId + "], an instance is already running."); } - + String markErrorMsg = "Could not start Entity Sync service, could not mark as running"; try { // not running, get started NOW @@ -912,11 +912,11 @@ } catch (GenericServiceException e) { throw new SyncServiceErrorException(markErrorMsg, e); } - + // finally create the initial history record this.createInitialHistory(); } - + public long setTotalRowCounts(ArrayList<GenericValue> valuesToCreate, ArrayList<GenericValue> valuesToStore, List<GenericEntity> keysToRemove) { this.totalRowsToCreate = valuesToCreate.size(); this.totalRowsToStore = valuesToStore.size(); @@ -924,11 +924,11 @@ this.totalRowsPerSplit = this.totalRowsToCreate + this.totalRowsToStore + this.totalRowsToRemove; return this.totalRowsPerSplit; } - + public void runPushSendData(ArrayList<GenericValue> valuesToCreate, ArrayList<GenericValue> valuesToStore, List<GenericEntity> keysToRemove) throws SyncOtherErrorException, SyncServiceErrorException { // grab the totals for this data this.setTotalRowCounts(valuesToCreate, valuesToStore, keysToRemove); - + // call service named on EntitySync, IFF there is actually data to send over if (this.totalRowsPerSplit > 0) { Map<String, Object> targetServiceMap = UtilMisc.toMap("entitySyncId", entitySyncId, "valuesToCreate", valuesToCreate, "valuesToStore", valuesToStore, "keysToRemove", keysToRemove, "userLogin", userLogin); @@ -941,9 +941,9 @@ if (ServiceUtil.isError(remoteStoreResult)) { throw new SyncOtherErrorException(serviceErrorMsg, null, null, remoteStoreResult, null); } - + this.totalStoreCalls++; - + long toCreateInsertedCur = remoteStoreResult.get("toCreateInserted") == null ? 0 : ((Long) remoteStoreResult.get("toCreateInserted")).longValue(); long toCreateUpdatedCur = remoteStoreResult.get("toCreateUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toCreateUpdated")).longValue(); long toCreateNotUpdatedCur = remoteStoreResult.get("toCreateNotUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toCreateNotUpdated")).longValue(); @@ -952,7 +952,7 @@ long toStoreNotUpdatedCur = remoteStoreResult.get("toStoreNotUpdated") == null ? 0 : ((Long) remoteStoreResult.get("toStoreNotUpdated")).longValue(); long toRemoveDeletedCur = remoteStoreResult.get("toRemoveDeleted") == null ? 0 : ((Long) remoteStoreResult.get("toRemoveDeleted")).longValue(); long toRemoveAlreadyDeletedCur = remoteStoreResult.get("toRemoveAlreadyDeleted") == null ? 0 : ((Long) remoteStoreResult.get("toRemoveAlreadyDeleted")).longValue(); - + this.toCreateInserted += toCreateInsertedCur; this.toCreateUpdated += toCreateUpdatedCur; this.toCreateNotUpdated += toCreateNotUpdatedCur; @@ -966,14 +966,14 @@ } } } - + // ======================== PULL Methods ======================== public void runPullStartOrRestoreSavedResults() throws SyncDataErrorException, SyncServiceErrorException, SyncAbortException { // if EntitySync.statusId is ESR_RUNNING, make sure startDate matches EntitySync.lastHistoryStartDate; or return error if (isEntitySyncRunning() && this.startDate == null) { throw new SyncAbortException("Not running EntitySync [" + entitySyncId + "], an instance is already running and no startDate for the current run was passed."); } - + if (this.startDate == null) { // get it started! String markErrorMsg = "Could not start Entity Sync service, could not mark as running"; @@ -987,7 +987,7 @@ } catch (GenericServiceException e) { throw new SyncServiceErrorException(markErrorMsg, e); } - + // finally create the initial history record this.createInitialHistory(); this.setSplitStartTime(); @@ -1021,7 +1021,7 @@ } catch (GenericEntityException e) { throw new SyncDataErrorException("Error getting existing EntitySyncHistory values", e); } - + // got the previous values, now add to them with the values from the context... this.toCreateInserted += UtilMisc.toLong(this.context.get("toCreateInserted")); this.toCreateUpdated += UtilMisc.toLong(this.context.get("toCreateUpdated")); @@ -1031,7 +1031,7 @@ this.toStoreNotUpdated += UtilMisc.toLong(this.context.get("toStoreNotUpdated")); this.toRemoveDeleted += UtilMisc.toLong(this.context.get("toRemoveDeleted")); this.toRemoveAlreadyDeleted += UtilMisc.toLong(this.context.get("toRemoveAlreadyDeleted")); - + this.totalStoreCalls++; this.saveResultsReportedFromDataStore(); @@ -1109,7 +1109,7 @@ public SyncErrorException(String str, List<Object> errorMsgList, Map<String, Object> errorMsgMap, Map<String, Object> nestedServiceResult, Throwable nested) { super(str, errorMsgList, errorMsgMap, nestedServiceResult, nested); } public abstract void saveSyncErrorInfo(EntitySyncContext esc); } - + /** This class signifies an error condition, so the state of the EntitySync value and the EntitySyncHistory value in the datasource should be changed to reflect the error */ public static class SyncOtherErrorException extends SyncErrorException { public SyncOtherErrorException() { super(); } @@ -1125,7 +1125,7 @@ } } } - + /** This class signifies an error condition, so the state of the EntitySync value and the EntitySyncHistory value in the datasource should be changed to reflect the error */ public static class SyncDataErrorException extends SyncErrorException { public SyncDataErrorException() { super(); } @@ -1141,7 +1141,7 @@ } } } - + /** This class signifies an error condition, so the state of the EntitySync value and the EntitySyncHistory value in the datasource should be changed to reflect the error */ public static class SyncServiceErrorException extends SyncErrorException { public SyncServiceErrorException() { super(); } |
Free forum by Nabble | Edit this page |