Skip to content
Snippets Groups Projects
Commit 5a83bed2 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin
Browse files

Merge branch 'feature/fix-net-usage-type-conversions' of /home/git/repositories/minicom/datasid

parents 86a6f498 42ce1377
No related branches found
No related tags found
No related merge requests found
......@@ -44,30 +44,52 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.transform.stream.StreamSource;
public class DataSID {
// enum does not work as expected inside an axis web service
// using simple constants instead
private static final int LINUX = 0;
private static final int WINDOWS = 1;
private static final String SA_INVENTORY = "telecenter_inventory";
private static final String SA_NET_USAGE = "net_usage";
private static final String SA_USER_HISTORY = "telecenter_user";
private static final File XML_INVENTORY_SCHEMA = new File("/home/datasid/conf/collected-data.xsd");
private static final File XML_NET_USAGE_SCHEMA = new File("/home/datasid/conf/net-collected-data.xsd");
private static final String AGENT_VERSION = "1.0.1";
private static final String AGENT_UPDATE_LINK = "http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.1-update.run";
private static final String WINDOWS_AGENT_VERSION = "1.0.0";
private static final String WINDOWS_UPDATE_LINK = "http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe";
// enum does not work as expected inside an axis web service
// using simple constants instead
private static final int ERROR = 0;
private static final int WARNING = 1;
private static final int INFO = 2;
private static final int DEBUG = 3;
private Properties prop;
private File xml_inventory_schema;
private File xml_net_usage_schema;
private String linux_agent_version;
private String linux_agent_update_link;
private String windows_agent_version;
private String windows_agent_update_link;
public DataSID() throws IOException {
try {
this.prop = new Properties();
this.prop.load(new FileInputStream("../conf/webservice.properties"));
}
catch (IOException e) {
System.err.println("Failed to load webservice.properties.");
throw e;
}
this.xml_inventory_schema = new File(this.prop.getProperty("xml_inventory_schema",
"../conf/collected-data.xsd"));
this.xml_net_usage_schema = new File(this.prop.getProperty("xml_net_usage_schema",
"../conf/net-collected-data.xsd"));
this.linux_agent_version = this.prop.getProperty("linux_agent_version", "1.0.0");
this.linux_agent_update_link = this.prop.getProperty("linux_agent_update_link",
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.run");
this.windows_agent_version = this.prop.getProperty("windows_agent_version", "1.0.0");
this.windows_agent_update_link = this.prop.getProperty("windows_agent_update_link",
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe");
}
/**
* Returns the name of the log level
*
......@@ -135,12 +157,12 @@ public class DataSID {
* @param OS Integer of OS Type
* @return String
*/
public static String getAgentVersion(int OS) {
public String getAgentVersion(int OS) {
switch(OS){
case LINUX:
return AGENT_VERSION;
return this.linux_agent_version;
case WINDOWS:
return WINDOWS_AGENT_VERSION;
return this.windows_agent_version;
default:
return "ERROR: invalid OS";
}
......@@ -155,13 +177,13 @@ public class DataSID {
* @param OS Integer of OS Type
* @return String
*/
public static String getUpdateLink(int OS)
public String getUpdateLink(int OS)
{
switch(OS){
case LINUX:
return AGENT_UPDATE_LINK;
return this.linux_agent_update_link;
case WINDOWS:
return WINDOWS_UPDATE_LINK;
return this.windows_agent_update_link;
default:
return "ERROR: invalid OS";
}
......@@ -176,7 +198,7 @@ public class DataSID {
* @param xmlData XML string of inventory
* @return String
*/
public static String setInventory(String xmlData) {
public String setInventory(String xmlData) {
try {
InitialContext cxt = new InitialContext();
DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/simmc");
......@@ -188,7 +210,7 @@ public class DataSID {
throw new Exception("Failed to get a database connection!");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(XML_INVENTORY_SCHEMA);
Schema schema = factory.newSchema(this.xml_inventory_schema);
JAXBContext context = JAXBContext.newInstance(CollectedData.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
......@@ -235,8 +257,8 @@ public class DataSID {
}
}
private static PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData, java.sql.Date contactDate) throws SQLException, ParseException {
final String query = "INSERT INTO " + SA_INVENTORY + " " +
private PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData, java.sql.Date contactDate) throws SQLException, ParseException {
final String query = "INSERT INTO telecenter_inventory " +
"(contact_date, machine_type, id_point, macaddr, agent_version, " +
" os_type, os_distro, os_kernel, " +
" processor, memory, " +
......@@ -345,9 +367,9 @@ public class DataSID {
return st;
}
private static PreparedStatement createUserHistoryStatement(Connection con, java.sql.Date contactDate,
private PreparedStatement createUserHistoryStatement(Connection con, java.sql.Date contactDate,
int id_point, Object macaddr, String name, String login, String logout) throws SQLException {
final String query = "INSERT INTO " + SA_USER_HISTORY + " " +
final String query = "INSERT INTO telecenter_user " +
"(contact_date, id_point, macaddr, name, login, logout) VALUES " +
"(?, ?, ?, ?, ?, ?);";
......@@ -385,7 +407,7 @@ public class DataSID {
* @param xmlData XML string of inventory
* @return String
*/
public static String setNetUsage(String xmlData)
public String setNetUsage(String xmlData)
{
try {
InitialContext cxt = new InitialContext();
......@@ -398,7 +420,7 @@ public class DataSID {
throw new Exception("Failed to get a database connection!");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(XML_NET_USAGE_SCHEMA);
Schema schema = factory.newSchema(this.xml_net_usage_schema);
JAXBContext context = JAXBContext.newInstance(NetCollectedData.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
......@@ -446,10 +468,10 @@ public class DataSID {
}
}
private static PreparedStatement createNetUsageStatement(Connection con, java.sql.Date contactDate,
BigInteger idpoint, Object macaddr, String collect_date, String collect_time, BigInteger down_kbits,
BigInteger down_packages, BigInteger up_kbits, BigInteger up_packages) throws SQLException {
final String query = "INSERT INTO " + SA_NET_USAGE + " " +
private PreparedStatement createNetUsageStatement(Connection con, java.sql.Date contactDate,
BigInteger idpoint, Object macaddr, String collect_date, String collect_time, long down_kbits,
BigInteger down_packages, long up_kbits, BigInteger up_packages) throws SQLException {
final String query = "INSERT INTO net_usage " +
"(contact_date, id_point, macaddr, collect_date, collect_time, " +
"down_kbits, down_packages, up_kbits, up_packages, ip, city_code) VALUES " +
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
......@@ -466,11 +488,11 @@ public class DataSID {
st.setTime(5, java.sql.Time.valueOf(collect_time));
st.setLong(6, down_kbits.LongValue() );
st.setLong(6, down_kbits);
st.setInt(7, down_packages.intValue());
st.setLong(8, up_kbits.LongValue());
st.setLong(8, up_kbits);
st.setInt(9, up_packages.intValue());
......
xml_inventory_schema=../conf/collected-data.xsd
xml_net_usage_schema=../conf/net-collected-data.xsd
linux_agent_version=1.0.1
linux_agent_update_link=http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.1-update.run
windows_agent_version=1.0.0
windows_agent_update_link=http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment