Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Story1606 sp12019 (#12)
Browse files Browse the repository at this point in the history
* Add defaultvalue for import models

* Add defaultValue Insertion part1

* #1606: Field import model

* #1606: Modif update database

* Correct error

* #1606: update database init
  • Loading branch information
vinsag authored and remipIGN committed Apr 12, 2019
1 parent 9b99f09 commit 02e286c
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 11 deletions.
1 change: 1 addition & 0 deletions database/init/create_metadata_schema_tpl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ FORMAT VARCHAR(255) not null,
IS_MANDATORY CHAR(1) null,
MASK VARCHAR(100) null,
LABEL_CSV VARCHAR(60) not null,
DEFAULT_VALUE VARCHAR(255) null,
constraint PK_FILE_FIELD primary key (DATA, FORMAT),
constraint file_field_format_label_csv_key UNIQUE (format, label_csv)
);
Expand Down
2 changes: 1 addition & 1 deletion database/init/metadata/file_field.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions database/update/v2.3.001/add_defaultvalue_fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Ajout des colonnes de statut
ALTER TABLE metadata.file_field ADD default_value varchar(255);
2 changes: 1 addition & 1 deletion database/update/v2.3.001/update_db_sprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function usage($mess = NULL) {
/* patch code here*/
//execCustSQLFile("$sprintDir/xxxx.sql", $config);
execCustSQLFile("$sprintDir/fix_especes_sensibles.sql", $config);

execCustSQLFile("$sprintDir/add_defaultvalue_fields.sql", $config);


} catch (Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class FileFieldData extends FieldData {
*/
private String labelCSV;

/**
* The defaultValue of the imported CSV file columns.
*/
private String defaultValue;

/**
* @return the isMandatory
*/
Expand All @@ -40,7 +45,7 @@ public Boolean getIsMandatory() {

/**
* @param isMandatory
* the isMandatory to set
* the isMandatory to set
*/
public void setIsMandatory(Boolean isMandatory) {
this.isMandatory = isMandatory;
Expand All @@ -55,7 +60,7 @@ public String getMask() {

/**
* @param mask
* the mask to set
* the mask to set
*/
public void setMask(String mask) {
this.mask = mask;
Expand All @@ -70,10 +75,25 @@ public String getLabelCSV() {

/**
* @param labelCSV
* the label of the CSV columns
* the label of the CSV columns
*/
public void setLabelCSV(String labelCSV) {
this.labelCSV = labelCSV;
}

/**
* @return the defaultValue
*/
public String getDefaultValue() {
return defaultValue;
}

/**
* @param defaultValue
* the defaultValue of the CSV columns
*/
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ public FileFieldData getFileField(String data) throws Exception {
result.setDefinition(rs.getString("definition"));
result.setIsMandatory(rs.getBoolean("is_mandatory"));
result.setMask(rs.getString("mask"));
result.setDefaultValue(rs.getString("default_value"));
}

} finally {
Expand Down Expand Up @@ -1206,6 +1207,8 @@ public FileFieldData getFileFieldFromLabelCSV(String labelCSV, String fileFormat
result.setDefinition(rs.getString("definition"));
result.setIsMandatory(rs.getBoolean("is_mandatory"));
result.setMask(rs.getString("mask"));
result.setDefaultValue(rs.getString("default_value"));

}

} finally {
Expand Down Expand Up @@ -1274,6 +1277,7 @@ public List<FileFieldData> getFileFields(String fileformat) throws Exception {
field.setDefinition(rs.getString("definition"));
field.setIsMandatory(rs.getBoolean("is_mandatory"));
field.setMask(rs.getString("mask"));
field.setDefaultValue(rs.getString("default_value"));
result.add(field);
logger.debug(rs.getString("data"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ public boolean insertData(Integer submissionId, Integer userSrid, String filePat

// Get the field descriptor
FileFieldData sourceFieldDescriptor = CSVsourceFieldDescriptors.get(col);

if(value.isEmpty() && (sourceFieldDescriptor.getDefaultValue() != null)) {
value = sourceFieldDescriptor.getDefaultValue();
}

// Check the mask if available and the variable is not a date (date format is tested with a date format)
if (sourceFieldDescriptor.getMask() != null && !sourceFieldDescriptor.getType().equalsIgnoreCase(DATE)
&& !sourceFieldDescriptor.getType().equalsIgnoreCase(TIME)) {
Expand Down Expand Up @@ -383,6 +386,9 @@ public boolean insertData(Integer submissionId, Integer userSrid, String filePat
String value = csvLine[col];
// The value once transformed into an Object
Object valueObj = null;
if(value.isEmpty() && (sourceFieldDescriptor.getDefaultValue() != null)) {
value = sourceFieldDescriptor.getDefaultValue();
}
// Check - once again, but it's ok, it's been checked before - and convert the type
valueObj = convertType(sourceFieldDescriptor, value);

Expand Down
5 changes: 5 additions & 0 deletions tools/dee_test_mnhnlight.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
altitudeMax;altitudeMin;altitudeMoyenne;anneeRefCommune;anneeRefDepartement;cdNom;cdRef;codeCommune;codeDepartement;codeEN;codeHabitat;codeHabRef;codeIDCNPDispositif;codeMaille;codeME;commentaire;dateDetermination;dateME;dEEFloutage;denombrementMax;denombrementMin;determinateurIdentite;determinateurMail;determinateurNomOrganisme;diffusionNiveauPrecision;dSPublique;geometrie;heureDateDebut;heureDateFin;identifiantOrigine;identifiantPermanent;identifiantRegroupementPermanent;jddCode;jddId;jddMetadonneeDEEId;jddSourceId;jourDateDebut;jourDateFin;methodeRegroupement;natureObjetGeo;nomCite;nomCommune;nomRefMaille;objetDenombrement;obsContexte;obsDescription;observateurIdentite;observateurMail;observateurNomOrganisme;obsMethode;occEtatBiologique;occMethodeDetermination;occNaturalite;occSexe;occStadeDeVie;occStatutBioGeographique;occStatutBiologique;organismeGestionnaireDonnee;organismeStandard;orgTransformation;precisionGeometrie;preuveExistante;preuveNonNumerique;preuveNumerique;profondeurMax;profondeurMin;profondeurMoyenne;referenceBiblio;refHabitat;statutObservation;statutSource;typeDenombrement;typeEN;typeInfoGeoCommune;typeInfoGeoDepartement;typeInfoGeoEN;typeInfoGeoMaille;typeInfoGeoME;typeRegroupement;validateurIdentite;validateurMail;validateurNomOrganisme;versionEN;versionME;versionRefHabitat;versionRefMaille;versionTAXREF
// ;;;;;;;;;;;;;;;; (yyyy-MM-dd) ; (yyyy-MM-dd) ;;;;;;;;*;; (HH:mm) *; (HH:mm) *;;*;;;;;; (yyyy-MM-dd) *; (yyyy-MM-dd) *;;;*;;;;;;;;;;;;;;;;;*;;;;;;;;;;;;*;*;;;;;;;;;;;;;;;;
2015;2;;;2017;89854;;;25;;;;;;;ceci est un commentaire long, qui comporte plus de 255 caractères, ce qui montre que le champ commentaire est un champ text. Sty qqe ryhqeru htu ryheuerq ytmlqeriutyeqrtyqoretyuo rqei rueitreom tiyre rrqetyroeqrue q q reqremt qret reqt ret yhg hf d drg qret qe ytq ey qer tqet q rqretiuqmotuùmqze uùqz tuyqr yqremotyoretyq ry mryt rqeom ;2015-01-01;;;;;;;;;NSP;POINT(6.31693378825738 47.104189164134);11:02;10:08;T82_1_1;0e8265ad-4fda-4736-b808-16f13863e47b;;BDMAP;T82;;;2014-10-01;2016-12-02;;In;Lynx 15 cdnom;;;;;;Pierre MICHEL;;FCEN;;;;;;;;;ONEMA;;MNHN-SPN;10;;;;;;;;;No;Te;;;;2;;;;;Solène ROB;;MNHN-SPN;;;;;V10.0
;;;;2017;60612;;;25;;;;;;;;2015-01-01;;;;;;;;;Pu;POINT(6.3169637882738 47.10418916134);11:02;10:08;T82_1_2;19169e91-9f2b-4976-9c3c-cc2e627d5e59;;BDMAP;T82;;;2014-10-01;2016-12-02;;In;Lynx 12 cdnom;;;;;;Rasta POPOULOS;;TINTIN;;;;;;;;;ONEMA;;MNHN-SPN;1;;;;;;;;;No;Te;;;;2;;;;;Test TEST, Test2 TEST 2;;Inconnu, Inconnu;;;;;V10.0
;;;;2017;;89854;;25;;;;;;;;2015-01-01;;;;;;;;;Pu;POINT(6.31693378827738 47.104189161534);11:02;10:08;T82_1_3;663d3838-8332-46ff-a9b6-f95d85d62440;;BDMAP;T82;;;2009-02-15;2016-12-13;;In;Lynx 15 cdref;;;;;;Ide FIX, Ob‚ LIX ;;RG, AG;;;;;;;;;ONEMA;;MNHN-SPN;1;;;;;;;;;Pr;Te;;;;2;;;;;Manu LARCENET;;Non renseign,;;;;;V10.0
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class FileField implements FieldInterface {
*/
private $format;

/**
*
* @var string @ORM\Column(name="default_value", type="string", length=255, nullable=true)
*/
private $defaultValue;

/**
* Set isMandatory
*
Expand Down Expand Up @@ -165,6 +171,29 @@ public function getFormat() {
return $this->format;
}

/**
* Set defaultValue
*
* @param string $defaultValue
*
* @return FileField
*/
public function setDefaultValue($defaultValue) {
$this->defaultValue = $defaultValue;

return $this;
}

/**
* Get defaultValue
*
* @return string
*/
public function getDefaultValue() {
return $this->defaultValue;
}


/**
* Return the unique identifier of the field.
*
Expand All @@ -188,6 +217,7 @@ public function toJSON() {
$json .= ',"isMandatory":' . json_encode($this->isMandatory);
$json .= ',"definition":' . json_encode($this->definition);
$json .= ',"mask":' . json_encode($this->mask);
$json .= ',"defaultValue":' . json_encode($this->defaultValue);

return $json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getFileFields($fileFormat) {
$rsm->addRootEntityFromClassMetadata($this->_entityName, 'ff');

// Get the fields specified by the format
$sql = "SELECT file_field.data, file_field.format, field.type, is_mandatory, mask, label_csv";
$sql = "SELECT file_field.data, file_field.format, field.type, is_mandatory, mask, label_csv,default_value";
$sql .= " FROM file_field ";
$sql .= " LEFT JOIN field on (file_field.data = field.data AND file_field.format = field.format) ";
$sql .= " WHERE file_field.format = :fileFormat ";
Expand All @@ -51,7 +51,7 @@ public function findFieldsByFileFormat($fileFormat) {
$query = $em->createQuery('SELECT DISTINCT dt.data as fieldName, tfi.labelCSV,
dt.label as label,
u.type as unitType, tfi.isMandatory,
tfi.mask
tfi.mask, tfi.defaultValue
FROM IgnGincoBundle:Metadata\FileField tfi
LEFT JOIN IgnGincoBundle:Metadata\FileFormat tfo
WITH tfo.format = tfi.format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ public function updateFieldsAction($datasetId, $format, $toMapping = false, Requ
$labelCSVs = $request->get('labelCSVs');
$mandatorys = $request->get('mandatorys');
$masks = $request->get('masks');
$defaultValues = $request->get('defaultValues');

// Handle the name of the fields
$data = explode(",", $fields);
$labelCSVs = explode(",", $labelCSVs);
$mandatorys = explode(",", $mandatorys);
$defaultValues = explode(",", $defaultValues);
$masks = explode(",", $masks);
$masks = array_map("urldecode", $masks);

Expand Down Expand Up @@ -162,10 +164,16 @@ public function updateFieldsAction($datasetId, $format, $toMapping = false, Requ
} else {
$mask = $masks[$i];
}


if ($defaultValues[$i] == 'null') {
$defaultValue = null;
} else {
$defaultValue = $defaultValues[$i];
}

$fileField = new FileField();
$field = new Field();

$dataField = $dataRepository->find($name);

if ($dataField !== null) {
Expand All @@ -181,6 +189,7 @@ public function updateFieldsAction($datasetId, $format, $toMapping = false, Requ
$fileField->setFormat($file);
$fileField->setMask($mask);
$fileField->setIsMandatory($mandatory);
$fileField->setDefaultValue($defaultValue);

$em->merge($fileField);
}
Expand Down Expand Up @@ -310,18 +319,21 @@ public function removeFieldAction($datasetId, $field, $format, Request $request)
$labelCSVs = $request->get('labelCSVs');
$mandatorys = $request->get('mandatorys');
$masks = $request->get('masks');
$defaultValues =$request->get('defaultValues');

// Remove trailing comas of fields to update
$fields = rtrim($fields, ",");
$labelCSVs = rtrim($labelCSVs, ",");
$mandatorys = rtrim($mandatorys, ",");
$defaultValues = rtrim($defaultValues, ",");
$masks = substr($masks, 0, -1);

// Convert fields to update to arrays
$fields = explode(',', $fields);
$labelCSVs = explode(',', $labelCSVs);
$mandatorys = explode(',', $mandatorys);
$masks = explode(',', $masks);
$defaultValues = explode(',',$defaultValues);

// Delete mapping relations first
$mappingRepository = $em->getRepository("IgnGincoBundle:Metadata\FieldMapping");
Expand All @@ -343,12 +355,14 @@ public function removeFieldAction($datasetId, $field, $format, Request $request)
unset($mandatorys[$fileFieldToRemovePosition]);
unset($masks[$fileFieldToRemovePosition]);
unset($fields[$fileFieldToRemovePosition]);
unset($defaultValues[$fileFieldToRemovePosition]);

// Re-index the update arrays
$labelCSVs = array_values($labelCSVs);
$mandatorys = array_values($mandatorys);
$masks = array_values($masks);
$fields = array_values($fields);
$defaultValues = array_values($defaultValues);

if (count($fields) == 0) {
return $this->redirectToRoute('configurateur_file_fields', array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ Field name: Nom du champ dans la table
Unit: Unité
Mandatory: Obligatoire
LabelCSV: Nom du champ dans le fichier
DefaultValue: Valeur par défaut

Parent table: Table parente
HierarchicalRelationsTitle: Définition des relations hiérarchiques
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<th data-field="label">{% trans %}Field name{% endtrans %}</th>
<th data-field="unitType">{% trans %}Unit{% endtrans %}</th>
<th data-field="labelCSV">{% trans %}LabelCSV{% endtrans %}</th>
<th data-field="defaultValue">{% trans %}DefaultValue{% endtrans %}</th>
<th data-field="mandatory">{% trans %}Mandatory{% endtrans %}</th>
<th data-field="mask">{% trans %}fileField.mask.label{% endtrans %}
<button type="button" class="btn btn-default btn-xs"
Expand All @@ -99,6 +100,7 @@
<td id="label"><div style="max-width:180px;" class="longtext" title="{{ champ.label }}">{{ champ.label }}</div></td>
<td id="unit">{{ champ.unitType }}</td>
<td><input id="labelCSV" class="text-center" value="{{ champ.labelCSV }}"></td>
<td><input id="defaultValue" class="text-center" value="{{ champ.defaultValue }}"></td>
<td id="mandatory" class=text-center">
{% if champ.fieldName in mandatoryFields %}
<input type="checkbox" checked="checked" disabled title="{% trans with {'%dataName%':champ.fieldName}%}data.compulsory_state_change.mapping.forbidden{% endtrans %}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<th data-field="unitType">{% trans %}Unit{% endtrans %}</th>
<th data-field="labelCSV">{% trans %}Nom de colonne dans le fichier{% endtrans %}</th>
<th data-field="mandatory">{% trans %}Mandatory{% endtrans %}</th>
<th data-field="defaultValue">{% trans %}DefaultValue{% endtrans %}</th>
<th data-field="mask">{% trans %}fileField.mask{% endtrans %}</th>
</tr>
</thead>
Expand All @@ -62,6 +63,7 @@
{% trans %}no{% endtrans %}
{% endif %}
</td>
<td>{{ champ.defaultValue }}</td>
<td>{{ champ.mask}}</td>
</tr>
{% endfor %}
Expand Down
Loading

0 comments on commit 02e286c

Please sign in to comment.