Skip to content

Commit fc22555

Browse files
committed
Author info collapsed on ORCID and if not, email
Helps to prevent duplication of author information in the RO manifest
1 parent b1fbe33 commit fc22555

File tree

3 files changed

+103
-6
lines changed

3 files changed

+103
-6
lines changed

src/main/java/org/commonwl/view/researchobject/HashableAgent.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,26 @@ public boolean equals(Object o) {
7878

7979
HashableAgent that = (HashableAgent) o;
8080

81-
if (name != null ? !name.equals(that.name) : that.name != null) return false;
81+
// ORCID is a unique identifier so if matches, the objects are equal
82+
if (orcid != null && orcid.equals(that.orcid)) return true;
83+
84+
// If no ORCID is present but email is the name, the objects are equal
85+
if (orcid == null && uri != null && uri.equals(that.uri)) return true;
86+
87+
// Default to checking all parameters
8288
if (orcid != null ? !orcid.equals(that.orcid) : that.orcid != null) return false;
89+
if (name != null ? !name.equals(that.name) : that.name != null) return false;
8390
return uri != null ? uri.equals(that.uri) : that.uri == null;
8491

8592
}
8693

94+
/**
95+
* ORCID is used as hashcode to fall back to comparison if missing
96+
* @return The hash code for this object
97+
*/
8798
@Override
8899
public int hashCode() {
89-
int result = name != null ? name.hashCode() : 0;
90-
result = 31 * result + (orcid != null ? orcid.hashCode() : 0);
91-
result = 31 * result + (uri != null ? uri.hashCode() : 0);
92-
return result;
100+
return orcid != null ? orcid.hashCode() : 0;
93101
}
94102

95103
}

src/main/java/org/commonwl/view/researchobject/ROBundleService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
303303
gitPath.toString());
304304

305305
if (cwl) {
306-
// Attempt to get authors from cwl description
306+
// Attempt to get authors from cwl description - takes priority
307307
ResultSet descAuthors = rdfService.getAuthors(bundlePath
308308
.resolve(file.getName()).toString().substring(10), url);
309309
if (descAuthors.hasNext()) {
@@ -318,6 +318,7 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
318318
if (authorSoln.contains("orcid")) {
319319
newAuthor.setOrcid(new URI(authorSoln.get("orcid").toString()));
320320
}
321+
fileAuthors.remove(newAuthor);
321322
fileAuthors.add(newAuthor);
322323
}
323324
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.commonwl.view.researchobject;
21+
22+
import org.junit.Test;
23+
24+
import java.net.URI;
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertNull;
30+
31+
public class HashableAgentTest {
32+
33+
/**
34+
* If the ORCID of two agents is the same, they are the same person
35+
* regardless of other information
36+
*/
37+
@Test
38+
public void orcidsMakeAgentsEqual() throws Exception {
39+
40+
HashableAgent firstOrcid = new HashableAgent("Mark Robindsason",
41+
new URI("http://orcid.org/0000-0002-8184-7507"),
42+
new URI("[email protected]"));
43+
44+
HashableAgent secondOrcid = new HashableAgent("Mark Robinson",
45+
new URI("http://orcid.org/0000-0002-8184-7507"),
46+
new URI("[email protected]"));
47+
48+
Set<HashableAgent> testSet = new HashSet<>();
49+
testSet.add(firstOrcid);
50+
testSet.remove(secondOrcid);
51+
testSet.add(secondOrcid);
52+
53+
assertEquals(1, testSet.size());
54+
HashableAgent fromSet = testSet.iterator().next();
55+
assertEquals("Mark Robinson", fromSet.getName());
56+
assertEquals(new URI("[email protected]"), fromSet.getUri());
57+
assertEquals(new URI("http://orcid.org/0000-0002-8184-7507"), fromSet.getOrcid());
58+
59+
}
60+
61+
/**
62+
* When no ORCID is present but emails are the same, the agents are
63+
* the same person regardless of name
64+
*/
65+
@Test
66+
public void noOrcidEmailSameMakesAgentsEqual() throws Exception {
67+
68+
HashableAgent firstEmail = new HashableAgent("Mark Robindsason",
69+
null,
70+
new URI("[email protected]"));
71+
72+
HashableAgent secondEmail = new HashableAgent("Mark Robinson",
73+
null,
74+
new URI("[email protected]"));
75+
76+
Set<HashableAgent> testSet = new HashSet<>();
77+
testSet.add(firstEmail);
78+
testSet.remove(secondEmail);
79+
testSet.add(secondEmail);
80+
81+
assertEquals(1, testSet.size());
82+
HashableAgent fromSet = testSet.iterator().next();
83+
assertEquals("Mark Robinson", fromSet.getName());
84+
assertEquals(new URI("[email protected]"), fromSet.getUri());
85+
assertNull(fromSet.getOrcid());
86+
87+
}
88+
}

0 commit comments

Comments
 (0)