Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
bca377b5
by Tony Chemit at 2022-04-15T12:31:51+02:00
6 changed files:
- client/core/src/main/java/fr/ird/observe/client/datasource/api/data/CopyDataTask.java
- client/core/src/main/java/fr/ird/observe/client/datasource/api/data/DataTaskSupport.java
- client/core/src/main/java/fr/ird/observe/client/datasource/api/data/DeleteDataTask.java
- client/core/src/main/java/fr/ird/observe/client/datasource/api/data/InsertMissingReferentialTask.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/export/actions/Start.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/data/actions/Apply.java
Changes:
| ... | ... | @@ -102,6 +102,11 @@ public class CopyDataTask extends DataTaskSupport { |
| 102 | 102 | return t(super.getLabel(), prefix, data);
|
| 103 | 103 | }
|
| 104 | 104 | |
| 105 | + @Override
|
|
| 106 | + public int stepCount() {
|
|
| 107 | + return 4;
|
|
| 108 | + }
|
|
| 109 | + |
|
| 105 | 110 | public boolean isDataExistOnOpposite() {
|
| 106 | 111 | return dataExistOnOpposite;
|
| 107 | 112 | }
|
| ... | ... | @@ -122,10 +127,14 @@ public class CopyDataTask extends DataTaskSupport { |
| 122 | 127 | if (tripResult.isDeleted()) {
|
| 123 | 128 | String message = sendLogResultMessage(progressModel, deleteI18nKey, sourceLabel, prefix, data, tripResult.getDeleteTime());
|
| 124 | 129 | log.info(message);
|
| 130 | + } else {
|
|
| 131 | + progressModel.increments();
|
|
| 125 | 132 | }
|
| 126 | 133 | if (tripResult.isImported()) {
|
| 127 | 134 | String message = sendLogResultMessage(progressModel, importI18nKey, sourceLabel, prefix, data, tripResult.getImportTime());
|
| 128 | 135 | log.info(message);
|
| 136 | + } else {
|
|
| 137 | + progressModel.increments();
|
|
| 129 | 138 | }
|
| 130 | 139 | }
|
| 131 | 140 |
| ... | ... | @@ -61,6 +61,7 @@ public abstract class DataTaskSupport { |
| 61 | 61 | return label;
|
| 62 | 62 | }
|
| 63 | 63 | |
| 64 | + public abstract int stepCount();
|
|
| 64 | 65 | String sendLogResultMessage(ProgressionModel progressModel,
|
| 65 | 66 | String i18nKey,
|
| 66 | 67 | String sourceLabel,
|
| ... | ... | @@ -77,6 +77,11 @@ public class DeleteDataTask extends DataTaskSupport { |
| 77 | 77 | }
|
| 78 | 78 | }
|
| 79 | 79 | |
| 80 | + @Override
|
|
| 81 | + public int stepCount() {
|
|
| 82 | + return 2;
|
|
| 83 | + }
|
|
| 84 | + |
|
| 80 | 85 | @Override
|
| 81 | 86 | public String getLabel() {
|
| 82 | 87 | return t(super.getLabel(), prefix, data);
|
| ... | ... | @@ -70,20 +70,20 @@ public class InsertMissingReferentialTask extends DataTaskSupport { |
| 70 | 70 | return I18n.t(super.getLabel());
|
| 71 | 71 | }
|
| 72 | 72 | |
| 73 | + @Override
|
|
| 74 | + public int stepCount() {
|
|
| 75 | + return 3;
|
|
| 76 | + }
|
|
| 77 | + |
|
| 73 | 78 | public void consume(ProgressionModel progressModel, Supplier<String> messageSupplier, ObserveSwingDataSource incomingSource, ObserveSwingDataSource targetSource) {
|
| 74 | 79 | progressModel.increments();
|
| 75 | 80 | |
| 76 | 81 | String targetSourceLabel = targetSource.getLabel();
|
| 77 | 82 | |
| 78 | - //FIXME Review this code, if a referential synchro was just performed before
|
|
| 79 | - //FIXME We then have already resolved all ids that are only on incoming source
|
|
| 80 | - //FIXME From this ids, retains all that are in data to export (on incoming source)
|
|
| 81 | - //FIXME That's all, no need to call target source
|
|
| 82 | 83 | ReferentialService targetReferentialService = targetSource.getReferentialService();
|
| 83 | 84 | ReferentialIds targetSourceReferential = targetReferentialService.getReferentialIds();
|
| 84 | 85 | MissingReferentialRequest missingReferentialRequest = MissingReferentialRequest.of(targetSourceReferential.getIds(), idsToCopy.toArray(new String[0]));
|
| 85 | 86 | MissingReferentialResult missingReferentialResult = incomingSource.getRootOpenableService().computeMissingReferential(dataType, missingReferentialRequest);
|
| 86 | - |
|
| 87 | 87 | progressModel.increments();
|
| 88 | 88 | |
| 89 | 89 | if (missingReferentialResult == null) {
|
| ... | ... | @@ -29,6 +29,8 @@ import fr.ird.observe.client.datasource.api.ObserveSwingDataSource; |
| 29 | 29 | import fr.ird.observe.client.datasource.api.data.CopyDataTask;
|
| 30 | 30 | import fr.ird.observe.client.datasource.api.data.DataManager;
|
| 31 | 31 | import fr.ird.observe.dto.ProgressionModel;
|
| 32 | +import org.apache.logging.log4j.LogManager;
|
|
| 33 | +import org.apache.logging.log4j.Logger;
|
|
| 32 | 34 | import org.nuiton.jaxx.runtime.swing.wizard.ext.WizardState;
|
| 33 | 35 | |
| 34 | 36 | import javax.swing.ActionMap;
|
| ... | ... | @@ -63,24 +65,17 @@ public class Start extends ExportUIActionSupport { |
| 63 | 65 | |
| 64 | 66 | AdminUIModel model = ui.getModel();
|
| 65 | 67 | ExportModel stepModel = model.getExportModel();
|
| 66 | -// ConfigModel configModel = model.getConfigModel();
|
|
| 67 | -// String sourceSourceLabel = configModel.getLeftSourceModel().getLabelWithUrl().substring(configModel.getLeftSourceModel().getLabel().length());
|
|
| 68 | -// String centralSourceLabel = configModel.getRightSourceModel().getLabelWithUrl().substring(configModel.getRightSourceModel().getLabel().length());
|
|
| 69 | - |
|
| 70 | - //get selected data
|
|
| 71 | 68 | List<CopyDataTask> tasks = stepModel.getTasks();
|
| 72 | - |
|
| 73 | 69 | if (tasks.isEmpty()) {
|
| 74 | 70 | throw new IllegalStateException("Can't export no trip...");
|
| 75 | 71 | }
|
| 76 | 72 | |
| 77 | - int stepCount = 2 + 2 * tasks.size();
|
|
| 73 | + int stepCount = 2 + tasks.stream().mapToInt(CopyDataTask::stepCount).sum();
|
|
| 78 | 74 | |
| 79 | 75 | ProgressionModel progressModel = stepModel.getProgressModel();
|
| 80 | 76 | progressModel.setMaximum(stepCount);
|
| 81 | 77 | progressModel.setValue(0);
|
| 82 | 78 | |
| 83 | - progressModel.increments();
|
|
| 84 | 79 | try (ObserveSwingDataSource localDataSource = openSource(stepModel.getSource())) {
|
| 85 | 80 | progressModel.increments();
|
| 86 | 81 | try (ObserveSwingDataSource centralDataSource = openSource(stepModel.getCentralSource())) {
|
| ... | ... | @@ -90,7 +85,9 @@ public class Start extends ExportUIActionSupport { |
| 90 | 85 | }
|
| 91 | 86 | }
|
| 92 | 87 | sendMessage(t("observe.ui.datasource.editor.actions.operation.message.done", new Date()));
|
| 93 | - |
|
| 88 | + log.warn(String.format("Expected count: %d - final step count: %d", stepCount, progressModel.getValue()));
|
|
| 94 | 89 | return WizardState.SUCCESSED;
|
| 95 | 90 | }
|
| 91 | + |
|
| 92 | + private static final Logger log = LogManager.getLogger(Start.class);
|
|
| 96 | 93 | } |
| ... | ... | @@ -39,12 +39,12 @@ import org.nuiton.jaxx.runtime.swing.wizard.ext.WizardState; |
| 39 | 39 | |
| 40 | 40 | import javax.swing.DefaultListModel;
|
| 41 | 41 | import java.awt.event.ActionEvent;
|
| 42 | +import java.util.Date;
|
|
| 42 | 43 | import java.util.Iterator;
|
| 43 | 44 | import java.util.LinkedHashSet;
|
| 44 | 45 | import java.util.LinkedList;
|
| 45 | 46 | import java.util.List;
|
| 46 | 47 | import java.util.Set;
|
| 47 | -import java.util.concurrent.atomic.AtomicInteger;
|
|
| 48 | 48 | |
| 49 | 49 | import static io.ultreia.java4all.i18n.I18n.t;
|
| 50 | 50 | |
| ... | ... | @@ -74,62 +74,51 @@ public class Apply extends DataSynchroUIActionSupport { |
| 74 | 74 | ObserveSwingDataSource leftSource = stepModel.getLeftSource();
|
| 75 | 75 | ObserveSwingDataSource rightSource = stepModel.getRightSource();
|
| 76 | 76 | DefaultListModel<DataTaskSupport> tasks = stepModel.getTasks();
|
| 77 | - List<String> leftDataIds = stepModel.getLeftSelectionDataModel().allDataIds();
|
|
| 78 | - List<String> rightDataIds = stepModel.getRightSelectionDataModel().allDataIds();
|
|
| 79 | - final AtomicInteger stepsCount = new AtomicInteger();
|
|
| 77 | + |
|
| 80 | 78 | Set<String> idsToCopyToLeft = new LinkedHashSet<>();
|
| 81 | 79 | Set<String> idsToCopyToRight = new LinkedHashSet<>();
|
| 82 | 80 | Iterator<DataTaskSupport> iterator = tasks.elements().asIterator();
|
| 83 | 81 | List<DataTaskSupport> finalTasksToConsume = new LinkedList<>();
|
| 84 | 82 | while (iterator.hasNext()) {
|
| 85 | 83 | DataTaskSupport task = iterator.next();
|
| 86 | - stepsCount.incrementAndGet();
|
|
| 87 | 84 | if (task instanceof CopyDataTask) {
|
| 88 | - stepsCount.addAndGet(2);
|
|
| 89 | 85 | task.getTaskSide().consume(
|
| 90 | 86 | (CopyDataTask) task,
|
| 91 | 87 | // add task id on right
|
| 92 | - t -> {
|
|
| 93 | - idsToCopyToRight.add(t.getData().getTopiaId());
|
|
| 94 | - if (rightDataIds.contains(t.getData().getTopiaId())) {
|
|
| 95 | - stepsCount.incrementAndGet();
|
|
| 96 | - }
|
|
| 97 | - },
|
|
| 88 | + t -> idsToCopyToRight.add(t.getData().getTopiaId()),
|
|
| 98 | 89 | // add task id on left
|
| 99 | - t -> {
|
|
| 100 | - idsToCopyToLeft.add(t.getData().getTopiaId());
|
|
| 101 | - if (leftDataIds.contains(t.getData().getTopiaId())) {
|
|
| 102 | - stepsCount.incrementAndGet();
|
|
| 103 | - }
|
|
| 104 | - });
|
|
| 90 | + t -> idsToCopyToLeft.add(t.getData().getTopiaId()));
|
|
| 105 | 91 | }
|
| 106 | 92 | finalTasksToConsume.add(task);
|
| 107 | 93 | }
|
| 108 | 94 | if (!idsToCopyToLeft.isEmpty()) {
|
| 109 | - stepsCount.addAndGet(3);
|
|
| 110 | 95 | // first add missing referential to left
|
| 111 | 96 | finalTasksToConsume.add(0, InsertMissingReferentialTask.of(TaskSide.FROM_RIGHT, dataType, idsToCopyToLeft));
|
| 112 | 97 | }
|
| 113 | 98 | if (!idsToCopyToRight.isEmpty()) {
|
| 114 | - stepsCount.addAndGet(3);
|
|
| 115 | 99 | // first add missing referential to right
|
| 116 | 100 | finalTasksToConsume.add(0, InsertMissingReferentialTask.of(TaskSide.FROM_LEFT, dataType, idsToCopyToRight));
|
| 117 | 101 | }
|
| 118 | - int totalStep = stepsCount.get();
|
|
| 119 | - log.info("Total step computed: " + totalStep);
|
|
| 102 | + int stepCount = 1 + finalTasksToConsume.stream().mapToInt(DataTaskSupport::stepCount).sum();
|
|
| 103 | + log.info("Total step computed: " + stepCount);
|
|
| 120 | 104 | ProgressionModel progressModel = stepModel.getProgressModel();
|
| 121 | - progressModel.setMaximum(totalStep);
|
|
| 105 | + progressModel.setMaximum(stepCount);
|
|
| 122 | 106 | DataManager dataManager = new DataManager(progressModel, leftSource, rightSource);
|
| 123 | 107 | |
| 108 | + progressModel.increments();
|
|
| 124 | 109 | try {
|
| 125 | 110 | dataManager.consume(finalTasksToConsume);
|
| 111 | + sendMessage(t("observe.ui.datasource.editor.actions.operation.message.done", new Date()));
|
|
| 112 | + return WizardState.SUCCESSED;
|
|
| 126 | 113 | } catch (Exception e) {
|
| 114 | + progressModel.increments();
|
|
| 127 | 115 | if (e instanceof UserCancelException) {
|
| 128 | 116 | return WizardState.CANCELED;
|
| 129 | 117 | }
|
| 130 | 118 | throw e;
|
| 119 | + } finally {
|
|
| 120 | + log.warn(String.format("Expected count: %d - final step count: %d", stepCount, progressModel.getValue()));
|
|
| 131 | 121 | }
|
| 132 | - return WizardState.SUCCESSED;
|
|
| 133 | 122 | }
|
| 134 | 123 | |
| 135 | 124 | } |