Commit 4be39791 authored by Matija Obreza's avatar Matija Obreza

Register Genesys as target for passport data for accessions with DOI

- when upserted through the API
parent 4b78d12d
......@@ -532,6 +532,11 @@
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-resttemplate</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
......@@ -33,6 +33,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils;
import org.genesys.glis.v1.TermConstants;
import org.genesys.glis.v1.api.GenesysApi;
import org.genesys.glis.v1.model.UpdateTargets;
import org.genesys.glis.v1.model.UpdatedTarget;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
......@@ -99,6 +103,9 @@ public class BatchRESTServiceImpl implements BatchRESTService {
@Autowired
private TaxonomyManager taxonomyManager;
@Autowired
private GenesysApi glisGenesysApi;
@Override
// Read-only, everything happens in manager
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
......@@ -264,7 +271,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
updateDoi(accession, accnJson.get(Api1Constants.Accession.DOI));
if (accession.getDoi()!=null) {
if (accession.getDoi() != null) {
// Update ACCENUMB if DOI is provided
accession.setAccessionName(dataJson.acceNumb);
}
......@@ -586,6 +593,26 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// Update PDCI
genesysService.updatePDCI(savedData.stream().map(a -> a.getId()).collect(Collectors.toSet()));
// Update GLIS
UpdateTargets targets = new UpdateTargets();
targets.addKwsItem(TermConstants.PASSPORT_DATA);
savedData.stream().map(a -> a.getDoi()).filter(doi -> doi != null).forEach(doi -> targets.addDoisItem(doi));
if (targets.getDois().size() > 0) {
try {
LOG.debug("Updating GLIS for {} accessions with DOIs", targets.getDois().size());
List<UpdatedTarget> glisResponse = glisGenesysApi.registerGenesysAsTarget(targets);
glisResponse.forEach(updatedTarget -> {
if (StringUtils.equals("OK", updatedTarget.getResult())) {
LOG.trace("GLIS for {} result={}", updatedTarget.getDoi(), updatedTarget.getResult());
} else if (StringUtils.equals("KO", updatedTarget.getResult())) {
LOG.info("GLIS for {} result={} msg={}", updatedTarget.getDoi(), updatedTarget.getResult());
}
});
} catch (Throwable e) {
LOG.error("Error updating GLIS targets: {}", e.getMessage(), e);
}
}
return upsertResponses;
}
......
......@@ -40,10 +40,10 @@ import org.springframework.core.io.Resource;
@Configuration
@Import({ CommonConfig.class, SchedulerConfig.class, DatabaseConfig.class, MailConfig.class, OAuth2ServerConfig.class, SecurityConfig.class, CacheConfig.class,
ElasticsearchConfig.class, FileRepositoryConfig.class, WebConfiguration.class, AuditConfig.class })
ElasticsearchConfig.class, FileRepositoryConfig.class, WebConfiguration.class, AuditConfig.class, GLISConfig.class })
public class ApplicationConfig {
public static final Logger LOG = LoggerFactory.getLogger(ApplicationConfig.class);
@Bean
public TransifexService transifexService() {
return new TransifexServiceImpl();
......
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.spring.config;
import org.genesys.glis.v1.GlisRateLimiter;
import org.genesys.glis.v1.invoker.ApiClient;
import org.genesys.glis.v1.invoker.auth.HttpBasicAuth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
// Get the beans!
@ComponentScan(basePackages = { "org.genesys.glis.v1.api" })
public class GLISConfig {
@Value("${itpgrfa.glis.basepath}")
private String basePath;
@Value("${itpgrfa.glis.username}")
private String username;
@Value("${itpgrfa.glis.password}")
private String password;
@Value("${itpgrfa.glis.ratelimit}")
private double glisRateLimit;
@Bean
public GlisRateLimiter glisRateLimiter() {
return new GlisRateLimiter(glisRateLimit);
}
@Bean
public ApiClient glisClient() {
ApiClient client = new ApiClient();
client.setDebugging("true".equals(System.getenv("GLIS_DEBUG")));
client.setBasePath(basePath);
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) client.getAuthentication("easySmta");
easySmtaAuth.setUsername(username);
easySmtaAuth.setPassword(password);
System.err.println("GLIS at " + client.getBasePath() + " with username=" + username);
return client;
}
}
......@@ -191,3 +191,9 @@ repository.ftp.keystore.password=changeit!
repository.ftp.port=8021
repository.ftp.passivePorts=2300-2350
repository.ftp.externalAddress=
# GLIS
itpgrfa.glis.basepath=https://glistest.planttreaty.org
itpgrfa.glis.username=
itpgrfa.glis.password=
itpgrfa.glis.ratelimit=20
......@@ -50,6 +50,7 @@ import org.genesys.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys.filerepository.service.impl.ImageGalleryServiceImpl;
import org.genesys.filerepository.service.impl.RepositoryServiceImpl;
import org.genesys.filerepository.service.impl.ThumbnailGenerator1;
import org.genesys.glis.v1.api.GenesysApi;
import org.genesys2.brapi.service.impl.BrAPIServiceImpl;
import org.genesys2.server.aspect.AsAdminAspect;
import org.genesys2.server.aspect.GenesysImageGalleryAspects;
......@@ -396,6 +397,11 @@ public abstract class AbstractRestTest extends BaseSpringTest {
public BatchRESTService batchRESTService() {
return new BatchRESTServiceImpl();
}
@Bean
public GenesysApi glisGenesysApi() {
return new GenesysApi();
}
@Bean
public TaxonomyManager taxonomyManager() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment