-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new functional mapper to create a shared data store (#254)
Create a shared data store, so that the shared data is accessible among the process instances and also among the different workflows. The shared data is grouped by its namespace, the key of the data must be unique in its namespace, but could be duplicate in different namespace.
- Loading branch information
1 parent
8f7b715
commit 7a45422
Showing
20 changed files
with
350 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
workflow-bot-app/src/main/java/com/symphony/bdk/workflow/shared/DefaultSharedDataStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.symphony.bdk.workflow.shared; | ||
|
||
import com.symphony.bdk.workflow.engine.executor.SharedDataStore; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
public class DefaultSharedDataStore implements SharedDataStore { | ||
private final SharedDataRepository repository; | ||
|
||
@Override | ||
public Map<String, Object> getNamespaceData(String namespace) { | ||
return repository.findByNamespace(namespace).orElse(new SharedData()).getProperties(); | ||
} | ||
|
||
@Override | ||
public void putNamespaceData(String namespace, String key, Object data) { | ||
SharedData sharedData = repository.findByNamespace(namespace).orElse(new SharedData().namespace(namespace)); | ||
sharedData.getProperties().put(key, data); | ||
sharedData.setLastUpdated(Instant.now().toEpochMilli()); | ||
repository.save(sharedData); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
workflow-bot-app/src/main/java/com/symphony/bdk/workflow/shared/SharedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.symphony.bdk.workflow.shared; | ||
|
||
import io.hypersistence.utils.hibernate.type.json.JsonType; | ||
import lombok.Data; | ||
import org.hibernate.annotations.GenericGenerator; | ||
import org.hibernate.annotations.NaturalId; | ||
import org.hibernate.annotations.Type; | ||
import org.hibernate.annotations.TypeDef; | ||
|
||
import java.time.Instant; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "SHARED_STATE_DATA") | ||
@TypeDef(name = "json", typeClass = JsonType.class) | ||
@Data | ||
public class SharedData { | ||
@Id | ||
@GeneratedValue(generator = "system-uuid") | ||
@GenericGenerator(name = "system-uuid", strategy = "uuid2") | ||
@Column(name = "ID") | ||
private String id; | ||
|
||
@NaturalId | ||
@Column(length = 15) | ||
private String namespace; | ||
|
||
@Type(type = "json") | ||
@Column(columnDefinition = "json") | ||
private Map<String, Object> properties = new HashMap<>(); | ||
|
||
@Column(name = "LAST_UPDATED", length = 50) | ||
private Long lastUpdated; | ||
|
||
public SharedData namespace(String namespace) { | ||
this.setNamespace(namespace); | ||
return this; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
workflow-bot-app/src/main/java/com/symphony/bdk/workflow/shared/SharedDataRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.symphony.bdk.workflow.shared; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface SharedDataRepository extends JpaRepository<SharedData, String> { | ||
Optional<SharedData> findByNamespace(String namespace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.