Skip to content

Commit

Permalink
SWORD: pre-populate "depositor" #457
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Mar 2, 2015
1 parent 115e108 commit 4e94934
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public DepositReceipt createNew(String collectionUri, Deposit deposit, AuthCrede
}

swordService.addDatasetContact(newDatasetVersion, user);
swordService.addDatasetDepositor(newDatasetVersion, user);
swordService.addDatasetSubjectIfMissing(newDatasetVersion);
swordService.setDatasetLicenseAndTermsOfUse(newDatasetVersion, deposit.getSwordEntry());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public DepositReceipt replaceMetadata(String uri, Deposit deposit, AuthCredentia
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "problem calling importXML: " + ex);
}
swordService.addDatasetContact(datasetVersion, user);
swordService.addDatasetDepositor(datasetVersion, user);
swordService.addDatasetSubjectIfMissing(datasetVersion);
swordService.setDatasetLicenseAndTermsOfUse(datasetVersion, deposit.getSwordEntry());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.harvard.iq.dataverse.DatasetFieldServiceBean;
import edu.harvard.iq.dataverse.DatasetFieldType;
import edu.harvard.iq.dataverse.DatasetVersion;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.users.User;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -46,6 +47,22 @@ public void addDatasetContact(DatasetVersion newDatasetVersion, User user) {

}

/**
* Mutate the dataset version, adding a depositor for the dataset.
*/
public void addDatasetDepositor(DatasetVersion newDatasetVersion, User user) {
if (!user.isAuthenticated()) {
logger.info("returning early since user is not authenticated");
return;
}
AuthenticatedUser au = (AuthenticatedUser) user;
DatasetFieldType depositorDatasetFieldType = datasetFieldService.findByNameOpt(DatasetFieldConstant.depositor);
DatasetField depositorDatasetField = DatasetField.createNewEmptyDatasetField(depositorDatasetFieldType, newDatasetVersion);
depositorDatasetField.setSingleValue(au.getLastName() + ", " + au.getFirstName());

newDatasetVersion.getDatasetFields().add(depositorDatasetField);
}

/**
* If no subject exists, mutate the dataset version, adding "N/A" for the
* subject. Otherwise, leave the dataset alone.
Expand Down

0 comments on commit 4e94934

Please sign in to comment.