
fr.ird.observe.dto.report.Report Maven / Gradle / Ivy
package fr.ird.observe.dto.report;
/*-
* #%L
* ObServe Toolkit :: Dto
* %%
* Copyright (C) 2017 - 2021 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 fr.ird.observe.dto.ObserveDto;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import static io.ultreia.java4all.i18n.I18n.t;
public class Report implements Serializable, ObserveDto {
/** Logger. */
private static final Logger log = LogManager.getLogger(Report.class);
/** l'id du report. */
protected final String id;
/** le libellé court du report. */
protected final String name;
/** la description du report. */
protected final String description;
/** les libellés des colonnes du report. */
protected final String[] columnHeaders;
/** les libellés des lignes du report. */
protected final String[] rowHeaders;
/** la liste des requêtes à jouer. */
protected final ReportRequest[] requests;
/** la liste des opérations à jouer. */
protected final ReportOperation[] operations;
/** la liste des variables du report. */
protected final ReportVariable>[] variables;
/** la liste des variables de type repeat du report */
protected final ReportVariable>[] repeatVariables;
/** Type de modèle utilisable pour ce report. */
protected final String modelType;
private static final long serialVersionUID = 1L;
public Report(String modelType,
String id,
String name,
String description,
String[] rowHeaders,
String[] columnHeaders,
ReportOperation[] operations,
ReportVariable>[] variables,
ReportVariable>[] repeatVariables,
ReportRequest... requests) {
this.modelType = modelType;
this.id = id;
this.name = name;
this.description = description;
this.rowHeaders = rowHeaders;
this.columnHeaders = columnHeaders;
this.requests = requests;
this.operations = operations;
this.variables = variables;
this.repeatVariables = repeatVariables;
log.debug(String.format("New report [%s:%s], nb requests : %d, nb objectOperations : %d, nb variables : %d, nb repeat variables : %d", id, name, requests.length, operations.length, variables.length, repeatVariables.length));
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public int getRows() {
return rowHeaders == null ? -1 : rowHeaders.length;
}
public int getColumns() {
return columnHeaders == null ? -1 : columnHeaders.length;
}
public String[] getColumnHeaders() {
return columnHeaders;
}
public String[] getRowHeaders() {
return rowHeaders;
}
public ReportRequest[] getRequests() {
return requests;
}
public ReportOperation[] getOperations() {
return operations;
}
public ReportVariable>[] getVariables() {
return variables;
}
public ReportVariable>[] getRepeatVariables() {
return repeatVariables;
}
public boolean isVariableRequired() {
return variables.length > 0;
}
@Override
public String toString() {
return t(name);
}
@SuppressWarnings("unchecked")
public ReportVariable getRepeatVariable(String name) {
return (ReportVariable) Arrays.stream(repeatVariables).filter(reportVariable -> name.equals(reportVariable.getName())).findFirst().orElse(null);
}
public boolean canExecute() {
for (ReportVariable> variable : getVariables()) {
// on verifie qu'on a bien cette variable
String name = variable.getName();
if (variable.getSelectedValue() == null) {
log.info(String.format("variable %s is missing", name));
return false;
}
}
// le report peut-être executé
return true;
}
public boolean canExecute(Map variables) {
for (ReportVariable> variable : getVariables()) {
// on verifie qu'on a bien cette variable
String name = variable.getName();
if (variables.get(name) == null) {
log.info(String.format("variable %s is missing", name));
return false;
}
}
// le report peut-être executé
return true;
}
public String getModelType() {
return modelType;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy