Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4828 - handle pre-registering providers when creating file pids #4830

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
String nonNullDefaultIfKeyNotFound = "";
String protocol = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
String authority = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound);
GlobalIdServiceBean idServiceBean = GlobalIdServiceBean.getBean(target.getProtocol(), ctxt);
// Get the idServiceBean that is configured to mint new IDs
GlobalIdServiceBean idServiceBean = GlobalIdServiceBean.getBean(protocol, ctxt);
try {
//Test to see if identifier already present
//if so, leave.
Expand All @@ -56,15 +57,20 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
}
String doiRetString = idServiceBean.createIdentifier(target);
if (doiRetString != null && doiRetString.contains(target.getIdentifier())) {
if (!idServiceBean.registerWhenPublished()) {
// Should register ID before publicize() is called
// For example, DOIEZIdServiceBean tries to recreate the id if the identifier isn't registered before
// publicizeIdentifier is called
target.setIdentifierRegistered(true);
target.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
}
if (target.isReleased()) {
idServiceBean.publicizeIdentifier(target);
}

if (!idServiceBean.registerWhenPublished() || target.isReleased()) {
if (idServiceBean.registerWhenPublished() && target.isReleased()) {
target.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
target.setIdentifierRegistered(true);
}

ctxt.em().merge(target);
ctxt.em().flush();
if (target.isInstanceofDataset()) {
Expand All @@ -81,10 +87,17 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
}
doiRetString = idServiceBean.createIdentifier(df);
if (doiRetString != null && doiRetString.contains(df.getIdentifier())) {
if (!idServiceBean.registerWhenPublished()) {
// Should register ID before publicize() is called
// For example, DOIEZIdServiceBean tries to recreate the id if the identifier isn't registered before
// publicizeIdentifier is called
df.setIdentifierRegistered(true);
df.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
}
if (df.isReleased()) {
idServiceBean.publicizeIdentifier(df);
}
if (!idServiceBean.registerWhenPublished() || df.isReleased()) {
if (idServiceBean.registerWhenPublished() && df.isReleased()) {
df.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
df.setIdentifierRegistered(true);
}
Expand Down