Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
import org.labkey.panoramapublic.message.PrivateDataMessageScheduler;
import org.labkey.panoramapublic.message.PrivateDataReminderSettings;
import org.labkey.panoramapublic.ncbi.MockNcbiPublicationSearchService;
import org.labkey.panoramapublic.ncbi.NcbiApiKeyCheck;
import org.labkey.panoramapublic.ncbi.NcbiPublicationSearchService;
import org.labkey.panoramapublic.ncbi.NcbiPublicationSearchServiceImpl;
import org.labkey.panoramapublic.ncbi.PublicationMatch;
Expand Down Expand Up @@ -10084,6 +10085,55 @@ public static ActionURL getViewExperimentModificationsURL(int experimentAnnotati
return result;
}

@RequiresPermission(AdminOperationsPermission.class)
public static class ValidateNcbiApiKeyAction extends MutatingApiAction<PrivateDataReminderSettingsForm>
{
@Override
public Object execute(PrivateDataReminderSettingsForm form, BindException errors)
{
ApiSimpleResponse response = new ApiSimpleResponse();
response.put("success", true);

// An empty field means check the key that is already saved, since the form never
// displays it.
boolean checkingSavedKey = StringUtils.isBlank(form.getNcbiApiKey());
String apiKey = checkingSavedKey
? PrivateDataReminderSettings.get().getNcbiApiKey()
: form.getNcbiApiKey().trim();

if (StringUtils.isBlank(apiKey))
{
response.put("valid", false);
response.put("message", "Enter a key to validate, or save one first.");
return response;
}

NcbiApiKeyCheck check = NcbiPublicationSearchService.get().checkApiKey(apiKey);
response.put("valid", check.isValid());
if (check.isValid())
{
// Validating does not store anything, so say so. Otherwise "accepted" reads as
// confirmation that the key is now in effect.
response.put("message", checkingSavedKey
? "NCBI accepted the saved key."
: "NCBI accepted this key. Click Save to store it.");
LOG.info("NCBI accepted an API key entered on the Private Data Reminder Settings page.");
}
else
{
// The short message goes beside the field. NCBI's own words are offered separately,
// since the admin holding the key is the one who has to act on them.
response.put("message", check.isRejected()
? "NCBI rejected this key."
: "Could not reach NCBI to check this key.");
response.put("detail", check.getMessage());
LOG.warn("Could not confirm an API key entered on the Private Data Reminder Settings page. {}",
check.getMessage());
}
return response;
}
}

@RequiresPermission(AdminOperationsPermission.class)
public static class PrivateDataReminderSettingsAction extends FormViewAction<PrivateDataReminderSettingsForm>
{
Expand Down Expand Up @@ -10146,6 +10196,8 @@ public ModelAndView getView(PrivateDataReminderSettingsForm form, boolean reshow
form.setExtensionLength(settings.getExtensionLength());
form.setEnablePublicationSearch(settings.isEnablePublicationSearch());
form.setPublicationSearchFrequency(settings.getPublicationSearchFrequency());
// Do not put the saved key in the form. The JSP shows only whether one is stored.
form.setNcbiApiKeySet(PrivateDataReminderSettings.hasNcbiApiKey());
}

VBox view = new VBox();
Expand All @@ -10168,6 +10220,17 @@ public boolean handlePost(PrivateDataReminderSettingsForm form, BindException er
settings.setPublicationSearchFrequency(form.getPublicationSearchFrequency());
PrivateDataReminderSettings.save(settings);

// A blank field leaves the saved key alone, so editing the reminder schedule cannot
// erase it. Removing a key takes the explicit checkbox.
if (form.isClearNcbiApiKey())
{
PrivateDataReminderSettings.saveNcbiApiKey(null);
}
else if (!StringUtils.isBlank(form.getNcbiApiKey()))
{
PrivateDataReminderSettings.saveNcbiApiKey(form.getNcbiApiKey());
}

PrivateDataMessageScheduler.getInstance().initialize(settings.isEnableReminders());
return true;
}
Expand Down Expand Up @@ -10205,6 +10268,9 @@ public static class PrivateDataReminderSettingsForm
private Integer _delayUntilFirstReminder;
private boolean _enablePublicationSearch;
private Integer _publicationSearchFrequency;
private String _ncbiApiKey;
private boolean _clearNcbiApiKey;
private boolean _ncbiApiKeySet;

public boolean isEnabled()
{
Expand Down Expand Up @@ -10275,6 +10341,36 @@ public void setPublicationSearchFrequency(Integer publicationSearchFrequency)
{
_publicationSearchFrequency = publicationSearchFrequency;
}

public String getNcbiApiKey()
{
return _ncbiApiKey;
}

public void setNcbiApiKey(String ncbiApiKey)
{
_ncbiApiKey = ncbiApiKey;
}

public boolean isClearNcbiApiKey()
{
return _clearNcbiApiKey;
}

public void setClearNcbiApiKey(boolean clearNcbiApiKey)
{
_clearNcbiApiKey = clearNcbiApiKey;
}

public boolean isNcbiApiKeySet()
{
return _ncbiApiKeySet;
}

public void setNcbiApiKeySet(boolean ncbiApiKeySet)
{
_ncbiApiKeySet = ncbiApiKeySet;
}
}

@RequiresPermission(AdminOperationsPermission.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.labkey.panoramapublic;

import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.admin.FolderSerializationRegistry;
Expand All @@ -34,6 +35,7 @@
import org.labkey.api.security.roles.RoleManager;
import org.labkey.api.settings.AdminConsole;
import org.labkey.api.targetedms.TargetedMSService;
import org.labkey.api.util.logging.LogHelper;
import org.labkey.api.view.ActionURL;
import org.labkey.api.view.BaseWebPartFactory;
import org.labkey.api.view.HtmlView;
Expand All @@ -46,6 +48,7 @@
import org.labkey.panoramapublic.bluesky.BlueskyApiClient;
import org.labkey.panoramapublic.bluesky.PanoramaPublicLogoResourceType;
import org.labkey.panoramapublic.catalog.CatalogImageAttachmentType;
import org.labkey.panoramapublic.message.PrivateDataMessageScheduler;
import org.labkey.panoramapublic.message.PrivateDataReminderSettings;
import org.labkey.panoramapublic.ncbi.NcbiPublicationSearchServiceImpl;
import org.labkey.panoramapublic.model.Journal;
Expand Down Expand Up @@ -82,6 +85,8 @@

public class PanoramaPublicModule extends SpringModule
{
private static final Logger LOG = LogHelper.getLogger(PanoramaPublicModule.class, "Panorama Public module");

public static final String NAME = "PanoramaPublic";
public static final String DOWNLOAD_DATA_INFO_WP = "Download Data";

Expand Down Expand Up @@ -151,6 +156,22 @@ protected void startupAfterSpringConfig(ModuleContext moduleContext)
{
fileContentService.addFileListener(new PanoramaPublicFileListener());
}

}

@Override
public void startBackgroundThreads()
{
// Re-establish the reminder schedule on every startup. Reminder messages contain absolute
// URLs, which are only safe to build once this method is called.
try
{
PrivateDataMessageScheduler.getInstance().initialize(PrivateDataReminderSettings.get().isEnableReminders());
}
catch (RuntimeException e)
{
LOG.error("Failed to schedule the Panorama Public private data reminder job", e);
}
}

@NotNull
Expand Down
Loading