
fr.ird.observe.services.configuration.DataSourceCreateConfigurationDto Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-service Show documentation
Show all versions of common-service Show documentation
ObServe Toolkit Common Service module
The newest version!
package fr.ird.observe.services.configuration;
/*
* #%L
* ObServe Toolkit :: Common Service
* %%
* Copyright (C) 2017 - 2020 IRD, Ultreia.io
* %%
* 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
* .
* #L%
*/
import com.google.common.collect.ImmutableSet;
import fr.ird.observe.dto.AbstractObserveDto;
import org.nuiton.topia.persistence.script.TopiaSqlScript;
import java.util.Objects;
/**
* Created on 22/08/15.
*
* @author Tony Chemit - [email protected]
*/
public class DataSourceCreateConfigurationDto extends AbstractObserveDto {
private static final long serialVersionUID = 1L;
/**
* Le contenu de la base à importer (Optionel).
*/
private TopiaSqlScript optionalImportDatabase;
/**
* Une configuration de la dataSource à utiliser pour importer le référentiel (Optionel).
*/
private ObserveDataSourceConfiguration optionalImportReferentialDataSourceConfiguration;
/**
* Une configuration de la dataSource à utiliser pour importer des données (Optionel).
*/
private ObserveDataSourceConfiguration optionalImportDataDataSourceConfiguration;
/**
* Les données à importer (ids des marées) (Optionel).
*/
private ImmutableSet optionalImportDataIds;
/**
* Pour autoriser la création d'une base vide (utilisé pour les bases temporaires)
*/
private boolean canCreateEmptyDatabase;
private boolean leaveOpenSource;
private boolean isCanCreateEmptyDatabase() {
return canCreateEmptyDatabase;
}
public void setCanCreateEmptyDatabase(boolean canCreateEmptyDatabase) {
this.canCreateEmptyDatabase = canCreateEmptyDatabase;
}
public boolean isImportDatabase() {
return optionalImportDatabase != null;
}
public boolean isImportReferential() {
return optionalImportReferentialDataSourceConfiguration != null;
}
public boolean isImportData() {
return optionalImportDataDataSourceConfiguration != null;
}
public boolean isLeaveOpenSource() {
return leaveOpenSource;
}
public void setLeaveOpenSource(boolean leaveOpenSource) {
this.leaveOpenSource = leaveOpenSource;
}
public TopiaSqlScript getImportDatabase() {
return optionalImportDatabase;
}
public ObserveDataSourceConfiguration getImportReferentialDataSourceConfiguration() {
return optionalImportReferentialDataSourceConfiguration;
}
public ObserveDataSourceConfiguration getImportDataDataSourceConfiguration() {
return optionalImportDataDataSourceConfiguration;
}
public ImmutableSet getImportDataIds() {
return optionalImportDataIds;
}
public void setImportDatabase(TopiaSqlScript importDatabase) {
Objects.requireNonNull(importDatabase, "'importDatabase' can't be null.");
this.optionalImportDatabase = importDatabase;
}
public void setImportReferentialDataSourceConfiguration(ObserveDataSourceConfiguration importReferentialDataSourceConfiguration) {
Objects.requireNonNull(importReferentialDataSourceConfiguration, "'importReferentialDataSourceConfiguration' can't be null.");
this.optionalImportReferentialDataSourceConfiguration = importReferentialDataSourceConfiguration;
}
public void setImportDataConfiguration(ObserveDataSourceConfiguration importDataDataSourceConfiguration, ImmutableSet importDataIds) {
Objects.requireNonNull(importDataDataSourceConfiguration, "'importDataDataSourceConfiguration' can't be null.");
Objects.requireNonNull(importDataIds, "'importDataIds' can't be null.");
this.optionalImportDataDataSourceConfiguration = importDataDataSourceConfiguration;
this.optionalImportDataIds = importDataIds;
}
public void validateConfiguration() throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException {
boolean importDatabase = isImportDatabase();
if (importDatabase) {
// on ne peut pas importer autre chose en même
if (isImportData() || isImportReferential()) {
throw new IncompatibleDataSourceCreateConfigurationException(this);
}
} else {
if (!isCanCreateEmptyDatabase() && !isImportReferential()) {
// on n'autorise pas la création d'une base sans référentiel.
throw new DataSourceCreateWithNoReferentialImportException(this);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy