1 16 17 18 41 package com.opensourcestrategies.crmsfa.cases; 42 43 import java.util.Map ; 44 import java.util.List ; 45 import java.util.ArrayList ; 46 import java.util.Iterator ; 47 48 import org.ofbiz.base.util.Debug; 49 import org.ofbiz.base.util.UtilMisc; 50 import org.ofbiz.entity.GenericDelegator; 51 import org.ofbiz.entity.GenericValue; 52 import org.ofbiz.entity.GenericEntityException; 53 import org.ofbiz.entity.condition.EntityConditionList; 54 import org.ofbiz.entity.condition.EntityExpr; 55 import org.ofbiz.entity.condition.EntityOperator; 56 import org.ofbiz.entity.util.EntityFindOptions; 57 import org.ofbiz.entity.util.EntityUtil; 58 import org.ofbiz.entity.util.EntityListIterator; 59 60 66 public class UtilCase { 67 68 public static final String module = UtilCase.class.getName(); 69 70 public static List CASE_STATUSES_COMPLETED = null; 72 static { 73 CASE_STATUSES_COMPLETED = UtilMisc.toList("CRQ_COMPLETED", "CRQ_CANCELLED", "CRQ_REJECTED"); 74 } 75 76 80 public static List getCaseAccountsAndContacts(GenericDelegator delegator, String custRequestId) throws GenericEntityException { 81 return getCasePartiesByRole(delegator, custRequestId, UtilMisc.toList("ACCOUNT", "CONTACT")); 82 } 83 84 88 public static String getCasePrimaryContactPartyId(GenericDelegator delegator, String custRequestId) throws GenericEntityException { 89 List candidates = getCasePartiesByRole(delegator, custRequestId, UtilMisc.toList("CONTACT")); 90 if (candidates.size() > 0) { 91 return ((GenericValue) candidates.get(0)).getString("partyId"); 92 } 93 return null; 94 } 95 96 100 public static String getCasePrimaryAccountPartyId(GenericDelegator delegator, String custRequestId) throws GenericEntityException { 101 List candidates = getCasePartiesByRole(delegator, custRequestId, UtilMisc.toList("ACCOUNT")); 102 if (candidates.size() > 0) { 103 return ((GenericValue) candidates.get(0)).getString("partyId"); 104 } 105 return null; 106 } 107 108 114 public static List getCasePartiesByRole(GenericDelegator delegator, String custRequestId, List roleTypeIds) 115 throws GenericEntityException { 116 117 List roleCondList = new ArrayList (); 119 for (Iterator iter = roleTypeIds.iterator(); iter.hasNext(); ) { 120 String roleTypeId = (String ) iter.next(); 121 roleCondList.add(new EntityExpr("roleTypeId", EntityOperator.EQUALS, roleTypeId)); 122 } 123 EntityConditionList roleEntityCondList = new EntityConditionList(roleCondList, EntityOperator.OR); 124 125 EntityConditionList mainCondList = new EntityConditionList(UtilMisc.toList( 127 roleEntityCondList, 128 new EntityExpr("custRequestId", EntityOperator.EQUALS, custRequestId), 129 EntityUtil.getFilterByDateExpr() 130 ), EntityOperator.AND); 131 132 EntityListIterator partiesIt = delegator.findListIteratorByCondition("PartyRelationshipAndCaseRole", mainCondList, null, 133 UtilMisc.toList("partyId"), null, new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true)); 136 return partiesIt.getCompleteList(); 137 } 138 139 148 public static EntityListIterator getCasesForParty(GenericDelegator delegator, String partyId, String roleTypeId, String casesOrderBy) throws GenericEntityException { 149 if (casesOrderBy == null) { 150 casesOrderBy = "priority DESC"; 151 } 152 EntityConditionList casesCond = new EntityConditionList(UtilMisc.toList( 153 new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CRQ_COMPLETED"), 154 new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CRQ_REJECTED"), 155 new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CRQ_CANCELLED"), 156 new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, roleTypeId), 157 new EntityExpr("partyIdFrom", EntityOperator.EQUALS, partyId) 158 ), EntityOperator.AND); 159 160 EntityListIterator myCases = delegator.findListIteratorByCondition("PartyRelationshipAndCaseRole", casesCond, null, 161 UtilMisc.toList("custRequestId", "custRequestName", "priority", "statusId", "custRequestTypeId", "custRequestCategoryId"), UtilMisc.toList(casesOrderBy), new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true)); 166 167 return myCases; 168 } 169 170 174 public static boolean caseIsInactive(GenericValue custRequest) { 175 for (Iterator iter = CASE_STATUSES_COMPLETED.iterator(); iter.hasNext(); ) { 176 if (iter.next().equals(custRequest.getString("statusId"))) { 177 return true; 178 } 179 } 180 return false; 181 } 182 } 183 | Popular Tags |