-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanges-java.diff
More file actions
757 lines (709 loc) · 35.3 KB
/
changes-java.diff
File metadata and controls
757 lines (709 loc) · 35.3 KB
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
diff --git a/dspace-api/src/main/java/org/dspace/app/reporting/model/PaginatedUserActionsResponse.java b/dspace-api/src/main/java/org/dspace/app/reporting/model/PaginatedUserActionsResponse.java
new file mode 100644
index 0000000000..a0353710a2
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/app/reporting/model/PaginatedUserActionsResponse.java
@@ -0,0 +1,85 @@
+/**
+ * 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.app.reporting.model;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Paginated response wrapper for user actions.
+ */
+public class PaginatedUserActionsResponse {
+
+ @JsonProperty("content")
+ private List<UserAction> content;
+
+ @JsonProperty("totalElements")
+ private long totalElements;
+
+ @JsonProperty("totalPages")
+ private int totalPages;
+
+ @JsonProperty("currentPage")
+ private int currentPage;
+
+ @JsonProperty("pageSize")
+ private int pageSize;
+
+ public PaginatedUserActionsResponse() {
+ }
+
+ public PaginatedUserActionsResponse(List<UserAction> content, long totalElements, int totalPages,
+ int currentPage, int pageSize) {
+ this.content = content;
+ this.totalElements = totalElements;
+ this.totalPages = totalPages;
+ this.currentPage = currentPage;
+ this.pageSize = pageSize;
+ }
+
+ public List<UserAction> getContent() {
+ return content;
+ }
+
+ public void setContent(List<UserAction> content) {
+ this.content = content;
+ }
+
+ public long getTotalElements() {
+ return totalElements;
+ }
+
+ public void setTotalElements(long totalElements) {
+ this.totalElements = totalElements;
+ }
+
+ public int getTotalPages() {
+ return totalPages;
+ }
+
+ public void setTotalPages(int totalPages) {
+ this.totalPages = totalPages;
+ }
+
+ public int getCurrentPage() {
+ return currentPage;
+ }
+
+ public void setCurrentPage(int currentPage) {
+ this.currentPage = currentPage;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+}
\ No newline at end of file
diff --git a/dspace-api/src/main/java/org/dspace/app/reporting/model/UserAction.java b/dspace-api/src/main/java/org/dspace/app/reporting/model/UserAction.java
index a173cf0fda..e8dbdf5233 100644
--- a/dspace-api/src/main/java/org/dspace/app/reporting/model/UserAction.java
+++ b/dspace-api/src/main/java/org/dspace/app/reporting/model/UserAction.java
@@ -47,6 +47,18 @@ public class UserAction {
@JsonProperty("itemUUID")
private String itemUUID;
+ /**
+ * Item identifier (same value as itemUUID for compatibility)
+ */
+ @JsonProperty("itemId")
+ private String itemId;
+
+ /**
+ * Item title
+ */
+ @JsonProperty("itemTitle")
+ private String itemTitle;
+
/**
* Additional details (e.g., "Approved for entry into archive")
*/
@@ -62,6 +74,7 @@ public class UserAction {
this.email = email;
this.actionDate = actionDate;
this.itemUUID = itemUUID;
+ this.itemId = itemUUID;
}
// Getters and Setters
@@ -103,6 +116,23 @@ public class UserAction {
public void setItemUUID(String itemUUID) {
this.itemUUID = itemUUID;
+ this.itemId = itemUUID;
+ }
+
+ public String getItemId() {
+ return itemId;
+ }
+
+ public void setItemId(String itemId) {
+ this.itemId = itemId;
+ }
+
+ public String getItemTitle() {
+ return itemTitle;
+ }
+
+ public void setItemTitle(String itemTitle) {
+ this.itemTitle = itemTitle;
}
public String getDetails() {
@@ -121,6 +151,8 @@ public class UserAction {
", email='" + email + '\'' +
", actionDate=" + actionDate +
", itemUUID='" + itemUUID + '\'' +
+ ", itemId='" + itemId + '\'' +
+ ", itemTitle='" + itemTitle + '\'' +
", details='" + details + '\'' +
'}';
}
diff --git a/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesActionsCacheService.java b/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesActionsCacheService.java
index b16d916670..f838a433d7 100644
--- a/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesActionsCacheService.java
+++ b/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesActionsCacheService.java
@@ -65,7 +65,8 @@ public class UsersActivitiesActionsCacheService {
}
// Get all provenance metadata values
- List<MetadataValue> provenanceValues = metadataValueService.findByField(context, provenanceField);
+ List<MetadataValue> provenanceValues = metadataValueService
+ .findByFieldWithDSpaceObject(context, provenanceField);
for (MetadataValue metadataValue : provenanceValues) {
String provenanceText = metadataValue.getValue();
@@ -77,9 +78,12 @@ public class UsersActivitiesActionsCacheService {
if (metadataValue.getDSpaceObject() instanceof Item) {
Item item = (Item) metadataValue.getDSpaceObject();
String itemUUID = item.getID().toString();
+ String itemTitle = item.getName();
for (UserAction action : actions) {
action.setItemUUID(itemUUID);
+ action.setItemId(itemUUID);
+ action.setItemTitle(itemTitle);
}
}
diff --git a/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportService.java b/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportService.java
index a68d355121..e4da02236a 100644
--- a/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportService.java
+++ b/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportService.java
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Map;
+import org.dspace.app.reporting.model.PaginatedUserActionsResponse;
import org.dspace.app.reporting.model.SummaryWithTrendData;
import org.dspace.app.reporting.model.UserAction;
import org.dspace.app.reporting.model.UserActivityStats;
@@ -30,6 +31,23 @@ public interface UsersActivitiesReportService {
*/
List<UserAction> getAllActions(Context context) throws SQLException;
+ /**
+ * Get actions with optional filters and pagination.
+ *
+ * @param context the DSpace context
+ * @param page page number (0-based)
+ * @param size page size
+ * @param itemId optional item id filter
+ * @param actionType optional action type filter
+ * @param userEmail optional user email filter
+ * @param userName optional user name filter
+ * @return paginated and filtered actions response
+ * @throws SQLException if database error occurs
+ */
+ PaginatedUserActionsResponse getActions(Context context, int page, int size, String itemId,
+ String actionType, String userEmail, String userName)
+ throws SQLException;
+
/**
* Get aggregated statistics per user (submissions and reviews)
*
diff --git a/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportServiceImpl.java b/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportServiceImpl.java
index 067006928e..53dce69fc1 100644
--- a/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/app/reporting/service/UsersActivitiesReportServiceImpl.java
@@ -9,12 +9,15 @@ package org.dspace.app.reporting.service;
import java.sql.SQLException;
import java.time.YearMonth;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import org.apache.logging.log4j.Logger;
+import org.dspace.app.reporting.model.PaginatedUserActionsResponse;
import org.dspace.app.reporting.model.SummaryWithTrendData;
import org.dspace.app.reporting.model.UserAction;
import org.dspace.app.reporting.model.UserActivityStats;
@@ -40,6 +43,53 @@ public class UsersActivitiesReportServiceImpl implements UsersActivitiesReportSe
return usersActivitiesActionsCacheService.getAllActions(context);
}
+ @Override
+ public PaginatedUserActionsResponse getActions(Context context, int page, int size, String itemId,
+ String actionType, String userEmail, String userName)
+ throws SQLException {
+ try {
+ List<UserAction> allActions = usersActivitiesActionsCacheService.getAllActions(context);
+
+ int normalizedPage = Math.max(page, 0);
+ int normalizedSize = size > 0 ? size : 100;
+ long offset = (long) normalizedPage * normalizedSize;
+ long upperExclusive = offset + normalizedSize;
+
+ String normalizedItemId = normalizeFilter(itemId);
+ String normalizedActionType = normalizeFilter(actionType);
+ String normalizedUserEmail = normalizeFilter(userEmail);
+ String normalizedUserName = normalizeFilter(userName);
+
+ long totalFilteredElements = 0;
+ List<UserAction> pageContent = new ArrayList<>();
+
+ for (UserAction action : allActions) {
+ if (!matchesFilters(action, normalizedItemId, normalizedActionType,
+ normalizedUserEmail, normalizedUserName)) {
+ continue;
+ }
+
+ if (totalFilteredElements >= offset && totalFilteredElements < upperExclusive) {
+ pageContent.add(action);
+ }
+ totalFilteredElements++;
+ }
+
+ int totalPages = totalFilteredElements == 0 ? 0
+ : (int) Math.ceil((double) totalFilteredElements / normalizedSize);
+
+ return new PaginatedUserActionsResponse(
+ pageContent,
+ totalFilteredElements,
+ totalPages,
+ normalizedPage,
+ normalizedSize);
+ } catch (Exception e) {
+ log.error("Error retrieving paginated actions", e);
+ throw new SQLException("Error retrieving paginated actions", e);
+ }
+ }
+
@Override
public Map<String, UserActivityStats> getUsersActivitiesStatistics(Context context) throws SQLException {
Map<String, UserActivityStats> stats = new TreeMap<>();
@@ -203,4 +253,33 @@ public class UsersActivitiesReportServiceImpl implements UsersActivitiesReportSe
throw new SQLException("Error generating total statistics with trends", e);
}
}
+
+ private boolean matchesFilters(UserAction action, String itemId, String actionType,
+ String userEmail, String userName) {
+ return containsIgnoreCase(action.getItemId(), itemId)
+ && containsIgnoreCase(action.getActionType(), actionType)
+ && containsIgnoreCase(action.getEmail(), userEmail)
+ && containsIgnoreCase(action.getUserName(), userName);
+ }
+
+ private String normalizeFilter(String filter) {
+ if (filter == null) {
+ return null;
+ }
+ String trimmed = filter.trim();
+ if (trimmed.isEmpty()) {
+ return null;
+ }
+ return trimmed.toLowerCase(Locale.ROOT);
+ }
+
+ private boolean containsIgnoreCase(String actualValue, String normalizedFilter) {
+ if (normalizedFilter == null) {
+ return true;
+ }
+ if (actualValue == null) {
+ return false;
+ }
+ return actualValue.toLowerCase(Locale.ROOT).contains(normalizedFilter);
+ }
}
diff --git a/dspace-api/src/main/java/org/dspace/content/MetadataValueServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/MetadataValueServiceImpl.java
index 97f0c2ccf4..de5f205b33 100644
--- a/dspace-api/src/main/java/org/dspace/content/MetadataValueServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/content/MetadataValueServiceImpl.java
@@ -26,7 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired;
/**
* Service implementation for the MetadataValue object.
- * This class is responsible for all business logic calls for the MetadataValue object and is autowired by spring.
+ * This class is responsible for all business logic calls for the MetadataValue
+ * object and is autowired by spring.
* This class should never be accessed directly.
*
* @author kevinvandevelde at atmire.com
@@ -52,11 +53,12 @@ public class MetadataValueServiceImpl implements MetadataValueService {
metadataValue.setMetadataField(metadataField);
metadataValue.setDSpaceObject(dso);
dso.addMetadata(metadataValue);
-//An update here isn't needed, this is persisted upon the merge of the owning object
-// metadataValueDAO.save(context, metadataValue);
+ // An update here isn't needed, this is persisted upon the merge of the owning
+ // object
+ // metadataValueDAO.save(context, metadataValue);
metadataValue = metadataValueDAO.create(context, metadataValue);
log.info(LogHelper.getHeader(context, "add_metadatavalue",
- "metadata_value_id=" + metadataValue.getID()));
+ "metadata_value_id=" + metadataValue.getID()));
return metadataValue;
}
@@ -69,10 +71,16 @@ public class MetadataValueServiceImpl implements MetadataValueService {
@Override
public List<MetadataValue> findByField(Context context, MetadataField metadataField)
- throws IOException, SQLException {
+ throws IOException, SQLException {
return metadataValueDAO.findByField(context, metadataField);
}
+ @Override
+ public List<MetadataValue> findByFieldWithDSpaceObject(Context context, MetadataField metadataField)
+ throws IOException, SQLException {
+ return metadataValueDAO.findByFieldWithDSpaceObject(context, metadataField);
+ }
+
@Override
public Iterator<MetadataValue> findByFieldAndValue(Context context, MetadataField metadataField, String value)
throws SQLException {
@@ -83,17 +91,17 @@ public class MetadataValueServiceImpl implements MetadataValueService {
public void update(Context context, MetadataValue metadataValue) throws SQLException {
metadataValueDAO.save(context, metadataValue);
log.info(LogHelper.getHeader(context, "update_metadatavalue",
- "metadata_value_id=" + metadataValue.getID()));
+ "metadata_value_id=" + metadataValue.getID()));
}
@Override
public void update(Context context, MetadataValue metadataValue, boolean updateLastModified)
- throws SQLException, AuthorizeException {
+ throws SQLException, AuthorizeException {
if (updateLastModified) {
authorizeService.authorizeAction(context, metadataValue.getDSpaceObject(), Constants.WRITE);
DSpaceObjectService<DSpaceObject> dSpaceObjectService = contentServiceFactory
- .getDSpaceObjectService(metadataValue.getDSpaceObject());
+ .getDSpaceObjectService(metadataValue.getDSpaceObject());
// get the right class for our dspaceobject not the DSpaceObject lazy proxy
DSpaceObject dso = dSpaceObjectService.find(context, metadataValue.getDSpaceObject().getID());
dSpaceObjectService.updateLastModified(context, dso);
@@ -101,11 +109,10 @@ public class MetadataValueServiceImpl implements MetadataValueService {
update(context, metadataValue);
}
-
@Override
public void delete(Context context, MetadataValue metadataValue) throws SQLException {
log.info(LogHelper.getHeader(context, "delete_metadata_value",
- " metadata_value_id=" + metadataValue.getID()));
+ " metadata_value_id=" + metadataValue.getID()));
metadataValueDAO.delete(context, metadataValue);
}
@@ -121,9 +128,9 @@ public class MetadataValueServiceImpl implements MetadataValueService {
@Override
public MetadataValue getMinimum(Context context, int metadataFieldId)
- throws SQLException {
+ throws SQLException {
return metadataValueDAO.getMinimum(context,
- metadataFieldId);
+ metadataFieldId);
}
@Override
diff --git a/dspace-api/src/main/java/org/dspace/content/dao/MetadataValueDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/MetadataValueDAO.java
index 6a09cfdd8e..9b856c3f06 100644
--- a/dspace-api/src/main/java/org/dspace/content/dao/MetadataValueDAO.java
+++ b/dspace-api/src/main/java/org/dspace/content/dao/MetadataValueDAO.java
@@ -18,9 +18,11 @@ import org.dspace.core.GenericDAO;
/**
* Database Access Object interface class for the MetadataValue object.
- * The implementation of this class is responsible for all database calls for the MetadataValue object and is
+ * The implementation of this class is responsible for all database calls for
+ * the MetadataValue object and is
* autowired by spring
- * This class should only be accessed from a single service and should never be exposed outside of the API
+ * This class should only be accessed from a single service and should never be
+ * exposed outside of the API
*
* @author kevinvandevelde at atmire.com
*/
@@ -28,8 +30,11 @@ public interface MetadataValueDAO extends GenericDAO<MetadataValue> {
public List<MetadataValue> findByField(Context context, MetadataField fieldId) throws SQLException;
+ public List<MetadataValue> findByFieldWithDSpaceObject(Context context, MetadataField fieldId)
+ throws SQLException;
+
public Iterator<MetadataValue> findItemValuesByFieldAndValue(Context context,
- MetadataField metadataField, String value)
+ MetadataField metadataField, String value)
throws SQLException;
public Iterator<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
@@ -37,7 +42,7 @@ public interface MetadataValueDAO extends GenericDAO<MetadataValue> {
public void deleteByMetadataField(Context context, MetadataField metadataField) throws SQLException;
public MetadataValue getMinimum(Context context, int metadataFieldId)
- throws SQLException;
+ throws SQLException;
int countRows(Context context) throws SQLException;
diff --git a/dspace-api/src/main/java/org/dspace/content/dao/impl/MetadataValueDAOImpl.java b/dspace-api/src/main/java/org/dspace/content/dao/impl/MetadataValueDAOImpl.java
index dc624c98c6..b66025c402 100644
--- a/dspace-api/src/main/java/org/dspace/content/dao/impl/MetadataValueDAOImpl.java
+++ b/dspace-api/src/main/java/org/dspace/content/dao/impl/MetadataValueDAOImpl.java
@@ -24,8 +24,10 @@ import org.dspace.core.AbstractHibernateDAO;
import org.dspace.core.Context;
/**
- * Hibernate implementation of the Database Access Object interface class for the MetadataValue object.
- * This class is responsible for all database calls for the MetadataValue object and is autowired by spring
+ * Hibernate implementation of the Database Access Object interface class for
+ * the MetadataValue object.
+ * This class is responsible for all database calls for the MetadataValue object
+ * and is autowired by spring
* This class should never be accessed directly.
*
* @author kevinvandevelde at atmire.com
@@ -35,11 +37,10 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
super();
}
-
@Override
public List<MetadataValue> findByField(Context context, MetadataField metadataField) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
- CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, MetadataValue.class);
+ CriteriaQuery<MetadataValue> criteriaQuery = getCriteriaQuery(criteriaBuilder, MetadataValue.class);
Root<MetadataValue> metadataValueRoot = criteriaQuery.from(MetadataValue.class);
Join<MetadataValue, MetadataField> join = metadataValueRoot.join("metadataField");
criteriaQuery.select(metadataValueRoot);
@@ -48,9 +49,24 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
return list(context, criteriaQuery, false, MetadataValue.class, -1, -1);
}
+ @Override
+ public List<MetadataValue> findByFieldWithDSpaceObject(Context context, MetadataField metadataField)
+ throws SQLException {
+ String queryString = "SELECT m FROM MetadataValue m "
+ + "JOIN FETCH m.dSpaceObject dso "
+ + "JOIN m.metadataField mf "
+ + "JOIN Item i ON m.dSpaceObject = i "
+ + "WHERE mf.id = :metadata_field_id";
+ Query query = createQuery(context, queryString);
+ query.setParameter("metadata_field_id", metadataField.getID());
+ @SuppressWarnings("unchecked")
+ List<MetadataValue> results = query.getResultList();
+ return results;
+ }
+
@Override
public Iterator<MetadataValue> findItemValuesByFieldAndValue(Context context,
- MetadataField metadataField, String value)
+ MetadataField metadataField, String value)
throws SQLException {
String queryString = "SELECT m from MetadataValue m " +
"join Item i on m.dSpaceObject = i where m.metadataField.id = :metadata_field_id " +
@@ -64,7 +80,7 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
@Override
public Iterator<MetadataValue> findByValueLike(Context context, String value) throws SQLException {
String queryString = "SELECT m FROM MetadataValue m JOIN m.metadataField f " +
- "WHERE m.value like concat('%', concat(:searchString,'%')) ORDER BY m.id ASC";
+ "WHERE m.value like concat('%', concat(:searchString,'%')) ORDER BY m.id ASC";
Query query = createQuery(context, queryString);
query.setParameter("searchString", value);
@@ -82,9 +98,9 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
@Override
public MetadataValue getMinimum(Context context, int metadataFieldId)
- throws SQLException {
+ throws SQLException {
String queryString = "SELECT m FROM MetadataValue m JOIN FETCH m.metadataField WHERE m.metadataField.id = " +
- ":metadata_field_id ORDER BY value";
+ ":metadata_field_id ORDER BY value";
Query query = createQuery(context, queryString);
query.setParameter("metadata_field_id", metadataFieldId);
query.setMaxResults(1);
diff --git a/dspace-api/src/main/java/org/dspace/content/service/MetadataValueService.java b/dspace-api/src/main/java/org/dspace/content/service/MetadataValueService.java
index 1cf26e37f1..01e33a04da 100644
--- a/dspace-api/src/main/java/org/dspace/content/service/MetadataValueService.java
+++ b/dspace-api/src/main/java/org/dspace/content/service/MetadataValueService.java
@@ -20,7 +20,8 @@ import org.dspace.core.Context;
/**
* Service interface class for the MetadataValue object.
- * The implementation of this class is responsible for all business logic calls for the MetadataValue object and is
+ * The implementation of this class is responsible for all business logic calls
+ * for the MetadataValue object and is
* autowired by spring
*
* @author kevinvandevelde at atmire.com
@@ -48,8 +49,7 @@ public interface MetadataValueService {
* @throws SQLException if database error
*/
public MetadataValue find(Context context, int valueId)
- throws IOException, SQLException;
-
+ throws IOException, SQLException;
/**
* Retrieves the metadata values for a given field from the database.
@@ -61,14 +61,27 @@ public interface MetadataValueService {
* @throws SQLException if database error
*/
public List<MetadataValue> findByField(Context context, MetadataField metadataField)
- throws IOException, SQLException;
+ throws IOException, SQLException;
+
+ /**
+ * Retrieves metadata values for a given field with linked DSpaceObject
+ * eagerly fetched.
+ *
+ * @param context dspace context
+ * @param metadataField metadata field whose values to look for
+ * @return metadata values with linked DSpaceObject initialized
+ * @throws IOException if IO error
+ * @throws SQLException if database error
+ */
+ public List<MetadataValue> findByFieldWithDSpaceObject(Context context, MetadataField metadataField)
+ throws IOException, SQLException;
/**
* Retrieves matching MetadataValues for a given field and value.
*
- * @param context dspace context
+ * @param context dspace context
* @param metadataField The field that must match
- * @param value The value that must match
+ * @param value The value that must match
* @return the matching MetadataValues
* @throws SQLException if database error
*/
@@ -85,7 +98,7 @@ public interface MetadataValueService {
public void update(Context context, MetadataValue metadataValue) throws SQLException;
public void update(Context context, MetadataValue metadataValue, boolean modifyParentObject)
- throws SQLException, AuthorizeException;
+ throws SQLException, AuthorizeException;
/**
* Delete the metadata field.
@@ -109,7 +122,8 @@ public interface MetadataValueService {
* @throws SQLException if database error
*/
public MetadataValue getMinimum(Context context, int metadataFieldId)
- throws SQLException;
+ throws SQLException;
+
int countTotal(Context context) throws SQLException;
}
diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/UsersActivitiesReportController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/UsersActivitiesReportController.java
index 25f284a0fd..9baf9ca590 100644
--- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/UsersActivitiesReportController.java
+++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/UsersActivitiesReportController.java
@@ -13,8 +13,8 @@ import java.util.Map;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.Logger;
+import org.dspace.app.reporting.model.PaginatedUserActionsResponse;
import org.dspace.app.reporting.model.SummaryWithTrendData;
-import org.dspace.app.reporting.model.UserAction;
import org.dspace.app.reporting.model.UserActivityStats;
import org.dspace.app.reporting.service.UsersActivitiesReportService;
import org.dspace.app.rest.utils.ContextUtil;
@@ -25,6 +25,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -94,18 +95,38 @@ public class UsersActivitiesReportController {
}
/**
- * Get all actions (submissions and reviews) without aggregation
+ * Get all actions (submissions and reviews) with optional filtering and
+ * pagination.
*
- * @param request HTTP request
- * @return list of all user actions
+ * @param request HTTP request
+ * @param page page number (0-based), default 0
+ * @param size page size, default 100
+ * @param itemId optional item id filter
+ * @param actionType optional action type filter
+ * @param userEmail optional user email filter
+ * @param userName optional user name filter
+ * @return paginated response with actions and page metadata
*/
@PreAuthorize("hasAuthority('ADMIN')")
@GetMapping("/actions")
- public ResponseEntity<?> getAllActions(HttpServletRequest request) {
+ public ResponseEntity<?> getAllActions(HttpServletRequest request,
+ @RequestParam(defaultValue = "0") int page,
+ @RequestParam(defaultValue = "100") int size,
+ @RequestParam(required = false) String itemId,
+ @RequestParam(required = false) String actionType,
+ @RequestParam(required = false) String userEmail,
+ @RequestParam(required = false) String userName) {
try {
Context context = ContextUtil.obtainContext(request);
- List<UserAction> actions = usersActivitiesReportService.getAllActions(context);
+ PaginatedUserActionsResponse actions = usersActivitiesReportService.getActions(
+ context,
+ page,
+ size,
+ itemId,
+ actionType,
+ userEmail,
+ userName);
context.complete();
return new ResponseEntity<>(actions, HttpStatus.OK);
diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/UsersActivitiesReportControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/UsersActivitiesReportControllerIT.java
index d42df9c08c..d4e41ab458 100644
--- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/UsersActivitiesReportControllerIT.java
+++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/UsersActivitiesReportControllerIT.java
@@ -154,11 +154,70 @@ public class UsersActivitiesReportControllerIT extends AbstractControllerIntegra
getClient(token).perform(get("/api/reports/users-activities/actions"))
.andExpect(status().isOk())
- .andExpect(jsonPath("$", Matchers.hasSize(2)))
- .andExpect(jsonPath("$[?(@.email=='user1@example.com')].actionType",
+ .andExpect(jsonPath("$.totalElements", Matchers.is(2)))
+ .andExpect(jsonPath("$.totalPages", Matchers.is(1)))
+ .andExpect(jsonPath("$.currentPage", Matchers.is(0)))
+ .andExpect(jsonPath("$.pageSize", Matchers.is(100)))
+ .andExpect(jsonPath("$.content", Matchers.hasSize(2)))
+ .andExpect(jsonPath("$.content[?(@.email=='user1@example.com')].actionType",
Matchers.contains("SUBMITTED")))
- .andExpect(jsonPath("$[?(@.email=='admin@example.com')].actionType",
- Matchers.contains("APPROVED")));
+ .andExpect(jsonPath("$.content[?(@.email=='user1@example.com')].itemUUID",
+ Matchers.contains(Matchers.notNullValue())))
+ .andExpect(jsonPath("$.content[?(@.email=='user1@example.com')].itemId",
+ Matchers.contains(Matchers.notNullValue())))
+ .andExpect(jsonPath("$.content[?(@.email=='user1@example.com')].itemTitle",
+ Matchers.contains("Item 1")))
+ .andExpect(jsonPath("$.content[?(@.email=='admin@example.com')].actionType",
+ Matchers.contains("APPROVED")))
+ .andExpect(jsonPath("$.content[?(@.email=='admin@example.com')].itemUUID",
+ Matchers.contains(Matchers.notNullValue())))
+ .andExpect(jsonPath("$.content[?(@.email=='admin@example.com')].itemId",
+ Matchers.contains(Matchers.notNullValue())))
+ .andExpect(jsonPath("$.content[?(@.email=='admin@example.com')].itemTitle",
+ Matchers.contains("Item 1")));
+ }
+
+ @Test
+ public void testGetAllActionsWithPaginationAndFilters() throws Exception {
+ context.turnOffAuthorisationSystem();
+ ItemBuilder.createItem(context, col)
+ .withTitle("Paged Item")
+ .withProvenanceData("Submitted by User One (user.one@example.com) on "
+ + "2024-01-15T12:00:00Z\n"
+ + "Approved for entry into archive by Admin User "
+ + "(admin@example.com) on 2024-01-16T10:30:00Z\n"
+ + "Rejected by Admin User (admin@example.com), reason: Oops on "
+ + "2024-01-17T10:30:00Z")
+ .build();
+ context.restoreAuthSystemState();
+
+ String token = getAuthToken(admin.getEmail(), password);
+
+ getClient(token).perform(get("/api/reports/users-activities/actions")
+ .param("userEmail", "ADMIN@EXAMPLE")
+ .param("userName", "admin")
+ .param("actionType", "rej")
+ .param("itemId", "-")
+ .param("page", "0")
+ .param("size", "1"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.totalElements", Matchers.is(1)))
+ .andExpect(jsonPath("$.totalPages", Matchers.is(1)))
+ .andExpect(jsonPath("$.currentPage", Matchers.is(0)))
+ .andExpect(jsonPath("$.pageSize", Matchers.is(1)))
+ .andExpect(jsonPath("$.content", Matchers.hasSize(1)))
+ .andExpect(jsonPath("$.content[0].actionType", Matchers.is("REJECTED")))
+ .andExpect(jsonPath("$.content[0].email", Matchers.is("admin@example.com")));
+
+ getClient(token).perform(get("/api/reports/users-activities/actions")
+ .param("size", "1")
+ .param("page", "1"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.totalElements", Matchers.is(3)))
+ .andExpect(jsonPath("$.totalPages", Matchers.is(3)))
+ .andExpect(jsonPath("$.currentPage", Matchers.is(1)))
+ .andExpect(jsonPath("$.pageSize", Matchers.is(1)))
+ .andExpect(jsonPath("$.content", Matchers.hasSize(1)));
}
@Test