Project

General

Profile

« Previous | Next » 

Revision c2f87993

Added by Andreas Kohlbecker over 6 years ago

ref #7018 adapting taxeditor to changes in cdm permission classes

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
19 19
import org.eclipse.jface.viewers.ISelection;
20 20
import org.eclipse.swt.SWT;
21 21
import org.eclipse.swt.custom.ScrolledComposite;
22
import org.eclipse.swt.layout.GridData;
23 22
import org.eclipse.swt.widgets.Composite;
24 23
import org.eclipse.swt.widgets.Control;
25 24
import org.springframework.security.core.GrantedAuthority;
......
36 35

  
37 36
/**
38 37
 * Viewer class for the {@link CdmAuthorityComposite} used in the editing of CDM Authorities.
39
 * 
38
 *
40 39
 * @author cmathew
41 40
 * @created Mar 28, 2013
42 41
 *
......
45 44

  
46 45
//FIXME:move warning dialogs to the table class
47 46
public class CdmAuthorityCompositeViewer extends ContentViewer {
48
	
49
	private IDirtyMarkable dirtyMarkerEditor;	
47

  
48
	private IDirtyMarkable dirtyMarkerEditor;
50 49
	private CdmAuthorityComposite cdmAuthorityComposite;
51 50
	private Group group;
52 51
	private boolean isDirty = false;
......
56 55
	private List<GrantedAuthorityImpl> cdmAuthorities;
57 56
	/**
58 57
	 * List which contains newly added (unsaved) authority objects.
59
	 * Used to make sure that new authority objects are always added 
58
	 * Used to make sure that new authority objects are always added
60 59
	 * to the top of the table.
61 60
	 */
62 61
	private List<GrantedAuthorityImpl> newCdmAuthorities;
63
	
64
	
62

  
63

  
65 64
	/**
66
	 * Creates a viewer with a {@link CdmAuthorityComposite} table, {@link Group} object as input 
67
	 * 
65
	 * Creates a viewer with a {@link CdmAuthorityComposite} table, {@link Group} object as input
66
	 *
68 67
	 * @param composite parent of generated {@link CdmAuthorityComposite}
69 68
	 * @param dirtyMarkerEditor provider to mark as dirty
70 69
	 * @param group input data object
71 70
	 */
72 71
	public CdmAuthorityCompositeViewer(Composite composite,
73
			IDirtyMarkable dirtyMarkerEditor, 
72
			IDirtyMarkable dirtyMarkerEditor,
74 73
			Group group) {
75 74
		this.dirtyMarkerEditor = dirtyMarkerEditor;
76 75
		this.group = group;
77
		newCdmAuthorities = new ArrayList<GrantedAuthorityImpl>();		
76
		newCdmAuthorities = new ArrayList<GrantedAuthorityImpl>();
78 77
		updateAuthorities();
79
		
78

  
80 79
		ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
81 80
		this.cdmAuthorityComposite = new CdmAuthorityComposite(sc, SWT.H_SCROLL | SWT.V_SCROLL, this);
82 81
		sc.setContent(cdmAuthorityComposite);
......
88 87

  
89 88
	/**
90 89
	 * Gets the {@link CdmAuthorityComposite}
91
	 * 
90
	 *
92 91
	 * @return {@link CdmAuthorityComposite} generated by this viewer
93 92
	 */
94 93
	public CdmAuthorityComposite getCdmAuthorityComposite() {
95 94
		return cdmAuthorityComposite;
96 95
	}
97
	
98
	
96

  
97

  
99 98
	/**
100 99
	 * Retrieves the {@link GrantedAuthorityImpl} objects of the group attached to this viewer
101 100
	 * creates a sub-list of only {@link CdmAuthority} objects.
102
	 * 
101
	 *
103 102
	 * @return list of {@link CdmAuthority} objects belonging to the input group
104 103
	 */
105 104
	public List<GrantedAuthorityImpl> updateAuthorities()  {
106 105
		// get all granted authorities
107 106
		Set<GrantedAuthority> grantedAuthorities = group.getGrantedAuthorities();
108
		cdmAuthorities = new ArrayList<GrantedAuthorityImpl>();	
109
		
110
		Iterator<GrantedAuthority> itr = grantedAuthorities.iterator();		
107
		cdmAuthorities = new ArrayList<GrantedAuthorityImpl>();
108

  
109
		Iterator<GrantedAuthority> itr = grantedAuthorities.iterator();
111 110
		while (itr.hasNext()) {
112 111
			GrantedAuthority grantedAuthority = itr.next();
113 112
			try {
114
				
115
				if(grantedAuthority != null && grantedAuthority instanceof GrantedAuthorityImpl) {			
113

  
114
				if(grantedAuthority != null && grantedAuthority instanceof GrantedAuthorityImpl) {
116 115
					// create a cdm authority from a granted authority
117 116
					// this could fail in which case an exception is thrown
118 117
					CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthority);
119
					cdmAuthorities.add((GrantedAuthorityImpl)grantedAuthority);				
118
					cdmAuthorities.add((GrantedAuthorityImpl)grantedAuthority);
120 119
				}
121 120
			} catch (Exception e) {
122
				// not a CdmAuthority				
121
				// not a CdmAuthority
123 122
				//e.printStackTrace();
124
			}			
123
			}
125 124
		}
126 125
		return cdmAuthorities;
127 126
	}
