1 25 package org.ofbiz.shark.mapping; 26 27 import java.util.List ; 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 31 import org.ofbiz.entity.GenericDelegator; 32 import org.ofbiz.entity.GenericEntityException; 33 import org.ofbiz.entity.GenericValue; 34 import org.ofbiz.shark.container.SharkContainer; 35 import org.ofbiz.shark.transaction.JtaTransaction; 36 import org.ofbiz.base.util.UtilMisc; 37 38 import org.enhydra.shark.api.internal.working.CallbackUtilities; 39 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMap; 40 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMappingManager; 41 import org.enhydra.shark.api.RootException; 42 import org.enhydra.shark.api.ParticipantMappingTransaction; 43 import org.enhydra.shark.api.TransactionException; 44 45 52 public class EntityParticipantMappingMgr implements ParticipantMappingManager { 53 54 public static final String module = EntityParticipantMappingMgr.class.getName(); 55 56 protected CallbackUtilities callBack = null; 57 58 public void configure(CallbackUtilities callbackUtilities) throws RootException { 59 this.callBack = callbackUtilities; 60 } 61 62 public boolean saveParticipantMapping(ParticipantMappingTransaction mappingTransaction, ParticipantMap participantMap) throws RootException { 63 ((EntityParticipantMap) participantMap).store(); 64 return true; 65 } 66 67 public boolean deleteParticipantMapping(ParticipantMappingTransaction mappingTransaction, ParticipantMap participantMap) throws RootException { 68 ((EntityParticipantMap) participantMap).remove(); 69 return true; 70 } 71 72 public List getAllParticipantMappings(ParticipantMappingTransaction mappingTransaction) throws RootException { 73 GenericDelegator delegator = SharkContainer.getDelegator(); 74 List lookupList = null; 75 try { 76 lookupList = delegator.findAll("WfParticipantMap"); 77 } catch (GenericEntityException e) { 78 throw new RootException(e); 79 } 80 if (lookupList != null) { 81 List compiledList = new ArrayList (); 82 Iterator i = lookupList.iterator(); 83 while (i.hasNext()) { 84 GenericValue v = (GenericValue) i.next(); 85 compiledList.add(EntityParticipantMap.getInstance(v)); 86 } 87 return compiledList; 88 } else { 89 return new ArrayList (); 90 } 91 } 92 93 public boolean doesParticipantMappingExist(ParticipantMappingTransaction mappingTransaction, ParticipantMap participantMap) throws RootException { 94 List mappings = getParticipantMappings(mappingTransaction, participantMap.getPackageId(), participantMap.getProcessDefinitionId(), participantMap.getParticipantId()); 95 if (mappings != null && mappings.size() > 0) { 96 return true; 97 } 98 return false; 99 } 100 101 public ParticipantMap createParticipantMap() { 102 return new EntityParticipantMap(SharkContainer.getDelegator()); 103 } 104 105 public List getParticipantMappings(ParticipantMappingTransaction mappingTransaction, String packageId, String processDefId, String participantId) throws RootException { 106 GenericDelegator delegator = SharkContainer.getDelegator(); 107 List lookupList = null; 108 try { 109 lookupList = delegator.findByAnd("WfParticipantMap", UtilMisc.toMap("packageId", packageId, "processDefId", processDefId, "participantId", participantId)); 110 } catch (GenericEntityException e) { 111 throw new RootException(e); 112 } 113 if (lookupList != null) { 114 List compiledList = new ArrayList (); 115 Iterator i = lookupList.iterator(); 116 while (i.hasNext()) { 117 GenericValue v = (GenericValue) i.next(); 118 compiledList.add(EntityParticipantMap.getInstance(v)); 119 } 120 return compiledList; 121 } else { 122 return new ArrayList (); 123 } 124 } 125 126 public List getParticipantMappings(ParticipantMappingTransaction mappingTransaction, String userName) throws RootException { 127 GenericDelegator delegator = SharkContainer.getDelegator(); 128 List lookupList = null; 129 try { 130 lookupList = delegator.findByAnd("WfParticipantMap", UtilMisc.toMap("userName", userName)); 131 } catch (GenericEntityException e) { 132 throw new RootException(e); 133 } 134 if (lookupList != null) { 135 List compiledList = new ArrayList (); 136 Iterator i = lookupList.iterator(); 137 while (i.hasNext()) { 138 GenericValue v = (GenericValue) i.next(); 139 compiledList.add(EntityParticipantMap.getInstance(v)); 140 } 141 return compiledList; 142 } else { 143 return new ArrayList (); 144 } 145 } 146 147 public boolean deleteParticipantMappings(ParticipantMappingTransaction mappingTransaction, String packageId, String processDefId, String participantId) throws RootException { 148 List participants = this.getParticipantMappings(mappingTransaction, packageId, processDefId, participantId); 149 if (participants != null) { 150 Iterator i = participants.iterator(); 151 while (i.hasNext()) { 152 EntityParticipantMap map = (EntityParticipantMap) i.next(); 153 map.remove(); 154 } 155 return true; 156 } else { 157 return false; 158 } 159 } 160 161 public boolean deleteParticipantMappings(ParticipantMappingTransaction mappingTransaction, String userName) throws RootException { 162 List participants = this.getParticipantMappings(mappingTransaction, userName); 163 if (participants != null) { 164 Iterator i = participants.iterator(); 165 while (i.hasNext()) { 166 EntityParticipantMap map = (EntityParticipantMap) i.next(); 167 map.remove(); 168 } 169 return true; 170 } else { 171 return false; 172 } 173 } 174 175 public List getUsernames(ParticipantMappingTransaction mappingTransaction, String packageId, String processDefId, String participantId) throws RootException { 176 List participants = this.getParticipantMappings(mappingTransaction, packageId, processDefId, participantId); 177 List compiledList = new ArrayList (); 178 if (participants != null) { 179 Iterator i = participants.iterator(); 180 while (i.hasNext()) { 181 EntityParticipantMap map = (EntityParticipantMap) i.next(); 182 compiledList.add(map.getUsername()); 183 } 184 } 185 return compiledList; 186 } 187 188 public ParticipantMappingTransaction getParticipantMappingTransaction() throws TransactionException { 189 return new JtaTransaction(); 190 } 191 } 192 | Popular Tags |