Skip to content

Commit

Permalink
java-wrapper: 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dsun0720 committed Apr 29, 2022
1 parent 29c88a8 commit b1915fa
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 72 deletions.
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>co.featureflags</groupId>
<artifactId>ffc-java-server-sdk-wrapper</artifactId>
<version>1.0</version>
<version>1.1</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -40,9 +40,15 @@
<repositories>
<repository>
<id>github-ffc-java-sdk-repo</id>
<name>The Maven Repository on Github</name>
<name>github-ffc-java-sdk-repo</name>
<url>https://feature-flags-co.github.io/ffc-java-sdk/maven-repo</url>
</repository>

<repository>
<id>github-ffc-java-intergrations-repo</id>
<name>The Maven Repository on Github</name>
<url>https://feature-flags-co.github.io/ffc-java-intergrations/maven-repo</url>
</repository>
</repositories>

<properties>
Expand All @@ -61,7 +67,7 @@

<dependency>
<groupId>co.featureflags</groupId>
<artifactId>ffc-java-server-sdk</artifactId>
<artifactId>ffc-java-springboot</artifactId>
<version>1.0</version>
</dependency>

Expand Down
61 changes: 0 additions & 61 deletions src/main/java/co/featureflags/wrapper/config/SDKConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FeatureFlagController {

private final FFCSDKService sdkService;

@Value("${ffc.envSecret}")
@Value("${ffc.spring.env-secret}")
private String envSecret;

private final static String INVALID_REQUEST = "Unauthorized";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/co/featureflags/wrapper/model/Message.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package co.featureflags.wrapper.model;

import co.featureflags.commons.model.BasicState;
import co.featureflags.commons.model.BasicFlagState;

public final class Message extends BasicState {
public final class Message extends BasicFlagState {
private Message(boolean success, String message) {
super(success, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@
import co.featureflags.commons.model.FlagState;
import co.featureflags.server.exterior.FFCClient;
import co.featureflags.wrapper.model.Message;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Service
public class FFCSDKServiceImp implements FFCSDKService {
public class FFCSDKServiceImp implements FFCSDKService, InitializingBean {

private final static Logger LOG = LoggerFactory.getLogger(FFCSDKServiceImp.class);

private final static String DEFAULT_VALUE = "NOT FOUND";

@Value("${ffc.offline}")
@Value("${ffc.spring.offline}")
private boolean offline;

@Value("${ffc.dataFile}")
Expand Down Expand Up @@ -63,4 +69,26 @@ public Message initializeFromExternalJson(String json) {
return Message.ERROR(unexpected.getMessage());
}
}

@Override
public void afterPropertiesSet() throws Exception {
if (offline) {
String json = null;
Path path = Paths.get(dataFile);
if (Files.isRegularFile(path)) {
try {
json = Files.lines(path)
.reduce((s, line) -> s.concat(line))
.orElse(null);
if (StringUtils.isNotEmpty(json)) {
client.initializeFromExternalJson(json);
LOG.info("initializing from a file works well");
}
} catch (IOException unexpected) {
LOG.warn("initializing from a file didn't work well: {}", unexpected.getMessage());
}
}
}
}

}
7 changes: 4 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=health
management.server.port=${healthPort:8081}

ffc.offline=${offline: true}
ffc.envSecret=${envSecret}
ffc.dataFile=${dataFile:/data/data.json}
ffc.dataFile=${dataFile:/data/data.json}

ffc.spring.env-secret=${envSecret}
ffc.spring.offline=${offline: true}

0 comments on commit b1915fa

Please sign in to comment.