Skip to content

Commit 908d6d6

Browse files
vins01-4scienceatarix83
authored andcommitted
Merged in 2023_02_x-DQ-26 (pull request DSpace#1676)
DQ-26 Approved-by: Giuseppe Digilio
2 parents e666ff8 + f18a000 commit 908d6d6

File tree

18 files changed

+497
-95
lines changed

18 files changed

+497
-95
lines changed

dspace-api/src/main/java/org/dspace/app/deduplication/service/impl/SolrDedupServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
import org.dspace.app.deduplication.service.DedupService;
4444
import org.dspace.app.deduplication.service.SearchDeduplication;
4545
import org.dspace.app.deduplication.service.SolrDedupServiceIndexPlugin;
46-
import org.dspace.app.deduplication.utils.DedupUtils;
4746
import org.dspace.app.deduplication.utils.DuplicateItemInfo;
47+
import org.dspace.app.deduplication.utils.IDedupUtils;
4848
import org.dspace.app.deduplication.utils.Signature;
4949
import org.dspace.app.util.Util;
5050
import org.dspace.authorize.AuthorizeException;
@@ -174,7 +174,7 @@ public class SolrDedupServiceImpl implements DedupService {
174174
protected VersioningService versioningService;
175175

176176
@Autowired(required = true)
177-
protected DedupUtils dedupUtils;
177+
protected IDedupUtils dedupUtils;
178178

179179
/***
180180
* Deduplication status
@@ -750,8 +750,8 @@ private void setDuplicateDecision(Context context, Item item, UUID duplicatedIte
750750
private List<DuplicateItemInfo> findDuplicationWithDecisions(Context context, Item item) {
751751
try {
752752
return dedupUtils.getAdminDuplicateByIdAndType(context, item.getID(), item.getType()).stream()
753-
.filter(duplication -> isNotEmpty(duplication.getDecisionTypes()))
754-
.collect(Collectors.toList());
753+
.filter(duplication -> isNotEmpty(duplication.getDecisionTypes()))
754+
.collect(Collectors.toList());
755755
} catch (SQLException | SearchServiceException e) {
756756
throw new RuntimeException(e);
757757
}

dspace-api/src/main/java/org/dspace/app/deduplication/utils/DedupUtils.java

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@
4747
import org.dspace.services.ConfigurationService;
4848
import org.dspace.util.ItemUtils;
4949
import org.springframework.beans.factory.annotation.Autowired;
50+
import org.springframework.stereotype.Service;
5051

5152
/**
5253
* Utility class used to search for duplicates inside the dedup solr core.
5354
*
5455
*/
55-
public class DedupUtils {
56+
57+
@Service
58+
public class DedupUtils implements IDedupUtils {
5659

5760
private static Logger log = LogManager.getLogger(DedupUtils.class);
5861

@@ -64,11 +67,14 @@ public class DedupUtils {
6467
@Autowired(required = true)
6568
protected ConfigurationService configurationService;
6669

67-
public DuplicateInfoList findSignatureWithDuplicate(Context context, String signatureType, int resourceType,
68-
int limit, int offset, int rule) throws SearchServiceException, SQLException {
70+
@Override
71+
public Collection<DuplicateInfo> findSignatureWithDuplicate(Context context, String signatureType, int resourceType,
72+
int limit, int offset, int rule)
73+
throws SearchServiceException, SQLException {
6974
return findPotentialMatch(context, signatureType, resourceType, limit, offset, rule);
7075
}
7176

77+
@Override
7278
public Map<String, Integer> countSignaturesWithDuplicates(String query, int resourceTypeId)
7379
throws SearchServiceException {
7480
Map<String, Integer> results = new HashMap<String, Integer>();
@@ -113,6 +119,7 @@ public Map<String, Integer> countSignaturesWithDuplicates(String query, int reso
113119
return results;
114120
}
115121

122+
@Override
116123
public Map<String, Integer> countSuggestedDuplicate(String query, int resourceTypeId)
117124
throws SearchServiceException {
118125
Map<String, Integer> results = new HashMap<String, Integer>();
@@ -241,8 +248,9 @@ private boolean hasStoredDecision(UUID firstItemID, UUID secondItemID, Duplicate
241248
return !response.getResults().isEmpty();
242249
}
243250

251+
@Override
244252
public boolean matchExist(Context context, UUID itemID, UUID targetItemID, Integer resourceType,
245-
String signatureType, Boolean isInWorkflow) throws SQLException, SearchServiceException {
253+
String signatureType, Boolean isInWorkflow) throws SQLException, SearchServiceException {
246254
boolean exist = false;
247255
List<DuplicateItemInfo> potentialDuplicates = findDuplicate(context, itemID, resourceType, null, isInWorkflow);
248256
for (DuplicateItemInfo match : potentialDuplicates) {
@@ -256,6 +264,7 @@ public boolean matchExist(Context context, UUID itemID, UUID targetItemID, Integ
256264

257265
}
258266

267+
@Override
259268
public boolean rejectAdminDups(Context context, UUID firstId, UUID secondId, Integer type)
260269
throws SQLException, AuthorizeException {
261270
if (firstId == secondId) {
@@ -309,6 +318,7 @@ public boolean rejectAdminDups(Context context, UUID firstId, UUID secondId, Int
309318
* @throws AuthorizeException
310319
* @throws SearchServiceException
311320
*/
321+
@Override
312322
public boolean rejectAdminDups(Context context, UUID itemID, String signatureType, int resourceType)
313323
throws SQLException, AuthorizeException, SearchServiceException {
314324

@@ -336,15 +346,17 @@ public boolean rejectAdminDups(Context context, UUID itemID, String signatureTyp
336346

337347
}
338348

349+
@Override
339350
public void rejectAdminDups(Context context, List<DSpaceObject> items, String signatureID)
340351
throws SQLException, AuthorizeException, SearchServiceException {
341352
for (DSpaceObject item : items) {
342353
rejectAdminDups(context, item.getID(), signatureID, item.getType());
343354
}
344355
}
345356

357+
@Override
346358
public void verify(Context context, int dedupId, UUID firstId, UUID secondId, int type, boolean toFix, String note,
347-
boolean check) throws SQLException, AuthorizeException {
359+
boolean check) throws SQLException, AuthorizeException {
348360
UUID[] sortedIds = new UUID[] { firstId, secondId };
349361
Arrays.sort(sortedIds);
350362
firstId = sortedIds[0];
@@ -417,8 +429,9 @@ private Deduplication retrieveDuplicationRow(Context context, UUID firstId, UUID
417429
return row;
418430
}
419431

432+
@Override
420433
public void setDuplicateDecision(Context context, UUID firstId, UUID secondId, Integer type,
421-
DuplicateDecisionObjectRest decisionObject)
434+
DuplicateDecisionObjectRest decisionObject)
422435
throws AuthorizeException, SQLException, SearchServiceException {
423436

424437
if (hasAuthorization(context, firstId, secondId)) {
@@ -478,6 +491,7 @@ public void setDuplicateDecision(Context context, UUID firstId, UUID secondId, I
478491
}
479492
}
480493

494+
@Override
481495
public boolean validateDecision(DuplicateDecisionObjectRest decisionObject) {
482496
boolean valid = false;
483497

@@ -500,8 +514,9 @@ public boolean validateDecision(DuplicateDecisionObjectRest decisionObject) {
500514
return valid;
501515
}
502516

517+
@Override
503518
public boolean rejectDups(Context context, UUID firstId, UUID secondId, Integer type, boolean notDupl, String note,
504-
boolean check) throws SQLException {
519+
boolean check) throws SQLException {
505520
UUID[] sortedIds = new UUID[] { firstId, secondId };
506521
Arrays.sort(sortedIds);
507522
Deduplication row = null;
@@ -547,11 +562,9 @@ public boolean rejectDups(Context context, UUID firstId, UUID secondId, Integer
547562
return false;
548563
}
549564

550-
private DuplicateInfoList findPotentialMatch(Context context, String signatureType, int resourceType, int start,
565+
private List<DuplicateInfo> findPotentialMatch(Context context, String signatureType, int resourceType, int start,
551566
int rows, int rule) throws SearchServiceException, SQLException {
552567

553-
DuplicateInfoList dil = new DuplicateInfoList();
554-
555568
if (StringUtils.isNotEmpty(signatureType)) {
556569
if (!StringUtils.contains(signatureType, "_signature")) {
557570
signatureType += "_signature";
@@ -594,7 +607,7 @@ private DuplicateInfoList findPotentialMatch(Context context, String signatureTy
594607

595608
FacetField facetField = responseFacet.getFacetField(signatureType);
596609

597-
List<DuplicateInfo> result = new ArrayList<DuplicateInfo>();
610+
List<DuplicateInfo> result = new ArrayList<>();
598611

599612
int index = 0;
600613
for (Count facetHit : facetField.getValues()) {
@@ -653,10 +666,7 @@ private DuplicateInfoList findPotentialMatch(Context context, String signatureTy
653666
}
654667
index++;
655668
}
656-
657-
dil.setDsi(result);
658-
dil.setSize(facetField.getValues().size());
659-
return dil;
669+
return result;
660670
}
661671

662672
private DuplicateSignatureInfo findPotentialMatchByID(Context context, String signatureType, int resourceType,
@@ -699,38 +709,45 @@ private DuplicateSignatureInfo findPotentialMatchByID(Context context, String si
699709
return dsi;
700710
}
701711

712+
@Override
702713
public DedupService getDedupService() {
703714
return dedupService;
704715
}
705716

717+
@Override
706718
public void setDedupService(DedupService dedupService) {
707719
this.dedupService = dedupService;
708720
}
709721

722+
@Override
710723
public void commit() {
711724
dedupService.commit();
712725
}
713726

727+
@Override
714728
public List<DuplicateItemInfo> getDuplicateByIDandType(Context context, UUID itemID, int typeID,
715-
boolean isInWorkflow) throws SQLException, SearchServiceException {
729+
boolean isInWorkflow)
730+
throws SQLException, SearchServiceException {
716731
return getDuplicateByIdAndTypeAndSignatureType(context, itemID, typeID, null, isInWorkflow);
717732
}
718733

734+
@Override
719735
public List<DuplicateItemInfo> getDuplicateByIdAndTypeAndSignatureType(Context context, UUID itemID, int typeID,
720-
String signatureType, boolean isInWorkflow) throws SQLException, SearchServiceException {
736+
String signatureType, boolean isInWorkflow)
737+
throws SQLException, SearchServiceException {
721738
return findDuplicate(context, itemID, typeID, signatureType, isInWorkflow);
722739
}
723740

741+
@Override
724742
public List<DuplicateItemInfo> getAdminDuplicateByIdAndType(Context context, UUID itemID, int typeID)
725743
throws SQLException, SearchServiceException {
726744
return findDuplicate(context, itemID, typeID, null, null);
727745
}
728746

729-
public DuplicateInfoList findSuggestedDuplicate(Context context, int resourceType, int start, int rows)
747+
@Override
748+
public List<DuplicateInfo> findSuggestedDuplicate(Context context, int resourceType, int start, int rows)
730749
throws SearchServiceException, SQLException {
731750

732-
DuplicateInfoList dil = new DuplicateInfoList();
733-
734751
SolrQuery solrQueryInternal = new SolrQuery();
735752

736753
solrQueryInternal.setQuery(SolrDedupServiceImpl.SUBQUERY_NOT_IN_REJECTED);
@@ -774,8 +791,6 @@ public DuplicateInfoList findSuggestedDuplicate(Context context, int resourceTyp
774791
index++;
775792
}
776793

777-
dil.setDsi(result);
778-
dil.setSize(solrDocumentList.getNumFound());
779-
return dil;
794+
return result;
780795
}
781796
}

dspace-api/src/main/java/org/dspace/app/deduplication/utils/DuplicateInfoList.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.app.deduplication.utils;
9+
10+
import java.sql.SQLException;
11+
import java.util.Collection;
12+
import java.util.List;
13+
import java.util.Map;
14+
import java.util.UUID;
15+
16+
import org.dspace.app.deduplication.model.DuplicateDecisionObjectRest;
17+
import org.dspace.app.deduplication.service.DedupService;
18+
import org.dspace.authorize.AuthorizeException;
19+
import org.dspace.content.DSpaceObject;
20+
import org.dspace.core.Context;
21+
import org.dspace.discovery.SearchServiceException;
22+
23+
/**
24+
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
25+
**/
26+
public interface IDedupUtils {
27+
Collection<DuplicateInfo> findSignatureWithDuplicate(Context context, String signatureType, int resourceType,
28+
int limit, int offset, int rule) throws SearchServiceException,
29+
SQLException;
30+
31+
Map<String, Integer> countSignaturesWithDuplicates(String query, int resourceTypeId)
32+
throws SearchServiceException;
33+
34+
Map<String, Integer> countSuggestedDuplicate(String query, int resourceTypeId)
35+
throws SearchServiceException;
36+
37+
boolean matchExist(Context context, UUID itemID, UUID targetItemID, Integer resourceType,
38+
String signatureType, Boolean isInWorkflow) throws SQLException, SearchServiceException;
39+
40+
boolean rejectAdminDups(Context context, UUID firstId, UUID secondId, Integer type)
41+
throws SQLException, AuthorizeException;
42+
43+
boolean rejectAdminDups(Context context, UUID itemID, String signatureType, int resourceType)
44+
throws SQLException, AuthorizeException, SearchServiceException;
45+
46+
void rejectAdminDups(Context context, List<DSpaceObject> items, String signatureID)
47+
throws SQLException, AuthorizeException, SearchServiceException;
48+
49+
void verify(Context context, int dedupId, UUID firstId, UUID secondId, int type, boolean toFix, String note,
50+
boolean check) throws SQLException, AuthorizeException;
51+
52+
void setDuplicateDecision(Context context, UUID firstId, UUID secondId, Integer type,
53+
DuplicateDecisionObjectRest decisionObject)
54+
throws AuthorizeException, SQLException, SearchServiceException;
55+
56+
boolean validateDecision(DuplicateDecisionObjectRest decisionObject);
57+
58+
boolean rejectDups(Context context, UUID firstId, UUID secondId, Integer type, boolean notDupl, String note,
59+
boolean check) throws SQLException;
60+
61+
DedupService getDedupService();
62+
63+
void setDedupService(DedupService dedupService);
64+
65+
void commit();
66+
67+
List<DuplicateItemInfo> getDuplicateByIDandType(Context context, UUID itemID, int typeID,
68+
boolean isInWorkflow) throws SQLException, SearchServiceException;
69+
70+
List<DuplicateItemInfo> getDuplicateByIdAndTypeAndSignatureType(Context context, UUID itemID, int typeID,
71+
String signatureType, boolean isInWorkflow)
72+
throws SQLException, SearchServiceException;
73+
74+
List<DuplicateItemInfo> getAdminDuplicateByIdAndType(Context context, UUID itemID, int typeID)
75+
throws SQLException, SearchServiceException;
76+
77+
Collection<DuplicateInfo> findSuggestedDuplicate(Context context, int resourceType, int start, int rows)
78+
throws SearchServiceException, SQLException;
79+
}

dspace-api/src/main/java/org/dspace/deduplication/service/DeduplicationService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.dspace.deduplication.Deduplication;
1616

1717
public interface DeduplicationService {
18+
1819
/**
1920
* Create a new Deduplication object
2021
*
@@ -23,7 +24,7 @@ public interface DeduplicationService {
2324
* @throws SQLException An exception that provides information on a database
2425
* access error or other errors.
2526
*/
26-
public Deduplication create(Context context, Deduplication dedup) throws SQLException;
27+
Deduplication create(Context context, Deduplication dedup) throws SQLException;
2728

2829
/***
2930
* Return all deduplication objects
@@ -35,7 +36,7 @@ public interface DeduplicationService {
3536
* @throws SQLException An exception that provides information on a database
3637
* access error or other errors.
3738
*/
38-
public List<Deduplication> findAll(Context context, int pageSize, int offset) throws SQLException;
39+
List<Deduplication> findAll(Context context, int pageSize, int offset) throws SQLException;
3940

4041
/**
4142
* Count all accounts.
@@ -55,11 +56,11 @@ public interface DeduplicationService {
5556
* @throws SQLException An exception that provides information on a database
5657
* access error or other errors.
5758
*/
58-
public void update(Context context, Deduplication dedup) throws SQLException;
59+
void update(Context context, Deduplication dedup) throws SQLException;
5960

60-
public List<Deduplication> getDeduplicationByFirstAndSecond(Context context, UUID firstId, UUID secondId)
61+
List<Deduplication> getDeduplicationByFirstAndSecond(Context context, UUID firstId, UUID secondId)
6162
throws SQLException;
6263

63-
public Deduplication uniqueDeduplicationByFirstAndSecond(Context context, UUID firstId, UUID secondId)
64+
Deduplication uniqueDeduplicationByFirstAndSecond(Context context, UUID firstId, UUID secondId)
6465
throws SQLException;
6566
}

0 commit comments

Comments
 (0)