Skip to content

Commit

Permalink
Merge pull request #685 from kbase/CE-225_credit_metadata_tweaks
Browse files Browse the repository at this point in the history
CE-225: new credit metadata fields
  • Loading branch information
ialarmedalien authored Apr 14, 2023
2 parents f992db1 + 7e0cfaf commit cdf7705
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 69 deletions.
62 changes: 60 additions & 2 deletions src/us/kbase/workspace/database/provenance/CreditMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public static ResourceType getResourceType(final String resourceType) {
}
}

private final String description;
private final String identifier;
private final String license;
private final String version;
private final Organization repository;
private final ResourceType resourceType;
private final List<String> comments;
private final List<Contributor> contributors;
Expand All @@ -55,9 +57,11 @@ public static ResourceType getResourceType(final String resourceType) {
private final List<Title> titles;

private CreditMetadata(
final String description,
final String identifier,
final String license,
final String version,
final Organization repository,
final ResourceType resourceType,
final List<String> comments,
final List<Contributor> contributors,
Expand All @@ -68,10 +72,12 @@ private CreditMetadata(
this.comments = comments;
this.contributors = contributors;
this.dates = dates;
this.description = description;
this.funding = funding;
this.identifier = identifier;
this.license = license;
this.relatedIdentifiers = relatedIdentifiers;
this.repository = repository;
this.resourceType = resourceType;
this.titles = titles;
this.version = version;
Expand All @@ -86,6 +92,15 @@ public String getIdentifier() {
return identifier;
}

/**
* Gets the description of the resource.
*
* @return description (if present)
*/
public Optional<String> getDescription() {
return Optional.ofNullable(description);
}

/*
* Gets the license for the resource; may be a string like 'Apache 2.0' or an URL in string
* form.
Expand All @@ -105,6 +120,15 @@ public Optional<String> getVersion() {
return Optional.ofNullable(version);
}

/*
* Gets the repository for the resource.
*
* @return the repository
*/
public Organization getRepository() {
return repository;
}

/*
* Gets the resource type.
*
Expand Down Expand Up @@ -173,10 +197,12 @@ public int hashCode() {
return Objects.hash(comments,
contributors,
dates,
description,
funding,
identifier,
license,
relatedIdentifiers,
repository,
resourceType,
titles,
version);
Expand All @@ -194,10 +220,12 @@ public boolean equals(Object obj) {
return Objects.equals(comments, other.comments)
&& Objects.equals(contributors, other.contributors)
&& Objects.equals(dates, other.dates)
&& Objects.equals(description, other.description)
&& Objects.equals(funding, other.funding)
&& Objects.equals(identifier, other.identifier)
&& Objects.equals(license, other.license)
&& Objects.equals(relatedIdentifiers, other.relatedIdentifiers)
&& Objects.equals(repository, other.repository)
&& Objects.equals(resourceType, other.resourceType)
&& Objects.equals(titles, other.titles)
&& Objects.equals(version, other.version);
Expand All @@ -210,6 +238,9 @@ public boolean equals(Object obj) {
* unique persistent ID for the resource (i.e. the source data for this
* workspace object). Should be in the format
* <database name>:<identifier within database>
* @param repository
* the repository (as an {@link Organization}) from which the resource can
* be accessed
* @param resourceType
* type of the resource, as a {@link ResourceType}
* @param contributors
Expand All @@ -222,14 +253,15 @@ public boolean equals(Object obj) {
*/
public static Builder getBuilder(
final String identifier,
final Organization repository,
final ResourceType resourceType,
final List<Contributor> contributors,
final List<Title> titles) {
final List<String> errorList = new ArrayList<>();
if (resourceType == null) {
errorList.add("resourceType cannot be null");
}
return new Builder(identifier, resourceType, contributors, titles,
return new Builder(identifier, repository, resourceType, contributors, titles,
errorList);
}

Expand All @@ -240,6 +272,9 @@ public static Builder getBuilder(
* unique persistent ID for the resource (i.e. the source data for this
* workspace object). Should be in the format
* <database name>:<identifier within database>
* @param repository
* the repository (as an {@link Organization}) from which the resource can
* be accessed
* @param resourceType
* type of the resource as a string
* @param contributors
Expand All @@ -252,6 +287,7 @@ public static Builder getBuilder(
*/
public static Builder getBuilder(
final String identifier,
final Organization repository,
final String resourceType,
final List<Contributor> contributors,
final List<Title> titles) {
Expand All @@ -268,7 +304,7 @@ public static Builder getBuilder(
errorList.add(e.getMessage());
}
}
return new Builder(identifier, rt, contributors, titles, errorList);
return new Builder(identifier, repository, rt, contributors, titles, errorList);
}


Expand All @@ -282,7 +318,9 @@ public static class Builder {
private final String identifier;
private String license = null;
private String version = null;
private final Organization repository;
private final ResourceType resourceType;
private String description = null;
private List<String> comments = null;
private final List<Contributor> contributors;
private List<EventDate> dates = null;
Expand All @@ -293,14 +331,20 @@ public static class Builder {

private Builder(
final String identifier,
final Organization repository,
final ResourceType resourceType,
final List<Contributor> contributors,
final List<Title> titles,
final List<String> errorList) {

this.errorList = errorList;
this.repository = repository;
this.resourceType = resourceType;

if (repository == null) {
this.errorList.add("repository cannot be null");
}

String checkedPid = identifier;
try {
checkedPid = Common.checkPid(identifier, "identifier", false);
Expand Down Expand Up @@ -345,6 +389,18 @@ public Builder withComments(final List<String> comments) {
return this;
}

/**
* Sets the description for the resource.
*
* @param description
* resource description as a string
* @return this builder
*/
public Builder withDescription(final String description) {
this.description = Common.processString(description);
return this;
}

/**
* Sets the license for the resource; can be a string like 'Apache 2.0' or an
* URL-like string; URL-like strings will be checked for well-formedness.
Expand Down Expand Up @@ -458,9 +514,11 @@ public CreditMetadata build() {

if (errorList.isEmpty()) {
return new CreditMetadata(
description,
identifier,
license,
version,
repository,
resourceType,
comments,
contributors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import us.kbase.workspace.database.provenance.CreditMetadata;
import us.kbase.workspace.database.provenance.CreditMetadata.ResourceType;
import us.kbase.workspace.database.provenance.CreditMetadataEntry;
import us.kbase.workspace.database.provenance.Organization;
import us.kbase.workspace.database.provenance.Title;
import us.kbase.workspace.database.WorkspaceUser;

Expand Down Expand Up @@ -56,8 +57,11 @@ public class CreditMetadataEntryTest {
Title.getBuilder("\t\t\f\t\n\rA Series of Unfortunate Elephants\n\n\n ")
.build());

private static final Organization ORG_1 = Organization.getBuilder("Pillowtronics").build();

private static final CreditMetadata CREDIT_METADATA_EXAMPLE = CreditMetadata
.getBuilder("some:boring_identifier",
ORG_1,
ResourceType.DATASET,
CONTRIBUTOR_LIST,
TITLE_LIST)
Expand Down
Loading

0 comments on commit cdf7705

Please sign in to comment.