This commit is contained in:
Michele Artini 2023-09-27 11:12:54 +02:00
parent ead98110b7
commit d2998b4a8a
12 changed files with 178 additions and 45 deletions

View File

@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.clients.CollectorClient;
import eu.dnetlib.common.clients.DnetServiceClientFactory;
import eu.dnetlib.common.clients.VocabularyClient;
import eu.dnetlib.common.controller.DnetRestController;
@ -26,6 +25,7 @@ import eu.dnetlib.domain.dsm.BrowseTerm;
import eu.dnetlib.domain.dsm.readonly.SimpleDsWithApis;
import eu.dnetlib.errors.DsmException;
import eu.dnetlib.services.dsm.service.DsmService;
import eu.dnetlib.services.dsm.service.ProtocolService;
import eu.dnetlib.services.dsm.utils.DsmBrowsableFields;
@RestController
@ -35,6 +35,9 @@ public class DsmAjaxController extends DnetRestController {
@Autowired
private DsmService dsmService;
@Autowired
private ProtocolService protocolService;
@Autowired
private DnetServiceClientFactory clientFactory;
@ -49,10 +52,9 @@ public class DsmAjaxController extends DnetRestController {
public Map<String, Iterable<?>> configuration() {
final Map<String, Iterable<?>> map = new LinkedHashMap<>();
final CollectorClient collectorClient = clientFactory.getClient(CollectorClient.class);
final VocabularyClient vocabularyClient = clientFactory.getClient(VocabularyClient.class);
map.put("protocols", collectorClient.listProtocols());
map.put("protocols", protocolService.listProtocols());
map.put("compatibilityLevels", vocabularyClient.findTermsByVocabulary("dnet:compatibilityLevel"));
map.put("contentDescTypes", vocabularyClient.findTermsByVocabulary("dnet:content_description_typologies"));
return map;

View File

@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.clients.DnetServiceClientFactory;
import eu.dnetlib.common.clients.WfLoggerClient;
import eu.dnetlib.common.clients.WfManagerClient;
import eu.dnetlib.domain.dsm.Api;
import eu.dnetlib.domain.dsm.Datasource;
import eu.dnetlib.domain.dsm.Identity;
@ -88,7 +88,7 @@ public class DsmApiControllerV1 extends AbstractDsmController {
@GetMapping("/ds/aggregationhistory/{dsId}")
public AggregationHistoryResponse aggregationHistory(@PathVariable final String dsId) throws DsmException {
final StopWatch stop = StopWatch.createStarted();
final List<AggregationInfo> history = clientFactory.getClient(WfLoggerClient.class).getAggregationHistory(dsId);
final List<AggregationInfo> history = clientFactory.getClient(WfManagerClient.class).getAggregationHistory(dsId);
final AggregationHistoryResponse rsp = new AggregationHistoryResponse(history);
rsp.setHeader(ResponseUtils.header(history.size()));

View File

@ -33,20 +33,20 @@ public class WfExecutorApplication extends AbstractDnetApp {
@Autowired(required = false)
private List<DnetXsltFunction> xsltFunctions;
@Autowired
private DnetServiceClientFactory clientFactory;
public static void main(final String[] args) {
SpringApplication.run(WfExecutorApplication.class, args);
}
@Bean
public XsltTransformFactory xsltTransformFactory() {
return new XsltTransformFactory(clientFactory.getClient(SimpleResourceClient.class), xsltFunctions != null ? xsltFunctions : new ArrayList<>());
return new XsltTransformFactory(dnetServiceClientFactory().getClient(SimpleResourceClient.class),
xsltFunctions != null ? xsltFunctions : new ArrayList<>());
}
@Bean
public CleanerFactory cleanerFactory() {
final DnetServiceClientFactory clientFactory = dnetServiceClientFactory();
return new CleanerFactory(clientFactory.getClient(SimpleResourceClient.class), clientFactory.getClient(VocabularyClient.class));
}

View File

@ -1,10 +1,21 @@
package eu.dnetlib.wfs;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import eu.dnetlib.common.app.AbstractDnetApp;
import eu.dnetlib.common.clients.DnetServiceClientFactory;
import eu.dnetlib.common.clients.SimpleResourceClient;
import eu.dnetlib.common.clients.VocabularyClient;
import eu.dnetlib.common.mapping.cleaner.CleanerFactory;
import eu.dnetlib.common.mapping.xslt.DnetXsltFunction;
import eu.dnetlib.common.mapping.xslt.XsltTransformFactory;
import eu.dnetlib.domain.wfs.WfHistoryEntry;
import eu.dnetlib.domain.wfs.WorkflowConfiguration;
import eu.dnetlib.domain.wfs.WorkflowSection;
@ -19,8 +30,22 @@ import eu.dnetlib.domain.wfs.WorkflowSubscription;
})
public class WfManagerApplication extends AbstractDnetApp {
@Autowired(required = false)
private List<DnetXsltFunction> xsltFunctions;
public static void main(final String[] args) {
SpringApplication.run(WfManagerApplication.class, args);
}
@Bean
public XsltTransformFactory xsltTransformFactory() {
return new XsltTransformFactory(dnetServiceClientFactory().getClient(SimpleResourceClient.class),
xsltFunctions != null ? xsltFunctions : new ArrayList<>());
}
@Bean
public CleanerFactory cleanerFactory() {
final DnetServiceClientFactory clientFactory = dnetServiceClientFactory();
return new CleanerFactory(clientFactory.getClient(SimpleResourceClient.class), clientFactory.getClient(VocabularyClient.class));
}
}

View File

@ -1,10 +1,12 @@
package eu.dnetlib.common.app;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import javax.annotation.PostConstruct;
@ -19,6 +21,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import eu.dnetlib.common.clients.DnetServiceClientFactory;
import eu.dnetlib.errors.DnetRuntimeException;
import io.micrometer.core.instrument.ImmutableTag;
import io.micrometer.core.instrument.Metrics;
import io.swagger.v3.oas.models.OpenAPI;
@ -34,7 +38,7 @@ public abstract class AbstractDnetApp {
protected static final License APACHE_2_LICENSE = new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0");
protected static final License AGPL_3_LICENSE =
new License().name("GNU Affero General Public License v3.0 or later").url("https://www.gnu.org/licenses/agpl-3.0.txt");
new License().name("GNU Affero General Public License v3.0 or later").url("https://www.gnu.org/licenses/agpl-3.0.txt");
@Value("${maven.pom.path}")
private ClassPathResource pom;
@ -79,25 +83,36 @@ public abstract class AbstractDnetApp {
}
return new OpenAPI()
.servers(servers)
.info(getSwaggerInfo())
.tags(getSwaggerTags());
.servers(servers)
.info(getSwaggerInfo())
.tags(getSwaggerTags());
}
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("Broker Public APIs")
.pathsToMatch("/**")
.build();
.group("Broker Public APIs")
.pathsToMatch("/**")
.build();
}
@Bean
public DnetServiceClientFactory dnetServiceClientFactory() {
try (InputStream input = getClass().getResourceAsStream("/dnet-services.properties")) {
final Properties prop = new Properties();
prop.load(input);
return new DnetServiceClientFactory(prop);
} catch (final IOException e) {
throw new DnetRuntimeException("Error configuring the client factory", e);
}
}
protected Info getSwaggerInfo() {
return new Info()
.title(serverTitle)
.description(serverDesc)
.version(swaggerVersion())
.license(swaggerLicense());
.title(serverTitle)
.description(serverDesc)
.version(swaggerVersion())
.license(swaggerLicense());
}
protected List<Tag> getSwaggerTags() {

View File

@ -1,16 +0,0 @@
package eu.dnetlib.common.clients;
public class CollectorClient extends DnetServiceClient {
// TODO
// Forse inutile, se serve solo per la UI conviene fare una diversa chiamata
public CollectorClient(final String baseUrl) {
super(baseUrl);
}
public Iterable<?> listProtocols() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,20 +1,42 @@
package eu.dnetlib.common.clients;
import org.springframework.stereotype.Component;
import java.util.Properties;
import eu.dnetlib.errors.DnetRuntimeException;
@Component
public class DnetServiceClientFactory {
public <T extends DnetServiceClient> T getClient(final String baseUrl, final Class<T> clazz) {
private final String defaultDsmBaseUrl;
private final String defaultMdstoreManagerBaseUrl;
private final String defaultContextManagerBaseUrl;
private final String defaultMailSenderBaseUrl;
private final String defaultResourceManagerBaseUrl;
private final String defaultVocabularyManagerBaseUrl;
private final String defaultWfExecutorBaseUrl;
private final String defaultWfManagerBaseUrl;
private final String defaultIndexerBaseUrl;
private final String defaultOaiExporterBaseUrl;
public DnetServiceClientFactory(final Properties prop) {
defaultDsmBaseUrl = prop.getProperty("dnet.services.datasource-manager.baseUrl");
defaultMdstoreManagerBaseUrl = prop.getProperty("dnet.services.mdstore-manager.baseUrl");
defaultContextManagerBaseUrl = prop.getProperty("dnet.services.context-manager.baseUrl");
defaultMailSenderBaseUrl = prop.getProperty("dnet.services.mail-sender.baseUrl");
defaultResourceManagerBaseUrl = prop.getProperty("dnet.services.resource-manager.baseUrl");
defaultVocabularyManagerBaseUrl = prop.getProperty("dnet.services.vocabulary-manager.baseUrl");
defaultWfExecutorBaseUrl = prop.getProperty("dnet.services.wf-executor.baseUrl");
defaultWfManagerBaseUrl = prop.getProperty("dnet.services.wf-manager.baseUrl");
defaultIndexerBaseUrl = prop.getProperty("dnet.services.indexer.baseUrl");
defaultOaiExporterBaseUrl = prop.getProperty("dnet.services.oai-exporter.baseUrl");
}
public <T extends DnetServiceClient> T getClient(final String baseUrl, final Class<T> clazz) {
try {
return clazz.getConstructor(String.class).newInstance(baseUrl);
} catch (final Exception e) {
throw new DnetRuntimeException("Client not available: " + clazz, e);
}
}
public <T extends DnetServiceClient> T getClient(final Class<T> clazz) {
@ -22,7 +44,59 @@ public class DnetServiceClientFactory {
}
private <T extends DnetServiceClient> String defaultBaseUrl(final Class<T> clazz) {
// TODO Auto-generated method stub
return null;
if (clazz == BaseMDStoreClient.class) {
getDefaultMdstoreManagerBaseUrl();
}
if (clazz == DsmClient.class) { return getDefaultDsmBaseUrl(); }
if (clazz == EmailClient.class) { return getDefaultMailSenderBaseUrl(); }
if (clazz == SimpleResourceClient.class) { return getDefaultResourceManagerBaseUrl(); }
if (clazz == VocabularyClient.class) { return getDefaultVocabularyManagerBaseUrl(); }
if (clazz == WfExecutorClient.class) { return getDefaultWfExecutorBaseUrl(); }
if (clazz == WfManagerClient.class) { return getDefaultWfManagerBaseUrl(); }
if (clazz == OaiExporterClient.class) { return getDefaultOaiExporterBaseUrl(); }
if (clazz == IndexerClient.class) { return getDefaultIndexerBaseUrl(); }
throw new DnetRuntimeException("Missing baseUrl for " + clazz);
}
public String getDefaultDsmBaseUrl() {
return defaultDsmBaseUrl;
}
public String getDefaultMdstoreManagerBaseUrl() {
return defaultMdstoreManagerBaseUrl;
}
public String getDefaultContextManagerBaseUrl() {
return defaultContextManagerBaseUrl;
}
public String getDefaultMailSenderBaseUrl() {
return defaultMailSenderBaseUrl;
}
public String getDefaultResourceManagerBaseUrl() {
return defaultResourceManagerBaseUrl;
}
public String getDefaultVocabularyManagerBaseUrl() {
return defaultVocabularyManagerBaseUrl;
}
public String getDefaultWfExecutorBaseUrl() {
return defaultWfExecutorBaseUrl;
}
public String getDefaultWfManagerBaseUrl() {
return defaultWfManagerBaseUrl;
}
public String getDefaultIndexerBaseUrl() {
return defaultIndexerBaseUrl;
}
public String getDefaultOaiExporterBaseUrl() {
return defaultOaiExporterBaseUrl;
}
}

View File

@ -9,6 +9,11 @@ public class DsmClient extends DnetServiceClient {
super(baseUrl);
}
public Iterable<?> listProtocols() {
// TODO Auto-generated method stub
return null;
}
public Api updateUpdateApiCollectionInfo(final String apiId, final String mdId, final long size) {
// TODO Auto-generated method stub
return null;

View File

@ -0,0 +1,9 @@
package eu.dnetlib.common.clients;
public class IndexerClient extends DnetServiceClient {
public IndexerClient(final String baseUrl) {
super(baseUrl);
}
}

View File

@ -0,0 +1,9 @@
package eu.dnetlib.common.clients;
public class OaiExporterClient extends DnetServiceClient {
public OaiExporterClient(final String baseUrl) {
super(baseUrl);
}
}

View File

@ -8,13 +8,13 @@ import org.apache.commons.logging.LogFactory;
import eu.dnetlib.domain.dsm.info.AggregationInfo;
import eu.dnetlib.errors.DsmException;
public class WfLoggerClient extends DnetServiceClient {
public class WfManagerClient extends DnetServiceClient {
public WfLoggerClient(final String baseUrl) {
public WfManagerClient(final String baseUrl) {
super(baseUrl);
}
private static final Log log = LogFactory.getLog(WfLoggerClient.class);
private static final Log log = LogFactory.getLog(WfManagerClient.class);
private final static String LOADTIME = "loadtime";

View File

@ -0,0 +1,10 @@
dnet.services.context-manager.baseUrl = http://context-manager:8080/context-manager
dnet.services.datasource-manager.baseUrl = http://dsm:8080/dsm
dnet.services.mail-sender.baseUrl = http://mail-sender:8080/mail-sender
dnet.services.indexer.baseUrl = http://indexer:8080/indexer
dnet.services.mdstore-manager.baseUrl = http://mdsm:8080/mdsm
dnet.services.oai-exporter.baseUrl = http://oai-exporter:8080/oai-exporter
dnet.services.resource-manager.baseUrl = http://resource-manager:8080/resource-manager
dnet.services.vocabulary-manager.baseUrl = http://vocabulary-manager:8080/vocabulary-manager
dnet.services.wf-executor.baseUrl = http://wf-exec-postgres:8080/wf-exec
dnet.services.wf-manager.baseUrl = http://wf-manager:8080/wf-manager