📄 entitypermissionchecker.java
字号:
for (int i=0; i < wid.intValue(); i++) buf.append("-"); buf.append(" "); } buf.append("\n"); if (entityList != null) { Iterator it = this.entityList.iterator(); while (it.hasNext()) { GenericValue contentPurposeOperation = (GenericValue)it.next(); /* String contentOperationId = contentPurposeOperation.getString(this.operationFieldName); if (UtilValidate.isEmpty(contentOperationId)) { contentOperationId = ""; } wid = (Integer)widths.get("operationFieldName"); buf.append(contentOperationId); 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 = ""; } wid = (Integer)widths.get("roleFieldName"); 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 = ""; } wid = (Integer)widths.get("auxiliaryFieldName"); 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 = ""; } buf.append(statusId); /* wid = (Integer)widths.get("statusFieldName"); 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 getList(); public void clearList(); public String dumpAsText(); } public static class StdAuxiliaryValueGetter implements AuxiliaryValueGetter { protected List entityList = new ArrayList(); 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 getList() { return entityList; } public void clearList() { this.entityList = new ArrayList(); } public void setList(List lst) { this.entityList = lst; } public void init(GenericDelegator delegator, String entityId) throws GenericEntityException { if (this.entityList == null) { this.entityList = new ArrayList(); } if (UtilValidate.isEmpty(this.entityName)) { return; } List values = delegator.findByAndCache(this.entityName, UtilMisc.toMap(this.entityIdName, entityId)); Iterator iter = values.iterator(); while (iter.hasNext()) { GenericValue entity = (GenericValue)iter.next(); this.entityList.add(entity.getString(this.auxiliaryFieldName)); } } public String dumpAsText() { StringBuffer buf = new StringBuffer(); buf.append("AUXILIARY: "); if (entityList != null) { for (int i=0; i < entityList.size(); i++) { String val = (String)entityList.get(i); buf.append(val); buf.append(" "); } } 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; public List getList(); public void clearList(); public void setList(List lst); public String dumpAsText(); public boolean isOwner(GenericValue entity, String targetPartyId); } public static class StdRelatedRoleGetter implements RelatedRoleGetter { protected List roleIdList = new ArrayList(); protected String roleTypeFieldName; protected String partyFieldName; protected String entityName; protected String roleEntityIdName; protected String roleEntityName; protected String ownerEntityFieldName; public StdRelatedRoleGetter () { this.roleTypeFieldName = "roleTypeId"; this.partyFieldName = "partyId"; this.ownerEntityFieldName = "ownerContentId"; this.entityName = "Content"; 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 ; this.entityName = entityName; 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"); this.entityName = getterElement.getAttribute("entity-name"); this.roleEntityName = getterElement.getAttribute("role-entity-name"); this.roleEntityIdName = getterElement.getAttribute("entity-id-name"); } public List getList() { return this.roleIdList; } public void clearList() { this.roleIdList = new ArrayList(); } public void setList(List lst) { this.roleIdList = lst; } public void init(GenericDelegator delegator, String entityId, String partyId, GenericValue entity) throws GenericEntityException { List lst = getUserRolesFromList(delegator, UtilMisc.toList(entityId), partyId, this.roleEntityIdName, this.partyFieldName, this.roleTypeFieldName, this.roleEntityName); this.roleIdList.addAll(lst); if (isOwner(entity, partyId)) { this.roleIdList.add("OWNER"); } return; } public void initWithAncestors(GenericDelegator delegator, GenericValue entity, String partyId) throws GenericEntityException { List ownedContentIdList = new ArrayList(); getEntityOwners(delegator, entity, ownedContentIdList, this.entityName, this.ownerEntityFieldName); if (ownedContentIdList.size() > 0) { List lst = getUserRolesFromList(delegator, ownedContentIdList, partyId, this.roleEntityIdName, this.partyFieldName, this.roleTypeFieldName, this.roleEntityName); this.roleIdList.addAll(lst); } return; } public boolean isOwner( GenericValue entity, String targetPartyId) { boolean isOwner = false; if (entity == null || targetPartyId == null) { return false; } GenericDelegator delegator = entity.getDelegator(); ModelEntity modelEntity = delegator.getModelEntity(entityName); if (modelEntity.getField("createdByUserLogin") == null) { return false; } if ( entity.get("createdByUserLogin") != null) { String userLoginIdCB = (String)entity.get("createdByUserLogin"); try { GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginIdCB )); if (userLogin != null) { String partyIdCB = userLogin.getString("partyId"); if (partyIdCB != null) { if (partyIdCB.equals(targetPartyId)) { isOwner = true; } } } } catch(GenericEntityException e) { Debug.logInfo(e.getMessage() + " Returning false for 'isOwner'.", module); } } return isOwner; } public String dumpAsText() { StringBuffer buf = new StringBuffer(); buf.append("ROLES: "); if (roleIdList != null) { for (int i=0; i < roleIdList.size(); i++) { String val = (String)roleIdList.get(i); buf.append(val); buf.append(" "); } } return buf.toString(); } } public static List getUserRolesFromList(GenericDelegator delegator, List idList, String partyId, String entityIdFieldName, String partyIdFieldName, String roleTypeIdFieldName, String entityName) throws GenericEntityException { EntityExpr expr = new EntityExpr(entityIdFieldName, EntityOperator.IN, idList); EntityExpr expr2 = new EntityExpr(partyIdFieldName, EntityOperator.EQUALS, partyId); EntityConditionList condList = new EntityConditionList(UtilMisc.toList(expr, expr2), EntityOperator.AND); List roleList = delegator.findByConditionCache(entityName, condList, null, null); List roleListFiltered = EntityUtil.filterByDate(roleList); HashSet distinctSet = new HashSet(); Iterator iter = roleListFiltered.iterator(); while (iter.hasNext()) { GenericValue contentRole = (GenericValue)iter.next(); String roleTypeId = contentRole.getString(roleTypeIdFieldName); distinctSet.add(roleTypeId); } List distinctList = Arrays.asList(distinctSet.toArray()); return distinctList; } public static void getEntityOwners(GenericDelegator delegator, GenericValue entity, List contentOwnerList, String entityName, String ownerIdFieldName) throws GenericEntityException { String ownerContentId = entity.getString(ownerIdFieldName); if (UtilValidate.isNotEmpty(ownerContentId)) { contentOwnerList.add(ownerContentId); ModelEntity modelEntity = delegator.getModelEntity(entityName); String pkFieldName = modelEntity.getFirstPkFieldName(); GenericValue ownerContent = delegator.findByPrimaryKeyCache(entityName, UtilMisc.to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -