Skip to content

Commit

Permalink
Dataset link simplification - protect code if http status is null (fo…
Browse files Browse the repository at this point in the history
…r example, a timeout) and check links from metadata url in capabilities start with http
  • Loading branch information
josegar74 committed Dec 17, 2024
1 parent de2ab95 commit 1654361
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -57,19 +58,22 @@ public List<CapabilitiesDatasetMetadataLink> createCapabilitiesDatasetMetadataLi
List<CapabilitiesDatasetMetadataLink> result = new ArrayList<>();
for (DatasetLink link : doc.getDatasetLinksList()) {

CapabilitiesDatasetMetadataLink item = new CapabilitiesDatasetMetadataLink();
item.setOgcLayerName(link.getOgcLayerName());
item.setLinkState(LinkState.Created);
item.setRawURL(link.getRawUrl());
item.setLinkCheckJobId(cap.getLinkCheckJobId());
item.setFixedURL(datasetLinkFixer.fix(link.getRawUrl()));
item.setIdentity(link.getIdentifier());
item.setAuthority(link.getAuthority());
item.setAuthorityName(link.getAuthorityName());
item.setCapabilitiesDocument(cap);
// Create the link if the URL starts with http
if (StringUtils.hasLength(link.getRawUrl()) && link.getRawUrl().toLowerCase().startsWith("http")) {
CapabilitiesDatasetMetadataLink item = new CapabilitiesDatasetMetadataLink();
item.setOgcLayerName(link.getOgcLayerName());
item.setLinkState(LinkState.Created);
item.setRawURL(link.getRawUrl());
item.setLinkCheckJobId(cap.getLinkCheckJobId());
item.setFixedURL(datasetLinkFixer.fix(link.getRawUrl()));
item.setIdentity(link.getIdentifier());
item.setAuthority(link.getAuthority());
item.setAuthorityName(link.getAuthorityName());
item.setCapabilitiesDocument(cap);

// item.setCapabilitiesDocument(cap);
result.add(item);
// item.setCapabilitiesDocument(cap);
result.add(item);
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void process() {
// Dataset link simplification
if (!localDatasetMetadataRecord.getDocumentLinks().isEmpty()) {
List<DocumentLink> viewLinksMetadataOnlineResources = localDatasetMetadataRecord.getDocumentLinks().stream()
.filter(x -> (x.getLinkState().equals(LinkState.Complete) && x.getLinkHTTPStatusCode() == 200) && (DocumentLink.validViewProtocols.contains(x.getProtocol().toLowerCase()) || x.getProtocol().toLowerCase().matches(DocumentLink.VALID_PROTOCOLS_VIEW_REGEX)))
.filter(x -> (x.getLinkState().equals(LinkState.Complete) && x.getLinkHTTPStatusCode() != null && x.getLinkHTTPStatusCode() == 200) && (DocumentLink.validViewProtocols.contains(x.getProtocol().toLowerCase()) || x.getProtocol().toLowerCase().matches(DocumentLink.VALID_PROTOCOLS_VIEW_REGEX)))
.collect(Collectors.toList());

if (!viewLinksMetadataOnlineResources.isEmpty()) {
Expand All @@ -348,7 +348,7 @@ private void process() {
// Dataset link simplification
if (!localDatasetMetadataRecord.getDocumentLinks().isEmpty()) {
List<DocumentLink> downloadLinksMetadataOnlineResources = localDatasetMetadataRecord.getDocumentLinks().stream()
.filter(x -> (x.getLinkState().equals(LinkState.Complete) && x.getLinkHTTPStatusCode() == 200) && (DocumentLink.validDownloadProtocols.contains(x.getProtocol().toLowerCase()) || x.getProtocol().toLowerCase().matches(DocumentLink.VALID_PROTOCOLS_DOWNLOAD_REGEX)))
.filter(x -> (x.getLinkState().equals(LinkState.Complete) && x.getLinkHTTPStatusCode() != null && x.getLinkHTTPStatusCode() == 200) && (DocumentLink.validDownloadProtocols.contains(x.getProtocol().toLowerCase()) || x.getProtocol().toLowerCase().matches(DocumentLink.VALID_PROTOCOLS_DOWNLOAD_REGEX)))
.collect(Collectors.toList());

if (!downloadLinksMetadataOnlineResources.isEmpty()) {
Expand Down

0 comments on commit 1654361

Please sign in to comment.