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

Commits:

11 changed files:

Changes:

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/save/SaveLocalModel.java
    ... ... @@ -132,7 +132,7 @@ public class SaveLocalModel extends AdminActionModel {
    132 132
         public boolean isCanSaveLocal() {
    
    133 133
             boolean validate = !doBackup ||
    
    134 134
                     backupFile != null &&
    
    135
    -                        !backupFile.exists() && backupFile.getParentFile().exists() && ObserveUtil.withSqlGzExtension(backupFile.getName());
    
    135
    +                        !backupFile.exists() && backupFile.getParentFile()!=null && backupFile.getParentFile().exists() && ObserveUtil.withSqlGzExtension(backupFile.getName());
    
    136 136
             if (validate) {
    
    137 137
                 String filename = getBackupFileName();
    
    138 138
                 validate = !filename.isEmpty() && !filename.contains(".");
    

  • client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/wizard/connexion/DataSourceSelectorHandler.java
    ... ... @@ -63,7 +63,7 @@ public class DataSourceSelectorHandler implements UIHandler<DataSourceSelector>
    63 63
             String text = null;
    
    64 64
             if (valid) {
    
    65 65
                 ObserveDataSourceInformation dataSourceInformation = model.getDataSourceInformation();
    
    66
    -            if (dataSourceInformation != null && dataSourceInformation.getVersion() != null) {
    
    66
    +            if (model.isInit() && dataSourceInformation != null && dataSourceInformation.getVersion() != null) {
    
    67 67
                     text = ObserveDataSourceInformationTemplate.generate(dataSourceInformation);
    
    68 68
                 }
    
    69 69
             } else {
    

  • client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/wizard/tabs/ChooseDbModeUIHandler.java
    ... ... @@ -52,8 +52,10 @@ class ChooseDbModeUIHandler extends StorageTabUIHandler<ChooseDbModeUI> implemen
    52 52
     
    
    53 53
             PropertyChangeListener listener = evt -> {
    
    54 54
                 StorageUIModel model = (StorageUIModel) evt.getSource();
    
    55
    -            String txt = StorageUIModelTemplate.generateDataSourceSelectModeResume(model);
    
    56
    -            ui.getResume().setText(txt);
    
    55
    +            if (model.isInit() && model.isValid()) {
    
    56
    +                String txt = StorageUIModelTemplate.generateDataSourceSelectModeResume(model);
    
    57
    +                ui.getResume().setText(txt);
    
    58
    +            }
    
    57 59
             };
    
    58 60
             StorageUIModel model = ui.getModel();
    
    59 61
             model.addPropertyChangeListener(StorageUIModel.DB_MODE_PROPERTY_NAME, listener);
    

  • client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/wizard/tabs/ConfigUIHandler.java
    ... ... @@ -124,7 +124,10 @@ public class ConfigUIHandler extends StorageTabUIHandler<ConfigUI> implements UI
    124 124
         }
    
    125 125
     
    
    126 126
         String updateConnexionStatusText(@SuppressWarnings("unused") ConnexionStatus status) {
    
    127
    -        return StorageUIModelTemplate.generateConnexionTestResult(ui.getModel());
    
    127
    +        if (ui.getModel().isInit()) {
    
    128
    +            return StorageUIModelTemplate.generateConnexionTestResult(ui.getModel());
    
    129
    +        }
    
    130
    +        return "";
    
    128 131
         }
    
    129 132
     
    
    130 133
     
    

  • persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java
    ... ... @@ -58,8 +58,9 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    58 58
         private static final String INSERT_LAST_UPDATE_PATTERN = "INSERT INTO COMMON.LASTUPDATEDATE (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, TYPE, LASTUPDATEDATE) VALUES ('fr.ird.observe.entities.LastUpdateDate#1236861982132#0.%03d', 0, CURRENT_TIMESTAMP, '%s', CURRENT_TIMESTAMP);";
    
    59 59
         private static final String CREATE_SCHEMA_SQL = "CREATE SCHEMA %s;";
    
    60 60
         protected final String authenticationToken;
    
    61
    -    private transient TopiaMetadataModelSupport topiaMetadataModelSupport;
    
    62 61
         private final TopiaSqlTablesFactory topiaSqlTablesFactory;
    
    62
    +    private transient TopiaMetadataModelSupport topiaMetadataModelSupport;
    
    63
    +    private transient ObserveTopiaUsageModel topiaUsageModel;
    
    63 64
     
    
    64 65
         /**
    
    65 66
          * Mise à {@code true} quand au moins une connection a été effectuée.
    
    ... ... @@ -89,6 +90,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    89 90
                             getSessionRegistry(),
    
    90 91
                             getTopiaMetadataModelSupport(),
    
    91 92
                             this,
    
    93
    +                        getTopiaUsageModel(),
    
    92 94
                             getConfiguration()
    
    93 95
                     )
    
    94 96
             );
    
    ... ... @@ -277,7 +279,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    277 279
             return referentialTables;
    
    278 280
         }
    
    279 281
     
    
    280
    -    public <E extends ReferentialEntity> TopiaSqlTables getReferentialTable(Class<E> entityType) {
    
    282
    +    public <E extends ReferentialEntity<?,?>> TopiaSqlTables getReferentialTable(Class<E> entityType) {
    
    281 283
             ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entityType);
    
    282 284
             return referentialTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), entityEnum);
    
    283 285
         }
    
    ... ... @@ -286,6 +288,10 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    286 288
             return topiaMetadataModelSupport == null ? topiaMetadataModelSupport = newModelSupport() : topiaMetadataModelSupport;
    
    287 289
         }
    
    288 290
     
    
    291
    +    public ObserveTopiaUsageModel getTopiaUsageModel() {
    
    292
    +        return topiaUsageModel == null ? topiaUsageModel = new ObserveTopiaUsageModel() : topiaUsageModel;
    
    293
    +    }
    
    294
    +
    
    289 295
         private void executeSqlStatements0(TopiaSqlScript content) {
    
    290 296
     
    
    291 297
             SqlScriptReader scriptLocation = content.getLocation();
    
    ... ... @@ -326,7 +332,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    326 332
     
    
    327 333
         private static class TripReplicateTablesPredicate implements TopiaSqlTablesFactory.TopiaSqlTablesPredicate {
    
    328 334
     
    
    329
    -        private final Set<TopiaMetadataEntity> dones = new LinkedHashSet<>();
    
    335
    +        private final Set<TopiaMetadataEntity> done = new LinkedHashSet<>();
    
    330 336
             private final Set<String> sections = ImmutableSet.of(
    
    331 337
                     ObserveEntityEnum.ll_observation_Branchline.name(),
    
    332 338
                     ObserveEntityEnum.ll_observation_Basket.name(),
    
    ... ... @@ -337,7 +343,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    337 343
     
    
    338 344
             @Override
    
    339 345
             public boolean acceptEntity(TopiaMetadataEntity metadataEntity) {
    
    340
    -            return dones.add(metadataEntity);
    
    346
    +            return done.add(metadataEntity);
    
    341 347
             }
    
    342 348
     
    
    343 349
             @Override
    

  • persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaPersistenceContext.java
    ... ... @@ -29,7 +29,6 @@ import org.apache.logging.log4j.LogManager;
    29 29
     import org.apache.logging.log4j.Logger;
    
    30 30
     import org.nuiton.topia.persistence.TopiaDao;
    
    31 31
     import org.nuiton.topia.persistence.TopiaEntity;
    
    32
    -import org.nuiton.topia.persistence.TopiaEntityEnumProvider;
    
    33 32
     import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContextConstructorParameter;
    
    34 33
     import org.nuiton.topia.persistence.internal.support.TopiaUsageSupportImpl;
    
    35 34
     import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    ... ... @@ -39,6 +38,7 @@ import org.nuiton.topia.persistence.script.TopiaSqlScript;
    39 38
     import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport;
    
    40 39
     import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    41 40
     import org.nuiton.topia.persistence.support.TopiaUsageSupport;
    
    41
    +import org.nuiton.topia.persistence.usage.TopiaUsageModel;
    
    42 42
     
    
    43 43
     import java.net.URL;
    
    44 44
     import java.sql.Connection;
    
    ... ... @@ -57,8 +57,8 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste
    57 57
     
    
    58 58
         private final boolean showSql;
    
    59 59
         private final TopiaMetadataModelSupport topiaMetadataModelSupport;
    
    60
    -    private TopiaEntityEnumProvider topiaEntityEnumProvider;
    
    61
    -    private TopiaUsageSupport topiaUsageSupport;
    
    60
    +    private final TopiaUsageModel topiaUsageModel;
    
    61
    +    private transient TopiaUsageSupport topiaUsageSupport;
    
    62 62
     
    
    63 63
         public ObserveTopiaPersistenceContext(AbstractTopiaPersistenceContextConstructorParameter parameter) {
    
    64 64
             super(parameter);
    
    ... ... @@ -68,17 +68,15 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste
    68 68
         public ObserveTopiaPersistenceContext(ObserveTopiaPersistenceContextConstructorParameter parameter) {
    
    69 69
             super(parameter);
    
    70 70
             topiaMetadataModelSupport = parameter.getTopiaMetadataModelSupport();
    
    71
    -        topiaEntityEnumProvider = parameter.getTopiaEntityEnumProvider();
    
    71
    +        topiaUsageModel = parameter.getTopiaUsageModel();
    
    72 72
             this.showSql = parameter.getConfiguration().isShowSql();
    
    73 73
         }
    
    74 74
     
    
    75 75
         public <E extends Entity> Date getLastUpdateDate(Class<E> entityType) {
    
    76
    -
    
    77 76
             LastUpdateDateTopiaDao dao = getDao(LastUpdateDate.class, LastUpdateDateTopiaDao.class);
    
    78 77
             LastUpdateDate lastUpdateDate = dao.findUniqueByType(entityType.getName());
    
    79 78
             log.debug("getLastUpdateDate: " + lastUpdateDate.getLastUpdateDate() + " for entity type: " + entityType.getName());
    
    80 79
             return lastUpdateDate.getLastUpdateDate();
    
    81
    -
    
    82 80
         }
    
    83 81
     
    
    84 82
         public <E extends Entity> void updateLastUpdateDate(E entity, Date date) {
    
    ... ... @@ -125,7 +123,6 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste
    125 123
             Objects.requireNonNull(entityEnum, "Entity " + entity + " is not managed by ToPIA");
    
    126 124
             //noinspection unchecked
    
    127 125
             return (Class<E>) entityEnum.getContract();
    
    128
    -
    
    129 126
         }
    
    130 127
     
    
    131 128
         public <E extends Entity> TopiaDao<E> getDao(E entity) {
    
    ... ... @@ -173,9 +170,7 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste
    173 170
                 }
    
    174 171
                 dao.delete(entity);
    
    175 172
             }
    
    176
    -
    
    177 173
             updateLastUpdateDate(entityType, now);
    
    178
    -
    
    179 174
         }
    
    180 175
     
    
    181 176
         public void executeSqlScript(URL location) {
    
    ... ... @@ -201,29 +196,27 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste
    201 196
         }
    
    202 197
     
    
    203 198
         public TopiaUsageSupport getTopiaUsageSupport() {
    
    204
    -        if (topiaUsageSupport == null) {
    
    205
    -            topiaUsageSupport = new TopiaUsageSupportImpl(this, topiaMetadataModelSupport, topiaEntityEnumProvider);
    
    206
    -        }
    
    207
    -        return topiaUsageSupport;
    
    199
    +        return topiaUsageSupport == null ? topiaUsageSupport = new TopiaUsageSupportImpl(this, topiaUsageModel) : topiaUsageSupport;
    
    208 200
         }
    
    209 201
     
    
    210
    -    public <E extends DataEntity> E getMultipleAssociationParent(Class<E> associationContainerType, String associationName, String associationId) {
    
    202
    +    public <E extends DataEntity<?, ?>> E getMultipleAssociationParent(Class<E> associationContainerType, String associationName, String associationId) {
    
    211 203
             ObserveEntityEnum parentEntityEnum = ObserveEntityEnum.valueOf(associationContainerType);
    
    212 204
             TopiaMetadataModel metadataModel = topiaMetadataModelSupport.getMetadataModel();
    
    213 205
             String parentId = metadataModel.getMultipleAssociationParentId(getSqlSupport(), parentEntityEnum, associationName, associationId);
    
    214 206
             return getAssociationParent(associationContainerType, associationName, associationId, parentId);
    
    215 207
         }
    
    216 208
     
    
    217
    -    public <E extends DataEntity> E getSingleAssociationParent(Class<E> associationContainerType, String associationName, String associationId) {
    
    209
    +    public <E extends DataEntity<?, ?>> E getSingleAssociationParent(Class<E> associationContainerType, String associationName, String associationId) {
    
    218 210
             ObserveEntityEnum parentEntityEnum = ObserveEntityEnum.valueOf(associationContainerType);
    
    219 211
             TopiaMetadataModel metadataModel = topiaMetadataModelSupport.getMetadataModel();
    
    220 212
             String parentId = metadataModel.getSingleAssociationParentId(getSqlSupport(), parentEntityEnum, associationName, associationId);
    
    221 213
             return getAssociationParent(associationContainerType, associationName, associationId, parentId);
    
    222 214
         }
    
    223 215
     
    
    224
    -    private <E extends DataEntity> E getAssociationParent(Class<E> associationContainerType, String associationName, String associationId, String parentId) {
    
    216
    +    @SuppressWarnings("unchecked")
    
    217
    +    private <E extends DataEntity<?, ?>> E getAssociationParent(Class<E> associationContainerType, String associationName, String associationId, String parentId) {
    
    225 218
             if (parentId == null) {
    
    226
    -            @SuppressWarnings("unchecked")
    
    219
    +            @SuppressWarnings({"rawtypes"})
    
    227 220
                 Class<? extends DataEntity> associationType = getTopiaIdFactory().getClassName(associationId);
    
    228 221
                 throw new DataAssociationParentNotFoundException(DbModelHelper.fromDataEntity(associationType).toDtoType(), associationName, associationId);
    
    229 222
             }
    

  • persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaPersistenceContextConstructorParameter.java
    ... ... @@ -29,13 +29,16 @@ import org.nuiton.topia.persistence.internal.HibernateProvider;
    29 29
     import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry;
    
    30 30
     import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport;
    
    31 31
     import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport;
    
    32
    +import org.nuiton.topia.persistence.support.TopiaUsageSupport;
    
    33
    +import org.nuiton.topia.persistence.usage.TopiaUsageModel;
    
    32 34
     
    
    33 35
     import java.util.Objects;
    
    34 36
     
    
    35 37
     class ObserveTopiaPersistenceContextConstructorParameter extends AbstractTopiaPersistenceContextConstructorParameter {
    
    36 38
     
    
    37 39
         private final TopiaMetadataModelSupport topiaMetadataModelSupport;
    
    38
    -    private final TopiaEntityEnumProvider topiaEntityEnumProvider;
    
    40
    +    private final TopiaEntityEnumProvider<?> topiaEntityEnumProvider;
    
    41
    +    private final TopiaUsageModel topiaUsageModel;
    
    39 42
         private final ObserveTopiaConfiguration configuration;
    
    40 43
     
    
    41 44
         /**
    
    ... ... @@ -45,13 +48,15 @@ class ObserveTopiaPersistenceContextConstructorParameter extends AbstractTopiaPe
    45 48
          * @param sessionRegistry           hibernate session registry
    
    46 49
          * @param topiaMetadataModelSupport metaData model support
    
    47 50
          * @param topiaEntityEnumProvider   entity enum provider
    
    51
    +     * @param topiaUsageModel           topia usage support
    
    48 52
          * @param configuration             topia configuration
    
    49 53
          */
    
    50
    -    public ObserveTopiaPersistenceContextConstructorParameter(HibernateProvider hibernateProvider, TopiaFiresSupport applicationFiresSupport, TopiaIdFactory topiaIdFactory, TopiaHibernateSessionRegistry sessionRegistry, TopiaMetadataModelSupport topiaMetadataModelSupport, TopiaEntityEnumProvider topiaEntityEnumProvider, ObserveTopiaConfiguration configuration) {
    
    54
    +    public ObserveTopiaPersistenceContextConstructorParameter(HibernateProvider hibernateProvider, TopiaFiresSupport applicationFiresSupport, TopiaIdFactory topiaIdFactory, TopiaHibernateSessionRegistry sessionRegistry, TopiaMetadataModelSupport topiaMetadataModelSupport, TopiaEntityEnumProvider<?> topiaEntityEnumProvider, TopiaUsageModel topiaUsageModel, ObserveTopiaConfiguration configuration) {
    
    51 55
             super(hibernateProvider, applicationFiresSupport, topiaIdFactory, sessionRegistry);
    
    52 56
             this.topiaMetadataModelSupport = Objects.requireNonNull(topiaMetadataModelSupport);
    
    53
    -        this.topiaEntityEnumProvider = topiaEntityEnumProvider;
    
    54
    -        this.configuration = configuration;
    
    57
    +        this.topiaEntityEnumProvider = Objects.requireNonNull(topiaEntityEnumProvider);
    
    58
    +        this.topiaUsageModel = Objects.requireNonNull(topiaUsageModel);
    
    59
    +        this.configuration = Objects.requireNonNull(configuration);
    
    55 60
         }
    
    56 61
     
    
    57 62
         public TopiaMetadataModelSupport getTopiaMetadataModelSupport() {
    
    ... ... @@ -62,7 +67,11 @@ class ObserveTopiaPersistenceContextConstructorParameter extends AbstractTopiaPe
    62 67
             return configuration;
    
    63 68
         }
    
    64 69
     
    
    65
    -    public TopiaEntityEnumProvider getTopiaEntityEnumProvider() {
    
    70
    +    public TopiaEntityEnumProvider<?> getTopiaEntityEnumProvider() {
    
    66 71
             return topiaEntityEnumProvider;
    
    67 72
         }
    
    73
    +
    
    74
    +    public TopiaUsageModel getTopiaUsageModel() {
    
    75
    +        return topiaUsageModel;
    
    76
    +    }
    
    68 77
     }

  • pom.xml
    ... ... @@ -24,7 +24,7 @@
    24 24
       <parent>
    
    25 25
         <groupId>io.ultreia.maven</groupId>
    
    26 26
         <artifactId>pom</artifactId>
    
    27
    -    <version>2020.26</version>
    
    27
    +    <version>2020.27</version>
    
    28 28
       </parent>
    
    29 29
     
    
    30 30
       <groupId>fr.ird.observe</groupId>
    
    ... ... @@ -162,7 +162,7 @@
    162 162
         <maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
    
    163 163
         <buildDate>${maven.build.timestamp}</buildDate>
    
    164 164
     
    
    165
    -    <lib.version.toolkit>4.31</lib.version.toolkit>
    
    165
    +    <lib.version.toolkit>4.32</lib.version.toolkit>
    
    166 166
         <lib.version.nuiton.validation>3.1</lib.version.nuiton.validation>
    
    167 167
         <!--can't use 1.4.197 (date has changed + blob also)-->
    
    168 168
         <lib.version.h2>1.4.196</lib.version.h2>
    
    ... ... @@ -176,7 +176,7 @@
    176 176
         <!--<lib.version.java4all.i18n>4.0-beta-3-SNAPSHOT</lib.version.java4all.i18n>-->
    
    177 177
         <!--<lib.version.java4all.config>1.0.8-SNAPSHOT</lib.version.java4all.config>-->
    
    178 178
         <!--<lib.version.nuiton.topia>3.4.2-SNAPSHOT</lib.version.nuiton.topia>-->
    
    179
    -<!--    <lib.version.java4all.topia>1.20-SNAPSHOT</lib.version.java4all.topia>-->
    
    179
    +    <lib.version.java4all.topia>1.22</lib.version.java4all.topia>
    
    180 180
         <!--<lib.version.java4all.http>1.0.17-SNAPSHOT</lib.version.java4all.http>-->
    
    181 181
     
    
    182 182
         <!-- license header configuration -->
    

  • services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/DeleteSqlStatementGenerator.java
    ... ... @@ -51,7 +51,7 @@ public class DeleteSqlStatementGenerator {
    51 51
         public DeleteSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity) {
    
    52 52
             this.metadataEntity = Objects.requireNonNull(metadataEntity);
    
    53 53
             this.associations = topiaMetadataModel.getAssociations(metadataEntity);
    
    54
    -        this.reverseAssociations = topiaMetadataModel.getReverseAssociations(metadataEntity);
    
    54
    +        this.reverseAssociations = topiaMetadataModel.getReverseManyToManyAssociations(metadataEntity);
    
    55 55
         }
    
    56 56
     
    
    57 57
         public List<String> generateSql(String id) {
    

  • services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/ReplaceSqlStatementGenerator.java
    ... ... @@ -58,7 +58,7 @@ public class ReplaceSqlStatementGenerator {
    58 58
     
    
    59 59
         public ReplaceSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity) {
    
    60 60
             this.compositions = Objects.requireNonNull(topiaMetadataModel).getReverseCompositions(Objects.requireNonNull(metadataEntity));
    
    61
    -        this.associations = topiaMetadataModel.getReverseAssociations(metadataEntity);
    
    61
    +        this.associations = topiaMetadataModel.getReverseManyToManyAssociations(metadataEntity);
    
    62 62
         }
    
    63 63
     
    
    64 64
         public ImmutableList<String> generateSql(String sourceId, String replacementId) {
    

  • services-local/src/main/java/fr/ird/observe/services/local/service/usage/UsageServiceLocal.java
    ... ... @@ -44,6 +44,8 @@ import fr.ird.observe.spi.context.DataDtoEntityContext;
    44 44
     import fr.ird.observe.spi.context.DtoEntityContext;
    
    45 45
     import fr.ird.observe.spi.context.ReferentialDtoEntityContext;
    
    46 46
     import fr.ird.observe.spi.map.ImmutableTypedMap;
    
    47
    +import org.apache.logging.log4j.LogManager;
    
    48
    +import org.apache.logging.log4j.Logger;
    
    47 49
     import org.nuiton.topia.persistence.TopiaEntity;
    
    48 50
     import org.nuiton.topia.persistence.support.TopiaUsageSupport;
    
    49 51
     
    
    ... ... @@ -58,17 +60,33 @@ import java.util.Map;
    58 60
      */
    
    59 61
     public class UsageServiceLocal extends ObserveServiceLocal implements UsageService {
    
    60 62
     
    
    63
    +    private static final Logger log = LogManager.getLogger(UsageServiceLocal.class);
    
    64
    +
    
    61 65
         @Override
    
    62 66
         public <D extends ReferentialDto> DtoUsageCountResult<D> count(DtoUsageCountRequest<D> request) {
    
    63 67
             ReferentialEntity<D, ?> entity = loadEntity(request.getDtoType(), request.getId());
    
    64 68
     
    
    65 69
             TopiaUsageSupport topiaUsageSupport = serviceContext.getTopiaPersistenceContext().getTopiaUsageSupport();
    
    66
    -        Map<Class<? extends TopiaEntity>, Long> compositions = topiaUsageSupport.countReverseCompositions(entity, e -> true);
    
    67
    -        Map<Class<? extends TopiaEntity>, Long> associations = topiaUsageSupport.countReverseAssociations(entity, DtoModelHelper::isData);
    
    68
    -
    
    69 70
             ImmutableTypedMap.Builder<Long> result = ImmutableTypedMap.builder();
    
    70
    -        buildCountUsageResult(compositions, result);
    
    71
    -        buildCountUsageResult(associations, result);
    
    71
    +
    
    72
    +        Map<Class<? extends TopiaEntity>, Long> compositions = topiaUsageSupport.countReverseCompositions(entity, e -> true);
    
    73
    +        long compositionsSum = compositions.values().stream().reduce(Long::sum).orElse(0L);
    
    74
    +        if (compositionsSum > 0) {
    
    75
    +            log.info(String.format("Found %d entity(ies) in reverse composition of entity: %s", compositionsSum, entity.getTopiaId()));
    
    76
    +            buildCountUsageResult(compositions, result);
    
    77
    +        }
    
    78
    +        Map<Class<? extends TopiaEntity>, Long> manyToManyAssociations = topiaUsageSupport.countReverseManyToManyAssociations(entity, DtoModelHelper::isData);
    
    79
    +        long manyToManyAssociationsSum = manyToManyAssociations.values().stream().reduce(Long::sum).orElse(0L);
    
    80
    +        if (manyToManyAssociationsSum > 0) {
    
    81
    +            log.info(String.format("Found %d entity(ies) in reverse many to many association of entity: %s", manyToManyAssociationsSum, entity.getTopiaId()));
    
    82
    +            buildCountUsageResult(manyToManyAssociations, result);
    
    83
    +        }
    
    84
    +        Map<Class<? extends TopiaEntity>, Long> oneToManyAssociations = topiaUsageSupport.countReverseOneToManyAssociations(entity, DtoModelHelper::isData);
    
    85
    +        long oneToManyAssociationsSum = oneToManyAssociations.values().stream().reduce(Long::sum).orElse(0L);
    
    86
    +        if (oneToManyAssociationsSum > 0) {
    
    87
    +            log.info(String.format("Found %d entity(ies) in reverse one to many association of entity: %s", oneToManyAssociationsSum, entity.getTopiaId()));
    
    88
    +//        buildCountUsageResult(oneToManyAssociations, result);
    
    89
    +        }
    
    72 90
             return new DtoUsageCountResult<>(request, result.build());
    
    73 91
         }
    
    74 92
     
    
    ... ... @@ -81,14 +99,23 @@ public class UsageServiceLocal extends ObserveServiceLocal implements UsageServi
    81 99
             Class<T> dtoType = DtoModelHelper.getDtoType(targetType);
    
    82 100
             DtoEntityContext<T, R, Entity, ?> entityContext = DbModelHelper.fromDto(dtoType);
    
    83 101
             Class<Entity> entityType = entityContext.toEntityType();
    
    84
    -
    
    85
    -        List<Entity> compositions = topiaUsageSupport.findReverseComposition(entity, entityType);
    
    86
    -        List<Entity> associations = topiaUsageSupport.findReverseAssociation(entity, entityType);
    
    87
    -
    
    88 102
             ImmutableSet.Builder<R> result = ImmutableSet.builder();
    
    89 103
     
    
    90
    -        buildUsageResult(entityType, compositions, result);
    
    91
    -        buildUsageResult(entityType, associations, result);
    
    104
    +        List<Entity> compositions = topiaUsageSupport.findReverseComposition(entity, entityType);
    
    105
    +        if (compositions.size() > 0) {
    
    106
    +            log.info(String.format("Found %d entity(ies) in reverse composition of entity: %s for type: %s", compositions.size(), entity.getTopiaId(), entityType.getName()));
    
    107
    +            buildFindUsageResult(entityType, compositions, result);
    
    108
    +        }
    
    109
    +        List<Entity> manyToManyAssociations = topiaUsageSupport.findReverseManyToManyAssociation(entity, entityType);
    
    110
    +        if (manyToManyAssociations.size() > 0) {
    
    111
    +            log.info(String.format("Found %d entity(ies) in reverse many to many composition of entity: %s for type: %s", manyToManyAssociations.size(), entity.getTopiaId(), entityType.getName()));
    
    112
    +            buildFindUsageResult(entityType, manyToManyAssociations, result);
    
    113
    +        }
    
    114
    +        List<Entity> oneToManyAssociations = topiaUsageSupport.findReverseOneToManyAssociation(entity, entityType);
    
    115
    +        if (oneToManyAssociations.size() > 0) {
    
    116
    +            log.info(String.format("Found %d entity(ies) in reverse one to many composition of entity: %s for type: %s", oneToManyAssociations.size(), entity.getTopiaId(), entityType.getName()));
    
    117
    +//        buildFindUsageResult(entityType, oneToManyAssociations, result);
    
    118
    +        }
    
    92 119
             return result.build();
    
    93 120
         }
    
    94 121
     
    
    ... ... @@ -106,7 +133,7 @@ public class UsageServiceLocal extends ObserveServiceLocal implements UsageServi
    106 133
         }
    
    107 134
     
    
    108 135
         @SuppressWarnings({"rawtypes", "unchecked"})
    
    109
    -    private <R extends DtoReference<?, R>> void buildUsageResult(Class<? extends TopiaEntity> type, List<? extends TopiaEntity> entities, ImmutableSet.Builder<R> result) {
    
    136
    +    private <R extends DtoReference<?, R>> void buildFindUsageResult(Class<? extends TopiaEntity> type, List<? extends TopiaEntity> entities, ImmutableSet.Builder<R> result) {
    
    110 137
             if (ReferentialEntity.class.isAssignableFrom(type)) {
    
    111 138
                 addAllReferentialUsage((Class) type, (List) entities, (ImmutableSet.Builder) result);
    
    112 139
             } else {