Commit 05a8b45a authored by LAVENIER's avatar LAVENIER
Browse files

[enh] Batch denormalization: use program properties, to detect if using...

[enh] Batch denormalization: use program properties, to detect if using TaxonGroup and/or ReferenceTaxon
[enh] CLI: add option --year, to filter data (e.g in Batch denormalization)
[enh] CLI: move CLI actions in a specific package (not load by server configuration)
[fix] Fix JMS / ActiveMQ in unit test
parent 9ad57666
......@@ -136,7 +136,6 @@
<jnr-ffi.version>2.2.2</jnr-ffi.version>
<kalium.version>0.8.1-SNAPSHOT</kalium.version>
<!--<kalium.version>0.8.1-SNAPSHOT</kalium.version>-->
<scrypt.version>1.4.0</scrypt.version>
<geojson-jackson.version>1.14</geojson-jackson.version>
<graphql-java.version>16.2</graphql-java.version>
......
......@@ -25,7 +25,6 @@ package net.sumaris.core.extraction.action;
*/
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.action.ActionUtils;
import net.sumaris.core.extraction.config.ExtractionConfiguration;
import net.sumaris.core.extraction.exception.UnknownFormatException;
import net.sumaris.core.extraction.format.ProductFormatEnum;
......
......@@ -25,7 +25,7 @@ package net.sumaris.core.extraction.action;
*/
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.action.ActionUtils;
import net.sumaris.cli.action.ActionUtils;
import net.sumaris.core.extraction.config.ExtractionConfiguration;
import net.sumaris.core.extraction.exception.UnknownFormatException;
import net.sumaris.core.extraction.service.ExtractionService;
......
......@@ -25,7 +25,6 @@ package net.sumaris.core.extraction.action;
*/
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.action.ActionUtils;
import net.sumaris.core.extraction.config.ExtractionConfiguration;
import net.sumaris.core.extraction.service.AggregationService;
import net.sumaris.core.extraction.service.ExtractionProductService;
......
......@@ -27,6 +27,7 @@ import net.sumaris.core.extraction.TestConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
......@@ -38,8 +39,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
*/
@SpringBootApplication(
exclude = {
LiquibaseAutoConfiguration.class,
FreeMarkerAutoConfiguration.class
LiquibaseAutoConfiguration.class,
FreeMarkerAutoConfiguration.class,
JmsAutoConfiguration.class
},
scanBasePackages = {
"net.sumaris.core"
......
......@@ -33,7 +33,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(
exclude = {
LiquibaseAutoConfiguration.class,
FreeMarkerAutoConfiguration.class
FreeMarkerAutoConfiguration.class,
LiquibaseAutoConfiguration.class,
},
scanBasePackages = {
"net.sumaris.core",
......
......@@ -29,8 +29,6 @@ import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
......@@ -56,10 +54,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
})
@EnableAsync
@Component("rdf-application")
public class Application extends net.sumaris.core.Application {
public class Application extends net.sumaris.cli.Application {
public static void run(String[] args, String configFile) {
net.sumaris.core.Application.run(Application.class, args, configFile);
net.sumaris.cli.Application.run(Application.class, args, configFile);
}
public static void main(String[] args) {
......
......@@ -26,7 +26,7 @@ package net.sumaris.rdf.action;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.action.ActionUtils;
import net.sumaris.cli.action.ActionUtils;
import net.sumaris.core.service.ServiceLocator;
import net.sumaris.rdf.config.RdfConfiguration;
import net.sumaris.rdf.service.store.RdfDatasetService;
......
......@@ -24,10 +24,6 @@ package net.sumaris.rdf.config;
* #L%
*/
import net.sumaris.core.action.DatabaseCreateSchemaAction;
import net.sumaris.core.action.DatabaseGenerateChangeLogAction;
import net.sumaris.core.action.DatabaseUpdateSchemaAction;
import net.sumaris.core.action.HelpAction;
import net.sumaris.rdf.action.RdfDatasetAction;
import org.nuiton.config.ConfigActionDef;
......
......@@ -208,8 +208,10 @@ public class SumarisConfiguration extends PropertyPlaceholderConfigurer {
applicationConfig.addAlias("-db", "--option", SumarisConfigurationOption.JDBC_URL.getKey());
applicationConfig.addAlias("--database", "--option", SumarisConfigurationOption.JDBC_URL.getKey());
// CLI options
applicationConfig.addAlias("--output", "--option", SumarisConfigurationOption.CLI_OUTPUT_FILE.getKey());
applicationConfig.addAlias("-f", "--option", SumarisConfigurationOption.CLI_FORCE_OUTPUT.getKey(), "true");
applicationConfig.addAlias("--year", "--option", SumarisConfigurationOption.CLI_FILTER_YEAR.getKey());
}
......@@ -769,6 +771,21 @@ public class SumarisConfiguration extends PropertyPlaceholderConfigurer {
return applicationConfig.getOptionAsBoolean(SumarisConfigurationOption.CLI_FORCE_OUTPUT.getKey());
}
/**
* <p>Get year, to filter data.</p>
* <p>Used by CLI (Command Line Interface) actions</p>
*
* @return a boolean.
*/
public Integer getCliFilterYear() {
int year = applicationConfig.getOptionAsInt(SumarisConfigurationOption.CLI_FILTER_YEAR.getKey());
return year == -1 ? null : year;
}
public Integer getCliFilterTripId() {
int tripId = applicationConfig.getOptionAsInt(SumarisConfigurationOption.CLI_FILTER_TRIP_ID.getKey());
return tripId == -1 ? null : tripId;
}
/**
* <p>getLaunchMode.</p>
......@@ -866,8 +883,8 @@ public class SumarisConfiguration extends PropertyPlaceholderConfigurer {
*
* @return a {@link Boolean}
*/
public boolean enableActiveMQ() {
return applicationConfig.getOptionAsBoolean(SumarisConfigurationOption.ACTIVEMQ_ENABLED.getKey());
public boolean enableActiveMQPool() {
return applicationConfig.getOptionAsBoolean(SumarisConfigurationOption.ACTIVEMQ_POOL_ENABLED.getKey());
}
/* -- protected methods -- */
......
......@@ -398,7 +398,7 @@ public enum SumarisConfigurationOption implements ConfigOptionDef {
/* -- Active MQ options-- */
ACTIVEMQ_ENABLED(
ACTIVEMQ_POOL_ENABLED(
"spring.activemq.pool.enabled",
n("sumaris.config.option.spring.activemq.pool.enabled.description"),
"false",
......@@ -458,6 +458,10 @@ public enum SumarisConfigurationOption implements ConfigOptionDef {
Integer.class,
false),
/*
* CLI options
*/
CLI_OUTPUT_FILE(
"sumaris.cli.output.file",
n("sumaris.config.option.cli.output.file.description"),
......@@ -472,6 +476,20 @@ public enum SumarisConfigurationOption implements ConfigOptionDef {
Boolean.class,
false),
CLI_FILTER_YEAR(
"sumaris.cli.filter.year",
n("sumaris.config.option.cli.filter.year.description"),
"-1",
Integer.class,
false),
CLI_FILTER_TRIP_ID(
"sumaris.cli.filter.tripId",
n("sumaris.config.option.cli.filter.tripId.description"),
"-1",
Integer.class,
false),
CSV_SEPARATOR(
"sumaris.csv.separator",
n("sumaris.config.option.csv.separator.description"),
......@@ -558,7 +576,29 @@ public enum SumarisConfigurationOption implements ConfigOptionDef {
n("sumaris.config.option.persistence.vessel.defaultProgram.label.description"),
"SIH",
Boolean.class,
false);
false),
ENABLE_BATCH_TAXON_NAME(
"sumaris.trip.operation.batch.taxonName.enable",
n("sumaris.config.option.trip.operation.batch.taxonName.enable.description"),
Boolean.TRUE.toString(),
Boolean.class,
false),
ENABLE_BATCH_TAXON_GROUP(
"sumaris.trip.operation.batch.taxonGroup.enable",
n("sumaris.config.option.trip.operation.batch.taxonGroup.enable.description"),
Boolean.TRUE.toString(),
Boolean.class,
false),
BATCH_TAXON_GROUP_LABELS_NO_WEIGHT(
"sumaris.trip.operation.batch.taxonGroups.noWeight",
n("sumaris.config.option.trip.operation.batch.taxonGroups.noWeight.description"),
"",
String.class,
false),
;
/**
* Configuration key.
......
......@@ -48,7 +48,6 @@ spring.jpa.hibernate.ddl-auto=none
spring.liquibase.enabled=false
spring.liquibase.compact.enabled=false
spring.jms.enabled=false
#spring.activemq.pool.enabled=false
#spring.activemq.broker-url=tcp://localhost:61616
......@@ -56,7 +55,7 @@ spring.jms.enabled=false
# Logging Levels
logging.level.ROOT=info
logging.level.net.sumaris=info
logging.level.net.sumaris.core.action.data=debug
logging.level.net.sumaris.cli.action.data=debug
#logging.level.net.sumaris.core.dao.technical.liquibase=debug
logging.level.org.springframework=warn
logging.level.org.nuiton=warn
......
package net.sumaris.core;
/*-
/*
* #%L
* Sumaris3 Batch :: Shape import/export
* SUMARiS
* %%
* Copyright (C) 2017 - 2018 Ifremer
* Copyright (C) 2019 SUMARiS Consortium
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package net.sumaris.cli;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.action.ActionUtils;
import net.sumaris.cli.action.ActionUtils;
import net.sumaris.core.config.SumarisConfiguration;
import net.sumaris.core.service.ServiceLocator;
import net.sumaris.core.service.technical.ConfigurationService;
import net.sumaris.core.util.ApplicationUtils;
import net.sumaris.core.util.I18nUtil;
import net.sumaris.core.util.StringUtils;
import org.hibernate.cache.jcache.ConfigSettings;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.core.annotation.Order;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManager;
/**
......@@ -218,8 +209,9 @@ public class Application {
}
@Bean
@ConditionalOnMissingBean({ObjectMapper.class})
public ObjectMapper objectMapper() {
@Primary
@ConditionalOnMissingBean
ObjectMapper jacksonObjectMapper() {
return new ObjectMapper();
}
}
......@@ -20,15 +20,15 @@
* #L%
*/
package net.sumaris.core.action.data;
package net.sumaris.cli.action.data;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.action.ActionUtils;
import net.sumaris.core.config.SumarisConfiguration;
import net.sumaris.core.model.IProgressionModel;
import net.sumaris.core.model.ProgressionModel;
import net.sumaris.core.service.ServiceLocator;
import net.sumaris.core.service.data.denormalize.DenormalizeTripService;
import net.sumaris.core.util.Dates;
import net.sumaris.core.vo.filter.TripFilterVO;
@Slf4j
......@@ -41,16 +41,19 @@ public class DenormalizeTripsAction {
SumarisConfiguration config = SumarisConfiguration.getInstance();
DenormalizeTripService tripService = ServiceLocator.instance().getService("denormalizeTripService", DenormalizeTripService.class);
// Create trip filter
TripFilterVO filter = TripFilterVO.builder()
//.startDate() // TODO build from cli option ?
.tripId(1340)
.build();
// Create filter
TripFilterVO.TripFilterVOBuilder filterBuilder = TripFilterVO.builder()
.tripId(config.getCliFilterTripId());
Integer year = config.getCliFilterYear();
if (year != null && year > 1970) {
filterBuilder.startDate(Dates.getFirstDayOfYear(year))
.endDate(Dates.getLastSecondOfYear(year));
}
// Execute job
ProgressionModel progression = new ProgressionModel();
progression.addPropertyChangeListener(IProgressionModel.Fields.MESSAGE, (event) -> log.info(progression.getMessage()));
tripService.denormalizeByFilter(filter, progression);
tripService.denormalizeByFilter(filterBuilder.build(), progression);
}
}
package net.sumaris.core.config;
/*-
/*
* #%L
* Quadrige3 Core :: Quadrige3 Server Core
* $Id:$
* $HeadURL:$
* SUMARiS
* %%
* Copyright (C) 2017 Ifremer
* Copyright (C) 2019 SUMARiS Consortium
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import net.sumaris.core.action.DatabaseCreateSchemaAction;
import net.sumaris.core.action.DatabaseGenerateChangeLogAction;
import net.sumaris.core.action.DatabaseUpdateSchemaAction;
import net.sumaris.core.action.HelpAction;
import net.sumaris.core.action.data.DenormalizeTripsAction;
package net.sumaris.cli.config;
import net.sumaris.cli.action.DatabaseCreateSchemaAction;
import net.sumaris.cli.action.DatabaseGenerateChangeLogAction;
import net.sumaris.cli.action.DatabaseUpdateSchemaAction;
import net.sumaris.cli.action.HelpAction;
import net.sumaris.cli.action.data.DenormalizeTripsAction;
import org.nuiton.config.ConfigActionDef;
/**
......@@ -36,7 +34,7 @@ import org.nuiton.config.ConfigActionDef;
* BatchesServerConfigurationAction class.
* </p>
*/
public enum SumarisCoreConfigurationAction implements ConfigActionDef {
public enum SumarisCliConfigurationAction implements ConfigActionDef {
HELP(HelpAction.class.getName() + "#show", "Shows help", "-h", "--help"),
......@@ -57,7 +55,7 @@ public enum SumarisCoreConfigurationAction implements ConfigActionDef {
public final String description;
public final String[] aliases;
SumarisCoreConfigurationAction(String action, String description, String... aliases) {
SumarisCliConfigurationAction(String action, String description, String... aliases) {
this.action = action;
this.description = description;
this.aliases = aliases;
......
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