|
8 | 8 | import it.wldt.core.state.DigitalTwinStateEventNotification; |
9 | 9 | import it.wldt.exception.StorageException; |
10 | 10 | import it.wldt.adapter.physical.PhysicalAssetPropertyVariation; |
| 11 | +import it.wldt.storage.model.StorageRecord; |
| 12 | +import it.wldt.storage.model.StorageStats; |
| 13 | +import it.wldt.storage.model.StorageStatsRecord; |
11 | 14 | import it.wldt.storage.model.digital.DigitalActionRequestRecord; |
12 | 15 | import it.wldt.storage.model.lifecycle.LifeCycleVariationRecord; |
13 | 16 | import it.wldt.storage.model.physical.*; |
@@ -672,9 +675,7 @@ public List<PhysicalAssetDescriptionNotificationRecord> getNewPhysicalAssetDescr |
672 | 675 |
|
673 | 676 | /** |
674 | 677 | * Save the updated Physical Asset Description |
675 | | - * |
676 | | - * @param physicalAssetDescriptionNotification |
677 | | - * @return the number of Physical Asset Description Available |
| 678 | + * @param physicalAssetDescriptionNotification the updated Physical Asset Description |
678 | 679 | */ |
679 | 680 | @Override |
680 | 681 | public void saveUpdatedPhysicalAssetDescriptionNotification(PhysicalAssetDescriptionNotification physicalAssetDescriptionNotification) throws StorageException { |
@@ -974,4 +975,50 @@ public List<PhysicalRelationshipInstanceVariationRecord> getPhysicalAssetRelatio |
974 | 975 | return result; |
975 | 976 | } |
976 | 977 |
|
| 978 | + /** |
| 979 | + * Get the number stored information of the target Map |
| 980 | + * @return th StorageStatsRecord associated to the target Map |
| 981 | + */ |
| 982 | + private StorageStatsRecord getStorageStatsFromMap(Map<Long, ? extends StorageRecord> targetMap){ |
| 983 | + |
| 984 | + StorageStatsRecord storageStatsRecord = new StorageStatsRecord(); |
| 985 | + storageStatsRecord.setRecordCount(targetMap.size()); |
| 986 | + |
| 987 | + if(!targetMap.isEmpty()){ |
| 988 | + List<Long> timestamps = new ArrayList<>(targetMap.keySet()); |
| 989 | + storageStatsRecord.setRecordStartTimestampMs(Collections.min(timestamps)); |
| 990 | + storageStatsRecord.setRecordEndTimestampMs(Collections.max(timestamps)); |
| 991 | + } |
| 992 | + |
| 993 | + return storageStatsRecord; |
| 994 | + } |
| 995 | + |
| 996 | + /** |
| 997 | + * Retrieve and returns storage statistics in terms of the number of stored records for each type and the |
| 998 | + * associated time range of the stored records (start and end timestamp) |
| 999 | + * @return the storage statistics |
| 1000 | + * @throws StorageException if an error occurs while retrieving the storage statistics |
| 1001 | + */ |
| 1002 | + @Override |
| 1003 | + public StorageStats getStorageStats() throws StorageException { |
| 1004 | + try { |
| 1005 | + // Set the StorageStateRecords in the final class |
| 1006 | + StorageStats storageStats = new StorageStats(); |
| 1007 | + storageStats.setStateVariationStats(getStorageStatsFromMap(digitalTwinStateMap)); |
| 1008 | + storageStats.setLifeCycleVariationStats(getStorageStatsFromMap(lifeCycleStateMap)); |
| 1009 | + storageStats.setPhysicalAssetPropertyVariationStats(getStorageStatsFromMap(physicalAssetPropertyVariationMap)); |
| 1010 | + storageStats.setPhysicalAssetEventNotificationStats(getStorageStatsFromMap(physicalEventNotificationsMap)); |
| 1011 | + storageStats.setPhysicalAssetActionRequestStats(getStorageStatsFromMap(physicalActionRequestMap)); |
| 1012 | + storageStats.setDigitalActionRequestStats(getStorageStatsFromMap(digitalActionRequestMap)); |
| 1013 | + storageStats.setNewPhysicalAssetDescriptionNotificationStats(getStorageStatsFromMap(newPhysicalAssetDescriptionNotificationMap)); |
| 1014 | + storageStats.setUpdatedPhysicalAssetDescriptionNotificationStats(getStorageStatsFromMap(updatedPhysicalAssetDescriptionNotificationMap)); |
| 1015 | + storageStats.setPhysicalRelationshipInstanceCreatedNotificationStats(getStorageStatsFromMap(physicalRelationshipInstanceCreatedMap)); |
| 1016 | + storageStats.setPhysicalRelationshipInstanceDeletedNotificationStats(getStorageStatsFromMap(physicalRelationshipInstanceDeletedMap)); |
| 1017 | + |
| 1018 | + return storageStats; |
| 1019 | + }catch (Exception e){ |
| 1020 | + throw new StorageException("Error while retrieving the storage statistics: " + e.getMessage()); |
| 1021 | + } |
| 1022 | + } |
| 1023 | + |
977 | 1024 | } |
0 commit comments