Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

application properties override #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 16 additions & 35 deletions src/main/java/services/change_detection/ChangeDetectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriter;
import org.openrdf.repository.RepositoryException;
import org.diachron.detection.repositories.SesameVirtRep;
import utils.PropertiesManager;

/**
* REST Web Service
Expand All @@ -44,7 +45,7 @@
@Path("change_detection")
public class ChangeDetectionImpl {

private static String propFile = "C:/config.properties";
PropertiesManager propertiesManager = PropertiesManager.getPropertiesManager();

public ChangeDetectionImpl() {
}
Expand Down Expand Up @@ -110,26 +111,14 @@ public Response changeDetectJSON(String inputMessage) {
throw new ParseException(-1);
}
///
Properties properties = new Properties();
try {
properties.load(new FileInputStream(propFile));
// properties.load(this.getClass().getResourceAsStream(propFile));
} catch (IOException ex) {
String message = ex.getMessage();
boolean result = false;
int code = 400;
String json = "{ \"Message\" : " + message + ", \"Result\" : " + result + " }";
return Response.status(code).entity(json).build();
}
///
String datasetUri = properties.getProperty("Dataset_Uri");
String changesOntologySchema = properties.getProperty("Changes_Ontology_Schema");
String datasetUri = propertiesManager.getPropertyValue("Dataset_Uri");
String changesOntologySchema = propertiesManager.getPropertyValue("Changes_Ontology_Schema");
ChangesDetector detector = null;
try {
ChangesManager cManager = new ChangesManager(properties, datasetUri, oldVersion, newVersion, false);
ChangesManager cManager = new ChangesManager(propertiesManager.getProperties(), datasetUri, oldVersion, newVersion, false);
String changesOntology = cManager.getChangesOntology();
cManager.terminate();
detector = new ChangesDetector(properties, changesOntology, changesOntologySchema);
detector = new ChangesDetector(propertiesManager.getProperties(), changesOntology, changesOntologySchema);
} catch (Exception ex) {
String json = "{ \"Success\" : false, "
+ "\"Message\" : \"Exception Occured: " + ex.getMessage() + " \" }";
Expand Down Expand Up @@ -186,16 +175,14 @@ public Response changeDetectJSON(String inputMessage) {
@Produces(MediaType.APPLICATION_JSON)
public Response queryChangesOntologyGet(@QueryParam("query") String query,
@QueryParam("format") String format) {
Properties prop = new Properties();
OutputStream output = null;
try {
prop.load(new FileInputStream(propFile));
// prop.load(this.getClass().getResourceAsStream(propFile));
String ip = prop.getProperty("Repository_IP");
String username = prop.getProperty("Repository_Username");
String password = prop.getProperty("Repository_Password");
String changesOntol = prop.getProperty("Changes_Ontology");
int port = Integer.parseInt(prop.getProperty("Repository_Port"));
String ip = propertiesManager.getPropertyValue("Repository_IP");
String username = propertiesManager.getPropertyValue("Repository_Username");
String password = propertiesManager.getPropertyValue("Repository_Password");
String changesOntol = propertiesManager.getPropertyValue("Changes_Ontology");
int port = Integer.parseInt(propertiesManager.getPropertyValue("Repository_Port"));
SesameVirtRep sesame = new SesameVirtRep(ip, port, username, password);
query = query.replace(" where ", " from <" + changesOntol + "> ");
TupleQuery tupleQuery = sesame.getCon().prepareTupleQuery(QueryLanguage.SPARQL, query);
Expand Down Expand Up @@ -233,8 +220,6 @@ public String toString() {
tupleQuery.evaluate(writer);
} catch (MalformedQueryException | QueryEvaluationException | TupleQueryResultHandlerException | RepositoryException ex) {
return Response.status(400).entity(ex.getMessage()).build();
} catch (IOException ex) {
return Response.status(400).entity(ex.getMessage()).build();
}
return Response.status(200).entity(output.toString()).build();
}
Expand Down Expand Up @@ -297,14 +282,12 @@ public Response queryChangesOntologyPost(String inputMessage) {
throw new ParseException(-1);
}
///
Properties prop = new Properties();
prop.load(new FileInputStream(propFile));
// prop.load(this.getClass().getResourceAsStream(propFile));
String ip = prop.getProperty("Repository_IP");
String username = prop.getProperty("Repository_Username");
String password = prop.getProperty("Repository_Password");
String changesOntol = prop.getProperty("Changes_Ontology");
int port = Integer.parseInt(prop.getProperty("Repository_Port"));
String ip = propertiesManager.getPropertyValue("Repository_IP");
String username = propertiesManager.getPropertyValue("Repository_Username");
String password = propertiesManager.getPropertyValue("Repository_Password");
String changesOntol = propertiesManager.getPropertyValue("Changes_Ontology");
int port = Integer.parseInt(propertiesManager.getPropertyValue("Repository_Port"));
SesameVirtRep sesame = new SesameVirtRep(ip, port, username, password);
query = query.replace(" where ", " from <" + changesOntol + "> ");
TupleQuery tupleQuery = sesame.getCon().prepareTupleQuery(QueryLanguage.SPARQL, query);
Expand Down Expand Up @@ -344,8 +327,6 @@ public String toString() {
}
} catch (MalformedQueryException | QueryEvaluationException | TupleQueryResultHandlerException | RepositoryException ex) {
return Response.status(400).entity(ex.getMessage()).build();
} catch (IOException ex) {
return Response.status(400).entity(ex.getMessage()).build();
} catch (ParseException ex) {
String message = "JSON input message could not be parsed.";
String json = "{ \"Success\" : false, "
Expand Down
49 changes: 12 additions & 37 deletions src/main/java/services/change_detection/ComplexChangeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.diachron.detection.complex_change.CCDefinitionError.CODE;
import org.diachron.detection.complex_change.CCManager;
import org.diachron.detection.repositories.JDBCVirtuosoRep;
import utils.PropertiesManager;
import utils.Utils;

/**
Expand All @@ -34,7 +35,7 @@
@Path("complex_change")
public class ComplexChangeImpl {

private static String propFile = "C:/config.properties";
PropertiesManager propertiesManager = PropertiesManager.getPropertiesManager();

/**
* Creates a new instance of ComplexChangeImpl
Expand Down Expand Up @@ -91,26 +92,16 @@ public Response getCCJSON(@PathParam("com_change") String name) {
boolean result = false;
String message = null;
int code = 0;
Properties prop = new Properties();
try {
prop.load(new FileInputStream(propFile));
// prop.load(this.getClass().getResourceAsStream(propFile));
} catch (IOException ex) {
message = ex.getMessage();
result = false;
code = 400;
String json = "{ \"Message\" : " + message + ", \"Result\" : " + result + " }";
return Response.status(code).entity(json).build();
}

JDBCVirtuosoRep jdbcRep;
try {
jdbcRep = new JDBCVirtuosoRep(prop);
jdbcRep = new JDBCVirtuosoRep(propertiesManager.getProperties());
} catch (ClassNotFoundException | SQLException | IOException ex) {
result = false;
String json = "{ \"Message\" : \"Exception Occured: " + ex.getMessage() + ", \"Result\" : " + result + " }";
return Response.status(400).entity(json).build();
}
String ontologySchema = prop.getProperty("Changes_Ontology_Schema");
String ontologySchema = propertiesManager.getPropertyValue("Changes_Ontology_Schema");
String query = "select ?json from <" + ontologySchema + "> where { ?s co:name \"" + name + "\"; co:json ?json. }";
ResultSet res = jdbcRep.executeSparqlQuery(query, false);
try {
Expand Down Expand Up @@ -157,23 +148,15 @@ public Response getCCJSON(@PathParam("com_change") String name) {
@Path("{com_change}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteCCJSON(@PathParam("com_change") String name) {
Properties properties = new Properties();
String message = null;
int code;
boolean result = false;
try {
properties.load(new FileInputStream(propFile));
// properties.load(this.getClass().getResourceAsStream(propFile));
} catch (IOException ex) {
result = false;
String json = "{ \"Message\" : \"Exception Occured: " + ex.getMessage() + ", \"Result\" : " + result + " }";
return Response.status(400).entity(json).build();
}
String changesOntologySchema = properties.getProperty("Changes_Ontology_Schema");
String datasetUri = properties.getProperty("Dataset_Uri");

String changesOntologySchema = propertiesManager.getPropertyValue("Changes_Ontology_Schema");
String datasetUri = propertiesManager.getPropertyValue("Dataset_Uri");
CCManager manager = null;
try {
manager = new CCManager(properties, changesOntologySchema);
manager = new CCManager(propertiesManager.getProperties(), changesOntologySchema);
} catch (Exception ex) {
result = false;
String json = "{ \"Message\" : \"Exception Occured: " + ex.getMessage() + ", \"Result\" : " + result + " }";
Expand Down Expand Up @@ -289,19 +272,11 @@ public Response deleteCCJSON(@PathParam("com_change") String name) {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response defineCCJSON(String inputMessage) {
Properties properties = new Properties();
try {
properties.load(new FileInputStream(propFile));
// properties.load(this.getClass().getResourceAsStream(propFile));
} catch (IOException ex) {
boolean result = false;
String json = "{ \"Message\" : \"Exception Occured: " + ex.getMessage() + ", \"Result\" : " + result + " }";
return Response.status(400).entity(json).build();
}

CCManager ccDef = null;
String changesOntologySchema = properties.getProperty("Changes_Ontology_Schema");
String changesOntologySchema = propertiesManager.getPropertyValue("Changes_Ontology_Schema");
try {
ccDef = JSONMessagesParser.createCCDefinition(properties, inputMessage, changesOntologySchema);
ccDef = JSONMessagesParser.createCCDefinition(propertiesManager.getProperties(), inputMessage, changesOntologySchema);
} catch (Exception ex) {
boolean result = false;
String json = "{ \"Message\" : \"Exception Occured: " + ex.getMessage() + ", \"Result\" : " + result + " }";
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/utils/PropertiesManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package utils;

import java.io.*;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author Simon Jupp
* @date 08/05/2015
* Samples, Phenotypes and Ontologies Team, EMBL-EBI
*/
public class PropertiesManager {

private static PropertiesManager propManager = null;
private static String initFilePath = "config.properties";
private static Properties prop;

public static PropertiesManager getPropertiesManager()
{
if(propManager==null)
{
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream(initFilePath);
prop = new Properties();
if (input != null) {
prop.load(input);
}

if (System.getProperty("diachron.config.location") != null) {
InputStream overideInput = new FileInputStream(new File(System.getProperty("diachron.config.location")));
Properties override = new Properties();
override.load(overideInput);
prop.putAll(override);
}

propManager = new PropertiesManager();
} catch (IOException ex) {
Logger.getLogger(PropertiesManager.class.getName()).log(Level.SEVERE, null, ex);
}
}

return propManager;
}

