1 package org.enhydra.shark.swingclient.workflowadmin.user; 2 3 import java.awt.*; 4 import java.util.*; 5 6 import javax.swing.*; 7 import javax.swing.table.*; 8 9 10 import org.enhydra.shark.api.client.wfservice.*; 11 12 import org.enhydra.jawe.xml.elements.*; 13 import org.enhydra.shark.swingclient.*; 14 import org.enhydra.shark.swingclient.workflowadmin.*; 15 import org.enhydra.shark.swingclient.workflowadmin.user.actions.*; 16 17 import org.enhydra.jawe.JaWE; 18 19 27 public class UserMappingManagement extends ActionPanel { 28 29 private SharkAdmin workflowAdmin; 30 private UserAccountManagement userAccountManagement; 31 32 private TablePanel existingMappingsPanel; 33 34 private Map participantKeyToParticipant=new HashMap(); 35 36 Map actions=new HashMap(); 37 38 public UserMappingManagement (SharkAdmin wa,UserAccountManagement uam) { 39 super(); 40 this.workflowAdmin=wa; 41 this.userAccountManagement=uam; 42 super.init(); 43 } 44 45 protected void createActions () { 46 defaultActions=new Action[] { 47 new AddUserMapping(this), 48 new RemoveUserMapping(this) 49 }; 50 } 51 52 protected Component createCenterComponent() { 53 Vector columnNames=new Vector(); 54 columnNames.add(ResourceManager.getLanguageDependentString("PackageIdKey")); 55 columnNames.add(ResourceManager.getLanguageDependentString("ProcessDefinitionIdKey")); 56 columnNames.add(ResourceManager.getLanguageDependentString("ParticipantIdKey")); 57 columnNames.add(ResourceManager.getLanguageDependentString("ParticipantNameKey")); 58 columnNames.add("-->"); 59 columnNames.add(ResourceManager.getLanguageDependentString("UsernameKey")); 60 columnNames.add(ResourceManager.getLanguageDependentString("FirstNameKey")); 61 columnNames.add(ResourceManager.getLanguageDependentString("LastNameKey")); 62 columnNames.add(ResourceManager.getLanguageDependentString("IsGroupUserKey")); 63 existingMappingsPanel=new TablePanel(columnNames, true); 64 JTable t=existingMappingsPanel.getTable(); 65 TableColumnModel tcm=t.getColumnModel(); 66 TableColumn column=t.getColumnModel().getColumn(4); 67 column.setMaxWidth(30); 68 column.setMinWidth(30); 69 column.setPreferredWidth(30); 70 column.setResizable(false); 71 72 return existingMappingsPanel; 73 } 74 75 public Map getParticipantKeyToParticipant () { 76 return participantKeyToParticipant; 77 } 78 79 public TablePanel getExistingMappingsPanel () { 80 return existingMappingsPanel; 81 } 82 83 public UserAccountManagement getUserAccountManagement () { 84 return userAccountManagement; 85 } 86 87 public void clear () { 88 participantKeyToParticipant.clear(); 89 existingMappingsPanel.removeAll(); 90 } 91 92 public synchronized void refresh (boolean mandatoryRefreshing) { 93 if (!(mandatoryRefreshing || isShowing())) return; 94 SharkConnection wcs=workflowAdmin.getService(); 95 if (wcs==null) return; 96 java.util.List allMappings=null; 97 UserGroupAdministration uga=SharkAdmin.getUserGroupAmin(); 98 99 try { 100 allMappings=new ArrayList(Arrays.asList(SharkAdmin.getParticipantMappingsAdmin().getAllParticipantMappings())); 101 } catch (Exception ex) { 102 ex.printStackTrace(); 103 System.out.println("Something went wrong during retrieval of participant mappings from engine"); 104 return; 105 } 106 Collection pkgs=JaWE.getInstance().getXMLInterface().getAllPackages(); 107 existingMappingsPanel.removeAll(); 108 participantKeyToParticipant.clear(); 109 110 createParticipantsMap(pkgs); 112 113 Iterator it=allMappings.iterator(); 115 while (it.hasNext()) { 116 ParticipantMap pm=(ParticipantMap)it.next(); 117 try { 118 Vector v=new Vector(); 119 v.add(pm.getPackageId()); 120 v.add(pm.getProcessDefinitionId()); 121 v.add(pm.getParticipantId()); 122 Participant p=((Participant)participantKeyToParticipant. 123 get(WorkflowUtilities. 124 createParticipantOrApplicationKey( 125 pm.getPackageId(), 126 pm.getProcessDefinitionId(), 127 pm.getParticipantId()))); 128 if (p!=null) { 129 v.add(p.get("Name").toString()); 130 } else { 131 v.add(""); 132 } 133 v.add(""); 134 v.add(pm.getUsername()); 135 try { 136 if( !pm.getIsGroupUser() ) { 138 v.add(uga.getUserFirstName(pm.getUsername())); 139 v.add(uga.getUserLastName(pm.getUsername())); 140 } 141 else { 142 v.add(""); 143 v.add(""); 144 } 145 } catch (Exception ex) { 147 v.add(""); 148 v.add(""); 149 } 150 v.add( new Boolean (pm.getIsGroupUser()) ); 151 try { 152 existingMappingsPanel.addElement(v); 153 } catch (Exception ex) { 154 System.out.println("Incorrect vector size"); 155 } 156 } catch (Exception ex) {} 157 } 158 } 159 160 private void createParticipantsMap (Collection packageColl) { 161 participantKeyToParticipant.clear(); 162 163 ArrayList allLoadedParticipants=new ArrayList(); 164 try { 165 ParticipantMap[] maps=SharkAdmin.getParticipantMappingsAdmin().getAllParticipants(); 166 for (int i=0; i<maps.length; i++) { 167 allLoadedParticipants.add( 168 WorkflowUtilities.createParticipantOrApplicationKey( 169 maps[i].getPackageId(), 170 maps[i].getProcessDefinitionId(), 171 maps[i].getParticipantId())); 172 } 173 } catch (Exception ex) { 174 } 175 176 if (allLoadedParticipants.size()==0) return; 177 178 org.enhydra.jawe.xml.elements.Package pkg; 179 Iterator packages=packageColl.iterator(); 180 while (packages.hasNext()) { 181 pkg=(org.enhydra.jawe.xml.elements.Package)packages.next(); 182 Participants ps=(Participants)pkg.get("Participants"); 183 Iterator participants=ps.toCollection().iterator(); 184 while (participants.hasNext()) { 185 Participant p=(Participant)participants.next(); 186 String participantKey=WorkflowUtilities.createParticipantOrApplicationKey( 187 pkg.get("Id").toString(),"",p.getID()); 188 if (allLoadedParticipants.contains(participantKey)) { 189 participantKeyToParticipant.put(participantKey,p); 190 } 191 } 192 Iterator processes=((WorkflowProcesses)pkg.get("WorkflowProcesses")). 193 toCollection().iterator(); 194 while (processes.hasNext()) { 195 WorkflowProcess wp=(WorkflowProcess)processes.next(); 196 ps=(Participants)wp.get("Participants"); 197 participants=ps.toCollection().iterator(); 198 while (participants.hasNext()) { 199 Participant p=(Participant)participants.next(); 200 String participantKey=WorkflowUtilities.createParticipantOrApplicationKey( 201 pkg.get("Id").toString(),wp.getID(),p.getID()); 202 if (allLoadedParticipants.contains(participantKey)) { 203 participantKeyToParticipant.put(participantKey,p); 204 } 205 } 206 } 207 } 208 } 209 210 public SharkAdmin getWorkflowAdmin () { 211 return workflowAdmin; 212 } 213 214 } 215 | Popular Tags |