-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strategy): add strategy support
- Loading branch information
Showing
7 changed files
with
108 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
public interface IConfigClient { | ||
|
||
String getGatewayName(); | ||
|
||
String getEDSStrategy(); | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/enums/EdsStrategyEnum.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,7 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.rulesmanager.enums; | ||
|
||
public enum EdsStrategyEnum { | ||
NO_EDS, | ||
NO_FHIR_EDS, | ||
NO_EDS_WITH_LOG | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/IConfigSRV.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,10 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.rulesmanager.service; | ||
|
||
public interface IConfigSRV { | ||
|
||
String getEdsStrategy(); | ||
|
||
boolean isNoEds(); | ||
|
||
boolean isNoFhirEds(); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.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,66 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.impl; | ||
|
||
|
||
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.client.IConfigClient; | ||
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.enums.EdsStrategyEnum; | ||
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.IConfigSRV; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.event.ApplicationStartedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Date; | ||
|
||
@Service | ||
public class ConfigSRV implements IConfigSRV { | ||
|
||
private static final Long DELTA_MS = 300000L; | ||
|
||
@Autowired | ||
private IConfigClient client; | ||
|
||
private String edsStrategy; | ||
|
||
private long lastUpdate; | ||
|
||
@Async | ||
@EventListener(ApplicationStartedEvent.class) | ||
void initialize() { | ||
refreshEdsStrategy(); | ||
} | ||
|
||
private void refreshEdsStrategy() { | ||
synchronized (this) { | ||
edsStrategy = client.getEDSStrategy(); | ||
lastUpdate = new Date().getTime(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getEdsStrategy() { | ||
long passedTime = new Date().getTime() - lastUpdate; | ||
if (passedTime >= DELTA_MS) { | ||
synchronized (this) { | ||
refreshEdsStrategy(); | ||
} | ||
} | ||
return edsStrategy; | ||
} | ||
|
||
@Override | ||
public boolean isNoFhirEds() { | ||
// Trigger refresh if necessary | ||
String out = getEdsStrategy(); | ||
// Evaluate | ||
return StringUtils.isNotBlank(out) && EdsStrategyEnum.NO_FHIR_EDS.name().equalsIgnoreCase(out); | ||
} | ||
|
||
//Se la strategy è null si setta come default no_eds (quindi non verranno emesse loggate) | ||
@Override | ||
public boolean isNoEds() { | ||
String out = getEdsStrategy(); | ||
return StringUtils.isBlank(out) || EdsStrategyEnum.NO_EDS.name().equalsIgnoreCase(out); | ||
} | ||
} |