Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

17 changed files:

Changes:

  • client/pom.xml
    ... ... @@ -348,6 +348,12 @@
    348 348
           <version>${project.version}</version>
    
    349 349
           <scope>runtime</scope>
    
    350 350
         </dependency>
    
    351
    +    <dependency>
    
    352
    +      <groupId>${project.groupId}</groupId>
    
    353
    +      <artifactId>test</artifactId>
    
    354
    +      <version>${project.version}</version>
    
    355
    +      <scope>test</scope>
    
    356
    +    </dependency>
    
    351 357
     
    
    352 358
         <!-- jaxx dependencies -->
    
    353 359
     
    
    ... ... @@ -709,6 +715,7 @@
    709 715
                     <template>dataSourceSelectModeResume</template>
    
    710 716
                     <template>initStorage</template>
    
    711 717
                     <template>storageModelDataSourceConfiguration</template>
    
    718
    +                <template>validationResult</template>
    
    712 719
                   </templateList>
    
    713 720
                 </configuration>
    
    714 721
               </execution>
    

  • client/src/main/ftl/validationReport_en.ftl
    1
    +<html>
    
    2
    +<body>
    
    3
    +<b>#TODO</b>
    
    4
    +<h1>Rapport de validation</h1>
    
    5
    +
    
    6
    +<h2>Configuration</h2>
    
    7
    +
    
    8
    +<ul>
    
    9
    +    <li>Rapport de validation généré le ${now}</li>
    
    10
    +    <li>Scopes : ${scopes?join(", ")}</li>
    
    11
    +    <li>Context : ${contextName}</li>
    
    12
    +</ul>
    
    13
    +
    
    14
    +<#list messageTypes as type>
    
    15
    +<h2>${decorateType(type)}</h2>
    
    16
    +<table>
    
    17
    +    <thead>
    
    18
    +    <tr>
    
    19
    +        <th>Identifiant</th>
    
    20
    +        <th>Libellé</th>
    
    21
    +        <th>Scope</th>
    
    22
    +        <th>Champs</th>
    
    23
    +        <th>Message</th>
    
    24
    +    </tr>
    
    25
    +    </thead>
    
    26
    +    <#list validationResult.getDtosForType(type) as dto>
    
    27
    +        <#list validationResult.getMessagesForId(dto.id) as message>
    
    28
    +            <tr>
    
    29
    +                <td>${dto.id}</td>
    
    30
    +                <td>${decorateReference(dto.reference)}</td>
    
    31
    +                <td>${message.scope}</td>
    
    32
    +                <td>${decorateProperty(message.fieldName)}</td>
    
    33
    +                <td>${message.message}</td>
    
    34
    +            </tr>
    
    35
    +        </#list>
    
    36
    +    </#list>
    
    37
    +</table>
    
    38
    +</#list>
    
    39
    +</body>
    
    40
    +</html>

  • client/src/main/ftl/validationReport_es.ftl
    1
    +<html>
    
    2
    +<body>
    
    3
    +<b>#TODO</b>
    
    4
    +<h1>Rapport de validation</h1>
    
    5
    +
    
    6
    +<h2>Configuration</h2>
    
    7
    +
    
    8
    +<ul>
    
    9
    +    <li>Rapport de validation généré le ${now}</li>
    
    10
    +    <li>Scopes : ${scopes?join(", ")}</li>
    
    11
    +    <li>Context : ${contextName}</li>
    
    12
    +</ul>
    
    13
    +
    
    14
    +<#list messageTypes as type>
    
    15
    +<h2>${decorateType(type)}</h2>
    
    16
    +<table>
    
    17
    +    <thead>
    
    18
    +    <tr>
    
    19
    +        <th>Identifiant</th>
    
    20
    +        <th>Libellé</th>
    
    21
    +        <th>Scope</th>
    
    22
    +        <th>Champs</th>
    
    23
    +        <th>Message</th>
    
    24
    +    </tr>
    
    25
    +    </thead>
    
    26
    +    <#list validationResult.getDtosForType(type) as dto>
    
    27
    +        <#list validationResult.getMessagesForId(dto.id) as message>
    
    28
    +            <tr>
    
    29
    +                <td>${dto.id}</td>
    
    30
    +                <td>${decorateReference(dto.reference)}</td>
    
    31
    +                <td>${message.scope}</td>
    
    32
    +                <td>${decorateProperty(message.fieldName)}</td>
    
    33
    +                <td>${message.message}</td>
    
    34
    +            </tr>
    
    35
    +        </#list>
    
    36
    +    </#list>
    
    37
    +</table>
    
    38
    +</#list>
    
    39
    +</body>
    
    40
    +</html>

  • client/src/main/ftl/validationReport_fr.ftl
    1
    +<html>
    
    2
    +<body>
    
    3
    +
    
    4
    +<h1>Rapport de validation</h1>
    
    5
    +
    
    6
    +<h2>Configuration</h2>
    
    7
    +
    
    8
    +<ul>
    
    9
    +    <li>Rapport de validation généré le ${now}</li>
    
    10
    +    <li>Scopes : ${scopes?join(", ")}</li>
    
    11
    +    <li>Context : ${contextName}</li>
    
    12
    +</ul>
    
    13
    +
    
    14
    +<#list messageTypes as type>
    
    15
    +<h2>${decorateType(type)}</h2>
    
    16
    +<table>
    
    17
    +    <thead>
    
    18
    +    <tr>
    
    19
    +        <th>Identifiant</th>
    
    20
    +        <th>Libellé</th>
    
    21
    +        <th>Scope</th>
    
    22
    +        <th>Champs</th>
    
    23
    +        <th>Message</th>
    
    24
    +    </tr>
    
    25
    +    </thead>
    
    26
    +    <#list validationResult.getDtosForType(type) as dto>
    
    27
    +        <#list validationResult.getMessagesForId(dto.id) as message>
    
    28
    +            <tr>
    
    29
    +                <td>${dto.id}</td>
    
    30
    +                <td>${decorateReference(dto.reference)}</td>
    
    31
    +                <td>${message.scope}</td>
    
    32
    +                <td>${decorateProperty(message.fieldName)}</td>
    
    33
    +                <td>${message.message}</td>
    
    34
    +            </tr>
    
    35
    +        </#list>
    
    36
    +    </#list>
    
    37
    +</table>
    
    38
    +</#list>
    
    39
    +</body>
    
    40
    +</html>

  • client/src/main/java/fr/ird/observe/client/ObserveRunner.java
    ... ... @@ -87,6 +87,10 @@ public abstract class ObserveRunner extends ApplicationRunner {
    87 87
     
    
    88 88
         private static ObserveResourceManager resourceManager;
    
    89 89
     
    
    90
    +    public static void setResourceManager(ObserveResourceManager resourceManager) {
    
    91
    +        ObserveRunner.resourceManager = resourceManager;
    
    92
    +    }
    
    93
    +
    
    90 94
         private static ObserveActionExecutor actionExecutor;
    
    91 95
     
    
    92 96
         public static ObserveRunner getRunner() {
    
    ... ... @@ -481,7 +485,7 @@ public abstract class ObserveRunner extends ApplicationRunner {
    481 485
             }
    
    482 486
         }
    
    483 487
     
    
    484
    -    private void initI18n(ClientConfig config) {
    
    488
    +    public static void initI18n(ClientConfig config) {
    
    485 489
     
    
    486 490
             I18n.close();
    
    487 491
     
    

  • client/src/main/java/fr/ird/observe/client/ObserveTextGenerator.java
    ... ... @@ -25,9 +25,11 @@ package fr.ird.observe.client;
    25 25
     import fr.ird.observe.client.configuration.ClientConfig;
    
    26 26
     import fr.ird.observe.client.db.ObserveDataSourcesManager;
    
    27 27
     import fr.ird.observe.client.db.ObserveSwingDataSource;
    
    28
    +import fr.ird.observe.client.ui.admin.validate.ValidateModel;
    
    28 29
     import fr.ird.observe.client.ui.storage.StorageUIModel;
    
    29 30
     import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration;
    
    30 31
     import fr.ird.observe.services.configuration.ObserveDataSourceInformation;
    
    32
    +import fr.ird.observe.services.service.actions.validate.ValidationResult;
    
    31 33
     import freemarker.cache.FileTemplateLoader;
    
    32 34
     import freemarker.template.Configuration;
    
    33 35
     import freemarker.template.Template;
    
    ... ... @@ -64,6 +66,8 @@ public class ObserveTextGenerator {
    64 66
     
    
    65 67
         private static final String INIT_STORAGE_TEMPLATE = "initStorage.ftl";
    
    66 68
     
    
    69
    +    private static final String VALIDATION_REPORT_TEMPLATE = "validationReport.ftl";
    
    70
    +
    
    67 71
         private final Configuration freemarkerConfiguration;
    
    68 72
     
    
    69 73
         private final ClientConfig observeConfiguration;
    
    ... ... @@ -115,6 +119,10 @@ public class ObserveTextGenerator {
    115 119
             return generateHtml(INIT_STORAGE_TEMPLATE, model);
    
    116 120
         }
    
    117 121
     
    
    122
    +    public String getValidationReport(ValidateModel model) {
    
    123
    +        return generateHtml(VALIDATION_REPORT_TEMPLATE, model);
    
    124
    +    }
    
    125
    +
    
    118 126
         protected String generateHtml(String templateName, Object model) {
    
    119 127
             return generateHtml(observeConfiguration.getLocale(), templateName, model);
    
    120 128
         }
    

  • client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateEntityListCellRenderer.java
    ... ... @@ -21,12 +21,12 @@
    21 21
      */
    
    22 22
     package fr.ird.observe.client.ui.admin.validate;
    
    23 23
     
    
    24
    -import com.google.common.collect.ImmutableSet;
    
    25 24
     import fr.ird.observe.client.ObserveSwingApplicationContext;
    
    26 25
     import fr.ird.observe.services.decoration.DecoratorService;
    
    27 26
     import fr.ird.observe.services.decoration.ObserveI18nDecoratorHelper;
    
    28 27
     import fr.ird.observe.services.dto.reference.AbstractReference;
    
    29 28
     import fr.ird.observe.services.dto.reference.ReferentialReference;
    
    29
    +import fr.ird.observe.services.service.actions.validate.ValidationResult;
    
    30 30
     import java.awt.Component;
    
    31 31
     import java.beans.PropertyChangeEvent;
    
    32 32
     import java.beans.PropertyChangeListener;
    
    ... ... @@ -61,15 +61,15 @@ public class ValidateEntityListCellRenderer extends DefaultListCellRenderer impl
    61 61
             this.model = model;
    
    62 62
             renderCache = new HashMap<>();
    
    63 63
             // on écoute les modifications de messages sur le model
    
    64
    -        this.model.addPropertyChangeListener(ValidateModel.PROPERTY_MESSAGES, this);
    
    64
    +        this.model.addPropertyChangeListener(ValidateModel.PROPERTY_VALIDATION_RESULT, this);
    
    65 65
         }
    
    66 66
     
    
    67 67
         @Override
    
    68 68
         public void propertyChange(PropertyChangeEvent evt) {
    
    69 69
     
    
    70
    -        ImmutableSet value = (ImmutableSet) evt.getNewValue();
    
    70
    +        ValidationResult value = (ValidationResult) evt.getNewValue();
    
    71 71
             if (log.isDebugEnabled()) {
    
    72
    -            log.debug(String.format("messages changed : %d, rebuild render cache", value == null ? 0 : value.size()));
    
    72
    +            log.debug(String.format("messages changed : %d, rebuild render cache", value == null ? 0 : value.getData().size()));
    
    73 73
             }
    
    74 74
             synchronized (renderCache) {
    
    75 75
                 renderCache.clear();
    

  • client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateModel.java
    ... ... @@ -30,29 +30,36 @@ import fr.ird.observe.client.ui.admin.AdminActionModel;
    30 30
     import fr.ird.observe.client.ui.admin.AdminStep;
    
    31 31
     import fr.ird.observe.client.ui.admin.AdminUIModel;
    
    32 32
     import fr.ird.observe.client.ui.util.ProgressModel;
    
    33
    +import fr.ird.observe.services.decoration.DecoratorService;
    
    34
    +import fr.ird.observe.services.decoration.ObserveI18nDecoratorHelper;
    
    33 35
     import fr.ird.observe.services.dto.reference.AbstractReference;
    
    36
    +import fr.ird.observe.services.dto.reference.DataReference;
    
    34 37
     import fr.ird.observe.services.dto.referential.ReferentialDto;
    
    38
    +import fr.ird.observe.services.service.actions.validate.ValidateService;
    
    39
    +import fr.ird.observe.services.service.actions.validate.ValidationResult;
    
    35 40
     import fr.ird.observe.services.service.actions.validate.ValidationResultDto;
    
    36 41
     import fr.ird.observe.services.service.actions.validate.ValidationResultDtoMessage;
    
    37
    -import fr.ird.observe.services.service.actions.validate.ValidateService;
    
    38 42
     import fr.ird.observe.services.validation.ValidatorDto;
    
    43
    +import java.beans.Introspector;
    
    39 44
     import java.beans.PropertyChangeListener;
    
    40 45
     import java.io.File;
    
    41
    -import java.util.Comparator;
    
    46
    +import java.text.SimpleDateFormat;
    
    42 47
     import java.util.Date;
    
    43 48
     import java.util.EnumMap;
    
    44 49
     import java.util.EnumSet;
    
    45 50
     import java.util.LinkedHashSet;
    
    46
    -import java.util.List;
    
    47 51
     import java.util.Set;
    
    48
    -import java.util.TreeSet;
    
    49 52
     import java.util.stream.Collectors;
    
    53
    +import org.apache.commons.lang3.StringUtils;
    
    50 54
     import org.apache.commons.lang3.mutable.MutableInt;
    
    51 55
     import org.apache.commons.logging.Log;
    
    52 56
     import org.apache.commons.logging.LogFactory;
    
    53 57
     import org.nuiton.jaxx.runtime.swing.wizard.ext.WizardState;
    
    54 58
     import org.nuiton.validator.NuitonValidatorScope;
    
    55 59
     
    
    60
    +
    
    61
    +import static org.nuiton.i18n.I18n.t;
    
    62
    +
    
    56 63
     /**
    
    57 64
      * Modele pour preparer une validation de donnees d'une base.
    
    58 65
      *
    
    ... ... @@ -66,7 +73,8 @@ public class ValidateModel extends AdminActionModel {
    66 73
         static final String PROPERTY_MODEL_MODE = "modelMode";
    
    67 74
         private static final String PROPERTY_GENERATE_REPORT = "generateReport";
    
    68 75
         private static final String PROPERTY_REPORT_FILE = "reportFile";
    
    69
    -    static final String PROPERTY_MESSAGES = "messages";
    
    76
    +
    
    77
    +    static final String PROPERTY_VALIDATION_RESULT = "validationResult";
    
    70 78
     
    
    71 79
         /** le pattern du fichier de rapport après validation */
    
    72 80
         private static final String REPORT_PATTERN = "report-%1$tF--%1$tk-%1$tM-%1$tS.txt";
    
    ... ... @@ -95,18 +103,16 @@ public class ValidateModel extends AdminActionModel {
    95 103
         /** les validateurs selectionnées */
    
    96 104
         private Set<ValidatorDto> validators;
    
    97 105
     
    
    98
    -    /** le dictionnaire des paths d'entites detectees */
    
    99
    -    private final Set<ValidationResultDto> messages;
    
    100
    -
    
    101 106
         private final Set<Class> messagesTypes;
    
    102
    -
    
    103 107
         private final ProgressModel progressModel = new ProgressModel();
    
    104 108
     
    
    109
    +    private ValidationResult<?> validationResult;
    
    110
    +    private DecoratorService decoratorService;
    
    111
    +
    
    105 112
         public ValidateModel() {
    
    106 113
             super(AdminStep.VALIDATE);
    
    107 114
             scopes = EnumSet.noneOf(NuitonValidatorScope.class);
    
    108 115
             this.messagesTypes = new LinkedHashSet<>();
    
    109
    -        this.messages = new TreeSet<>(Comparator.comparing(m -> m.getReference().getId()));
    
    110 116
         }
    
    111 117
     
    
    112 118
     
    
    ... ... @@ -184,36 +190,41 @@ public class ValidateModel extends AdminActionModel {
    184 190
             return validators;
    
    185 191
         }
    
    186 192
     
    
    187
    -    public void setMessages(ImmutableSet<ValidationResultDto> messages) {
    
    188
    -        this.messages.clear();
    
    193
    +    @SuppressWarnings("unused")
    
    194
    +    public ValidationResult<?> getValidationResult() {
    
    195
    +        return validationResult;
    
    196
    +    }
    
    197
    +
    
    198
    +    public void setValidationResult(ValidationResult<?> validationResult) {
    
    199
    +        this.validationResult = validationResult;
    
    189 200
             this.messagesTypes.clear();
    
    190
    -        this.messages.addAll(messages);
    
    191
    -        Set<Class> collect = messages.stream().map(m -> m.getReference().getType()).collect(Collectors.toSet());
    
    192
    -        this.messagesTypes.addAll(collect);
    
    193
    -        firePropertyChange(PROPERTY_MESSAGES, messages);
    
    201
    +        if (validationResult != null) {
    
    202
    +            this.messagesTypes.addAll(validationResult.getTypes());
    
    203
    +        }
    
    204
    +        firePropertyChange(PROPERTY_VALIDATION_RESULT, null, validationResult);
    
    194 205
         }
    
    195 206
     
    
    196
    -    Set<Class> getMessageTypes() {
    
    207
    +    public Set<Class> getMessageTypes() {
    
    197 208
             return messagesTypes;
    
    198 209
         }
    
    199 210
     
    
    200
    -    List<AbstractReference> getMessagesDto(Class dtoType) {
    
    211
    +    public ImmutableSet<ValidationResultDto> getMessagesDto(Class dtoType) {
    
    201 212
     
    
    202
    -        return messages.stream().filter(m -> dtoType.equals(m.getReference().getType())).map(ValidationResultDto::getReference).collect(Collectors.toList());
    
    213
    +        return validationResult == null ? ImmutableSet.of() : validationResult.getDtosForType(dtoType);
    
    203 214
     
    
    204 215
         }
    
    205 216
     
    
    206
    -    public Set<ValidationResultDto> getMessages() {
    
    207
    -        return messages;
    
    217
    +    public ImmutableSet<ValidationResultDto> getMessages() {
    
    218
    +        return validationResult == null ? ImmutableSet.of() : validationResult.getData();
    
    208 219
         }
    
    209 220
     
    
    210
    -    List<ValidationResultDtoMessage> getMessages(AbstractReference<?> dtoType) {
    
    221
    +    public ImmutableSet<ValidationResultDtoMessage> getMessages(AbstractReference<?> dtoType) {
    
    211 222
     
    
    212
    -        return messages.stream().filter(m -> dtoType.equals(m.getReference())).flatMap(m -> m.getMessages().stream()).collect(Collectors.toList());
    
    223
    +        return validationResult == null ? ImmutableSet.of() : validationResult.getMessagesForId(dtoType.getId());
    
    213 224
     
    
    214 225
         }
    
    215 226
     
    
    216
    -    void addScope(NuitonValidatorScope scope) {
    
    227
    +    public void addScope(NuitonValidatorScope scope) {
    
    217 228
             scopes.add(scope);
    
    218 229
             validators = null;
    
    219 230
             firePropertyChange(PROPERTY_SCOPES, null, scopes);
    
    ... ... @@ -228,9 +239,6 @@ public class ValidateModel extends AdminActionModel {
    228 239
         @Override
    
    229 240
         public void destroy() {
    
    230 241
             super.destroy();
    
    231
    -        if (messages != null) {
    
    232
    -            setMessages(ImmutableSet.of());
    
    233
    -        }
    
    234 242
             if (validators != null) {
    
    235 243
                 validators = null;
    
    236 244
             }
    
    ... ... @@ -270,6 +278,12 @@ public class ValidateModel extends AdminActionModel {
    270 278
             setReportFile(reportFile);
    
    271 279
         }
    
    272 280
     
    
    281
    +    private static final SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyy HH:mm");
    
    282
    +
    
    283
    +    public String getNow() {
    
    284
    +        return df.format(new Date());
    
    285
    +    }
    
    286
    +
    
    273 287
         public boolean validate(AdminUIModel uiModel) {
    
    274 288
             return uiModel.validate(AdminStep.SELECT_DATA) && uiModel.getStepState(step) == WizardState.SUCCESSED;
    
    275 289
         }
    
    ... ... @@ -294,8 +308,8 @@ public class ValidateModel extends AdminActionModel {
    294 308
     
    
    295 309
         }
    
    296 310
     
    
    297
    -    boolean withoutMessages() {
    
    298
    -        return messages.isEmpty();
    
    311
    +    public boolean withoutMessages() {
    
    312
    +        return validationResult == null || validationResult.getData().isEmpty();
    
    299 313
         }
    
    300 314
     
    
    301 315
         EnumMap<NuitonValidatorScope, Integer> getScopesCount(AbstractReference<?> value) {
    
    ... ... @@ -305,10 +319,14 @@ public class ValidateModel extends AdminActionModel {
    305 319
                 temp.put(scope, new MutableInt());
    
    306 320
             }
    
    307 321
     
    
    308
    -        messages.stream()
    
    309
    -                .filter(m -> value.equals(m.getReference())).flatMap(m -> m.getMessages().stream())
    
    310
    -                .map(ValidationResultDtoMessage::getScope)
    
    311
    -                .forEach(s -> temp.get(s).incrementAndGet());
    
    322
    +        if (validationResult != null) {
    
    323
    +            getMessages().stream()
    
    324
    +                    .filter(m -> value.equals(m.getReference())).flatMap(m -> m.getMessages().stream())
    
    325
    +                    .map(ValidationResultDtoMessage::getScope)
    
    326
    +                    .forEach(s -> temp.get(s).incrementAndGet());
    
    327
    +
    
    328
    +        }
    
    329
    +
    
    312 330
             EnumMap<NuitonValidatorScope, Integer> result = new EnumMap<>(NuitonValidatorScope.class);
    
    313 331
     
    
    314 332
             temp.entrySet().stream()
    
    ... ... @@ -316,4 +334,24 @@ public class ValidateModel extends AdminActionModel {
    316 334
                     .forEach(entry -> result.put(entry.getKey(), entry.getValue().toInteger()));
    
    317 335
             return result;
    
    318 336
         }
    
    337
    +
    
    338
    +    @SuppressWarnings({"unchecked", "unused"})
    
    339
    +    public String decorateReference(AbstractReference reference) {
    
    340
    +        if (reference instanceof DataReference<?>) {
    
    341
    +            return decoratorService.getDataReferenceDecorator(reference.getType()).toString(reference);
    
    342
    +        }
    
    343
    +        return decoratorService.getReferentialReferenceDecorator(reference.getType()).toString(reference);
    
    344
    +    }
    
    345
    +
    
    346
    +    public String decorateType(Class type) {
    
    347
    +        return t(ObserveI18nDecoratorHelper.getTypeI18nKey(type));
    
    348
    +    }
    
    349
    +
    
    350
    +    public String decorateProperty(String propertyName) {
    
    351
    +        return t(ObserveI18nDecoratorHelper.getPropertyI18nKey(propertyName));
    
    352
    +    }
    
    353
    +
    
    354
    +    public void setDecoratorService(DecoratorService decoratorService) {
    
    355
    +        this.decoratorService = decoratorService;
    
    356
    +    }
    
    319 357
     }

  • client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateUIHandler.java
    ... ... @@ -37,16 +37,16 @@ import fr.ird.observe.client.ui.admin.config.SelectDataUI;
    37 37
     import fr.ird.observe.client.ui.tree.selection.SelectionTreeModel;
    
    38 38
     import fr.ird.observe.client.ui.util.ObserveValidationMessageTableRenderer;
    
    39 39
     import fr.ird.observe.client.ui.util.ProgressModel;
    
    40
    -import fr.ird.observe.services.decoration.DecoratorService;
    
    41 40
     import fr.ird.observe.services.decoration.ObserveI18nDecoratorHelper;
    
    41
    +import fr.ird.observe.services.dto.constants.ReferentialLocale;
    
    42 42
     import fr.ird.observe.services.dto.reference.AbstractReference;
    
    43 43
     import fr.ird.observe.services.dto.reference.DataReference;
    
    44 44
     import fr.ird.observe.services.service.actions.validate.DataValidationRequest;
    
    45 45
     import fr.ird.observe.services.service.actions.validate.ReferentialValidationRequest;
    
    46
    -import fr.ird.observe.services.service.actions.validate.ValidationResultDtoMessage;
    
    47
    -import fr.ird.observe.services.service.actions.validate.ValidationResultDto;
    
    48 46
     import fr.ird.observe.services.service.actions.validate.ValidateService;
    
    49 47
     import fr.ird.observe.services.service.actions.validate.ValidationResult;
    
    48
    +import fr.ird.observe.services.service.actions.validate.ValidationResultDto;
    
    49
    +import fr.ird.observe.services.service.actions.validate.ValidationResultDtoMessage;
    
    50 50
     import fr.ird.observe.services.validation.ValidatorDto;
    
    51 51
     import java.io.File;
    
    52 52
     import java.io.IOException;
    
    ... ... @@ -54,6 +54,7 @@ import java.util.Collections;
    54 54
     import java.util.Date;
    
    55 55
     import java.util.List;
    
    56 56
     import java.util.Set;
    
    57
    +import java.util.stream.Collectors;
    
    57 58
     import javax.swing.DefaultListModel;
    
    58 59
     import javax.swing.JCheckBox;
    
    59 60
     import javax.swing.JTable;
    
    ... ... @@ -229,12 +230,12 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    229 230
     
    
    230 231
                 Class<?> type = (Class<?>) o;
    
    231 232
     
    
    232
    -            List<AbstractReference> refs = tabUI.getStepModel().getMessagesDto(type);
    
    233
    -            for (AbstractReference<?> ref : Iterables.limit(refs, 100)) {
    
    233
    +            ImmutableSet<ValidationResultDto> refs = tabUI.getStepModel().getMessagesDto(type);
    
    234
    +            for (ValidationResultDto ref : Iterables.limit(refs, 100)) {
    
    234 235
                     if (log.isDebugEnabled()) {
    
    235 236
                         log.debug("add ref = " + ref);
    
    236 237
                     }
    
    237
    -                tabUI.refModel.addElement(ref);
    
    238
    +                tabUI.refModel.addElement(ref.getReference());
    
    238 239
                 }
    
    239 240
                 tabUI.refList.setSelectedIndex(0);
    
    240 241
             } finally {
    
    ... ... @@ -268,7 +269,7 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    268 269
                 log.debug(ref);
    
    269 270
             }
    
    270 271
     
    
    271
    -        List<ValidationResultDtoMessage> messages = tabUI.getStepModel().getMessages(ref);
    
    272
    +        ImmutableSet<ValidationResultDtoMessage> messages = tabUI.getStepModel().getMessages(ref);
    
    272 273
     
    
    273 274
             tabUI.messagesModel.setMessages(messages);
    
    274 275
     
    
    ... ... @@ -349,7 +350,7 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    349 350
             AdminUIModel model = ui.getModel();
    
    350 351
             // on vide les anciens messages
    
    351 352
             ValidateModel stepModel = model.getValidateModel();
    
    352
    -        stepModel.setMessages(ImmutableSet.of());
    
    353
    +        stepModel.setValidationResult(null);
    
    353 354
     
    
    354 355
             SelectionTreeModel dataModel = model.getSelectDataModel().getSelectionDataModel();
    
    355 356
     
    
    ... ... @@ -380,6 +381,8 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    380 381
             ImmutableSet<NuitonValidatorScope> scopes = ImmutableSet.copyOf(stepModel.getScopes());
    
    381 382
             String contextName = stepModel.getContextName();
    
    382 383
     
    
    384
    +        ValidationResult<?> result = null;
    
    385
    +
    
    383 386
             if (dataModel.isLoadReferential()) {
    
    384 387
     
    
    385 388
                 // validation des referentiels selectionnes
    
    ... ... @@ -391,11 +394,17 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    391 394
     
    
    392 395
                 progressModel.incrementsCurrentStep();
    
    393 396
     
    
    394
    -            ValidationResult<ReferentialValidationRequest> result = validateService.validateReferential(request);
    
    397
    +            result = validateService.validateReferential(request);
    
    395 398
     
    
    396
    -            messages.addAll(result.getData());
    
    397 399
             } else if (dataModel.isUseData()) {
    
    398 400
     
    
    401
    +            DataValidationRequest mainRequest = new DataValidationRequest();
    
    402
    +            mainRequest.setDataIds(ImmutableSet.copyOf(dataModel.getSelectedData().stream().map(DataReference::getId).collect(Collectors.toSet())));
    
    403
    +            mainRequest.setScopes(scopes);
    
    404
    +            mainRequest.setValidationContext(contextName);
    
    405
    +
    
    406
    +            ValidationResult.Builder<DataValidationRequest> resultBuilder = ValidationResult.builder(ReferentialLocale.valueOf(ObserveSwingApplicationContext.get().getConfig().getDbLocale()), mainRequest);
    
    407
    +
    
    399 408
                 for (DataReference<?> dataReference : dataModel.getSelectedData()) {
    
    400 409
     
    
    401 410
                     String id = dataReference.getId();
    
    ... ... @@ -407,17 +416,20 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    407 416
     
    
    408 417
                     sendMessage(t("observe.actions.validate.message.validate.trip", getDecoratorService().getDataReferenceDecorator(dataReference.getType()).toString(dataReference)));
    
    409 418
                     progressModel.incrementsCurrentStep();
    
    410
    -                ValidationResult<DataValidationRequest> result = validateService.validateData(request);
    
    411
    -                messages.addAll(result.getData());
    
    419
    +
    
    420
    +                result = validateService.validateData(request);
    
    421
    +                resultBuilder.addMessages(result.getData());
    
    412 422
     
    
    413 423
                 }
    
    414 424
     
    
    425
    +            result = resultBuilder.build();
    
    426
    +
    
    415 427
             } else throw new IllegalStateException();
    
    416 428
     
    
    417 429
             progressModel.incrementsCurrentStep();
    
    418 430
             dataSourceToValidate.close();
    
    419 431
     
    
    420
    -        stepModel.setMessages(messages.build());
    
    432
    +        stepModel.setValidationResult(result);
    
    421 433
     
    
    422 434
         }
    
    423 435
     
    
    ... ... @@ -445,60 +457,18 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements
    445 457
             }
    
    446 458
         }
    
    447 459
     
    
    448
    -    //FIXME A remplacer par une template
    
    449 460
         private void generateReportFile(ValidateModel validationModel) throws IOException {
    
    450 461
             File reportFile = validationModel.getReportFile();
    
    451 462
             if (log.isInfoEnabled()) {
    
    452 463
                 log.info("save report in " + reportFile);
    
    453 464
             }
    
    454 465
     
    
    455
    -        DecoratorService service = getDecoratorService();
    
    456
    -        StringBuilder builder = new StringBuilder();
    
    457
    -        builder.append(LINE).append('\n');
    
    466
    +        validationModel.setDecoratorService(getDecoratorService());
    
    458 467
     
    
    459
    -        builder.append(t("observe.actions.validate.report.title", new Date())).append('\n');
    
    460
    -        builder.append(t("observe.actions.validate.report.scopes", validationModel.getScopes())).append('\n');
    
    461
    -        builder.append(t("observe.actions.validate.report.contextName", validationModel.getContextName())).append('\n');
    
    468
    +        String content = ObserveSwingApplicationContext.get().getTextGenerator().getValidationReport(validationModel);
    
    462 469
     
    
    463
    -//        Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> messages = validationModel.getMessages();
    
    464
    -//
    
    465
    -//        builder.append(t("observe.actions.validate.report.entities.with.messages", messages.size())).append('\n');
    
    466
    -//        builder.append(LINE).append('\n').append('\n');
    
    467
    -//
    
    468
    -//        for (ValidateResultForDtoType<?> validateResultForDtoType : messages.values()) {
    
    469
    -//
    
    470
    -//            ImmutableSet<? extends ValidateResultForDto<?>> validateResultForHelper = validateResultForDtoType.getValidateResultForDto();
    
    471
    -//            for (ValidateResultForDto<?> validateResultForDto : validateResultForHelper) {
    
    472
    -//                AbstractReference<?> referenceDto = validateResultForDto.getReference();
    
    473
    -//
    
    474
    -//                String refStr = service.getReferenceDecorator(referenceDto.getType()).toString(referenceDto);
    
    475
    -//
    
    476
    -//                Set<ValidationResultDtoMessage> refMessages = validateResultForDto.getMessages();
    
    477
    -//
    
    478
    -//                EnumSet<NuitonValidatorScope> scopes = getScopes(validateResultForDto);
    
    479
    -//
    
    480
    -//                builder.append(t("observe.actions.validate.report.entity", referenceDto.getId(), refStr, refMessages.size(), scopes)).append('\n');
    
    481
    -//                for (NuitonValidatorScope scope : scopes) {
    
    482
    -//
    
    483
    -//                    List<ValidationResultDtoMessage> messagesByScope = scopeMessageFilter(scope, validateResultForDto);
    
    484
    -//
    
    485
    -//                    for (ValidationResultDtoMessage message : messagesByScope) {
    
    486
    -//
    
    487
    -//                        builder.append(message.getScope()).append(" - ").append(message.getMessage()).append('\n');
    
    488
    -//
    
    489
    -//                    }
    
    490
    -//
    
    491
    -//                    builder.append('\n');
    
    492
    -//                }
    
    493
    -//
    
    494
    -//            }
    
    495
    -//            builder.append(LINE).append('\n').append('\n');
    
    496
    -//        }
    
    497
    -
    
    498
    -        String content = builder.toString();
    
    499
    -        if (log.isInfoEnabled()) {
    
    500
    -            log.info(content);
    
    501
    -        }
    
    470
    +        log.debug(content);
    
    471
    +        addMessage(AdminStep.SHOW_RESUME, content);
    
    502 472
             FileUtils.write(reportFile, content, Charsets.UTF_8.name());
    
    503 473
         }
    
    504 474
     
    

  • client/src/test/java/fr/ird/observe/client/ClientTestClassResource.java
    1
    +package fr.ird.observe.client;
    
    2
    +
    
    3
    +/*
    
    4
    + * #%L
    
    5
    + * ObServe :: Services ToPIA Implementation
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + * 
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + * 
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.client.configuration.ClientConfig;
    
    26
    +import fr.ird.observe.client.db.ObserveSwingDataSource;
    
    27
    +import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
    
    28
    +import fr.ird.observe.services.dto.source.DataSourceCreateConfigurationDto;
    
    29
    +import fr.ird.observe.services.dto.source.DataSourceCreateWithNoReferentialImportException;
    
    30
    +import fr.ird.observe.services.dto.source.IncompatibleDataSourceCreateConfigurationException;
    
    31
    +import fr.ird.observe.services.service.BabModelVersionException;
    
    32
    +import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException;
    
    33
    +import fr.ird.observe.services.service.DatabaseNotFoundException;
    
    34
    +import fr.ird.observe.test.ObserveTestConfiguration;
    
    35
    +import fr.ird.observe.test.ObserveTestResources;
    
    36
    +import fr.ird.observe.test.TestClassResourceSupport;
    
    37
    +import fr.ird.observe.test.spi.DatabaseClassifier;
    
    38
    +import java.io.File;
    
    39
    +import java.io.IOException;
    
    40
    +import java.nio.file.Files;
    
    41
    +import java.util.Locale;
    
    42
    +import org.apache.commons.logging.Log;
    
    43
    +import org.apache.commons.logging.LogFactory;
    
    44
    +import org.junit.runner.Description;
    
    45
    +import org.nuiton.i18n.I18n;
    
    46
    +import org.nuiton.i18n.init.ClassPathI18nInitializer;
    
    47
    +import org.nuiton.version.Version;
    
    48
    +
    
    49
    +/**
    
    50
    + * Created on 18/08/15.
    
    51
    + *
    
    52
    + * @author Tony Chemit - dev@tchemit.fr
    
    53
    + */
    
    54
    +public class ClientTestClassResource extends TestClassResourceSupport {
    
    55
    +
    
    56
    +    /** Logger. */
    
    57
    +    private static final Log log = LogFactory.getLog(ClientTestClassResource.class);
    
    58
    +
    
    59
    +    private final DataSourcesForTestManager dataSourcesForTestManager;
    
    60
    +    private ObserveSwingApplicationContext applicationContext;
    
    61
    +
    
    62
    +    public ClientTestClassResource() {
    
    63
    +        this(DatabaseClassifier.DEFAULT);
    
    64
    +    }
    
    65
    +
    
    66
    +    public ClientTestClassResource(DatabaseClassifier classifier) {
    
    67
    +        super(classifier);
    
    68
    +
    
    69
    +        dataSourcesForTestManager = new DataSourcesForTestManager();
    
    70
    +    }
    
    71
    +
    
    72
    +    public DataSourcesForTestManager getDataSourcesForTestManager() {
    
    73
    +        return dataSourcesForTestManager;
    
    74
    +    }
    
    75
    +
    
    76
    +    public ObserveSwingApplicationContext getApplicationContext() {
    
    77
    +        return applicationContext;
    
    78
    +    }
    
    79
    +
    
    80
    +    public ObserveSwingDataSource createDataSourceConfiguration(Version dbVersion, String dbName, File targetPath, String login, char[] password) throws DataSourceCreateWithNoReferentialImportException, IOException, IncompatibleDataSourceCreateConfigurationException, DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
    
    81
    +
    
    82
    +        ObserveDataSourceConfigurationTopiaH2 sharedDatabaseConfiguration = dataSourcesForTestManager.createSharedDataSourceConfigurationH2(dbVersion, dbName, login, password);
    
    83
    +
    
    84
    +        File sharedDatabaseFile = sharedDatabaseConfiguration.getDatabaseFile();
    
    85
    +
    
    86
    +        ObserveDataSourceConfigurationTopiaH2 dataSourceConfiguration;
    
    87
    +
    
    88
    +        ObserveSwingDataSource observeSwingDataSource;
    
    89
    +        boolean sharedDatabaseExist = sharedDatabaseFile.exists();
    
    90
    +        if (!sharedDatabaseExist) {
    
    91
    +
    
    92
    +            if (log.isInfoEnabled()) {
    
    93
    +                log.info("Create shared database: " + dbVersion.toString() + "/" + dbName + " to " + sharedDatabaseFile);
    
    94
    +            }
    
    95
    +
    
    96
    +            DataSourceCreateConfigurationDto createConfiguration = new DataSourceCreateConfigurationDto();
    
    97
    +
    
    98
    +            String scriptPath = "/db/" + dbVersion.toString() + "/" + dbName + ".sql.gz";
    
    99
    +
    
    100
    +            byte[] databaseToImportContent = ObserveTestResources.getResourceContent(scriptPath);
    
    101
    +
    
    102
    +            createConfiguration.setImportDatabase(databaseToImportContent);
    
    103
    +
    
    104
    +            observeSwingDataSource = applicationContext.getDataSourcesManager().newDataSource(sharedDatabaseConfiguration);
    
    105
    +            observeSwingDataSource.create(createConfiguration);
    
    106
    +
    
    107
    +        }
    
    108
    +
    
    109
    +        if (targetPath == null) {
    
    110
    +
    
    111
    +            dataSourceConfiguration = sharedDatabaseConfiguration;
    
    112
    +
    
    113
    +            observeSwingDataSource = applicationContext.getDataSourcesManager().newDataSource(sharedDatabaseConfiguration);
    
    114
    +
    
    115
    +        } else {
    
    116
    +
    
    117
    +            // Use a copy
    
    118
    +
    
    119
    +            dataSourceConfiguration = dataSourcesForTestManager.createDataSourceConfigurationH2(targetPath, dbVersion, dbName, login, password);
    
    120
    +            File databaseFileTarget = dataSourceConfiguration.getDatabaseFile();
    
    121
    +
    
    122
    +            if (log.isInfoEnabled()) {
    
    123
    +                log.info("Copy database: " + dbVersion.toString() + "/" + dbName + " to " + databaseFileTarget);
    
    124
    +            }
    
    125
    +            Files.createDirectories(databaseFileTarget.toPath().getParent());
    
    126
    +            Files.copy(sharedDatabaseFile.toPath(), databaseFileTarget.toPath());
    
    127
    +
    
    128
    +            observeSwingDataSource = applicationContext.getDataSourcesManager().newDataSource(sharedDatabaseConfiguration);
    
    129
    +
    
    130
    +        }
    
    131
    +
    
    132
    +        dataSourceConfiguration.setModelVersion(ObserveTestConfiguration.getModelVersion());
    
    133
    +
    
    134
    +        if (!observeSwingDataSource.isOpen()) {
    
    135
    +            observeSwingDataSource.open();
    
    136
    +        }
    
    137
    +        return observeSwingDataSource;
    
    138
    +
    
    139
    +    }
    
    140
    +
    
    141
    +    @Override
    
    142
    +    protected void before(Description description) throws Exception {
    
    143
    +        super.before(description);
    
    144
    +
    
    145
    +        if (ObserveSwingApplicationContext.isInit()) {
    
    146
    +
    
    147
    +            ObserveSwingApplicationContext.get().close();
    
    148
    +        }
    
    149
    +
    
    150
    +        ClientConfig config = new ClientConfig();
    
    151
    +
    
    152
    +        config.setDataDirectory(getTestDirectory());
    
    153
    +        config.initConfig(new ObserveResourceManager().getResource(ObserveResourceManager.Resource.application));
    
    154
    +
    
    155
    +        ObserveRunner.setResourceManager(new ObserveResourceManager());
    
    156
    +        ObserveRunner.initI18n(config);
    
    157
    +
    
    158
    +//        config.getTemplatesDirectory().mkdirs();
    
    159
    +
    
    160
    +        applicationContext = new ObserveSwingApplicationContext(config);
    
    161
    +
    
    162
    +        I18n.init(new ClassPathI18nInitializer(), Locale.FRANCE);
    
    163
    +
    
    164
    +    }
    
    165
    +
    
    166
    +    protected void after(Description description) throws IOException {
    
    167
    +
    
    168
    +        super.after(description);
    
    169
    +        applicationContext.close();
    
    170
    +    }
    
    171
    +
    
    172
    +}

  • client/src/test/java/fr/ird/observe/client/ClientTestMethodResource.java
    1
    +package fr.ird.observe.client;
    
    2
    +
    
    3
    +/*
    
    4
    + * #%L
    
    5
    + * ObServe :: Services ToPIA Implementation
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + * 
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + * 
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.client.db.ObserveSwingDataSource;
    
    26
    +import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
    
    27
    +import fr.ird.observe.test.ObserveTestConfiguration;
    
    28
    +import fr.ird.observe.test.TestMethodResourceSupport;
    
    29
    +import fr.ird.observe.test.spi.CopyDatabaseConfiguration;
    
    30
    +import java.io.File;
    
    31
    +import java.util.Objects;
    
    32
    +import org.junit.runner.Description;
    
    33
    +
    
    34
    +
    
    35
    +/**
    
    36
    + * Created on 18/08/15.
    
    37
    + *
    
    38
    + * @author Tony Chemit - dev@tchemit.fr
    
    39
    + */
    
    40
    +public class ClientTestMethodResource extends TestMethodResourceSupport<ClientTestClassResource> {
    
    41
    +
    
    42
    +    private ObserveSwingDataSource dataSource;
    
    43
    +
    
    44
    +    public ClientTestMethodResource(ClientTestClassResource clientTestClassResource) {
    
    45
    +        super(clientTestClassResource);
    
    46
    +    }
    
    47
    +
    
    48
    +    public ObserveSwingDataSource getDataSource() {
    
    49
    +        return dataSource;
    
    50
    +    }
    
    51
    +
    
    52
    +    public ObserveDataSourceConfigurationTopiaH2 createDataSourceConfigurationH2(Class<?> testClass, String dbName) {
    
    53
    +
    
    54
    +        return testClassResource.getDataSourcesForTestManager().createDataSourceConfigurationH2(
    
    55
    +                getTestDirectory(), testClass, dbName, getLogin(), getPassword());
    
    56
    +
    
    57
    +    }
    
    58
    +
    
    59
    +    @Override
    
    60
    +    protected void before(Description description) throws Throwable {
    
    61
    +
    
    62
    +        super.before(description);
    
    63
    +
    
    64
    +        Objects.requireNonNull(getDbName(), "Pas de nom de base spécifié");
    
    65
    +        Objects.requireNonNull(getDbVersion(), "Pas de version de base spécifié");
    
    66
    +        Objects.requireNonNull(getLogin(), "Pas de login spécifié");
    
    67
    +        Objects.requireNonNull(getPassword(), "Pas de password spécifié");
    
    68
    +
    
    69
    +        CopyDatabaseConfiguration copyDatabaseConfiguration = ObserveTestConfiguration.getCopyDatabaseConfigurationAnnotation(testClassMethod, testClassResource.getClassifier());
    
    70
    +        boolean useSharedDatabase = copyDatabaseConfiguration == null;
    
    71
    +
    
    72
    +        File databasePath = useSharedDatabase ? null : getTestDirectory().toPath().resolve("localDb").toFile();
    
    73
    +
    
    74
    +        dataSource = testClassResource.createDataSourceConfiguration(getDbVersion(), getDbName(), databasePath, getLogin(), getPassword());
    
    75
    +
    
    76
    +    }
    
    77
    +
    
    78
    +}

  • client/src/test/java/fr/ird/observe/client/ClientTestSupport.java
    1
    +package fr.ird.observe.client;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Services ToPIA Implementation
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + * 
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + * 
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.test.DatabaseName;
    
    26
    +import fr.ird.observe.test.ObserveTestConfiguration;
    
    27
    +import fr.ird.observe.test.spi.DatabaseLoginConfiguration;
    
    28
    +import fr.ird.observe.test.spi.DatabaseNameConfiguration;
    
    29
    +import fr.ird.observe.test.spi.DatabasePasswordConfiguration;
    
    30
    +import fr.ird.observe.test.spi.DatabaseVersionConfiguration;
    
    31
    +import org.junit.ClassRule;
    
    32
    +import org.junit.Rule;
    
    33
    +
    
    34
    +/**
    
    35
    + * Created on 26/12/15.
    
    36
    + *
    
    37
    + * @author Tony Chemit - dev@tchemit.fr
    
    38
    + */
    
    39
    +@DatabaseNameConfiguration(DatabaseName.referentiel)
    
    40
    +@DatabaseVersionConfiguration(ObserveTestConfiguration.MODEL_VERSION)
    
    41
    +@DatabaseLoginConfiguration()
    
    42
    +@DatabasePasswordConfiguration(ObserveTestConfiguration.H2_PASSWORD)
    
    43
    +public abstract class ClientTestSupport {
    
    44
    +
    
    45
    +    @ClassRule
    
    46
    +    public static final ClientTestClassResource TEST_CLASS_RESOURCE = new ClientTestClassResource();
    
    47
    +
    
    48
    +    @Rule
    
    49
    +    public final ClientTestMethodResource testMethodResource = new ClientTestMethodResource(TEST_CLASS_RESOURCE);
    
    50
    +
    
    51
    +}

  • client/src/test/java/fr/ird/observe/client/DataSourcesForTestManager.java
    1
    +package fr.ird.observe.client;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Services ToPIA Implementation
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + * 
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + * 
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
    
    26
    +import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
    
    27
    +import fr.ird.observe.test.TestHelper;
    
    28
    +import java.io.File;
    
    29
    +import java.io.IOException;
    
    30
    +import java.nio.file.Files;
    
    31
    +import java.nio.file.Path;
    
    32
    +import org.apache.commons.logging.Log;
    
    33
    +import org.apache.commons.logging.LogFactory;
    
    34
    +import org.nuiton.version.Version;
    
    35
    +
    
    36
    +/**
    
    37
    + * Created on 26/12/15.
    
    38
    + *
    
    39
    + * @author Tony Chemit - dev@tchemit.fr
    
    40
    + */
    
    41
    +public class DataSourcesForTestManager {
    
    42
    +
    
    43
    +    /** Logger. */
    
    44
    +    private static final Log log = LogFactory.getLog(DataSourcesForTestManager.class);
    
    45
    +
    
    46
    +    /**
    
    47
    +     * Root path of shared databases.
    
    48
    +     */
    
    49
    +    private static Path sharedDatabasesRootPath;
    
    50
    +
    
    51
    +    private Path getSharedDatabasesRootPath() {
    
    52
    +        if (sharedDatabasesRootPath == null) {
    
    53
    +            sharedDatabasesRootPath = TestHelper.getCommonsDir().toPath();
    
    54
    +        }
    
    55
    +        return sharedDatabasesRootPath;
    
    56
    +    }
    
    57
    +
    
    58
    +    private Path getDatabasePath(Path rootPath, Version dbVersion, String dbName) {
    
    59
    +        return rootPath.resolve(dbVersion.getValidName()).resolve(dbName);
    
    60
    +    }
    
    61
    +
    
    62
    +    public ObserveDataSourceConfigurationTopiaH2 createSharedDataSourceConfigurationH2(Version dbVersion, String dbName, String login, char[] password) {
    
    63
    +        Path databasePath = getDatabasePath(getSharedDatabasesRootPath(), dbVersion, dbName);
    
    64
    +        return createDataSourceConfigurationH2(databasePath.toFile(), dbVersion, dbName, login, password);
    
    65
    +    }
    
    66
    +
    
    67
    +    public ObserveDataSourceConfigurationTopiaH2 createDataSourceConfigurationH2(File localDbFile, Version dbVersion, String dbName, String login, char[] password) {
    
    68
    +
    
    69
    +        ObserveDataSourceConfigurationTopiaH2 configurationTopiaH2 = new ObserveDataSourceConfigurationTopiaH2();
    
    70
    +
    
    71
    +        if (log.isDebugEnabled()) {
    
    72
    +            log.debug("db directory: " + localDbFile);
    
    73
    +        }
    
    74
    +        configurationTopiaH2.setLabel("Commons database#" + dbName);
    
    75
    +        configurationTopiaH2.setUsername(login);
    
    76
    +        configurationTopiaH2.setPassword(password);
    
    77
    +        configurationTopiaH2.setDirectory(localDbFile);
    
    78
    +        configurationTopiaH2.setDbName("obstuna");
    
    79
    +        configurationTopiaH2.setAutoMigrate(true);
    
    80
    +        configurationTopiaH2.setShowMigrationProgression(true);
    
    81
    +        configurationTopiaH2.setShowMigrationSql(true);
    
    82
    +        configurationTopiaH2.setModelVersion(dbVersion);
    
    83
    +        return configurationTopiaH2;
    
    84
    +
    
    85
    +    }
    
    86
    +
    
    87
    +    public ObserveDataSourceConfigurationTopiaH2 createDataSourceConfigurationH2(File testDirectory, Class<?> testClass, String dbName, String login, char[] password) {
    
    88
    +
    
    89
    +        ObserveDataSourceConfigurationTopiaH2 configurationTopiaH2 = new ObserveDataSourceConfigurationTopiaH2();
    
    90
    +
    
    91
    +        File localDbFile = new File(testDirectory, dbName);
    
    92
    +
    
    93
    +        if (log.isInfoEnabled()) {
    
    94
    +            log.info("db directory: " + localDbFile);
    
    95
    +        }
    
    96
    +        configurationTopiaH2.setLabel(testClass.getSimpleName() + "#" + dbName);
    
    97
    +        configurationTopiaH2.setUsername(login);
    
    98
    +        configurationTopiaH2.setPassword(password);
    
    99
    +        configurationTopiaH2.setDirectory(localDbFile);
    
    100
    +        configurationTopiaH2.setDbName("obstuna");
    
    101
    +        configurationTopiaH2.setAutoMigrate(true);
    
    102
    +        configurationTopiaH2.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
    
    103
    +        return configurationTopiaH2;
    
    104
    +
    
    105
    +    }
    
    106
    +
    
    107
    +    public void clear() throws IOException {
    
    108
    +        Path sharedDatabasesRootPath = getSharedDatabasesRootPath();
    
    109
    +        log.info(String.format("Clear share databases directory: %s", sharedDatabasesRootPath));
    
    110
    +        if (Files.exists(sharedDatabasesRootPath)) {
    
    111
    +            Files.newDirectoryStream(sharedDatabasesRootPath).forEach(this::deleteDirectory);
    
    112
    +        }
    
    113
    +    }
    
    114
    +
    
    115
    +    private void deleteDirectory(Path directory) {
    
    116
    +        try {
    
    117
    +            log.debug(String.format("Delete directory: %s", directory));
    
    118
    +            Files.walk(directory).filter(f->!f.equals(directory)).forEach(f -> {
    
    119
    +                try {
    
    120
    +                    if (Files.isDirectory(f)) {
    
    121
    +                        deleteDirectory(f);
    
    122
    +                        return;
    
    123
    +                    }
    
    124
    +                    log.debug(String.format("Delete file: %s", f));
    
    125
    +                    Files.delete(f);
    
    126
    +                } catch (IOException e) {
    
    127
    +                    throw new IllegalStateException(e);
    
    128
    +                }
    
    129
    +            });
    
    130
    +
    
    131
    +            Files.delete(directory);
    
    132
    +        } catch (IOException e) {
    
    133
    +            throw new IllegalStateException(e);
    
    134
    +        }
    
    135
    +    }
    
    136
    +}

  • client/src/test/java/fr/ird/observe/client/ObserveTextGeneratorTest.java
    1
    +package fr.ird.observe.client;
    
    2
    +
    
    3
    +import com.google.common.collect.ImmutableSet;
    
    4
    +import fr.ird.observe.client.db.ObserveSwingDataSource;
    
    5
    +import fr.ird.observe.client.ui.admin.validate.ValidateModel;
    
    6
    +import fr.ird.observe.services.service.actions.validate.DataValidationRequest;
    
    7
    +import fr.ird.observe.services.service.actions.validate.ValidateService;
    
    8
    +import fr.ird.observe.services.service.actions.validate.ValidationResult;
    
    9
    +import fr.ird.observe.test.DatabaseName;
    
    10
    +import fr.ird.observe.test.ObserveFixtures;
    
    11
    +import fr.ird.observe.test.spi.DatabaseNameConfiguration;
    
    12
    +import org.apache.commons.logging.Log;
    
    13
    +import org.apache.commons.logging.LogFactory;
    
    14
    +import org.junit.Assert;
    
    15
    +import org.junit.Test;
    
    16
    +import org.nuiton.validator.NuitonValidatorScope;
    
    17
    +
    
    18
    +/**
    
    19
    + * Created by tchemit on 14/08/17.
    
    20
    + *
    
    21
    + * @author Tony Chemit - dev@tchemit.fr
    
    22
    + */
    
    23
    +public class ObserveTextGeneratorTest extends ClientTestSupport {
    
    24
    +
    
    25
    +    /** Logger. */
    
    26
    +    private static final Log log = LogFactory.getLog(ObserveTextGeneratorTest.class);
    
    27
    +
    
    28
    +    @DatabaseNameConfiguration(DatabaseName.dataForTestSeine)
    
    29
    +    @Test
    
    30
    +    public void getValidationReport() {
    
    31
    +
    
    32
    +        ObserveSwingDataSource dataSource = testMethodResource.getDataSource();
    
    33
    +
    
    34
    +        DataValidationRequest request = new DataValidationRequest();
    
    35
    +        request.setDataIds(ImmutableSet.of(ObserveFixtures.TRIP_SEINE_ID_1));
    
    36
    +        request.setScopes(ImmutableSet.of(NuitonValidatorScope.ERROR, NuitonValidatorScope.WARNING));
    
    37
    +        request.setValidationContext(ValidateService.UPDATE_VALIDATION_CONTEXT);
    
    38
    +        request.setValidationSpeedEnable(true);
    
    39
    +        request.setValidationLengthWeightEnable(true);
    
    40
    +        request.setValidationSpeedMaxValue(TEST_CLASS_RESOURCE.getApplicationContext().getConfig().getValidationSpeedMaxValue());
    
    41
    +
    
    42
    +        ValidationResult<DataValidationRequest> result = dataSource.getValidateService().validateData(request);
    
    43
    +
    
    44
    +        ValidateModel model = new ValidateModel();
    
    45
    +        model.setDecoratorService(TEST_CLASS_RESOURCE.getApplicationContext().getDecoratorService());
    
    46
    +        model.setValidationResult(result);
    
    47
    +        model.setContextName(request.getValidationContext());
    
    48
    +        model.addScope(NuitonValidatorScope.ERROR);
    
    49
    +        model.addScope(NuitonValidatorScope.WARNING);
    
    50
    +        model.setContextName(request.getValidationContext());
    
    51
    +        String content = TEST_CLASS_RESOURCE.getApplicationContext().getTextGenerator().getValidationReport(model);
    
    52
    +        Assert.assertNotNull(content);
    
    53
    +        log.info(content);
    
    54
    +    }
    
    55
    +
    
    56
    +
    
    57
    +}
    \ No newline at end of file

  • client/src/test/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineDetailCompositionValidatorServiceTest.javaclient/src/test/java/fr/ird/observe/client/ui/content/impl/longline/LonglineDetailCompositionValidatorServiceTest.java

  • services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidationResult.java
    ... ... @@ -77,6 +77,10 @@ public class ValidationResult<R extends ValidationRequest> implements ObserveDto
    77 77
             return ImmutableSet.copyOf(data.stream().filter(d -> type.equals(d.getType())).flatMap(d -> d.getMessages().stream()).collect(Collectors.toSet()));
    
    78 78
         }
    
    79 79
     
    
    80
    +    public ImmutableSet<ValidationResultDto> getDtosForType(Class type) {
    
    81
    +        return ImmutableSet.copyOf(data.stream().filter(d -> type.equals(d.getType())).collect(Collectors.toSet()));
    
    82
    +    }
    
    83
    +
    
    80 84
         public ImmutableSet<ValidationResultDtoMessage> getMessagesForId(String id) {
    
    81 85
             return ImmutableSet.copyOf(data.stream().filter(d -> id.equals(d.getId())).flatMap(d -> d.getMessages().stream()).collect(Collectors.toSet()));
    
    82 86
         }
    
    ... ... @@ -148,5 +152,11 @@ public class ValidationResult<R extends ValidationRequest> implements ObserveDto
    148 152
             public Collection<ValidationResultDtoMessage> get(String id) {
    
    149 153
                 return data.keySet().stream().filter(d -> id.equals(d.getId())).findFirst().map(data::get).orElse(Collections.emptyList());
    
    150 154
             }
    
    155
    +
    
    156
    +        public void addMessages(ImmutableSet<ValidationResultDto> data) {
    
    157
    +            for (ValidationResultDto datum : data) {
    
    158
    +                this.data.putAll(datum.getReference(), datum.getMessages());
    
    159
    +            }
    
    160
    +        }
    
    151 161
         }
    
    152 162
     }

  • test/src/main/java/fr/ird/observe/test/TestClassResourceSupport.java
    ... ... @@ -98,6 +98,10 @@ public abstract class TestClassResourceSupport implements TestRule {
    98 98
             return classifier;
    
    99 99
         }
    
    100 100
     
    
    101
    +    public File getTestDirectory() {
    
    102
    +        return testDirectory;
    
    103
    +    }
    
    104
    +
    
    101 105
         public String getServerDbName() {
    
    102 106
             return serverDbName;
    
    103 107
         }
    
    ... ... @@ -118,7 +122,7 @@ public abstract class TestClassResourceSupport implements TestRule {
    118 122
             };
    
    119 123
         }
    
    120 124
     
    
    121
    -    protected void before(Description description) {
    
    125
    +    protected void before(Description description) throws Exception{
    
    122 126
     
    
    123 127
             Class<?> testClass = description.getTestClass();
    
    124 128
             if (log.isDebugEnabled()) {