Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe
Commits:
-
5ad12da3
by Tony Chemit at 2020-05-18T12:41:05+02:00
-
4b175471
by Tony Chemit at 2020-05-18T12:41:21+02:00
-
a0611f51
by Tony Chemit at 2020-05-18T12:56:36+02:00
10 changed files:
- client-core/src/main/java/fr/ird/observe/client/ui/admin/AdminUIHandler.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/ng/ReferentialSynchronizeSqlListRequestBuilder.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/InsertSqlGenerator.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/InsertSqlStatementGenerator.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/InsertSqlWithCascadeStatementGenerator.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/UpdateSqlGenerator.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/UpdateSqlStatementGenerator.java
- services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/UpdateSqlWithCascadeStatementGenerator.java
- + services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/WithCascadeStatementGenerator.java
Changes:
| ... | ... | @@ -45,6 +45,7 @@ import org.nuiton.jaxx.runtime.swing.wizard.ext.WizardState; |
| 45 | 45 |
import javax.swing.Icon;
|
| 46 | 46 |
import javax.swing.JCheckBox;
|
| 47 | 47 |
import javax.swing.JComponent;
|
| 48 |
+import javax.swing.SwingUtilities;
|
|
| 48 | 49 |
import javax.swing.border.TitledBorder;
|
| 49 | 50 |
import java.awt.Component;
|
| 50 | 51 |
import java.util.Arrays;
|
| ... | ... | @@ -281,7 +282,9 @@ public class AdminUIHandler implements UIHandler<AdminUI> { |
| 281 | 282 |
|
| 282 | 283 |
if (ui.getModel().getStepState(AdminStep.SAVE_LOCAL) == WizardState.PENDING) {
|
| 283 | 284 |
SaveLocalUI tabUI = (SaveLocalUI) ui.getStepUI(AdminStep.SAVE_LOCAL);
|
| 284 |
- tabUI.getStartAction().doClick();
|
|
| 285 |
+ if (!tabUI.getStepModel().isLocalSourceNeedSave()) {
|
|
| 286 |
+ SwingUtilities.invokeLater(tabUI.getContinueAction()::doClick);
|
|
| 287 |
+ }
|
|
| 285 | 288 |
}
|
| 286 | 289 |
|
| 287 | 290 |
}
|
| ... | ... | @@ -110,7 +110,7 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 110 | 110 |
TopiaMetadataEntity metadataEntity = metadataModel.getEntity(referentielName);
|
| 111 | 111 |
if (request.withReferentialToAdd()) {
|
| 112 | 112 |
|
| 113 |
- InsertSqlStatementGenerator<D> sqlStatementGenerator = new InsertSqlStatementGenerator<>(metadataModel, metadataEntity, dtoType);
|
|
| 113 |
+ InsertSqlStatementGenerator sqlStatementGenerator = new InsertSqlStatementGenerator(metadataModel, metadataEntity);
|
|
| 114 | 114 |
ImmutableSet<D> referentialToAdd = request.getReferentialToAdd();
|
| 115 | 115 |
if (ObjectMaterialDto.class.equals(dtoType)) {
|
| 116 | 116 |
|
| ... | ... | @@ -127,7 +127,7 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 127 | 127 |
|
| 128 | 128 |
if (request.withReferentialToUpdate()) {
|
| 129 | 129 |
|
| 130 |
- UpdateSqlStatementGenerator<D> sqlStatementGenerator = new UpdateSqlStatementGenerator<>(metadataModel, metadataEntity, dtoType);
|
|
| 130 |
+ UpdateSqlStatementGenerator sqlStatementGenerator = new UpdateSqlStatementGenerator(metadataModel, metadataEntity);
|
|
| 131 | 131 |
for (D referentialDto : request.getReferentialToUpdate()) {
|
| 132 | 132 |
ImmutableList<String> sql = sqlStatementGenerator.generateSql(referentialDto, null, null);
|
| 133 | 133 |
result.addAll(sql);
|
| ... | ... | @@ -169,8 +169,11 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 169 | 169 |
E e = dao.forTopiaIdEquals(id).findUnique();
|
| 170 | 170 |
Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(e);
|
| 171 | 171 |
int count = 0;
|
| 172 |
- for (List<? extends TopiaEntity> entities : allUsages.values()) {
|
|
| 173 |
- count += entities.size();
|
|
| 172 |
+ for (Map.Entry<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> entry : allUsages.entrySet()) {
|
|
| 173 |
+ if (ObserveReferentialEntity.class.isAssignableFrom(entry.getKey())) {
|
|
| 174 |
+ continue;
|
|
| 175 |
+ }
|
|
| 176 |
+ count+=entry.getValue().size();
|
|
| 174 | 177 |
}
|
| 175 | 178 |
return count;
|
| 176 | 179 |
|
| ... | ... | @@ -144,20 +144,13 @@ public class ReferentialSynchronizeSqlListRequestBuilder { |
| 144 | 144 |
Class<E> entityType = binder.getEntityType();
|
| 145 | 145 |
Class<D> dtoType = binder.getDtoType();
|
| 146 | 146 |
List<E> insertEntities = loadEntities(entityType, tasks);
|
| 147 |
- InsertSqlGenerator<D> insertGenerator;
|
|
| 147 |
+ InsertSqlGenerator insertGenerator;
|
|
| 148 | 148 |
if (metadata.withEntities()) {
|
| 149 | 149 |
Multimap<Class<? extends ReferentialDto>, String> allIds = ArrayListMultimap.create(request.getIdsOnlyExistingOnThisSide());
|
| 150 | 150 |
allIds.putAll(newIds);
|
| 151 |
- insertGenerator = new InsertSqlWithCascadeStatementGenerator<D>(metadataModel, metadata, dtoType, allIds) {
|
|
| 152 |
- |
|
| 153 |
- @Override
|
|
| 154 |
- protected <DD extends ReferentialDto> ImmutableList<String> insertMissingReferential(Class<DD> referentialType, String id) {
|
|
| 155 |
- ReferentialDtoEntityContext<DD, ?, ?> modelContext = DbModelHelper.fromReferentialDto(referentialType);
|
|
| 156 |
- return addExtraInsertStatement(id, modelContext.toEntityBinder());
|
|
| 157 |
- }
|
|
| 158 |
- };
|
|
| 151 |
+ insertGenerator = new InsertSqlWithCascadeStatementGenerator(service, metadataModel, metadata, dtoType, allIds);
|
|
| 159 | 152 |
} else {
|
| 160 |
- insertGenerator = new InsertSqlStatementGenerator<>(metadataModel, metadata, dtoType);
|
|
| 153 |
+ insertGenerator = new InsertSqlStatementGenerator(metadataModel, metadata);
|
|
| 161 | 154 |
}
|
| 162 | 155 |
|
| 163 | 156 |
for (E entity : insertEntities) {
|
| ... | ... | @@ -173,24 +166,13 @@ public class ReferentialSynchronizeSqlListRequestBuilder { |
| 173 | 166 |
|
| 174 | 167 |
private <D extends ReferentialDto, E extends ObserveReferentialEntity> void onUpdate(TopiaMetadataEntity metadata, Set<ReferentialSynchronizeTask> tasks, ReferentialEntityDtoBinderSupport<D, E> binder, Multimap<Class<? extends ReferentialDto>, String> newIds) {
|
| 175 | 168 |
|
| 176 |
- Class<D> dtoType = binder.getDtoType();
|
|
| 177 |
- UpdateSqlGenerator<D> updateGenerator;
|
|
| 178 |
- |
|
| 169 |
+ UpdateSqlGenerator updateGenerator;
|
|
| 179 | 170 |
if (metadata.withEntities()) {
|
| 180 |
- |
|
| 181 | 171 |
Multimap<Class<? extends ReferentialDto>, String> allIds = ArrayListMultimap.create(request.getIdsOnlyExistingOnThisSide());
|
| 182 | 172 |
allIds.putAll(newIds);
|
| 183 |
- |
|
| 184 |
- updateGenerator = new UpdateSqlWithCascadeStatementGenerator<D>(metadataModel, metadata, dtoType, request.getIdsOnlyExistingOnThisSide()) {
|
|
| 185 |
- @Override
|
|
| 186 |
- protected <DD extends ReferentialDto> ImmutableList<String> insertMissingReferential(Class<DD> referentialType, String id) {
|
|
| 187 |
- ReferentialEntityDtoBinderSupport<DD, ObserveReferentialEntity> binder = DbModelHelper.fromReferentialDto(referentialType).toEntityBinder();
|
|
| 188 |
- return addExtraInsertStatement(id, binder);
|
|
| 189 |
- }
|
|
| 190 |
- };
|
|
| 191 |
- |
|
| 173 |
+ updateGenerator = new UpdateSqlWithCascadeStatementGenerator(service, metadataModel, metadata, request.getIdsOnlyExistingOnThisSide());
|
|
| 192 | 174 |
} else {
|
| 193 |
- updateGenerator = new UpdateSqlStatementGenerator<>(metadataModel, metadata, dtoType);
|
|
| 175 |
+ updateGenerator = new UpdateSqlStatementGenerator(metadataModel, metadata);
|
|
| 194 | 176 |
}
|
| 195 | 177 |
|
| 196 | 178 |
for (ReferentialSynchronizeTask task : tasks) {
|
| ... | ... | @@ -208,7 +190,7 @@ public class ReferentialSynchronizeSqlListRequestBuilder { |
| 208 | 190 |
|
| 209 | 191 |
private <D extends ReferentialDto, E extends ObserveReferentialEntity> void onRevert(TopiaMetadataEntity metadata, Set<ReferentialSynchronizeTask> tasks, ReferentialEntityDtoBinderSupport<D, E> binder) {
|
| 210 | 192 |
|
| 211 |
- UpdateSqlStatementGenerator<D> updateGenerator = new UpdateSqlStatementGenerator<>(metadataModel, metadata, binder.getDtoType());
|
|
| 193 |
+ UpdateSqlStatementGenerator updateGenerator = new UpdateSqlStatementGenerator(metadataModel, metadata);
|
|
| 212 | 194 |
for (ReferentialSynchronizeTask task : tasks) {
|
| 213 | 195 |
E entity = loadEntity(task);
|
| 214 | 196 |
D referential = binder.toDto(referentialLocale, entity);
|
| ... | ... | @@ -279,20 +261,6 @@ public class ReferentialSynchronizeSqlListRequestBuilder { |
| 279 | 261 |
|
| 280 | 262 |
}
|
| 281 | 263 |
|
| 282 |
- private <D extends ReferentialDto, E extends ObserveReferentialEntity> ImmutableList<String> addExtraInsertStatement(String id, ReferentialEntityDtoBinderSupport<D, E> binder) {
|
|
| 283 |
- |
|
| 284 |
- Class<E> entityType = binder.getEntityType();
|
|
| 285 |
- Class<D> dtoType = binder.getDtoType();
|
|
| 286 |
- String referentialName = ObserveEntityEnum.valueOf(entityType).name();
|
|
| 287 |
- TopiaMetadataEntity metadata = metadataModel.getEntity(referentialName);
|
|
| 288 |
- |
|
| 289 |
- InsertSqlStatementGenerator<D> insertGenerator = new InsertSqlStatementGenerator<>(metadataModel, metadata, dtoType);
|
|
| 290 |
- D referential = service.loadEntityToReferentialDto(binder, id);
|
|
| 291 |
- |
|
| 292 |
- return insertGenerator.generateSql(referential);
|
|
| 293 |
- |
|
| 294 |
- }
|
|
| 295 |
- |
|
| 296 | 264 |
private <E extends ObserveReferentialEntity> List<E> loadEntities(Class<E> entityType, Set<ReferentialSynchronizeTask> tasks) {
|
| 297 | 265 |
Set<String> ids = tasks.stream().map(ReferentialSynchronizeTask::getReferentialId).collect(Collectors.toSet());
|
| 298 | 266 |
return service.getTopiaPersistenceContext().loadEntities(entityType, ids);
|
| ... | ... | @@ -29,7 +29,7 @@ import fr.ird.observe.dto.referential.ReferentialDto; |
| 29 | 29 |
* @author Tony Chemit - dev@tchemit.fr
|
| 30 | 30 |
* @since ?
|
| 31 | 31 |
*/
|
| 32 |
-public interface InsertSqlGenerator<D extends ReferentialDto> {
|
|
| 32 |
+public interface InsertSqlGenerator {
|
|
| 33 | 33 |
|
| 34 |
- ImmutableList<String> generateSql(D referentialDto);
|
|
| 34 |
+ ImmutableList<String> generateSql(ReferentialDto referentialDto);
|
|
| 35 | 35 |
}
|
| ... | ... | @@ -48,7 +48,7 @@ import java.util.Set; |
| 48 | 48 |
*
|
| 49 | 49 |
* @author Tony Chemit - dev@tchemit.fr
|
| 50 | 50 |
*/
|
| 51 |
-public class InsertSqlStatementGenerator<D extends ReferentialDto> implements InsertSqlGenerator<D> {
|
|
| 51 |
+public class InsertSqlStatementGenerator implements InsertSqlGenerator {
|
|
| 52 | 52 |
|
| 53 | 53 |
private final TopiaMetadataEntity metadataEntity;
|
| 54 | 54 |
private final Set<TopiaMetadataComposition> compositions;
|
| ... | ... | @@ -61,7 +61,7 @@ public class InsertSqlStatementGenerator<D extends ReferentialDto> implements In |
| 61 | 61 |
private final Set<String> primitiveLongPropertyNames;
|
| 62 | 62 |
private final Set<String> primitiveFloatPropertyNames;
|
| 63 | 63 |
|
| 64 |
- public InsertSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity, Class<D> dtoType) {
|
|
| 64 |
+ public InsertSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity) {
|
|
| 65 | 65 |
this.metadataEntity = Objects.requireNonNull(metadataEntity);
|
| 66 | 66 |
this.compositions = topiaMetadataModel.getCompositions(this.metadataEntity);
|
| 67 | 67 |
this.associations = topiaMetadataModel.getAssociations(this.metadataEntity);
|
| ... | ... | @@ -79,7 +79,7 @@ public class InsertSqlStatementGenerator<D extends ReferentialDto> implements In |
| 79 | 79 |
|
| 80 | 80 |
@SuppressWarnings("unchecked")
|
| 81 | 81 |
@Override
|
| 82 |
- public ImmutableList<String> generateSql(D referentialDto) {
|
|
| 82 |
+ public ImmutableList<String> generateSql(ReferentialDto referentialDto) {
|
|
| 83 | 83 |
|
| 84 | 84 |
ImmutableList.Builder<String> result = ImmutableList.builder();
|
| 85 | 85 |
|
| ... | ... | @@ -153,9 +153,8 @@ public class InsertSqlStatementGenerator<D extends ReferentialDto> implements In |
| 153 | 153 |
for (TopiaMetadataAssociation association : associations) {
|
| 154 | 154 |
|
| 155 | 155 |
Collection<ReferentialDtoReference<?, ?>> associationValues = referentialDto.get(association.getTargetPropertyName());
|
| 156 |
- for (ReferentialDtoReference<?, ?> associationValue : associationValues) {
|
|
| 157 |
- String insertAssocationSql = TopiaSqlStatements.generateAssociationInsertStatement(association, id, associationValue.getId());
|
|
| 158 |
- result.add(TopiaSqlStatements.boxAssociationStatement(insertAssocationSql));
|
|
| 156 |
+ for (@SuppressWarnings("rawtypes") ReferentialDtoReference associationValue : associationValues) {
|
|
| 157 |
+ addAssociation(association, id, associationValue, result);
|
|
| 159 | 158 |
}
|
| 160 | 159 |
}
|
| 161 | 160 |
return result.build();
|
| ... | ... | @@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableList; |
| 26 | 26 |
import com.google.common.collect.Multimap;
|
| 27 | 27 |
import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 28 | 28 |
import fr.ird.observe.dto.referential.ReferentialDto;
|
| 29 |
+import fr.ird.observe.services.local.service.actions.synchro.referential.ng.ReferentialSynchronizeServiceLocal;
|
|
| 29 | 30 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataAssociation;
|
| 30 | 31 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
| 31 | 32 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| ... | ... | @@ -40,16 +41,17 @@ import java.util.List; |
| 40 | 41 |
* @author Tony Chemit - dev@tchemit.fr
|
| 41 | 42 |
* @since 5.0
|
| 42 | 43 |
*/
|
| 43 |
-public abstract class InsertSqlWithCascadeStatementGenerator<D extends ReferentialDto> implements InsertSqlGenerator<D>{
|
|
| 44 |
+public class InsertSqlWithCascadeStatementGenerator extends WithCascadeStatementGenerator implements InsertSqlGenerator {
|
|
| 44 | 45 |
|
| 45 |
- private final InsertSqlStatementGenerator<D> delegateGenerator;
|
|
| 46 |
- private final Multimap<Class<? extends ReferentialDto>, String> idsOnlyExistingOnThisSide;
|
|
| 46 |
+ private final InsertSqlStatementGenerator delegateGenerator;
|
|
| 47 | 47 |
|
| 48 |
- protected InsertSqlWithCascadeStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity,
|
|
| 49 |
- Class<D> dtoType,
|
|
| 48 |
+ public InsertSqlWithCascadeStatementGenerator(ReferentialSynchronizeServiceLocal service,
|
|
| 49 |
+ TopiaMetadataModel topiaMetadataModel,
|
|
| 50 |
+ TopiaMetadataEntity metadataEntity,
|
|
| 51 |
+ Class<? extends ReferentialDto> dtoType,
|
|
| 50 | 52 |
Multimap<Class<? extends ReferentialDto>, String> idsOnlyExistingOnThisSide) {
|
| 51 |
- this.idsOnlyExistingOnThisSide = idsOnlyExistingOnThisSide;
|
|
| 52 |
- this.delegateGenerator = new InsertSqlStatementGenerator<D>(topiaMetadataModel, metadataEntity, dtoType) {
|
|
| 53 |
+ super(service, topiaMetadataModel);
|
|
| 54 |
+ this.delegateGenerator = new InsertSqlStatementGenerator(topiaMetadataModel, metadataEntity) {
|
|
| 53 | 55 |
|
| 54 | 56 |
@Override
|
| 55 | 57 |
<DD extends ReferentialDto, RR extends ReferentialDtoReference<DD, RR>> void addAssociation(TopiaMetadataAssociation association,
|
| ... | ... | @@ -57,45 +59,26 @@ public abstract class InsertSqlWithCascadeStatementGenerator<D extends Referenti |
| 57 | 59 |
RR associationValue,
|
| 58 | 60 |
ImmutableList.Builder<String> builder) {
|
| 59 | 61 |
super.addAssociation(association, sourceId, associationValue, builder);
|
| 60 |
- addMissingReferentialIfNecessary(associationValue.getDtoType(), associationValue.getId(), builder);
|
|
| 62 |
+ addMissingReferentialIfNecessary(idsOnlyExistingOnThisSide, associationValue.getDtoType(), associationValue.getId(), builder);
|
|
| 61 | 63 |
}
|
| 62 | 64 |
|
| 63 | 65 |
@Override
|
| 64 | 66 |
protected <DD extends ReferentialDto, RR extends ReferentialDtoReference<DD, RR>> void addReferentialReferenceParameter(RR parameter, List<String> parameters, ImmutableList.Builder<String> result) {
|
| 65 | 67 |
super.addReferentialReferenceParameter(parameter, parameters, result);
|
| 66 |
- addMissingReferentialIfNecessary(parameter.getDtoType(), parameter.getId(), result);
|
|
| 68 |
+ addMissingReferentialIfNecessary(idsOnlyExistingOnThisSide, parameter.getDtoType(), parameter.getId(), result);
|
|
| 67 | 69 |
}
|
| 68 | 70 |
|
| 69 | 71 |
@Override
|
| 70 | 72 |
protected <DD extends ReferentialDto> void addReferentialDtoParameter(DD parameter, List<String> parameters, ImmutableList.Builder<String> result) {
|
| 71 | 73 |
super.addReferentialDtoParameter(parameter, parameters, result);
|
| 72 |
- addMissingReferentialIfNecessary(dtoType, parameter.getId(), result);
|
|
| 74 |
+ addMissingReferentialIfNecessary(idsOnlyExistingOnThisSide, dtoType, parameter.getId(), result);
|
|
| 73 | 75 |
}
|
| 74 | 76 |
};
|
| 75 | 77 |
}
|
| 76 | 78 |
|
| 77 |
- protected abstract <DD extends ReferentialDto> ImmutableList<String> insertMissingReferential(Class<DD> referentialType, String id);
|
|
| 78 |
- |
|
| 79 | 79 |
@Override
|
| 80 |
- public ImmutableList<String> generateSql(D referentialDto) {
|
|
| 81 |
- |
|
| 80 |
+ public ImmutableList<String> generateSql(ReferentialDto referentialDto) {
|
|
| 82 | 81 |
return delegateGenerator.generateSql(referentialDto);
|
| 83 |
- |
|
| 84 |
- }
|
|
| 85 |
- |
|
| 86 |
- private <DD extends ReferentialDto> void addMissingReferentialIfNecessary(Class<DD> associationType, String associationId, ImmutableList.Builder<String> builder) {
|
|
| 87 |
- |
|
| 88 |
- if (idsOnlyExistingOnThisSide.containsEntry(associationType, associationId)) {
|
|
| 89 |
- |
|
| 90 |
- // il faut insérer aussi ce référentiel
|
|
| 91 |
- ImmutableList<String> sql = insertMissingReferential(associationType, associationId);
|
|
| 92 |
- |
|
| 93 |
- builder.addAll(sql);
|
|
| 94 |
- |
|
| 95 |
- // ce référentiel est désormais présent dans les deux sources
|
|
| 96 |
- idsOnlyExistingOnThisSide.remove(associationType, associationId);
|
|
| 97 |
- |
|
| 98 |
- }
|
|
| 99 | 82 |
}
|
| 100 | 83 |
|
| 101 | 84 |
}
|
| ... | ... | @@ -32,7 +32,7 @@ import java.util.Date; |
| 32 | 32 |
* @author Tony Chemit - dev@tchemit.fr
|
| 33 | 33 |
* @since 5
|
| 34 | 34 |
*/
|
| 35 |
-public interface UpdateSqlGenerator<D extends ReferentialDto> {
|
|
| 35 |
+public interface UpdateSqlGenerator {
|
|
| 36 | 36 |
|
| 37 | 37 |
/**
|
| 38 | 38 |
* Generate update sql requests for the given{@code referentialDto}.
|
| ... | ... | @@ -55,7 +55,7 @@ import java.util.stream.Collectors; |
| 55 | 55 |
*
|
| 56 | 56 |
* @author Tony Chemit - dev@tchemit.fr
|
| 57 | 57 |
*/
|
| 58 |
-public class UpdateSqlStatementGenerator<D extends ReferentialDto>implements UpdateSqlGenerator<D> {
|
|
| 58 |
+public class UpdateSqlStatementGenerator implements UpdateSqlGenerator {
|
|
| 59 | 59 |
|
| 60 | 60 |
private static final Logger log = LogManager.getLogger(UpdateSqlStatementGenerator.class);
|
| 61 | 61 |
private final Map<String, String> columnNames;
|
| ... | ... | @@ -69,7 +69,7 @@ public class UpdateSqlStatementGenerator<D extends ReferentialDto>implements Upd |
| 69 | 69 |
private final Set<String> primitiveFloatPropertyNames;
|
| 70 | 70 |
private final Set<String> primitiveDoublePropertyNames;
|
| 71 | 71 |
|
| 72 |
- public UpdateSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity, Class<D> dtoType) {
|
|
| 72 |
+ public UpdateSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity) {
|
|
| 73 | 73 |
this.metadataEntity = Objects.requireNonNull(metadataEntity);
|
| 74 | 74 |
this.compositions = topiaMetadataModel.getCompositions(metadataEntity);
|
| 75 | 75 |
this.associations = topiaMetadataModel.getAssociations(metadataEntity);
|
| ... | ... | @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableSet; |
| 27 | 27 |
import com.google.common.collect.Multimap;
|
| 28 | 28 |
import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 29 | 29 |
import fr.ird.observe.dto.referential.ReferentialDto;
|
| 30 |
+import fr.ird.observe.services.local.service.actions.synchro.referential.ng.ReferentialSynchronizeServiceLocal;
|
|
| 30 | 31 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataAssociation;
|
| 31 | 32 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
| 32 | 33 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| ... | ... | @@ -41,17 +42,16 @@ import java.util.Date; |
| 41 | 42 |
* @author Tony Chemit - dev@tchemit.fr
|
| 42 | 43 |
* @since 5.0
|
| 43 | 44 |
*/
|
| 44 |
-public abstract class UpdateSqlWithCascadeStatementGenerator<D extends ReferentialDto> implements UpdateSqlGenerator<D> {
|
|
| 45 |
+public class UpdateSqlWithCascadeStatementGenerator extends WithCascadeStatementGenerator implements UpdateSqlGenerator {
|
|
| 45 | 46 |
|
| 46 |
- private final UpdateSqlStatementGenerator<D> delegateGenerator;
|
|
| 47 |
- private final Multimap<Class<? extends ReferentialDto>, String> idsOnlyExistingOnThisSide;
|
|
| 47 |
+ private final UpdateSqlStatementGenerator delegateGenerator;
|
|
| 48 | 48 |
|
| 49 |
- protected UpdateSqlWithCascadeStatementGenerator(TopiaMetadataModel topiaMetadataModel,
|
|
| 49 |
+ public UpdateSqlWithCascadeStatementGenerator(ReferentialSynchronizeServiceLocal service,
|
|
| 50 |
+ TopiaMetadataModel topiaMetadataModel,
|
|
| 50 | 51 |
TopiaMetadataEntity metadataEntity,
|
| 51 |
- Class<D> dtoType,
|
|
| 52 | 52 |
Multimap<Class<? extends ReferentialDto>, String> idsOnlyExistingOnThisSide) {
|
| 53 |
- this.idsOnlyExistingOnThisSide = idsOnlyExistingOnThisSide;
|
|
| 54 |
- this.delegateGenerator = new UpdateSqlStatementGenerator<D>(topiaMetadataModel, metadataEntity, dtoType) {
|
|
| 53 |
+ super(service, topiaMetadataModel);
|
|
| 54 |
+ this.delegateGenerator = new UpdateSqlStatementGenerator(topiaMetadataModel, metadataEntity) {
|
|
| 55 | 55 |
|
| 56 | 56 |
|
| 57 | 57 |
<DD extends ReferentialDto, RR extends ReferentialDtoReference<DD, RR>> void addAssociation(TopiaMetadataAssociation association,
|
| ... | ... | @@ -59,41 +59,25 @@ public abstract class UpdateSqlWithCascadeStatementGenerator<D extends Referenti |
| 59 | 59 |
RR associationValue,
|
| 60 | 60 |
ImmutableList.Builder<String> builder) {
|
| 61 | 61 |
super.addAssociation(association, sourceId, associationValue, builder);
|
| 62 |
- addMissingReferentialIfNecessary(associationValue.getDtoType(), associationValue.getId(), builder);
|
|
| 62 |
+ addMissingReferentialIfNecessary(idsOnlyExistingOnThisSide, associationValue.getDtoType(), associationValue.getId(), builder);
|
|
| 63 | 63 |
}
|
| 64 | 64 |
|
| 65 | 65 |
@Override
|
| 66 | 66 |
protected <DD extends ReferentialDto, RR extends ReferentialDtoReference<DD, RR>> void addReferentialReferenceParameter(String columnName, RR parameter, StringBuilder parameters, ImmutableList.Builder<String> result) {
|
| 67 | 67 |
super.addReferentialReferenceParameter(columnName, parameter, parameters, result);
|
| 68 |
- addMissingReferentialIfNecessary(parameter.getDtoType(), parameter.getId(), result);
|
|
| 68 |
+ addMissingReferentialIfNecessary(idsOnlyExistingOnThisSide, parameter.getDtoType(), parameter.getId(), result);
|
|
| 69 | 69 |
}
|
| 70 | 70 |
|
| 71 | 71 |
@Override
|
| 72 | 72 |
protected <DD extends ReferentialDto> void addReferentialDtoParameter(String columnName, DD parameter, StringBuilder parameters, ImmutableList.Builder<String> result) {
|
| 73 | 73 |
super.addReferentialDtoParameter(columnName, parameter, parameters, result);
|
| 74 |
- addMissingReferentialIfNecessary(parameter.getClass(), parameter.getId(), result);
|
|
| 74 |
+ addMissingReferentialIfNecessary(idsOnlyExistingOnThisSide, parameter.getClass(), parameter.getId(), result);
|
|
| 75 | 75 |
}
|
| 76 | 76 |
};
|
| 77 | 77 |
}
|
| 78 | 78 |
|
| 79 |
- protected abstract <DD extends ReferentialDto> ImmutableList<String> insertMissingReferential(Class<DD> referentialType, String id);
|
|
| 80 |
- |
|
| 81 | 79 |
@Override
|
| 82 |
- public ImmutableList<String> generateSql(ReferentialDto referentialDto, ImmutableSet<String> properties, Date addLastUpdateDate) {
|
|
| 83 |
- return delegateGenerator.generateSql(referentialDto, properties, addLastUpdateDate);
|
|
| 80 |
+ public ImmutableList<String> generateSql(ReferentialDto referentialDto, ImmutableSet<String> properties, Date lastUpdateDate) {
|
|
| 81 |
+ return delegateGenerator.generateSql(referentialDto, properties, lastUpdateDate);
|
|
| 84 | 82 |
}
|
| 85 |
- |
|
| 86 |
- private <DD extends ReferentialDto> void addMissingReferentialIfNecessary(Class<DD> associationType, String associationId, ImmutableList.Builder<String> result) {
|
|
| 87 |
- |
|
| 88 |
- if (idsOnlyExistingOnThisSide.containsEntry(associationType, associationId)) {
|
|
| 89 |
- |
|
| 90 |
- // il faut insérer aussi ce référentiel
|
|
| 91 |
- ImmutableList<String> sqlList = insertMissingReferential(associationType, associationId);
|
|
| 92 |
- result.addAll(sqlList);
|
|
| 93 |
- // ce référentiel est désormais présent dans les deux sources
|
|
| 94 |
- idsOnlyExistingOnThisSide.remove(associationType, associationId);
|
|
| 95 |
- |
|
| 96 |
- }
|
|
| 97 |
- }
|
|
| 98 |
- |
|
| 99 | 83 |
}
|
| 1 |
+package fr.ird.observe.services.local.service.actions.synchro.referential.sql;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Services local
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2020 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 com.google.common.collect.ImmutableList;
|
|
| 26 |
+import com.google.common.collect.Multimap;
|
|
| 27 |
+import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
|
| 28 |
+import fr.ird.observe.dto.referential.ReferentialDto;
|
|
| 29 |
+import fr.ird.observe.entities.referentiel.ObserveReferentialEntity;
|
|
| 30 |
+import fr.ird.observe.persistence.ObserveEntityEnum;
|
|
| 31 |
+import fr.ird.observe.services.local.service.actions.synchro.referential.ng.ReferentialSynchronizeServiceLocal;
|
|
| 32 |
+import fr.ird.observe.spi.DbModelHelper;
|
|
| 33 |
+import fr.ird.observe.spi.context.ReferentialDtoEntityContext;
|
|
| 34 |
+import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
|
| 35 |
+import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
|
| 36 |
+ |
|
| 37 |
+/**
|
|
| 38 |
+ * Support statement generator when a cascade can be done on adding new referential.
|
|
| 39 |
+ *
|
|
| 40 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 41 |
+ * @since 8.0
|
|
| 42 |
+ */
|
|
| 43 |
+public abstract class WithCascadeStatementGenerator {
|
|
| 44 |
+ |
|
| 45 |
+ private final ReferentialSynchronizeServiceLocal service;
|
|
| 46 |
+ private final TopiaMetadataModel metadataModel;
|
|
| 47 |
+ |
|
| 48 |
+ protected WithCascadeStatementGenerator(ReferentialSynchronizeServiceLocal service, TopiaMetadataModel metadataModel) {
|
|
| 49 |
+ this.service = service;
|
|
| 50 |
+ this.metadataModel = metadataModel;
|
|
| 51 |
+ }
|
|
| 52 |
+ |
|
| 53 |
+ public <D extends ReferentialDto> void addMissingReferentialIfNecessary(Multimap<Class<? extends ReferentialDto>, String> idsOnlyExistingOnThisSide, Class<D> associationType, String associationId, ImmutableList.Builder<String> builder) {
|
|
| 54 |
+ |
|
| 55 |
+ if (idsOnlyExistingOnThisSide.containsEntry(associationType, associationId)) {
|
|
| 56 |
+ // need to add this referential on this other side
|
|
| 57 |
+ ImmutableList<String> sqlList = insertMissingReferential(associationType, associationId);
|
|
| 58 |
+ builder.addAll(sqlList);
|
|
| 59 |
+ // now this referential is on both side
|
|
| 60 |
+ idsOnlyExistingOnThisSide.remove(associationType, associationId);
|
|
| 61 |
+ }
|
|
| 62 |
+ }
|
|
| 63 |
+ |
|
| 64 |
+ protected <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> ImmutableList<String> insertMissingReferential(Class<D> referentialType, String id) {
|
|
| 65 |
+ ReferentialDtoEntityContext<D, R, E> modelContext = DbModelHelper.fromReferentialDto(referentialType);
|
|
| 66 |
+ |
|
| 67 |
+ Class<E> entityType = modelContext.toEntityType();
|
|
| 68 |
+ String referentialName = ObserveEntityEnum.valueOf(entityType).name();
|
|
| 69 |
+ TopiaMetadataEntity metadata = metadataModel.getEntity(referentialName);
|
|
| 70 |
+ |
|
| 71 |
+ InsertSqlStatementGenerator insertGenerator = new InsertSqlStatementGenerator(metadataModel, metadata);
|
|
| 72 |
+ D referential = service.loadEntityToReferentialDto(modelContext.toEntityBinder(), id);
|
|
| 73 |
+ return insertGenerator.generateSql(referential);
|
|
| 74 |
+ }
|
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+}
|