public String getPropertyValue(String key)
{
return prop.getProperty(key);
}

public Properties getProperties () {
return prop;
}
}

Binary file removed target/ForthMaven-1.0.war
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/activation-1.1.jar
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/asm-3.1.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/jaxb-api-2.1.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/jettison-1.1.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/mimepull-1.4.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/stax-api-1.0-2.jar
Binary file not shown.
Binary file removed target/ForthMaven-1.0/WEB-INF/lib/stax-api-1.0.1.jar
Binary file not shown.
Binary file not shown.
17 changes: 0 additions & 17 deletions target/ForthMaven-1.0/WEB-INF/web.xml

This file was deleted.

13 changes: 0 additions & 13 deletions target/ForthMaven-1.0/index.jsp

This file was deleted.

Binary file removed target/classes/clients/TestChangeDetection.class
Binary file not shown.
Binary file removed target/classes/clients/TestDefineCC.class
Binary file not shown.
Binary file removed target/classes/clients/TestDeleteCC.class
Binary file not shown.
Binary file removed target/classes/clients/TestInfoCC.class
Binary file not shown.
Binary file removed target/classes/clients/TestQuery.class
Binary file not shown.
Binary file removed target/classes/clients/TestRepair.class
Binary file not shown.
Binary file removed target/classes/clients/TestValidation.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed target/classes/services/repair/RepairImpl.class
Binary file not shown.
Binary file removed target/classes/services/repair/ValidationImpl.class
Binary file not shown.
Binary file removed target/classes/utils/Utils.class
Binary file not shown.
Binary file removed target/endorsed/javaee-endorsed-api-6.0.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions target/maven-archiver/pom.properties

This file was deleted.