Skip to content

Commit

Permalink
Merge pull request #684 from kbase/CE-225_schema_dot_org_schema_tweaks
Browse files Browse the repository at this point in the history
CE-225: Award => grant, org name/ID to Organization object
  • Loading branch information
ialarmedalien authored Apr 14, 2023
2 parents 8e9d4b9 + dc422dd commit f992db1
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 242 deletions.
166 changes: 66 additions & 100 deletions src/us/kbase/workspace/database/provenance/FundingReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,69 @@
import java.util.List;
import java.util.ArrayList;
import java.util.Optional;
import us.kbase.workspace.database.Util;

/**
* A funding reference for a resource, including the funding body and the grant
* awarded.
* A funding reference for a resource, including the funding body and the grant.
*/
public class FundingReference {

private final String funderID;
private final String funderName;
private final String awardID;
private final String awardTitle;
private final URL awardURL;
private final Organization funder;
private final String grantID;
private final String grantTitle;
private final URL grantURL;

private FundingReference(
final String funderID,
final String funderName,
final String awardID,
final String awardTitle,
final URL awardURL) {
this.funderID = funderID;
this.funderName = funderName;
this.awardID = awardID;
this.awardTitle = awardTitle;
this.awardURL = awardURL;
final Organization funder,
final String grantID,
final String grantTitle,
final URL grantURL) {
this.funder = funder;
this.grantID = grantID;
this.grantTitle = grantTitle;
this.grantURL = grantURL;
}

/**
* Gets the funder ID, for example ROR:04xm1d337.
* Gets the funding organization.
*
* @return the funder ID, if present.
* @return the funder organization.
*/
public Optional<String> getFunderID() {
return Optional.ofNullable(funderID);
public Organization getFunder() {
return funder;
}

/**
* Gets the funder name, for example US Department of Energy.
*
* @return the funder name.
*/
public String getFunderName() {
return funderName;
}

/**
* Gets the code assigned by the funder to the award, for example
* Gets the code assigned by the funder to the grant, for example
* DOI:10.46936/10.25585/60000745.
*
* @return the award ID, if present.
* @return the grant ID, if present.
*/
public Optional<String> getAwardID() {
return Optional.ofNullable(awardID);
public Optional<String> getGrantID() {
return Optional.ofNullable(grantID);
}

/**
* Gets the title of the award, for example "Metagenomic analysis of the
* Gets the title of the grant, for example "Metagenomic analysis of the
* rhizosphere of three biofuel crops at the KBS intensive site".
*
* @return the award title, if present.
* @return the grant title, if present.
*/
public Optional<String> getAwardTitle() {
return Optional.ofNullable(awardTitle);
public Optional<String> getGrantTitle() {
return Optional.ofNullable(grantTitle);
}

/**
* Gets the URL of the award.
* Gets the URL of the grant.
*
* @return the award URL, if present.
* @return the grant URL, if present.
*/
public Optional<URL> getAwardURL() {
return Optional.ofNullable(awardURL);
public Optional<URL> getGrantURL() {
return Optional.ofNullable(grantURL);
}

@Override
public int hashCode() {
return Objects.hash(awardID, awardTitle, awardURL, funderID, funderName);
return Objects.hash(grantID, grantTitle, grantURL, funder);
}

@Override
Expand All @@ -93,114 +79,94 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
FundingReference other = (FundingReference) obj;
return Objects.equals(awardID, other.awardID) && Objects.equals(awardTitle, other.awardTitle)
&& Objects.equals(awardURL, other.awardURL) && Objects.equals(funderID, other.funderID)
&& Objects.equals(funderName, other.funderName);
return Objects.equals(grantID, other.grantID) && Objects.equals(grantTitle, other.grantTitle)
&& Objects.equals(grantURL, other.grantURL) && Objects.equals(funder, other.funder);
}

/**
* Gets a builder for an {@link FundingReference}.
*
* @param funderName
* name of the funding body
* @param funder
* the funding body
*
* @return the builder.
*/
public static Builder getBuilder(final String funderName) {
return new Builder(funderName);
public static Builder getBuilder(final Organization funder) {
return new Builder(funder);
}

/** A builder for an {@link FundingReference}. */
public static class Builder {

private String funderID = null;
private String funderName;
private String awardID = null;
private String awardTitle = null;
private URL awardURL = null;
private final Organization funder;
private String grantID = null;
private String grantTitle = null;
private URL grantURL = null;
private List<String> errorList = new ArrayList<>();

private Builder(final String funderName) {
try {
this.funderName = Util.checkString(funderName, "funderName");
} catch (Exception e) {
this.errorList.add(e.getMessage());
}
}

/**
* Sets the ID of the funder, for example ROR:04xm1d337.
*
* @param funderID
* the ID of the funder. Null or the empty string removes any
* current ID in the builder.
* @return this builder.
*/
public Builder withFunderID(final String funderID) {
try {
this.funderID = Common.checkPid(funderID, "funderID", true);
} catch (Exception e) {
this.errorList.add(e.getMessage());
private Builder(final Organization funder) {
if (funder == null) {
this.errorList.add("funder cannot be null");
}
return this;
this.funder = funder;
}

/**
* Sets the ID of the award, for example DOI:10.46936/10.25585/60000745.
* N.b. not all award IDs conform to the standard PID syntax.
* Sets the ID of the grant, for example DOI:10.46936/10.25585/60000745.
* N.b. not all grant IDs conform to the standard PID syntax.
*
* @param awardID
* the ID of the award. Null or the empty string removes any
* @param grantID
* the ID of the grant. Null or the empty string removes any
* current ID in the builder.
* @return this builder.
*/
public Builder withAwardID(final String awardID) {
this.awardID = Common.processString(awardID);
public Builder withGrantID(final String grantID) {
this.grantID = Common.processString(grantID);
return this;
}

/**
* Sets the title of the award, for example "Metagenomic analysis of the
* Sets the title of the grant, for example "Metagenomic analysis of the
* rhizosphere of three biofuel crops at the KBS intensive site".
*
* @param awardTitle
* the title of the award. Null or the empty string removes
* @param grantTitle
* the title of the grant. Null or the empty string removes
* any current ID in the builder.
* @return this builder.
*/
public Builder withAwardTitle(final String awardTitle) {
this.awardTitle = Common.processString(awardTitle);
public Builder withGrantTitle(final String grantTitle) {
this.grantTitle = Common.processString(grantTitle);
return this;
}

/**
* Sets the URL for the award.
* Sets the URL for the grant.
*
* @param awardURL
* the URL for the award. Null or the empty string removes any
* @param grantURL
* the URL for the grant. Null or the empty string removes any
* current url in the builder.
* @return this builder.
*/
public Builder withAwardURL(final String awardURL) {
public Builder withGrantURL(final String grantURL) {
try {
this.awardURL = Common.processURL(awardURL, "awardURL");
this.grantURL = Common.processURL(grantURL, "grantURL");
} catch (Exception e) {
this.errorList.add(e.getMessage());
}
return this;
}

/**
* Sets the URL for the award.
* Sets the URL for the grant.
*
* @param awardURL
* the URL of the award. Null removes any current url in the
* @param grantURL
* the URL of the grant. Null removes any current url in the
* builder.
* @return this builder.
*/
public Builder withAwardURL(final URL awardURL) {
public Builder withGrantURL(final URL grantURL) {
try {
this.awardURL = Common.processURL(awardURL, "awardURL");
this.grantURL = Common.processURL(grantURL, "grantURL");
} catch (Exception e) {
this.errorList.add(e.getMessage());
}
Expand All @@ -214,7 +180,7 @@ public Builder withAwardURL(final URL awardURL) {
*/
public FundingReference build() {
if (errorList.isEmpty()) {
return new FundingReference(funderID, funderName, awardID, awardTitle, awardURL);
return new FundingReference(funder, grantID, grantTitle, grantURL);
}
throw new IllegalArgumentException("Errors in FundingReference construction:\n" +
String.join("\n", errorList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
import us.kbase.workspace.database.provenance.Event;
import us.kbase.workspace.database.provenance.EventDate;
import us.kbase.workspace.database.provenance.FundingReference;
import us.kbase.workspace.database.provenance.Organization;
import us.kbase.workspace.database.provenance.PermanentID;
import us.kbase.workspace.database.provenance.Title;

public class CreditMetadataTest {

private static final String INCORRECT = "incorrect ";
private static final String NO_MUTATION = "no mutation";
// field names
private static final String COMMENTS = "comments";
private static final String ID = "identifier";
Expand Down Expand Up @@ -134,11 +136,13 @@ public class CreditMetadataTest {
private static final List<EventDate> DATE_LIST_DUPES_NULLS = Arrays.asList(
ED1, ED2, null, ED1, ED2, null, ED1, ED2, null);

private static final Organization ORG_1 = Organization.getBuilder("Ransome the Clown's Emporium of Wonder").build();
private static final Organization ORG_2 = Organization.getBuilder("Pillowtronics").build();

private static final FundingReference F1 = FundingReference
.getBuilder("New World Order LLC").build();
.getBuilder(ORG_1).build();
private static final FundingReference F2 = FundingReference
.getBuilder("Daddy Warbucks").build();
.getBuilder(ORG_2).build();

private static final List<FundingReference> FUNDING_LIST = Arrays.asList(F1);
private static final List<FundingReference> FUNDING_LIST_DUPES_NULLS = Arrays.asList(
Expand Down Expand Up @@ -508,7 +512,7 @@ public void assertContributorsImmutable() throws Exception {

// mutating the input list should not affect the contributor list
contributorList.add(C3);
assertThat("no mutation", contributorList, is(Arrays.asList(C1, C2, C3)));
assertThat(NO_MUTATION, contributorList, is(Arrays.asList(C1, C2, C3)));
assertThat(INCORRECT_CONTRIBUTORS, cm.getContributors(), is(CONTRIBUTOR_LIST));

try {
Expand All @@ -534,7 +538,7 @@ public void assertCommentsImmutable() throws Exception {

// mutating the input list should not affect the comments
commentList.add("blah blah blah");
assertThat("no mutation", commentList, is(Arrays.asList(
assertThat(NO_MUTATION, commentList, is(Arrays.asList(
"What a load of nonsense",
"Prime codswallop",
"blah blah blah"
Expand Down Expand Up @@ -564,7 +568,7 @@ public void assertDatesImmutable() throws Exception {

// mutating the input list should not affect the date list
dateList.add(ED3);
assertThat("no mutation", dateList, is(Arrays.asList(ED1, ED2, ED3)));
assertThat(NO_MUTATION, dateList, is(Arrays.asList(ED1, ED2, ED3)));
assertThat(INCORRECT_DATES, cm.getDates(), is(DATE_LIST));

try {
Expand All @@ -588,7 +592,7 @@ public void assertFundingImmutable() throws Exception {

// mutating the input list should not affect the funding list
fundingList.add(F2);
assertThat("no mutation", fundingList, is(Arrays.asList(F1, F2)));
assertThat(NO_MUTATION, fundingList, is(Arrays.asList(F1, F2)));
assertThat(INCORRECT_FUNDING, cm.getFunding(), is(FUNDING_LIST));

try {
Expand All @@ -611,7 +615,7 @@ public void assertRelatedIdentifiersImmutable() throws Exception {
.build();
// mutating the input list should not affect the related ID list
pidList.add(PID3);
assertThat("no mutation", pidList, is(Arrays.asList(PID1, PID2, PID3)));
assertThat(NO_MUTATION, pidList, is(Arrays.asList(PID1, PID2, PID3)));
assertThat(INCORRECT_RELATED_IDS, cm.getRelatedIdentifiers(), is(RELATED_ID_LIST));

try {
Expand All @@ -633,7 +637,7 @@ public void assertTitlesImmutable() throws Exception {
.build();
// mutating the input list should not affect the title list
titleList.add(T3);
assertThat("no mutation", titleList, is(Arrays.asList(T1, T2, T3)));
assertThat(NO_MUTATION, titleList, is(Arrays.asList(T1, T2, T3)));
assertThat(INCORRECT_TITLES, cm.getTitles(), is(TITLE_LIST));

try {
Expand Down
Loading

0 comments on commit f992db1

Please sign in to comment.