use of io.arlas.server.ogc.csw.CSWService in project ARLAS-server by gisaia.
the class ArlasServer method run.
@Override
public void run(ArlasServerConfiguration configuration, Environment environment) throws Exception {
configuration.check();
LOGGER.info("Checked configuration: " + (new ObjectMapper()).writer().writeValueAsString(configuration));
CacheFactory cacheFactory = (CacheFactory) Class.forName(configuration.arlasCacheFactoryClass).getConstructor(ArlasServerConfiguration.class).newInstance(configuration);
DatabaseToolsFactory dbToolFactory = (DatabaseToolsFactory) Class.forName(configuration.arlasDatabaseFactoryClass).getConstructor(Environment.class, ArlasServerConfiguration.class, CacheManager.class).newInstance(environment, configuration, cacheFactory.getCacheManager());
CollectionReferenceManager.getInstance().init(dbToolFactory.getCollectionReferenceService(), cacheFactory.getCacheManager());
if (configuration.zipkinConfiguration != null) {
Optional<HttpTracing> tracing = configuration.zipkinConfiguration.build(environment);
}
ExploreService exploration = dbToolFactory.getExploreService();
environment.getObjectMapper().setSerializationInclusion(Include.NON_NULL);
environment.jersey().register(MultiPartFeature.class);
environment.jersey().register(new ArlasExceptionMapper());
environment.jersey().register(new IllegalArgumentExceptionMapper());
environment.jersey().register(new JsonProcessingExceptionMapper());
environment.jersey().register(new ConstraintViolationExceptionMapper());
environment.jersey().register(new AtomHitsMessageBodyWriter(exploration));
environment.jersey().register(new AtomGetRecordsMessageBodyWriter(configuration));
environment.jersey().register(new XmlGetRecordsMessageBodyWriter());
environment.jersey().register(new XmlMDMetadataMessageBodyWriter());
environment.jersey().register(new XmlRecordMessageBodyBuilder());
environment.jersey().register(new AtomRecordMessageBodyWriter());
if (configuration.arlasServiceExploreEnabled) {
environment.jersey().register(new CountRESTService(exploration));
environment.jersey().register(new SearchRESTService(exploration));
environment.jersey().register(new AggregateRESTService(exploration));
environment.jersey().register(new GeoSearchRESTService(exploration));
environment.jersey().register(new GeoAggregateRESTService(exploration));
environment.jersey().register(new SuggestRESTService(exploration));
environment.jersey().register(new DescribeRESTService(exploration));
environment.jersey().register(new RawRESTService(exploration));
environment.jersey().register(new DescribeCollectionRESTService(exploration));
environment.jersey().register(new ComputeRESTService(exploration));
LOGGER.info("Explore API enabled");
} else {
LOGGER.info("Explore API disabled");
}
// Auth
if (configuration.arlasAuthConfiguration.enabled) {
environment.jersey().register(new AuthenticationFilter(configuration.arlasAuthConfiguration));
environment.jersey().register(new AuthorizationFilter(configuration.arlasAuthConfiguration));
}
if (configuration.arlasServiceCollectionsEnabled) {
LOGGER.info("Collection API enabled");
environment.jersey().register(new CollectionService(configuration, dbToolFactory.getCollectionReferenceService()));
} else {
LOGGER.info("Collection API disabled");
}
if (configuration.arlasServiceWFSEnabled) {
LOGGER.info("WFS Service enabled");
WFSHandler wfsHandler = new WFSHandler(configuration.wfsConfiguration, configuration.ogcConfiguration, configuration.inspireConfiguration, configuration.arlasBaseUri);
environment.jersey().register(new WFSService(dbToolFactory.getCollectionReferenceService(), dbToolFactory.getWFSToolService(), wfsHandler));
} else {
LOGGER.info("WFS Service disabled");
}
if (configuration.arlasServiceOPENSEARCHEnabled) {
LOGGER.info("OPENSEARCH Service enabled");
environment.jersey().register(new OpenSearchDescriptorService(exploration));
} else {
LOGGER.info("OPENSEARCH Service disabled");
}
if (configuration.arlasServiceCSWEnabled) {
LOGGER.info("CSW Service enabled");
CSWHandler cswHandler = new CSWHandler(configuration.ogcConfiguration, configuration.cswConfiguration, configuration.inspireConfiguration, configuration.arlasBaseUri);
environment.jersey().register(new CSWService(dbToolFactory.getCollectionReferenceService(), dbToolFactory.getOGCCollectionReferenceDao(), cswHandler, configuration));
} else {
LOGGER.info("CSW Service disabled");
}
if (configuration.arlasServiceRasterTileEnabled) {
LOGGER.info("Raster Tile Service enabled");
environment.jersey().register(new TileRESTService(exploration));
} else {
LOGGER.info("Raster Tile Service disabled");
}
if (configuration.arlasServiceSTACEnabled) {
LOGGER.info("STAC Service enabled");
// Add OpenAPI v3 endpoint
String baseUri = configuration.arlasBaseUri;
if (baseUri.endsWith("/")) {
baseUri = baseUri.substring(0, baseUri.length() - 1);
}
Info info = new Info().title("ARLAS STAC API").version("1.0.0");
SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(new OpenAPI().info(info).servers(Collections.singletonList(new Server().url(baseUri)))).prettyPrint(true).resourceClasses(Stream.of("io.arlas.server.stac.api.StacCoreRESTService", "io.arlas.server.stac.api.StacCollectionsRESTService", "io.arlas.server.stac.api.StacConformanceRESTService", "io.arlas.server.stac.api.StacSearchRESTService").collect(Collectors.toSet()));
environment.jersey().register(new OpenApiResource().openApiConfiguration(oasConfig));
//
environment.jersey().register(new StacCoreRESTService(configuration.stacConfiguration, configuration.arlasRestCacheTimeout, dbToolFactory.getCollectionReferenceService(), dbToolFactory.getExploreService()));
environment.jersey().register(new StacCollectionsRESTService(configuration.stacConfiguration, configuration.arlasRestCacheTimeout, dbToolFactory.getCollectionReferenceService(), dbToolFactory.getExploreService()));
environment.jersey().register(new StacConformanceRESTService(configuration.stacConfiguration, configuration.arlasRestCacheTimeout, dbToolFactory.getCollectionReferenceService(), dbToolFactory.getExploreService()));
environment.jersey().register(new StacSearchRESTService(configuration.stacConfiguration, configuration.arlasRestCacheTimeout, dbToolFactory.getCollectionReferenceService(), dbToolFactory.getExploreService()));
} else {
LOGGER.info("STAC Service disabled");
}
// filters
environment.jersey().register(PrettyPrintFilter.class);
environment.jersey().register(InsensitiveCaseFilter.class);
// tasks
environment.admin().addTask(new CollectionAutoDiscover(dbToolFactory.getCollectionReferenceService(), configuration));
int scheduleAutoDiscover = configuration.collectionAutoDiscoverConfiguration.schedule;
if (scheduleAutoDiscover > 0) {
String nameFormat = "collection-auto-discover-%d";
ScheduledExecutorServiceBuilder sesBuilder = environment.lifecycle().scheduledExecutorService(nameFormat);
ScheduledExecutorService ses = sesBuilder.build();
Runnable autoDiscoverTask = new CollectionAutoDiscover(dbToolFactory.getCollectionReferenceService(), configuration);
ses.scheduleWithFixedDelay(autoDiscoverTask, 10, scheduleAutoDiscover, TimeUnit.SECONDS);
}
// healthchecks
dbToolFactory.getHealthChecks().forEach((name, check) -> environment.healthChecks().register(name, check));
// cors
if (configuration.arlarsCorsConfiguration.enabled) {
configureCors(environment, configuration.arlarsCorsConfiguration);
} else {
CrossOriginFilter filter = new CrossOriginFilter();
final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CrossOriginFilter", filter);
// Expose always HttpHeaders.WWW_AUTHENTICATE to authentify on client side a non public uri call
cors.setInitParameter(CrossOriginFilter.EXPOSED_HEADERS_PARAM, HttpHeaders.WWW_AUTHENTICATE);
}
}
Aggregations