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