force is_similar to clone duplicate

This commit is contained in:
Michele Artini 2021-11-09 11:28:03 +01:00
parent 7ba3c61768
commit 01fd913c1d
1 changed files with 21 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@ -159,7 +160,7 @@ public class DatabaseUtils {
final List<OpenaireDuplicate> dups = openaireDuplicateRepository.findByLocalId(oldId)
.stream()
.map(d -> new OpenaireDuplicate(newId, d.getOaOriginalId(), SimilarityType.suggested.toString(), d.getOaCollectedFrom()))
.map(d -> prepareNewDuplicate(newId, oldId, d))
.collect(Collectors.toList());
openaireDuplicateRepository.saveAll(dups);
@ -209,6 +210,25 @@ public class DatabaseUtils {
return newId;
}
private OpenaireDuplicate prepareNewDuplicate(final String newId, final String oldId, final OpenaireDuplicate old) {
final OpenaireDuplicate d = new OpenaireDuplicate();
d.setLocalId(newId);
d.setOaOriginalId(old.getOaOriginalId());
d.setOaCollectedFrom(old.getOaCollectedFrom());
if (oldId != null
&& newId.startsWith(OpenOrgsConstants.OPENORGS_PREFIX)
&& oldId.startsWith(OpenOrgsConstants.OPENORGS_PENDING_PREFIX)
&& StringUtils.substringAfter(oldId, OpenOrgsConstants.OPENORGS_PENDING_PREFIX).equalsIgnoreCase(DigestUtils.md5Hex(d.getOaOriginalId()))) {
d.setRelType(SimilarityType.is_similar.toString());
} else {
d.setRelType(SimilarityType.suggested.toString());
}
return d;
}
@Transactional
public void saveDuplicates(final List<OpenaireDuplicate> simrels, final String user) {
final OffsetDateTime now = OffsetDateTime.now();