Skip to content

Commit

Permalink
RSDEV-271: Integration with Digital Commons Data
Browse files Browse the repository at this point in the history
  • Loading branch information
rs-nicof committed Aug 19, 2024
1 parent 1306570 commit 4fddd9d
Show file tree
Hide file tree
Showing 25 changed files with 1,518 additions and 20 deletions.
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,25 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.rspace-os</groupId>
<artifactId>rspace-digital-commons-data-adapter</artifactId>
<version>0.0.2</version>
<exclusions>
<exclusion>
<groupId>com.github.rspace-os</groupId>
<artifactId>repository-spi</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.rspace-os</groupId>
<artifactId>protocols-java-client</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/axiope/service/cfg/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.researchspace.auth.WhiteListIPCheckerImpl;
import com.researchspace.core.util.ResponseUtil;
import com.researchspace.dao.customliquibaseupdates.LiveLiqUpdater;
import com.researchspace.dcd.rspaceadapter.DigitalCommonsDataRepository;
import com.researchspace.document.importer.DocumentImporterFromWord2HTML;
import com.researchspace.document.importer.EvernoteEnexImporter;
import com.researchspace.document.importer.ExternalFileImporter;
Expand Down Expand Up @@ -1278,6 +1279,18 @@ public IRepository zenodoRepository() {
return rc;
}

/**
* Creates a new {@link IRepository} bean for Digital Commons Data.
*
* @return the repository adapter
*/
@Bean(name = "digital_commons_dataRepository")
public IRepository digitalCommonsDataRepository() {
DigitalCommonsDataRepository rc = new DigitalCommonsDataRepository();
log.info("Setting in repository implementation {}", rc);
return rc;
}

