Skip to content

Commit

Permalink
force all calls to create identifier to set protocol/auth as well
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Jan 11, 2024
1 parent 0f3d24f commit 17dada6
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 51 deletions.
4 changes: 1 addition & 3 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2108,8 +2108,6 @@ private String init(boolean initFull) {
editMode = EditMode.CREATE;
selectedHostDataverse = dataverseService.find(ownerId);
dataset.setOwner(selectedHostDataverse);
dataset.setProtocol(protocol);
dataset.setAuthority(authority);

if (dataset.getOwner() == null) {
return permissionsWrapper.notFound();
Expand All @@ -2121,7 +2119,7 @@ private String init(boolean initFull) {
if ( isEmpty(dataset.getIdentifier()) && systemConfig.directUploadEnabled(dataset) ) {
CommandContext ctxt = commandEngine.getContext();
PidProvider pidProvider = ctxt.dvObjects().getEffectivePidGenerator(dataset);
dataset.setIdentifier(pidProvider.generateDatasetIdentifier(dataset));
pidProvider.generatePid(dataset);
}
dataverseTemplates.addAll(dataverseService.find(ownerId).getTemplates());
if (!dataverseService.find(ownerId).isTemplateRoot()) {
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/edu/harvard/iq/dataverse/S3PackageImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,7 @@ public DataFile createPackageDataFile(Dataset dataset, String folderName, long t
FileUtil.generateS3PackageStorageIdentifier(packageFile);
PidProvider pidProvider = commandEngine.getContext().dvObjects().getEffectivePidGenerator(dataset);
if (packageFile.getIdentifier() == null || packageFile.getIdentifier().isEmpty()) {
String packageIdentifier = pidProvider.generateDataFileIdentifier(packageFile);
packageFile.setIdentifier(packageIdentifier);
}

if (packageFile.getProtocol() == null) {
packageFile.setProtocol(pidProvider.getProtocol());
}
if (packageFile.getAuthority() == null) {
packageFile.setAuthority(pidProvider.getAuthority());
pidProvider.generatePid(packageFile);
}

if (!packageFile.isIdentifierRegistered()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,7 @@ private DataFile createPackageDataFile(List<File> files) {

PidProvider pidProvider = commandEngine.getContext().dvObjects().getEffectivePidGenerator(dataset);
if (packageFile.getIdentifier() == null || packageFile.getIdentifier().isEmpty()) {
packageFile.setIdentifier(pidProvider.generateDataFileIdentifier(packageFile));
}
if (packageFile.getProtocol() == null) {
packageFile.setProtocol(pidProvider.getProtocol());
}
if (packageFile.getAuthority() == null) {
packageFile.setAuthority(pidProvider.getAuthority());
pidProvider.generatePid(packageFile);
}

if (!packageFile.isIdentifierRegistered()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
PidProvider pidProvider = ctxt.dvObjects().getEffectivePidGenerator(theDataset);

if ( isEmpty(theDataset.getIdentifier()) ) {
theDataset.setIdentifier(pidProvider.generateDatasetIdentifier(theDataset));
pidProvider.generatePid(theDataset);
}

DatasetVersion dsv = getVersionToPersist(theDataset);
Expand Down Expand Up @@ -119,7 +119,7 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
theDataset.setStorageIdentifier(driverId + DataAccess.SEPARATOR + theDataset.getAuthorityForFileStorage() + "/" + theDataset.getIdentifierForFileStorage());
}
if (theDataset.getIdentifier()==null) {
theDataset.setIdentifier(pidProvider.generateDatasetIdentifier(theDataset));
pidProvider.generatePid(theDataset);
}

// Attempt the registration if importing dataset through the API, or the app (but not harvest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected void registerExternalIdentifier(Dataset theDataset, CommandContext ctx
int attempts = 0;
if(retry) {
do {
theDataset.setIdentifier(pidProvider.generateDatasetIdentifier(theDataset));
pidProvider.generatePid(theDataset);
logger.log(Level.INFO, "Attempting to register external identifier for dataset {0} (trying: {1}).",
new Object[]{theDataset.getId(), theDataset.getIdentifier()});
attempts++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
//Test to see if identifier already present
//if so, leave.
if (target.getIdentifier() == null || target.getIdentifier().isEmpty()) {

if (target.isInstanceofDataset()) {
target.setIdentifier(pidProvider.generateDatasetIdentifier((Dataset) target));

} else {
target.setIdentifier(pidProvider.generateDataFileIdentifier((DataFile) target));
}
if (target.getProtocol() == null) {
target.setProtocol(pidProvider.getProtocol());
}
if (target.getAuthority() == null) {
target.setAuthority(pidProvider.getAuthority());
}
pidProvider.generatePid(target);
}

if (pidProvider.alreadyRegistered(target)) {
Expand Down Expand Up @@ -92,13 +80,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
Dataset dataset = (Dataset) target;
for (DataFile df : dataset.getFiles()) {
if (df.getIdentifier() == null || df.getIdentifier().isEmpty()) {
df.setIdentifier(pidProvider.generateDataFileIdentifier(df));
if (df.getProtocol() == null || df.getProtocol().isEmpty()) {
df.setProtocol(pidProvider.getProtocol());
}
if (df.getAuthority() == null || df.getAuthority().isEmpty()) {
df.setAuthority(pidProvider.getAuthority());
}
pidProvider.generatePid(df);
}
doiRetString = pidProvider.createIdentifier(df);
if (doiRetString != null && doiRetString.contains(df.getIdentifier())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ public boolean alreadyRegistered(DvObject dvo) throws Exception {
public DvObject generatePid(DvObject dvObject) {

if (dvObject.getProtocol() == null) {
dvObject.setProtocol(protocol);
dvObject.setProtocol(getProtocol());
} else {
if (!dvObject.getProtocol().equals(getProtocol())) {
logger.warning("The protocol of the DvObject (" + dvObject.getProtocol() + ") does not match the configured protocol (" + getProtocol() + ")");
throw new IllegalArgumentException("The protocol of the DvObject (" + dvObject.getProtocol() + ") doesn't match that of the provider, id: " + getId());
}
}
if (dvObject.getAuthority() == null) {
dvObject.setAuthority(authority);
dvObject.setAuthority(getAuthority());
} else {
logger.warning("The authority of the DvObject (" + dvObject.getAuthority() + ") does not match the configured authority (" + getAuthority() + ")");
throw new IllegalArgumentException("The authority of the DvObject (" + dvObject.getAuthority() + ") doesn't match that of the provider, id: " + getId());
Expand All @@ -208,9 +208,7 @@ public DvObject generatePid(DvObject dvObject) {
return dvObject;
}

//ToDo just send the DvObject.DType
public String generateDatasetIdentifier(Dataset dataset) {
//ToDo - track these in the bean
private String generateDatasetIdentifier(Dataset dataset) {
String shoulder = getShoulder();

switch (getIdentifierGenerationStyle()) {
Expand Down Expand Up @@ -349,8 +347,7 @@ public String getSeparator() {
return SEPARATOR;
}

@Override
public String generateDataFileIdentifier(DataFile datafile) {
private String generateDataFileIdentifier(DataFile datafile) {
String doiDataFileFormat = getDatafilePidFormat();

String prepend = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public interface PidProvider {

boolean publicizeIdentifier(DvObject studyIn);

String generateDatasetIdentifier(Dataset dataset);
String generateDataFileIdentifier(DataFile datafile);
boolean isGlobalIdUnique(GlobalId globalId);

String getUrlPrefix();
Expand Down

0 comments on commit 17dada6

Please sign in to comment.