-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from freestarcapital/feature/ENG-716
Feature/eng 716
- Loading branch information
Showing
80 changed files
with
3,476 additions
and
24 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DSP_SIM_MODEL.json |
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,142 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.atg.openssp</groupId> | ||
<artifactId>open-ssp-data-services</artifactId> | ||
<version>0.1</version> | ||
<name>open-ssp-data-services</name> | ||
<url>http://maven.apache.org</url> | ||
<packaging>war</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<my.dev.catalina.home>y</my.dev.catalina.home> | ||
</properties> | ||
<profiles> | ||
<profile> | ||
<id>mock-catalina-home</id> | ||
<activation> | ||
<property> | ||
<name>!env.catalina.home</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemProperties> | ||
<property> | ||
<name>catalina.home</name> | ||
<value>${my.dev.catalina.home}</value> | ||
</property> | ||
</systemProperties> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<finalName>ssp-data-provider</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.tomcat.maven</groupId> | ||
<artifactId>tomcat7-maven-plugin</artifactId> | ||
<version>2.2</version> | ||
<configuration> | ||
<path>/${project.build.finalName}</path> | ||
<uriEncoding>utf-8</uriEncoding> | ||
<systemProperties> | ||
<JAVA_OPTS>-Xms512m -Xmx1024m</JAVA_OPTS> | ||
</systemProperties> | ||
<port>9090</port> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>properties-maven-plugin</artifactId> | ||
<version>1.0.0</version> | ||
<configuration> | ||
<properties></properties> | ||
<outputFile> | ||
${project.build.outputDirectory}/app.properties | ||
</outputFile> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>write-project-properties</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.6</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.6.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>2.6.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<version>2.8</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.atg.openssp</groupId> | ||
<artifactId>open-ssp-common</artifactId> | ||
<version>0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.atg.openssp</groupId> | ||
<artifactId>core</artifactId> | ||
<version>0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.atg.openssp</groupId> | ||
<artifactId>open-ssp-openrtb</artifactId> | ||
<version>0.3</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
data-services/src/main/java/com/atg/openssp/dataprovider/provider/dto/TokenWrapper.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,17 @@ | ||
package com.atg.openssp.dataprovider.provider.dto; | ||
|
||
/** | ||
* @author André Schmer | ||
*/ | ||
public class TokenWrapper { | ||
private String token; | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public void setToken(final String token) { | ||
this.token = token; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...-services/src/main/java/com/atg/openssp/dataprovider/provider/handler/AppDataHandler.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,70 @@ | ||
package com.atg.openssp.dataprovider.provider.handler; | ||
|
||
import com.atg.openssp.core.cache.broker.dto.AppDto; | ||
import com.atg.openssp.core.system.LocalContext; | ||
import com.google.gson.Gson; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import util.properties.ProjectProperty; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.xml.bind.PropertyException; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Brian Sorensen | ||
*/ | ||
public class AppDataHandler extends DataHandler { | ||
private static final Logger log = LoggerFactory.getLogger(AppDataHandler.class); | ||
public static final String CONTEXT = "/lookup/app"; | ||
|
||
public AppDataHandler(HttpServletRequest request, HttpServletResponse response) { | ||
if (LocalContext.isAppDataServiceEnabled()) { | ||
try { | ||
String location; | ||
try { | ||
location = ProjectProperty.getPropertiesResourceLocation()+"/"; | ||
} catch (PropertyException e) { | ||
log.warn("property file not found."); | ||
location=""; | ||
} | ||
Gson gson = new Gson(); | ||
String content = new String(Files.readAllBytes(Paths.get(location+"app_db.json")), StandardCharsets.UTF_8); | ||
|
||
AppDto data = gson.fromJson(content, AppDto.class); | ||
|
||
Map<String,String> parms = queryToMap(request.getQueryString()); | ||
String t = parms.get("t"); | ||
|
||
if (LoginHandler.TOKEN.equals(t)) { | ||
String result = new Gson().toJson(data); | ||
|
||
response.setStatus(200); | ||
response.setContentType("application/json; charset=UTF8"); | ||
OutputStream os = response.getOutputStream(); | ||
os.write(result.getBytes()); | ||
os.close(); | ||
} else { | ||
response.setStatus(401); | ||
} | ||
} catch (IOException e) { | ||
response.setStatus(500); | ||
log.error(e.getMessage(), e); | ||
} | ||
} else { | ||
response.setStatus(404); | ||
} | ||
} | ||
|
||
@Override | ||
public void cleanUp() { | ||
|
||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...ices/src/main/java/com/atg/openssp/dataprovider/provider/handler/CurrencyDataHandler.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,69 @@ | ||
package com.atg.openssp.dataprovider.provider.handler; | ||
|
||
import com.atg.openssp.core.cache.broker.dto.CurrencyDto; | ||
import com.atg.openssp.core.system.LocalContext; | ||
import com.google.gson.Gson; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import util.properties.ProjectProperty; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.xml.bind.PropertyException; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Brian Sorensen | ||
*/ | ||
public class CurrencyDataHandler extends DataHandler { | ||
private static final Logger log = LoggerFactory.getLogger(CurrencyDataHandler.class); | ||
public static final String CONTEXT = "/lookup/eurref"; | ||
|
||
public CurrencyDataHandler(HttpServletRequest request, HttpServletResponse response) { | ||
if (LocalContext.isCurrencyDataServiceEnabled()) { | ||
try { | ||
String location; | ||
try { | ||
location = ProjectProperty.getPropertiesResourceLocation()+"/"; | ||
} catch (PropertyException e) { | ||
log.warn("property file not found."); | ||
location=""; | ||
} | ||
Gson gson = new Gson(); | ||
String content = new String(Files.readAllBytes(Paths.get(location+"currency_db.json")), StandardCharsets.UTF_8); | ||
CurrencyDto data = gson.fromJson(content, CurrencyDto.class); | ||
|
||
Map<String,String> parms = queryToMap(request.getQueryString()); | ||
String t = parms.get("t"); | ||
|
||
if (LoginHandler.TOKEN.equals(t)) { | ||
String result = new Gson().toJson(data); | ||
|
||
response.setStatus(200); | ||
response.setContentType("application/json; charset=UTF8"); | ||
OutputStream os = response.getOutputStream(); | ||
os.write(result.getBytes()); | ||
os.close(); | ||
} else { | ||
response.setStatus(401); | ||
} | ||
} catch (IOException e) { | ||
response.setStatus(500); | ||
log.error(e.getMessage(), e); | ||
} | ||
} else { | ||
response.setStatus(404); | ||
} | ||
} | ||
|
||
@Override | ||
public void cleanUp() { | ||
|
||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
data-services/src/main/java/com/atg/openssp/dataprovider/provider/handler/DataHandler.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,94 @@ | ||
package com.atg.openssp.dataprovider.provider.handler; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.*; | ||
import java.net.URLDecoder; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author André Schmer | ||
*/ | ||
public abstract class DataHandler { | ||
public abstract void cleanUp(); | ||
|
||
protected static Map<String, String> queryToMap(String query){ | ||
Map<String, String> result = new HashMap<String, String>(); | ||
if (query != null) { | ||
for (String param : query.split("&")) { | ||
String pair[] = param.split("="); | ||
if (pair.length>1) { | ||
result.put(pair[0], pair[1]); | ||
}else{ | ||
result.put(pair[0], ""); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
protected static String queryFromBodyString(InputStream is){ | ||
BufferedReader br = new BufferedReader(new InputStreamReader(is)); | ||
String query; | ||
try { | ||
query = br.readLine(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
query=""; | ||
} | ||
return query; | ||
} | ||
|
||
protected static Map<String, String> attributesToMap(HttpServletRequest request){ | ||
Map<String, String> result = (Map<String, String>) request.getAttribute("attributes"); | ||
if (result == null) { | ||
result = new HashMap<String, String>(); | ||
} | ||
return result; | ||
} | ||
|
||
protected void populateFromBody(Map<String, String> parameters, String query) { | ||
if (query != null) { | ||
String pairs[] = query.split("[&]"); | ||
|
||
for (String pair : pairs) { | ||
String param[] = pair.split("[=]"); | ||
|
||
String key = null; | ||
String value = null; | ||
if (param.length > 0) { | ||
try { | ||
key = URLDecoder.decode(param[0], "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
key = param[0]; | ||
} | ||
} | ||
|
||
if (param.length > 1) { | ||
try { | ||
value = URLDecoder.decode(param[1], "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
value = param[1]; | ||
} | ||
} | ||
|
||
if (parameters.containsKey(key)) { | ||
Object obj = parameters.get(key); | ||
if(obj instanceof List<?>) { | ||
List<String> values = (List<String>)obj; | ||
values.add(value); | ||
} else if(obj instanceof String) { | ||
List<String> values = new ArrayList<String>(); | ||
values.add((String)obj); | ||
values.add(value); | ||
} | ||
} else { | ||
parameters.put(key, value); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.