diff --git a/src/main/java/org/auscope/portal/core/view/knownlayer/CSWRecordSelector.java b/src/main/java/org/auscope/portal/core/view/knownlayer/CSWRecordSelector.java index 0b215ca56..dd305c136 100644 --- a/src/main/java/org/auscope/portal/core/view/knownlayer/CSWRecordSelector.java +++ b/src/main/java/org/auscope/portal/core/view/knownlayer/CSWRecordSelector.java @@ -10,18 +10,18 @@ */ public class CSWRecordSelector implements KnownLayerSelector { - private String recordId; - private String descriptiveKeyword; - private String serviceName; + private String[] recordIds; + private String[] descriptiveKeywords; + private String[] serviceNames; /** * @param descriptiveKeyword * the descriptive keyword used to identify CSW records */ public CSWRecordSelector() { - this.descriptiveKeyword = null; - this.recordId = null; - this.serviceName = null; + this.descriptiveKeywords = new String[0]; + this.recordIds = new String[0]; + this.serviceNames = new String[0]; } /** @@ -29,8 +29,8 @@ public CSWRecordSelector() { * * @return record id string */ - public String getRecordId() { - return recordId; + public String[] getRecordIds() { + return recordIds; } /** @@ -39,8 +39,8 @@ public String getRecordId() { * @param recordId record id string * @return */ - public void setRecordId(String recordId) { - this.recordId = recordId; + public void setRecordIds(String[] recordIds) { + this.recordIds = recordIds; } /** @@ -48,8 +48,8 @@ public void setRecordId(String recordId) { * * @return the descriptiveKeyword */ - public String getDescriptiveKeyword() { - return descriptiveKeyword; + public String[] getDescriptiveKeywords() { + return descriptiveKeywords; } /** @@ -58,8 +58,8 @@ public String getDescriptiveKeyword() { * @param descriptiveKeyword * the descriptiveKeyword to set */ - public void setDescriptiveKeyword(String descriptiveKeyword) { - this.descriptiveKeyword = descriptiveKeyword; + public void setDescriptiveKeywords(String[] descriptiveKeywords) { + this.descriptiveKeywords = descriptiveKeywords; } /** @@ -67,8 +67,8 @@ public void setDescriptiveKeyword(String descriptiveKeyword) { * * @return the service name */ - public String getServiceName() { - return serviceName; + public String[] getServiceNames() { + return serviceNames; } /** @@ -77,8 +77,8 @@ public String getServiceName() { * @param serviceName the service name string to search for in CSW records * */ - public void setServiceName(String serviceName) { - this.serviceName = serviceName; + public void setServiceNames(String[] serviceNames) { + this.serviceNames = serviceNames; } /** @@ -87,18 +87,21 @@ public void setServiceName(String serviceName) { */ @Override public RelationType isRelatedRecord(CSWRecord record) { - if (recordId != null && recordId.equals(record.getFileIdentifier())) { - return RelationType.Belongs; + for (String recordId: recordIds) { + if (recordId.equals(record.getFileIdentifier())) { + return RelationType.Belongs; + } } - - if (descriptiveKeyword != null && record.containsKeyword(descriptiveKeyword)) { - return RelationType.Belongs; + for (String descriptiveKeyword: descriptiveKeywords) { + if (record.containsKeyword(descriptiveKeyword)) { + return RelationType.Belongs; + } + } + for (String serviceName: serviceNames) { + if (serviceName.equals(record.getServiceName())) { + return RelationType.Belongs; + } } - - if (serviceName != null && serviceName.equals(record.getServiceName())) { - return RelationType.Belongs; - } - return RelationType.NotRelated; } } diff --git a/src/test/java/org/auscope/portal/core/view/knownlayer/TestKnownLayerSelectors.java b/src/test/java/org/auscope/portal/core/view/knownlayer/TestKnownLayerSelectors.java index 737763396..4430cc081 100644 --- a/src/test/java/org/auscope/portal/core/view/knownlayer/TestKnownLayerSelectors.java +++ b/src/test/java/org/auscope/portal/core/view/knownlayer/TestKnownLayerSelectors.java @@ -104,11 +104,12 @@ public void setupRecordList() throws MalformedURLException { @Test public void testCSWKeywordSelector() { CSWRecordSelector selector = new CSWRecordSelector(); - selector.setDescriptiveKeyword("Report"); + String[] keywords = {"Report", "WMS"}; + selector.setDescriptiveKeywords(keywords); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(0))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(1))); - Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(2))); + Assert.assertEquals(RelationType.Belongs, selector.isRelatedRecord(recordList.get(2))); Assert.assertEquals(RelationType.Belongs, selector.isRelatedRecord(recordList.get(3))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(4))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(5))); @@ -122,9 +123,10 @@ public void testCSWKeywordSelector() { @Test public void testCSWServiceNameSelector() { CSWRecordSelector selector = new CSWRecordSelector(); - selector.setServiceName("name4"); + String[] names = {"name1", "name4"}; + selector.setServiceNames(names); - Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(0))); + Assert.assertEquals(RelationType.Belongs, selector.isRelatedRecord(recordList.get(0))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(1))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(2))); Assert.assertEquals(RelationType.Belongs, selector.isRelatedRecord(recordList.get(3))); @@ -140,10 +142,11 @@ public void testCSWServiceNameSelector() { @Test public void testCSWIdSelector() { CSWRecordSelector selector = new CSWRecordSelector(); - selector.setRecordId("id4"); + String[] ids = {"id2", "id4"}; + selector.setRecordIds(ids); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(0))); - Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(1))); + Assert.assertEquals(RelationType.Belongs, selector.isRelatedRecord(recordList.get(1))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(2))); Assert.assertEquals(RelationType.Belongs, selector.isRelatedRecord(recordList.get(3))); Assert.assertEquals(RelationType.NotRelated, selector.isRelatedRecord(recordList.get(4)));