From 2063f9dd1ae0046cfbc855618b79bff02b80385f Mon Sep 17 00:00:00 2001 From: "stuart.woodman" Date: Thu, 19 Sep 2024 16:36:04 +1000 Subject: [PATCH] Fixed issue where CSWRecords with null OnlineResources would cause the KnownLayers build to fail silently. --- .../services/responses/csw/CSWRecord.java | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/auscope/portal/core/services/responses/csw/CSWRecord.java b/src/main/java/org/auscope/portal/core/services/responses/csw/CSWRecord.java index 9158d0510..994b9bb11 100644 --- a/src/main/java/org/auscope/portal/core/services/responses/csw/CSWRecord.java +++ b/src/main/java/org/auscope/portal/core/services/responses/csw/CSWRecord.java @@ -267,7 +267,10 @@ public String getServiceName() { * @return the online resources */ public List getOnlineResources() { - return onlineResources; + if (onlineResources == null) { + onlineResources = new ArrayList(); + } + return onlineResources; } /** @@ -706,23 +709,24 @@ public String toString() { */ public List getOnlineResourcesByType(AbstractCSWOnlineResource.OnlineResourceType... types) { List result = new ArrayList<>(); - - for (AbstractCSWOnlineResource r : onlineResources) { - if (r == null) { - continue; - } - boolean matching = false; - AbstractCSWOnlineResource.OnlineResourceType typeToMatch = r.getType(); - for (AbstractCSWOnlineResource.OnlineResourceType type : types) { - if (typeToMatch == type) { - matching = true; - break; - } - } - - if (matching) { - result.add(r); - } + if (onlineResources != null) { + for (AbstractCSWOnlineResource r : onlineResources) { + if (r == null) { + continue; + } + boolean matching = false; + AbstractCSWOnlineResource.OnlineResourceType typeToMatch = r.getType(); + for (AbstractCSWOnlineResource.OnlineResourceType type : types) { + if (typeToMatch == type) { + matching = true; + break; + } + } + + if (matching) { + result.add(r); + } + } } return result; @@ -743,24 +747,25 @@ public List getOnlineResourcesByType( CSWRecordsFilterVisitor visitor, AbstractCSWOnlineResource.OnlineResourceType... types) { List result = new ArrayList<>(); - - for (AbstractCSWOnlineResource r : onlineResources) { - if (r == null) { - continue; - } - boolean matching = false; - AbstractCSWOnlineResource.OnlineResourceType typeToMatch = r - .getType(); - for (AbstractCSWOnlineResource.OnlineResourceType type : types) { - if (typeToMatch == type) { - matching = true; - break; - } - } - - if (matching && r.accept(visitor)) { - result.add(r); - } + if (onlineResources != null) { + for (AbstractCSWOnlineResource r : onlineResources) { + if (r == null) { + continue; + } + boolean matching = false; + AbstractCSWOnlineResource.OnlineResourceType typeToMatch = r + .getType(); + for (AbstractCSWOnlineResource.OnlineResourceType type : types) { + if (typeToMatch == type) { + matching = true; + break; + } + } + + if (matching && r.accept(visitor)) { + result.add(r); + } + } } return result;