Skip to content

Commit

Permalink
Reading .json files from properties ctx.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmermeister committed Feb 20, 2018
1 parent 77b05ba commit 65eee78
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.xml.bind.PropertyException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,6 +15,8 @@
import com.atg.openssp.core.cache.type.PricelayerCache;
import com.google.gson.Gson;

import util.properties.ProjectProperty;

/**
* @author André Schmer
*
Expand All @@ -27,7 +31,8 @@ public PricelayerBrokerJson() {}
protected boolean doCaching() {
final Gson gson = new Gson();
try {
final String content = new String(Files.readAllBytes(Paths.get("price_layer.json")), StandardCharsets.UTF_8);
final String path = ProjectProperty.readFile("price_layer.json").getAbsolutePath();
final String content = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
final PricelayerDto dto = gson.fromJson(content, PricelayerDto.class);
if (dto != null) {
log.info("sizeof pricelayer data=" + dto.getPricelayer().size());
Expand All @@ -39,7 +44,7 @@ protected boolean doCaching() {

log.error("no price data");
return false;
} catch (final IOException e) {
} catch (final IOException | PropertyException e) {
log.error(getClass() + ", " + e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.xml.bind.PropertyException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,6 +15,8 @@
import com.atg.openssp.core.cache.type.SiteDataCache;
import com.google.gson.Gson;

import util.properties.ProjectProperty;

/**
* @author André Schmer
*
Expand All @@ -27,7 +31,8 @@ public SiteDataBrokerJson() {}
protected boolean doCaching() {
final Gson gson = new Gson();
try {
final String content = new String(Files.readAllBytes(Paths.get("site_db.json")), StandardCharsets.UTF_8);
final String path = ProjectProperty.readFile("site_db.json").getAbsolutePath();
final String content = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
final SiteDto dto = gson.fromJson(content, SiteDto.class);
if (dto != null) {
log.info("sizeof site data=" + dto.getSites().size());
Expand All @@ -36,10 +41,9 @@ protected boolean doCaching() {
});
return true;
}

log.error("no Site data");
return false;
} catch (final IOException e) {
} catch (final PropertyException | IOException e) {
log.error(getClass() + ", " + e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.xml.bind.PropertyException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,6 +16,8 @@
import com.atg.openssp.core.exchange.channel.rtb.OpenRtbConnector;
import com.google.gson.Gson;

import util.properties.ProjectProperty;

/**
*
* This special data broker loads the {@see SupplierDto} data from a file based store which holds the data for the supplier, also known as DSP. and put into a
Expand All @@ -36,7 +40,8 @@ public SupplierDataBrokerJson() {}
public boolean doCaching() {
final Gson gson = new Gson();
try {
final String content = new String(Files.readAllBytes(Paths.get("supplier_db.json")), StandardCharsets.UTF_8);
final String path = ProjectProperty.readFile("supplier_db.json").getAbsolutePath();
final String content = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
final SupplierDto dto = gson.fromJson(content, SupplierDto.class);
if (dto != null) {
log.info("sizeof supplier data=" + dto.getSupplier().size());
Expand All @@ -49,7 +54,7 @@ public boolean doCaching() {

log.error("no Supplier data");
return false;
} catch (final IOException e) {
} catch (final IOException | PropertyException e) {
log.error(getClass() + ", " + e.getMessage());
}

Expand Down

0 comments on commit 65eee78

Please sign in to comment.