Skip to content

Commit

Permalink
Merge pull request #461 from AuScope/AUS-4017
Browse files Browse the repository at this point in the history
AUS-4017 Create CSW layers using multiple ids, keywords or service names
  • Loading branch information
laughing0li authored Nov 8, 2023
2 parents abb85c0 + 267dacb commit 297fdcf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
*/
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];
}

/**
* Matches a CSWRecord by an exact matching record id
*
* @return record id string
*/
public String getRecordId() {
return recordId;
public String[] getRecordIds() {
return recordIds;
}

/**
Expand All @@ -39,17 +39,17 @@ 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;
}

/**
* Gets the descriptive keyword used to identify CSW records
*
* @return the descriptiveKeyword
*/
public String getDescriptiveKeyword() {
return descriptiveKeyword;
public String[] getDescriptiveKeywords() {
return descriptiveKeywords;
}

/**
Expand All @@ -58,17 +58,17 @@ 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;
}

/**
* Gets the service name (title) used to identify CSW records
*
* @return the service name
*/
public String getServiceName() {
return serviceName;
public String[] getServiceNames() {
return serviceNames;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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)));
Expand All @@ -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)));
Expand Down

0 comments on commit 297fdcf

Please sign in to comment.