/
Group.java
1430 lines (1220 loc) · 41.5 KB
/
Group.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.eperson;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeConfiguration;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.event.Event;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.storage.rdbms.TableRowIterator;
/**
* Class representing a group of e-people.
*
* @author David Stuve
* @version $Revision$
*/
public class Group extends DSpaceObject
{
// findAll sortby types
public static final int ID = 0; // sort by ID
public static final int NAME = 1; // sort by NAME (default)
/** log4j logger */
private static Logger log = Logger.getLogger(Group.class);
/** ID of Anonymous Group */
public static final int ANONYMOUS_ID = 0;
/** ID of Administrator Group */
public static final int ADMIN_ID = 1;
/** Our context */
private Context myContext;
/** The row in the table representing this object */
private TableRow myRow;
/** lists of epeople and groups in the group */
private List<EPerson> epeople = new ArrayList<EPerson>();
private List<Group> groups = new ArrayList<Group>();
/** lists that need to be written out again */
private boolean epeopleChanged = false;
private boolean groupsChanged = false;
/** is this just a stub, or is all data loaded? */
private boolean isDataLoaded = false;
/** Flag set when metadata is modified, for events */
private boolean modifiedMetadata;
/**
* Construct a Group from a given context and tablerow
*
* @param context
* @param row
*/
Group(Context context, TableRow row) throws SQLException
{
myContext = context;
myRow = row;
// Cache ourselves
context.cache(this, row.getIntColumn("eperson_group_id"));
modifiedMetadata = false;
clearDetails();
}
/**
* Populate Group with eperson and group objects
*
* @throws SQLException
*/
public void loadData()
{
// only populate if not already populated
if (!isDataLoaded)
{
// naughty thing to do - swallowing SQL exception and throwing it as
// a RuntimeException - a hack to avoid changing the API all over
// the place
try
{
// get epeople objects
TableRowIterator tri = DatabaseManager.queryTable(myContext,"eperson",
"SELECT eperson.* FROM eperson, epersongroup2eperson WHERE " +
"epersongroup2eperson.eperson_id=eperson.eperson_id AND " +
"epersongroup2eperson.eperson_group_id= ?",
myRow.getIntColumn("eperson_group_id"));
try
{
while (tri.hasNext())
{
TableRow r = (TableRow) tri.next();
// First check the cache
EPerson fromCache = (EPerson) myContext.fromCache(
EPerson.class, r.getIntColumn("eperson_id"));
if (fromCache != null)
{
epeople.add(fromCache);
}
else
{
epeople.add(new EPerson(myContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
{
tri.close();
}
}
// now get Group objects
tri = DatabaseManager.queryTable(myContext,"epersongroup",
"SELECT epersongroup.* FROM epersongroup, group2group WHERE " +
"group2group.child_id=epersongroup.eperson_group_id AND "+
"group2group.parent_id= ? ",
myRow.getIntColumn("eperson_group_id"));
try
{
while (tri.hasNext())
{
TableRow r = (TableRow) tri.next();
// First check the cache
Group fromCache = (Group) myContext.fromCache(Group.class,
r.getIntColumn("eperson_group_id"));
if (fromCache != null)
{
groups.add(fromCache);
}
else
{
groups.add(new Group(myContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
{
tri.close();
}
}
}
catch (Exception e)
{
throw new IllegalStateException(e);
}
isDataLoaded = true;
}
}
/**
* Create a new group
*
* @param context
* DSpace context object
*/
public static Group create(Context context) throws SQLException,
AuthorizeException
{
// FIXME - authorization?
if (!AuthorizeManager.isAdmin(context))
{
throw new AuthorizeException(
"You must be an admin to create an EPerson Group");
}
// Create a table row
TableRow row = DatabaseManager.create(context, "epersongroup");
Group g = new Group(context, row);
log.info(LogManager.getHeader(context, "create_group", "group_id="
+ g.getID()));
context.addEvent(new Event(Event.CREATE, Constants.GROUP, g.getID(), null));
return g;
}
/**
* get the ID of the group object
*
* @return id
*/
public int getID()
{
return myRow.getIntColumn("eperson_group_id");
}
/**
* get name of group
*
* @return name
*/
public String getName()
{
return myRow.getStringColumn("name");
}
/**
* set name of group
*
* @param name
* new group name
*/
public void setName(String name)
{
myRow.setColumn("name", name);
modifiedMetadata = true;
addDetails("name");
}
/**
* add an eperson member
*
* @param e
* eperson
*/
public void addMember(EPerson e)
{
loadData(); // make sure Group has data loaded
if (isMember(e))
{
return;
}
epeople.add(e);
epeopleChanged = true;
myContext.addEvent(new Event(Event.ADD, Constants.GROUP, getID(), Constants.EPERSON, e.getID(), e.getEmail()));
}
/**
* add group to this group
*
* @param g
*/
public void addMember(Group g)
{
loadData(); // make sure Group has data loaded
// don't add if it's already a member
// and don't add itself
if (isMember(g) || getID()==g.getID())
{
return;
}
groups.add(g);
groupsChanged = true;
myContext.addEvent(new Event(Event.ADD, Constants.GROUP, getID(), Constants.GROUP, g.getID(), g.getName()));
}
/**
* remove an eperson from a group
*
* @param e
* eperson
*/
public void removeMember(EPerson e)
{
loadData(); // make sure Group has data loaded
if (epeople.remove(e))
{
epeopleChanged = true;
myContext.addEvent(new Event(Event.REMOVE, Constants.GROUP, getID(), Constants.EPERSON, e.getID(), e.getEmail()));
}
}
/**
* remove group from this group
*
* @param g
*/
public void removeMember(Group g)
{
loadData(); // make sure Group has data loaded
if (groups.remove(g))
{
groupsChanged = true;
myContext.addEvent(new Event(Event.REMOVE, Constants.GROUP, getID(), Constants.GROUP, g.getID(), g.getName()));
}
}
/**
* check to see if an eperson is a direct member.
* If the eperson is a member via a subgroup will be returned <code>false</code>
*
* @param e
* eperson to check membership
*/
public boolean isMember(EPerson e)
{
// special, group 0 is anonymous
if (getID() == Group.ANONYMOUS_ID)
{
return true;
}
loadData(); // make sure Group has data loaded
return epeople.contains(e);
}
/**
* Check to see if g is a direct group member.
* If g is a subgroup via another group will be returned <code>false</code>
*
* @param g
* group to check
*/
public boolean isMember(Group g)
{
loadData(); // make sure Group has data loaded
return groups.contains(g);
}
/**
* fast check to see if an eperson is a member called with eperson id, does
* database lookup without instantiating all of the epeople objects and is
* thus a static method
*
* @param c
* context
* @param groupid
* group ID to check
*/
public static boolean isMember(Context c, int groupid) throws SQLException
{
// special, everyone is member of group 0 (anonymous)
if (groupid == 0)
{
return true;
}
EPerson currentuser = c.getCurrentUser();
return epersonInGroup(c, groupid, currentuser);
}
/**
* Get all of the groups that an eperson is a member of.
*
* @param c
* @param e
* @throws SQLException
*/
public static Group[] allMemberGroups(Context c, EPerson e)
throws SQLException
{
List<Group> groupList = new ArrayList<Group>();
Set<Integer> myGroups = allMemberGroupIDs(c, e);
// now convert those Integers to Groups
Iterator<Integer> i = myGroups.iterator();
while (i.hasNext())
{
groupList.add(Group.find(c, (i.next()).intValue()));
}
return groupList.toArray(new Group[groupList.size()]);
}
/**
* get Set of Integers all of the group memberships for an eperson
*
* @param c
* @param e
* @return Set of Integer groupIDs
* @throws SQLException
*/
public static Set<Integer> allMemberGroupIDs(Context c, EPerson e)
throws SQLException
{
Set<Integer> groupIDs = new HashSet<Integer>();
if (e != null)
{
// two queries - first to get groups eperson is a member of
// second query gets parent groups for groups eperson is a member of
TableRowIterator tri = DatabaseManager.queryTable(c,
"epersongroup2eperson",
"SELECT * FROM epersongroup2eperson WHERE eperson_id= ?", e
.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
int childID = row.getIntColumn("eperson_group_id");
groupIDs.add(Integer.valueOf(childID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
{
tri.close();
}
}
}
// Also need to get all "Special Groups" user is a member of!
// Otherwise, you're ignoring the user's membership to these groups!
// However, we only do this is we are looking up the special groups
// of the current user, as we cannot look up the special groups
// of a user who is not logged in.
if ((c.getCurrentUser() == null) || (((c.getCurrentUser() != null) && (c.getCurrentUser().getID() == e.getID()))))
{
Group[] specialGroups = c.getSpecialGroups();
for(Group special : specialGroups)
{
groupIDs.add(Integer.valueOf(special.getID()));
}
}
// all the users are members of the anonymous group
groupIDs.add(Integer.valueOf(0));
// now we have all owning groups, also grab all parents of owning groups
// yes, I know this could have been done as one big query and a union,
// but doing the Oracle port taught me to keep to simple SQL!
StringBuilder groupQuery = new StringBuilder();
groupQuery.append("SELECT * FROM group2groupcache WHERE ");
Iterator<Integer> i = groupIDs.iterator();
// Build a list of query parameters
Object[] parameters = new Object[groupIDs.size()];
int idx = 0;
while (i.hasNext())
{
int groupID = (i.next()).intValue();
parameters[idx++] = Integer.valueOf(groupID);
groupQuery.append("child_id= ? ");
if (i.hasNext())
{
groupQuery.append(" OR ");
}
}
// was member of at least one group
// NOTE: even through the query is built dynamically, all data is
// separated into the parameters array.
TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
groupQuery.toString(),
parameters);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
int parentID = row.getIntColumn("parent_id");
groupIDs.add(Integer.valueOf(parentID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
{
tri.close();
}
}
return groupIDs;
}
/**
* Get all of the epeople who are a member of the
* specified group, or a member of a sub-group of the
* specified group, etc.
*
* @param c
* DSpace context
* @param g
* Group object
* @return Array of EPerson objects
* @throws SQLException
*/
public static EPerson[] allMembers(Context c, Group g)
throws SQLException
{
List<EPerson> epersonList = new ArrayList<EPerson>();
Set<Integer> myEpeople = allMemberIDs(c, g);
// now convert those Integers to EPerson objects
Iterator<Integer> i = myEpeople.iterator();
while (i.hasNext())
{
epersonList.add(EPerson.find(c, (i.next()).intValue()));
}
return epersonList.toArray(new EPerson[epersonList.size()]);
}
/**
* Get Set of all Integers all of the epeople
* members for a group
*
* @param c
* DSpace context
* @param g
* Group object
* @return Set of Integer epersonIDs
* @throws SQLException
*/
public static Set<Integer> allMemberIDs(Context c, Group g)
throws SQLException
{
// two queries - first to get all groups which are a member of this group
// second query gets all members of each group in the first query
Set<Integer> epeopleIDs = new HashSet<Integer>();
// Get all groups which are a member of this group
TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
"SELECT * FROM group2groupcache WHERE parent_id= ? ",
g.getID());
Set<Integer> groupIDs = new HashSet<Integer>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
int childID = row.getIntColumn("child_id");
groupIDs.add(Integer.valueOf(childID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
{
tri.close();
}
}
// now we have all the groups (including this one)
// it is time to find all the EPeople who belong to those groups
// and filter out all duplicates
Object[] parameters = new Object[groupIDs.size()+1];
int idx = 0;
Iterator<Integer> i = groupIDs.iterator();
// don't forget to add the current group to this query!
parameters[idx++] = Integer.valueOf(g.getID());
StringBuilder epersonQuery = new StringBuilder();
epersonQuery.append("SELECT * FROM epersongroup2eperson WHERE ");
epersonQuery.append("eperson_group_id= ? ");
if (i.hasNext())
{
epersonQuery.append(" OR ");
}
while (i.hasNext())
{
int groupID = (i.next()).intValue();
parameters[idx++] = Integer.valueOf(groupID);
epersonQuery.append("eperson_group_id= ? ");
if (i.hasNext())
{
epersonQuery.append(" OR ");
}
}
//get all the EPerson IDs
// Note: even through the query is dynamically built all data is separated
// into the parameters array.
tri = DatabaseManager.queryTable(c, "epersongroup2eperson",
epersonQuery.toString(),
parameters);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
int epersonID = row.getIntColumn("eperson_id");
epeopleIDs.add(Integer.valueOf(epersonID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
{
tri.close();
}
}
return epeopleIDs;
}
private static boolean epersonInGroup(Context c, int groupID, EPerson e)
throws SQLException
{
Set<Integer> groupIDs = Group.allMemberGroupIDs(c, e);
return groupIDs.contains(Integer.valueOf(groupID));
}
/**
* find the group by its ID
*
* @param context
* @param id
*/
public static Group find(Context context, int id) throws SQLException
{
// First check the cache
Group fromCache = (Group) context.fromCache(Group.class, id);
if (fromCache != null)
{
return fromCache;
}
TableRow row = DatabaseManager.find(context, "epersongroup", id);
if (row == null)
{
return null;
}
else
{
return new Group(context, row);
}
}
/**
* Find the group by its name - assumes name is unique
*
* @param context
* @param name
*
* @return the named Group, or null if not found
*/
public static Group findByName(Context context, String name)
throws SQLException
{
TableRow row = DatabaseManager.findByUnique(context, "epersongroup",
"name", name);
if (row == null)
{
return null;
}
else
{
// First check the cache
Group fromCache = (Group) context.fromCache(Group.class, row
.getIntColumn("eperson_group_id"));
if (fromCache != null)
{
return fromCache;
}
else
{
return new Group(context, row);
}
}
}
/**
* Finds all groups in the site
*
* @param context
* DSpace context
* @param sortField
* field to sort by -- Group.ID or Group.NAME
*
* @return array of all groups in the site
*/
public static Group[] findAll(Context context, int sortField)
throws SQLException
{
String s;
switch (sortField)
{
case ID:
s = "eperson_group_id";
break;
case NAME:
s = "name";
break;
default:
s = "name";
}
// NOTE: The use of 's' in the order by clause can not cause an SQL
// injection because the string is derived from constant values above.
TableRowIterator rows = DatabaseManager.queryTable(
context, "epersongroup",
"SELECT * FROM epersongroup ORDER BY "+s);
try
{
List<TableRow> gRows = rows.toList();
Group[] groups = new Group[gRows.size()];
for (int i = 0; i < gRows.size(); i++)
{
TableRow row = gRows.get(i);
// First check the cache
Group fromCache = (Group) context.fromCache(Group.class, row
.getIntColumn("eperson_group_id"));
if (fromCache != null)
{
groups[i] = fromCache;
}
else
{
groups[i] = new Group(context, row);
}
}
return groups;
}
finally
{
if (rows != null)
{
rows.close();
}
}
}
/**
* Find the groups that match the search query across eperson_group_id or name
*
* @param context
* DSpace context
* @param query
* The search string
*
* @return array of Group objects
*/
public static Group[] search(Context context, String query)
throws SQLException
{
return search(context, query, -1, -1);
}
/**
* Find the groups that match the search query across eperson_group_id or name
*
* @param context
* DSpace context
* @param query
* The search string
* @param offset
* Inclusive offset
* @param limit
* Maximum number of matches returned
*
* @return array of Group objects
*/
public static Group[] search(Context context, String query, int offset, int limit)
throws SQLException
{
String params = "%"+query.toLowerCase()+"%";
StringBuffer queryBuf = new StringBuffer();
queryBuf.append("SELECT * FROM epersongroup WHERE LOWER(name) LIKE LOWER(?) OR eperson_group_id = ? ORDER BY name ASC ");
// Add offset and limit restrictions - Oracle requires special code
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
{
// First prepare the query to generate row numbers
if (limit > 0 || offset > 0)
{
queryBuf.insert(0, "SELECT /*+ FIRST_ROWS(n) */ rec.*, ROWNUM rnum FROM (");
queryBuf.append(") ");
}
// Restrict the number of rows returned based on the limit
if (limit > 0)
{
queryBuf.append("rec WHERE rownum<=? ");
// If we also have an offset, then convert the limit into the maximum row number
if (offset > 0)
{
limit += offset;
}
}
// Return only the records after the specified offset (row number)
if (offset > 0)
{
queryBuf.insert(0, "SELECT * FROM (");
queryBuf.append(") WHERE rnum>?");
}
}
else
{
if (limit > 0)
{
queryBuf.append(" LIMIT ? ");
}
if (offset > 0)
{
queryBuf.append(" OFFSET ? ");
}
}
String dbquery = queryBuf.toString();
// When checking against the eperson-id, make sure the query can be made into a number
Integer int_param;
try {
int_param = Integer.valueOf(query);
}
catch (NumberFormatException e) {
int_param = Integer.valueOf(-1);
}
// Create the parameter array, including limit and offset if part of the query
Object[] paramArr = new Object[]{params, int_param};
if (limit > 0 && offset > 0)
{
paramArr = new Object[]{params, int_param, limit, offset};
}
else if (limit > 0)
{
paramArr = new Object[]{params, int_param, limit};
}
else if (offset > 0)
{
paramArr = new Object[]{params, int_param, offset};
}
TableRowIterator rows =
DatabaseManager.query(context, dbquery, paramArr);
try
{
List<TableRow> groupRows = rows.toList();
Group[] groups = new Group[groupRows.size()];
for (int i = 0; i < groupRows.size(); i++)
{
TableRow row = groupRows.get(i);
// First check the cache
Group fromCache = (Group) context.fromCache(Group.class, row
.getIntColumn("eperson_group_id"));
if (fromCache != null)
{
groups[i] = fromCache;
}
else
{
groups[i] = new Group(context, row);
}
}
return groups;
}
finally
{
if (rows != null)
{
rows.close();
}
}
}
/**
* Returns the total number of groups returned by a specific query, without the overhead
* of creating the Group objects to store the results.
*
* @param context
* DSpace context
* @param query
* The search string
*
* @return the number of groups matching the query
*/
public static int searchResultCount(Context context, String query)
throws SQLException
{
String params = "%"+query.toLowerCase()+"%";
String dbquery = "SELECT count(*) as gcount FROM epersongroup WHERE LOWER(name) LIKE LOWER(?) OR eperson_group_id = ? ";
// When checking against the eperson-id, make sure the query can be made into a number
Integer int_param;
try {
int_param = Integer.valueOf(query);
}
catch (NumberFormatException e) {
int_param = Integer.valueOf(-1);
}
// Get all the epeople that match the query
TableRow row = DatabaseManager.querySingle(context, dbquery, new Object[] {params, int_param});
// use getIntColumn for Oracle count data
Long count;
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
{
count = Long.valueOf(row.getIntColumn("gcount"));
}
else //getLongColumn works for postgres
{
count = Long.valueOf(row.getLongColumn("gcount"));
}
return count.intValue();
}
/**
* Delete a group
*
*/
public void delete() throws SQLException
{
// FIXME: authorizations
myContext.addEvent(new Event(Event.DELETE, Constants.GROUP, getID(), getName()));