-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Simplified configuration when the configuration of api client is the same 4 properties added to BdkConfig to specify the global configurations for host, port, scheme and context. These properties can be used if they are not configured in the api client configuration. Version of configuration file is also removed because it seems useless. * Using enhanced configuration in bdk example * Add more test cases and update documentation * Update documentation * Datafeed Repository implementation Create an interface DatafeedRepository for handling storing a datafeed id which is created by using DatafeedServiceV1. Create OnDiskDatafeedRepository implementing the DatafeedRepository for storing datafeed id on disk. In DatafeedServiceV1, users can use the OnDiskDatafeedRepository implementation by default or we can inject their own repository, for example: MongoDB, SQL storage... Update unittest * Update Thibault's comment Rename DatafeedRepository to DatafeedIdRepository Make DatafeedRepository#read return Optional<String> * Update unittest
- Loading branch information
1 parent
9623d47
commit 5b30c83
Showing
6 changed files
with
239 additions
and
72 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...y-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/DatafeedIdRepository.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,24 @@ | ||
package com.symphony.bdk.core.service.datafeed; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* A repository interface for storing a datafeed id. | ||
* By using {@link com.symphony.bdk.core.service.datafeed.impl.DatafeedServiceV1}, the created datafeed id should be persisted manually on the BDK side. | ||
*/ | ||
public interface DatafeedIdRepository { | ||
|
||
/** | ||
* Persists the created datafeed id into the storage. | ||
* | ||
* @param datafeedId the datafeed id to be persisted. | ||
*/ | ||
void write(String datafeedId); | ||
|
||
/** | ||
* Read the persisted datafeed id from the storage. | ||
* | ||
* @return The persisted datafeed id. | ||
*/ | ||
Optional<String> read(); | ||
} |
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
77 changes: 77 additions & 0 deletions
77
...src/main/java/com/symphony/bdk/core/service/datafeed/impl/OnDiskDatafeedIdRepository.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,77 @@ | ||
package com.symphony.bdk.core.service.datafeed.impl; | ||
|
||
import com.symphony.bdk.core.config.model.BdkConfig; | ||
import com.symphony.bdk.core.service.datafeed.DatafeedIdRepository; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* The implementation of {@link DatafeedIdRepository} interface for persisting a datafeed id on disk. | ||
*/ | ||
@Slf4j | ||
public class OnDiskDatafeedIdRepository implements DatafeedIdRepository { | ||
|
||
private static final String DATAFEED_ID_FILE = "datafeed.id"; | ||
|
||
private final BdkConfig config; | ||
|
||
public OnDiskDatafeedIdRepository(BdkConfig config) { | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void write(String datafeedId) { | ||
log.debug("Writing datafeed id {} to file: {}", datafeedId, this.getDatafeedIdFile().toString()); | ||
String agentUrl = this.config.getAgent().getHost() + ":" + this.config.getAgent().getPort(); | ||
try { | ||
FileUtils.writeStringToFile(this.getDatafeedIdFile(), datafeedId + "@" + agentUrl, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
log.error(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Optional<String> read() { | ||
log.debug("Reading datafeed id from file: {}", this.getDatafeedIdFile().toString()); | ||
String datafeedId; | ||
try { | ||
File file = this.getDatafeedIdFile(); | ||
Path datafeedIdPath = Paths.get(file.getPath()); | ||
List<String> lines = Files.readAllLines(datafeedIdPath); | ||
if (lines.isEmpty() || !lines.get(0).contains("@")) { | ||
return Optional.empty(); | ||
} | ||
String[] persistedDatafeed = lines.get(0).split("@"); | ||
datafeedId = persistedDatafeed[0]; | ||
log.info("Retrieved datafeed id from datafeed repository: {}", datafeedId); | ||
return Optional.of(datafeedId); | ||
} catch (IOException e) { | ||
log.debug("No persisted datafeed id could be retrieved from disk"); | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
private File getDatafeedIdFile() { | ||
File file = new File(this.config.getDatafeed().getIdFilePath()); | ||
if (file.isDirectory()) { | ||
file = new File(this.config.getDatafeed().getIdFilePath() + File.separator + DATAFEED_ID_FILE); | ||
} | ||
return file; | ||
} | ||
} |
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.