128
	
127

  
129 128
	public boolean isDirty() {
130 129
		return isDirty;
131 130
	}
132 131
	/**
133 132
	 * Adds a new {@link CdmAuthority} to the group attached to this viewer
134 133
	 * based on the input {@link CdmBase} object.
135
	 * 
134
	 *
136 135
	 * @param cb {@link CdmBase} object used to construct the cdm authority
137 136
	 */
138 137
	public void addCdmAuthority(CdmBase cb) {
139 138
		// Default permission is to READ
140 139
		EnumSet<CRUD> defaultOperation = EnumSet.noneOf(CRUD.class);
141 140
		defaultOperation.add(CRUD.READ);
142
		CdmAuthority cdma = new CdmAuthority(cb, defaultOperation, cb.getUuid());
141
		CdmAuthority cdma = new CdmAuthority(cb, defaultOperation);
143 142
		GrantedAuthorityImpl gai;
144
		
143

  
145 144
		try {
146
			// create a granted authrity from a cdm authority 
145
			// create a granted authrity from a cdm authority
147 146
			gai = cdma.asNewGrantedAuthority();
148
		} catch (Exception e) {			
147
		} catch (Exception e) {
149 148
			MessagingUtils.warningDialog("Parsing Error", this, "Could not parse authority string");
150 149
			return;
151 150
		}
......
153 152
		//        need to have a comparator which only checks permission class and uuid
154 153
		if(cdmAuthorities.contains(gai) || newCdmAuthorities.contains(gai)) {
155 154
			MessagingUtils.warningDialog("Duplicate CDM Authority", this, "Chosen CDM Authority is already attached to current group");
156
		} else {								
155
		} else {
157 156
			group.addGrantedAuthority(gai);
158 157
			newCdmAuthorities.add(gai);
159 158
			isDirty = true;
160
			dirtyMarkerEditor.changed(group);		
159
			dirtyMarkerEditor.changed(group);
161 160
			cdmAuthorityComposite.refresh();
162 161
		}
163 162
	}
164
	
163

  
165 164
	/**
166 165
	 * Removes the given {@link GrantedAuthorityImpl} object from the list of
167 166
	 * granted authorities belonging to the group attached to this viewer.
168
	 * 
167
	 *
169 168
	 * @param gai {@link GrantedAuthorityImpl} object to remove
170 169
	 */
