Skip to content

Commit

Permalink
Dataset link simplification - Improve metadata links protocol inferen…
Browse files Browse the repository at this point in the history
…ce from url
  • Loading branch information
josegar74 committed Dec 5, 2024
1 parent d52ce80 commit de2ab95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public DatasetDocumentLink create(DatasetMetadataRecord datasetMetadataRecord, O
if (!isViewUrlProtocol && isDownloadUrlProtocol) {
result.setProtocol(protocolFromUrl);
}
} else { // If no valid protocol from the protocol field, and the inferred protocol is valid --> use the inferred protocol
if ((isDownloadUrlProtocol) || (isViewUrlProtocol)) {
result.setProtocol(protocolFromUrl);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

package net.geocat.eventprocessor.processors.processlinks;

import net.geocat.database.linkchecker.entities.DatasetDocumentLink;
import net.geocat.database.linkchecker.entities.LocalDatasetMetadataRecord;
import net.geocat.database.linkchecker.entities.helper.ServiceMetadataDocumentState;
import net.geocat.database.linkchecker.repos.CapabilitiesDocumentRepo;
Expand All @@ -52,7 +53,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

import static java.util.Comparator.comparingLong;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
import static net.geocat.database.linkchecker.service.DatabaseUpdateService.convertToString;

@Component
Expand Down Expand Up @@ -101,6 +106,15 @@ public class EventProcessor_ProcessDatasetDocLinksEvent extends BaseEventProcess
public EventProcessor_ProcessDatasetDocLinksEvent internalProcessing() throws Exception {

localDatasetMetadataRecord = localDatasetMetadataRecordRepo.findById(getInitiatingEvent().getDatasetDocumentId()).get();// make sure we re-load
// Dataset metadata record uses FetchMode.JOIN with DatasetIdentifier and DatasetDocumentLink
// If the metadata has more than 1 dataset identifier retrieves DatasetDocumentLink duplicated
// TODO: Check if possible to use instead FetchMode.SUBSELECT
List<DatasetDocumentLink> uniqueDatasetDocumentLinks = localDatasetMetadataRecord.getDocumentLinks().stream()
.collect(collectingAndThen(toCollection(() -> new TreeSet<>(comparingLong(DatasetDocumentLink::getDatasetMetadataLinkId))),
ArrayList::new));

localDatasetMetadataRecord.setDocumentLinks(uniqueDatasetDocumentLinks);

if (localDatasetMetadataRecord.getState() == ServiceMetadataDocumentState.NOT_APPLICABLE)
return this; //nothing to do

Expand Down

0 comments on commit de2ab95

Please sign in to comment.