Skip to content

Commit

Permalink
Release 0.4.0 with Storage Layer to support DT's Storage Management a…
Browse files Browse the repository at this point in the history
…nd a Query System
  • Loading branch information
piconem committed Sep 5, 2024
1 parent a9e5cbd commit 618652a
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 12 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# WhiteLabel Digital Twin Framework

The White Label Digital Twin (WLDT) library aims to support the design, development, and deployment of Digital Twins within the Internet of Things (IoT) ecosystems.
The library has been designed following the latest DT definitions coming from both Industrial and Scientific domains and identifying DTs as active, flexible and scalable software components.

The complete Documentation of the Library is available at the following link: [https://wldt.github.io/](https://wldt.github.io/)

## Library Dependency Import

The official library repository is available at the following link [https://central.sonatype.com/artifact/io.github.wldt/wldt-core/](https://central.sonatype.com/artifact/io.github.wldt/wldt-core/)
Expand All @@ -10,14 +15,14 @@ For Maven projects you can import the WLDT Library into your ``<dependencies></d
<dependency>
<groupId>io.github.wldt</groupId>
<artifactId>wldt-core</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</dependency>
```

If you are using Gradle use instead the following:

```groovy
implementation group: 'io.github.wldt', name: 'wldt-core', version: '0.3.0'
implementation group: 'io.github.wldt', name: 'wldt-core', version: '0.4.0'
```

## Scientitic Citation & Reference
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file was generated by the Gradle 'init' task.
*/
group = "io.github.wldt"
version = "0.3.0"
version = "0.4.0"
description = "The core library to build White Label Digital Twins"
java.sourceCompatibility = JavaVersion.VERSION_1_8

Expand All @@ -19,7 +19,7 @@ repositories {

dependencies {
api("org.apache.commons:commons-lang3:3.9")
api("ch.qos.logback:logback-classic:1.4.12")
api("ch.qos.logback:logback-classic:1.4.14")
api("javax.inject:javax.inject:1")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.1")
}
Expand Down Expand Up @@ -52,8 +52,8 @@ publishing {
val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots"
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
credentials {
username = (properties["ossrhUsername"] as String?)
password = (properties["ossrhPassword"] as String?)
username = (properties["ossrhToken"] as String?)
password = (properties["ossrhTokenPassword"] as String?)
}
}
maven {
Expand Down
53 changes: 50 additions & 3 deletions src/main/java/it/wldt/storage/DefaultWldtStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import it.wldt.core.state.DigitalTwinStateEventNotification;
import it.wldt.exception.StorageException;
import it.wldt.adapter.physical.PhysicalAssetPropertyVariation;
import it.wldt.storage.model.StorageRecord;
import it.wldt.storage.model.StorageStats;
import it.wldt.storage.model.StorageStatsRecord;
import it.wldt.storage.model.digital.DigitalActionRequestRecord;
import it.wldt.storage.model.lifecycle.LifeCycleVariationRecord;
import it.wldt.storage.model.physical.*;
Expand Down Expand Up @@ -672,9 +675,7 @@ public List<PhysicalAssetDescriptionNotificationRecord> getNewPhysicalAssetDescr

/**
* Save the updated Physical Asset Description
*
* @param physicalAssetDescriptionNotification
* @return the number of Physical Asset Description Available
* @param physicalAssetDescriptionNotification the updated Physical Asset Description
*/
@Override
public void saveUpdatedPhysicalAssetDescriptionNotification(PhysicalAssetDescriptionNotification physicalAssetDescriptionNotification) throws StorageException {
Expand Down Expand Up @@ -974,4 +975,50 @@ public List<PhysicalRelationshipInstanceVariationRecord> getPhysicalAssetRelatio
return result;
}

/**
* Get the number stored information of the target Map
* @return th StorageStatsRecord associated to the target Map
*/
private StorageStatsRecord getStorageStatsFromMap(Map<Long, ? extends StorageRecord> targetMap){

StorageStatsRecord storageStatsRecord = new StorageStatsRecord();
storageStatsRecord.setRecordCount(targetMap.size());

if(!targetMap.isEmpty()){
List<Long> timestamps = new ArrayList<>(targetMap.keySet());
storageStatsRecord.setRecordStartTimestampMs(Collections.min(timestamps));
storageStatsRecord.setRecordEndTimestampMs(Collections.max(timestamps));
}

return storageStatsRecord;
}

/**
* Retrieve and returns storage statistics in terms of the number of stored records for each type and the
* associated time range of the stored records (start and end timestamp)
* @return the storage statistics
* @throws StorageException if an error occurs while retrieving the storage statistics
*/
@Override
public StorageStats getStorageStats() throws StorageException {
try {
// Set the StorageStateRecords in the final class
StorageStats storageStats = new StorageStats();
storageStats.setStateVariationStats(getStorageStatsFromMap(digitalTwinStateMap));
storageStats.setLifeCycleVariationStats(getStorageStatsFromMap(lifeCycleStateMap));
storageStats.setPhysicalAssetPropertyVariationStats(getStorageStatsFromMap(physicalAssetPropertyVariationMap));
storageStats.setPhysicalAssetEventNotificationStats(getStorageStatsFromMap(physicalEventNotificationsMap));
storageStats.setPhysicalAssetActionRequestStats(getStorageStatsFromMap(physicalActionRequestMap));
storageStats.setDigitalActionRequestStats(getStorageStatsFromMap(digitalActionRequestMap));
storageStats.setNewPhysicalAssetDescriptionNotificationStats(getStorageStatsFromMap(newPhysicalAssetDescriptionNotificationMap));
storageStats.setUpdatedPhysicalAssetDescriptionNotificationStats(getStorageStatsFromMap(updatedPhysicalAssetDescriptionNotificationMap));
storageStats.setPhysicalRelationshipInstanceCreatedNotificationStats(getStorageStatsFromMap(physicalRelationshipInstanceCreatedMap));
storageStats.setPhysicalRelationshipInstanceDeletedNotificationStats(getStorageStatsFromMap(physicalRelationshipInstanceDeletedMap));

return storageStats;
}catch (Exception e){
throw new StorageException("Error while retrieving the storage statistics: " + e.getMessage());
}
}

}
10 changes: 9 additions & 1 deletion src/main/java/it/wldt/storage/WldtStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.wldt.core.state.DigitalTwinStateEventNotification;
import it.wldt.exception.StorageException;
import it.wldt.adapter.physical.PhysicalAssetPropertyVariation;
import it.wldt.storage.model.StorageStats;
import it.wldt.storage.model.digital.DigitalActionRequestRecord;
import it.wldt.storage.model.lifecycle.LifeCycleVariationRecord;
import it.wldt.storage.model.physical.*;
Expand Down Expand Up @@ -390,7 +391,6 @@ public void setStorageId(String storageId) {

/**
* Save the updated Physical Asset Description
* @return the number of Physical Asset Description Available
*/
public abstract void saveUpdatedPhysicalAssetDescriptionNotification(PhysicalAssetDescriptionNotification physicalAssetDescriptionNotification) throws StorageException;

Expand Down Expand Up @@ -508,6 +508,14 @@ public void setStorageId(String storageId) {
*/
public abstract List<PhysicalRelationshipInstanceVariationRecord> getPhysicalAssetRelationshipInstanceDeletedNotificationInRange(int startIndex, int endIndex) throws StorageException, IndexOutOfBoundsException, IllegalArgumentException;

/**
* Retrieve and returns storage statistics in terms of the number of stored records for each type and the
* associated time range of the stored records (start and end timestamp)
* @return the storage statistics
* @throws StorageException if an error occurs while retrieving the storage statistics
*/
public abstract StorageStats getStorageStats() throws StorageException;

/**
* Initialize the WLDT Storage
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/it/wldt/storage/model/StorageRecord.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package it.wldt.storage.model;

/**
* Author: Marco Picone ([email protected])
* Date: 01/08/2024
* Storage Record Class
* Represents a singola record in the storage with a unique id
* Represents a single record in the storage with a unique id
*/
public class StorageRecord {

Expand Down
Loading

0 comments on commit 618652a

Please sign in to comment.