@Bean(name = "dataCiteConnector")
public DataCiteConnector getDataCiteConnector() {
return new DataCiteConnectorImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,13 @@ public interface IPropertyHolder extends Versionable {

String getZenodoApiUrl();

String getDigitalCommonsDataBaseUrl();

String getDigitalCommonsDataCallbackBaseUrl();

String getDigitalCommonsDataClientId();

String getDigitalCommonsDataClientSecret();

boolean isAsposeEnabled();
}
21 changes: 21 additions & 0 deletions src/main/java/com/researchspace/properties/PropertyHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.security.Key;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -210,6 +211,26 @@ public class PropertyHolder implements IMutablePropertyHolder {
@Value("${zenodo.url}")
private String zenodoApiUrl;

@Value("${dcd.base.url}")
@Getter
@Setter
private String digitalCommonsDataBaseUrl;

@Value("${dcd.callback.base.url}")
@Getter
@Setter
private String digitalCommonsDataCallbackBaseUrl;

@Value("${dcd.client.id}")
@Getter
@Setter
private String digitalCommonsDataClientId;

@Value("${dcd.client.secret}")
@Getter
@Setter
private String digitalCommonsDataClientSecret;

@Value("${aspose.enabled:true}")
private String asposeEnabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ public interface IntegrationsHandler {
String PROTOCOLS_IO_APP_NAME = "PROTOCOLS_IO";
String PYRAT_APP_NAME = "PYRAT";
String DMPTOOL_APP_NAME = "DMPTOOL";
String DIGITAL_COMMONS_DATA_APP_NAME = "DIGITAL_COMMONS_DATA";
String CLUSTERMARKET_APP_NAME = "CLUSTERMARKET";
String OMERO_APP_NAME = "OMERO";
String JOVE_APP_NAME = "JOVE";
String DRYAD_APP_NAME = "DRYAD";
String ARGOS_APP_NAME = "ARGOS";
String ZENODO_APP_NAME = "ZENODO";
String DMPONLINE_APP_NAME = "DMPONLINE";

String PYRAT_USER_TOKEN = "PYRAT_USER_TOKEN";
String ZENODO_USER_TOKEN = "ZENODO_USER_TOKEN";
String DIGITAL_COMMONS_DATA_USER_TOKEN = "DIGITAL_COMMONS_DATA_USER_TOKEN";
String EGNYTE_DOMAIN_SETTING = "EGNYTE_DOMAIN";
String ACCESS_TOKEN_SETTING = "ACCESS_TOKEN";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ RepoUIConfigInfo getDataverseRepoUIConfigInfo(AppConfigElementSet appCfg, User u
RepoUIConfigInfo getDryadRepoUIConfigInfo(User user) throws MalformedURLException;

RepoUIConfigInfo getZenodoRepoUIConfigInfo(User user) throws MalformedURLException;

RepoUIConfigInfo getDigitalCommonsDataRepoUIConfigInfo(User user) throws MalformedURLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ void postProcessInfo(IntegrationInfo info, User user) {
case ZENODO_APP_NAME:
setSingleUserToken(info, user, ZENODO_APP_NAME, ZENODO_USER_TOKEN);
return;
case DIGITAL_COMMONS_DATA_APP_NAME:
setSingleUserToken(
info, user, DIGITAL_COMMONS_DATA_APP_NAME, DIGITAL_COMMONS_DATA_USER_TOKEN);
return;
default:
}
}
Expand Down Expand Up @@ -403,6 +407,7 @@ private boolean isAppConfigIntegration(String integrationName) {
case DRYAD_APP_NAME:
case ARGOS_APP_NAME:
case ZENODO_APP_NAME:
case DIGITAL_COMMONS_DATA_APP_NAME:
return true;
}
return isSingleOptionSetAppConfigIntegration(integrationName);
Expand All @@ -426,4 +431,9 @@ private boolean isSingleOptionSetAppConfigIntegration(String integrationName) {
private String getSysPropertyFromIntegrationName(String name) {
return name.toLowerCase() + ".available"; // see SystemProperty table
}

/* For test purposed */
protected void setUserConnectionManager(UserConnectionManager userConnectionManager) {
this.userConnManager = userConnectionManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import com.researchspace.service.UserAppConfigManager;
import com.researchspace.service.UserConnectionManager;
import com.researchspace.service.UserManager;
import com.researchspace.webapp.controller.repositories.DigitalCommonsDataUIConnectionConfig;
import com.researchspace.webapp.controller.repositories.DryadUIConnectionConfig;
import com.researchspace.webapp.controller.repositories.FigshareUIConnectionConfig;
import com.researchspace.webapp.controller.repositories.RSDataverseConnectionConfig;
import com.researchspace.webapp.controller.repositories.RSpaceRepoConnectionConfig;
import com.researchspace.webapp.controller.repositories.ZenodoUIConnectionConfig;
import com.researchspace.webapp.integrations.digitalcommonsdata.DigitalCommonsDataController;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
Expand All @@ -45,6 +48,7 @@
public class RepositoryDepositHandlerImpl implements RepositoryDepositHandler {

@Autowired private IPropertyHolder propertyHolder;
@Autowired private DigitalCommonsDataController digitalCommonsDataController;

private @Autowired UserManager userManager;
private @Autowired RepositoryFactory repoFactory;
Expand Down Expand Up @@ -113,28 +117,25 @@ public RepositoryOperationResult sendArchiveToRepository(

private RepositoryConfig getRepoConnectionInfo(
Optional<AppConfigElementSet> cfg, App app, User subject) throws MalformedURLException {
RepositoryConfig repoCfg = null;
RSpaceRepoConnectionConfig uiConnectionConfig;
if (cfg.isPresent() && app.getName().equals(App.APP_DATAVERSE)) {
repoCfg =
repoCfgFactory.createRepositoryConfigFromAppCfg(
new RSDataverseConnectionConfig(cfg.get()), subject);
uiConnectionConfig = new RSDataverseConnectionConfig(cfg.get());
} else if (app.getName().equalsIgnoreCase(App.APP_FIGSHARE)) {
FigshareUIConnectionConfig figshareUIConnectionConfig =
new FigshareUIConnectionConfig(userConnectionManager, subject);
repoCfg =
repoCfgFactory.createRepositoryConfigFromAppCfg(figshareUIConnectionConfig, subject);
uiConnectionConfig = new FigshareUIConnectionConfig(userConnectionManager, subject);
} else if (app.getName().equalsIgnoreCase(App.APP_DRYAD)) {
DryadUIConnectionConfig dryadUIConnectionConfig =
uiConnectionConfig =
new DryadUIConnectionConfig(userConnectionManager, subject, this.propertyHolder);
repoCfg = repoCfgFactory.createRepositoryConfigFromAppCfg(dryadUIConnectionConfig, subject);
} else if (app.getName().equalsIgnoreCase(App.APP_ZENODO)) {
ZenodoUIConnectionConfig zenodoUIConnectionConfig =
uiConnectionConfig =
new ZenodoUIConnectionConfig(userConnectionManager, subject, this.propertyHolder);
repoCfg = repoCfgFactory.createRepositoryConfigFromAppCfg(zenodoUIConnectionConfig, subject);
} else if (app.getName().equalsIgnoreCase(App.APP_DIGITAL_COMMONS_DATA)) {
uiConnectionConfig =
new DigitalCommonsDataUIConnectionConfig(
digitalCommonsDataController, userConnectionManager, subject, this.propertyHolder);
} else {
throw new IllegalArgumentException("Unknown or unconfigured repository: " + app.getName());
}
return repoCfg;
return repoCfgFactory.createRepositoryConfigFromAppCfg(uiConnectionConfig, subject);
}

protected void checkConnectionState(App app, User subject) {
Expand Down Expand Up @@ -227,6 +228,21 @@ public RepoUIConfigInfo getZenodoRepoUIConfigInfo(User user) throws MalformedURL
return getRepositoryConfiguration(appCfg.getApp(), repoConnectionInfo);
}

@Override
public RepoUIConfigInfo getDigitalCommonsDataRepoUIConfigInfo(User user)
throws MalformedURLException {
UserAppConfig appCfg =
userAppConfigMgr.getByAppName(
getAppNameFromIntegrationName(IntegrationsHandler.DIGITAL_COMMONS_DATA_APP_NAME), user);
checkConnectionState(appCfg.getApp(), userManager.getAuthenticatedUserInSession());
DigitalCommonsDataUIConnectionConfig cfg =
new DigitalCommonsDataUIConnectionConfig(
digitalCommonsDataController, userConnectionManager, user, propertyHolder);
RepositoryConfig repoConnectionInfo =
repoCfgFactory.createRepositoryConfigFromAppCfg(cfg, user);
return getRepositoryConfiguration(appCfg.getApp(), repoConnectionInfo);
}

// makes API calls to repository to get static info about licenses, subjects etc
private RepoUIConfigInfo getRepositoryConfiguration(App app, RepositoryConfig repoCfg) {
IRepository repo = repoFactory.getRepository(getRepoName(app));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.researchspace.service.IntegrationsHandler.ARGOS_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.CLUSTERMARKET_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DATAVERSE_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DIGITAL_COMMONS_DATA_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DMPONLINE_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DMPTOOL_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DRYAD_APP_NAME;
Expand Down Expand Up @@ -138,6 +139,9 @@ private Map<String, IntegrationInfo> getAll(User user) {
rc.put(ARGOS_APP_NAME, integrationsHandler.getIntegration(user, ARGOS_APP_NAME));
rc.put(ZENODO_APP_NAME, integrationsHandler.getIntegration(user, ZENODO_APP_NAME));
rc.put(OMERO_APP_NAME, integrationsHandler.getIntegration(user, OMERO_APP_NAME));
rc.put(
DIGITAL_COMMONS_DATA_APP_NAME,
integrationsHandler.getIntegration(user, DIGITAL_COMMONS_DATA_APP_NAME));
return rc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.researchspace.model.dto.IntegrationInfo.getAppNameFromIntegrationName;
import static com.researchspace.service.IntegrationsHandler.DATAVERSE_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DIGITAL_COMMONS_DATA_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.DRYAD_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.FIGSHARE_APP_NAME;
import static com.researchspace.service.IntegrationsHandler.ZENODO_APP_NAME;
Expand Down Expand Up @@ -133,6 +134,8 @@ private RepoUIConfigInfo getRepoUIConfigInfo(User user, String integrationInfoNa
info = depositHandler.getDryadRepoUIConfigInfo(user);
} else if (ZENODO_APP_NAME.equals(integrationInfoName)) {
info = depositHandler.getZenodoRepoUIConfigInfo(user);
} else if (DIGITAL_COMMONS_DATA_APP_NAME.equals(integrationInfoName)) {
info = depositHandler.getDigitalCommonsDataRepoUIConfigInfo(user);
}
if (info == null) {
throw new IllegalStateException("unknown or undefined integration");
Expand All @@ -146,6 +149,9 @@ private Map<String, IntegrationInfo> getRepositoryIntegrationInfos(User user) {
rc.put(FIGSHARE_APP_NAME, integrationsHandler.getIntegration(user, FIGSHARE_APP_NAME));
rc.put(DRYAD_APP_NAME, integrationsHandler.getIntegration(user, DRYAD_APP_NAME));
rc.put(ZENODO_APP_NAME, integrationsHandler.getIntegration(user, ZENODO_APP_NAME));
rc.put(
DIGITAL_COMMONS_DATA_APP_NAME,
integrationsHandler.getIntegration(user, DIGITAL_COMMONS_DATA_APP_NAME));
return rc;
}

Expand All @@ -166,6 +172,8 @@ private boolean isConfiguredActive(Entry<String, IntegrationInfo> e) {
return e.getValue().isOauthConnected();
} else if (ZENODO_APP_NAME.equals(e.getKey())) {
return e.getValue().hasOptions();
} else if (DIGITAL_COMMONS_DATA_APP_NAME.equals(e.getKey())) {
return e.getValue().hasOptions();
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.researchspace.webapp.controller.repositories;

import static com.researchspace.service.IntegrationsHandler.DIGITAL_COMMONS_DATA_APP_NAME;

import com.researchspace.model.User;
import com.researchspace.model.oauth.UserConnection;
import com.researchspace.properties.IPropertyHolder;
import com.researchspace.service.UserConnectionManager;
import com.researchspace.webapp.integrations.digitalcommonsdata.DigitalCommonsDataController;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.Principal;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.support.BindingAwareModelMap;

@Slf4j
public class DigitalCommonsDataUIConnectionConfig implements RSpaceRepoConnectionConfig {

private User subject;
private UserConnectionManager userConnectionManager;
private DigitalCommonsDataController digitalCommonsDataController;
private IPropertyHolder propertyHolder;
private static final String FAKE_ID = "FAKE_ID";

public DigitalCommonsDataUIConnectionConfig(
DigitalCommonsDataController digitalCommonsDataController,
UserConnectionManager source,
User subject,
IPropertyHolder propertyHolder) {
this.subject = subject;
this.userConnectionManager = source;
this.propertyHolder = propertyHolder;
this.digitalCommonsDataController = digitalCommonsDataController;
}

@Override
public Optional<URL> getRepositoryURL() {
try {
return Optional.of(new URL(this.propertyHolder.getDigitalCommonsDataBaseUrl()));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(
"Couldn't create Digital Commons Data repositoryURL: " + e.getMessage());
}
}

@Override
public String getApiKey() {
Optional<UserConnection> optUserConnection =
userConnectionManager.findByUserNameProviderName(
subject.getUsername(), DIGITAL_COMMONS_DATA_APP_NAME);
Principal principal = () -> subject.getUsername();
if (optUserConnection.isEmpty()) {
throw new IllegalArgumentException(
"No UserConnection exists for: " + DIGITAL_COMMONS_DATA_APP_NAME);
}
String accessToken = optUserConnection.get().getAccessToken();

if (!digitalCommonsDataController.isConnectionAlive(principal)) {
digitalCommonsDataController.refreshToken(new BindingAwareModelMap(), principal);
accessToken =
userConnectionManager
.findByUserNameProviderName(subject.getUsername(), DIGITAL_COMMONS_DATA_APP_NAME)
.get()
.getAccessToken();
}
return accessToken;
}
}
Loading

0 comments on commit 4fddd9d

Please sign in to comment.