171 170
	public void removeCdmAuthority(GrantedAuthorityImpl gai) {
172
		
173
		if(cdmAuthorities.contains(gai)) {					
174
			cdmAuthorities.remove(gai);		
171

  
172
		if(cdmAuthorities.contains(gai)) {
173
			cdmAuthorities.remove(gai);
175 174
			isDirty = true;
176
		} else {						
175
		} else {
177 176
			newCdmAuthorities.remove(gai);
178 177
			if(newCdmAuthorities.isEmpty() && !isDirty) {
179 178
				isDirty = false;
180 179
			}
181 180
		}
182
		group.removeGrantedAuthority(gai);		
183
		dirtyMarkerEditor.changed(group);		
181
		group.removeGrantedAuthority(gai);
182
		dirtyMarkerEditor.changed(group);
184 183
		cdmAuthorityComposite.refresh();
185 184
	}
186
	
185

  
187 186
	/**
188 187
	 * Updates an existing {@link GrantedAuthorityImpl} object using a {@link CdmAuthority} object.
189
	 * 
188
	 *
190 189
	 * @param grantedAuthorityI to update.
191 190
	 * @param cdmAuthority to use in updating the granted authority object.
192 191
	 */
193 192
	public GrantedAuthorityImpl updateGrantedAuthority(GrantedAuthorityImpl grantedAuthorityI, CdmAuthority cdmAuthority) {
194 193
		if(grantedAuthorityI.getAuthority().equals(cdmAuthority.getAuthority())) {
195
			
194

  
196 195
		} else {
197 196
			try {
198 197
				// since granted authority is just a wrapper object around a string
......
212 211
		}
213 212
		return grantedAuthorityI;
214 213
	}
215
	
214

  
216 215
	/**
217 216
	 * @return list of existing cdm authority objects
218 217
	 */
219 218
	public List<GrantedAuthorityImpl> getCdmAuthorities() {
220 219
		return cdmAuthorities;
221 220
	}
222
	
221

  
223 222
	/**
224 223
	 * @return list of newly added cdm authority objects
225 224
	 */
226 225
	public List<GrantedAuthorityImpl> getNewCdmAuthorities() {
227 226
		return newCdmAuthorities;
228 227
	}
229
	
228

  
230 229

  
231 230
	/**
232 231
	 * Empty the list of newly create autrity objects
......
235 234
		newCdmAuthorities.clear();
236 235
	}
237 236

  
238
	
237

  
239 238
	/**
240
	 * 
241
	 * 
239
	 *
240
	 *
242 241
	 */
243 242
	public void save() {
244
		clearNewCdmAuthorities();		
243
		clearNewCdmAuthorities();
245 244
		refresh();
246
		
247
	}	
248
	
245

  
246
	}
247

  
249 248
	/* (non-Javadoc)
250 249
	 * @see org.eclipse.jface.viewers.Viewer#getControl()
251 250
	 */
......
270 269
	public void refresh() {
271 270
		updateAuthorities();
272 271
		cdmAuthorityComposite.refresh();
273
		
272

  
274 273
	}
275 274

  
276 275
	/* (non-Javadoc)
......
279 278
	@Override
280 279
	public void setSelection(ISelection selection, boolean reveal) {
281 280
		// TODO Auto-generated method stub
282
		
281

  
283 282
	}
284 283
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/grantedAuthority/GrantedAuthorityLabelTextProvider.java
9 9
import eu.etaxonomy.cdm.api.service.IClassificationService;
10 10
import eu.etaxonomy.cdm.api.service.IDescriptionService;
11 11
import eu.etaxonomy.cdm.api.service.INameService;
12
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
12 13
import eu.etaxonomy.cdm.api.service.IReferenceService;
14
import eu.etaxonomy.cdm.api.service.IRegistrationService;
13 15
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
14 16
import eu.etaxonomy.cdm.api.service.ITaxonService;
15 17
import eu.etaxonomy.cdm.api.service.IUserService;
......
18 20
import eu.etaxonomy.taxeditor.store.CdmStore;
19 21

  
20 22
public class GrantedAuthorityLabelTextProvider {
21
	
23

  
22 24
	public static final Logger logger = Logger.getLogger(CdmAuthority.class);
23
	
24
	
25

  
26

  
25 27
	public static String getText(GrantedAuthority grantedAuthority){
26 28
		String labelText =  grantedAuthority.getAuthority();
27 29
		try {
......
30 32
			if(targetLabelText.length() > 0){
31 33
				labelText = grantedAuthority.getAuthority().replace(cdmAuthority.getTargetUUID().toString(), targetLabelText);
32 34
			}
33
		} catch (Exception e) { 
34
			/* will in most cases catch a ParsingException 
35
		} catch (Exception e) {
36
			/* will in most cases catch a ParsingException
35 37
			 * this is ignored
36 38
			 */
37 39
			if(!e.getClass().getSimpleName().equals("ParsingException")){
......
42 44
		}
43 45
		return labelText;
44 46
	}
45
	
47

  
46 48
 	public static String getTargetText(GrantedAuthority grantedAuthority){
47 49
 		if(grantedAuthority instanceof CdmAuthority){
48 50
 			return getCdmAuthorityTargetText((CdmAuthority)grantedAuthority);
49
 			
51

  
50 52
 		}
51 53
 		return "";
52 54
 	}
53 55

  
54 56
	private static String getCdmAuthorityTargetText(CdmAuthority cdmAuthority) {
55
		
57

  
56 58
		UUID uuid = cdmAuthority.getTargetUUID();
57 59
		String targetText = "";
58
		
60

  
59 61
		if(uuid != null){
60 62
			targetText = uuid.toString();
61 63
			if(cdmAuthority.getPermissionClass() != null){
......
91 93
					case CLASSIFICATION:
92 94
						targetText = CdmStore.getService(IClassificationService.class).load(uuid).getTitleCache();
93 95
						break;
94
					case REFERENCE: 
96
					case REFERENCE:
95 97
						targetText = CdmStore.getService(IReferenceService.class).load(uuid).getTitleCache();
96 98
						break;
97 99
					case TAXONNAME:
......
100 102
					case TEAMORPERSONBASE:
101 103
						targetText = CdmStore.getService(IAgentService.class).load(uuid).getTitleCache();
102 104
						break;
103
						
105
                    case REGISTRATION:
106
                        targetText = CdmStore.getService(IRegistrationService.class).load(uuid).getIdentifier();
107
                        break;
108
                    case SPECIMENOROBSERVATIONBASE:
109
                        targetText = CdmStore.getService(IOccurrenceService.class).load(uuid).getTitleCache();
110
                        break;
111
                    default:
112
                        break;
113

  
104 114
					}
105 115
				} catch (NullPointerException e){
106 116
					logger.warn("Either no service found for " + cdmAuthority.getPermissionClass() + " or entitiy not found" , e);
107 117
				}
108 118
			}
109 119
		}
110
		
120

  
111 121
		return targetText;
112 122
	}
113
 	
123

  
114 124

  
115 125
}

Also available in: Unified diff