Skip to content
Snippets Groups Projects
Commit 3448e321 authored by Edileuton Henrique de Oliveira's avatar Edileuton Henrique de Oliveira
Browse files

webservice: Add createUserHistoryStatement() function

parent ae6a89ac
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ public class DataSID { ...@@ -44,6 +44,7 @@ public class DataSID {
private static final String SA_INVENTORY = "telecenter_inventory"; private static final String SA_INVENTORY = "telecenter_inventory";
private static final String SA_NET_USAGE = "telecenter_net_usage"; private static final String SA_NET_USAGE = "telecenter_net_usage";
private static final String SA_USER_HISTORY = "telecenter_user_history";
private static final File XML_INVENTORY_SCHEMA = new File("/home/datasid/apache-tomcat/webapps/axis2/WEB-INF/collected-data.xsd"); private static final File XML_INVENTORY_SCHEMA = new File("/home/datasid/apache-tomcat/webapps/axis2/WEB-INF/collected-data.xsd");
private static final File XML_NET_USAGE_SCHEMA = new File("/home/datasid/apache-tomcat/webapps/axis2/WEB-INF/net-collected-data.xsd"); private static final File XML_NET_USAGE_SCHEMA = new File("/home/datasid/apache-tomcat/webapps/axis2/WEB-INF/net-collected-data.xsd");
...@@ -176,10 +177,24 @@ public class DataSID { ...@@ -176,10 +177,24 @@ public class DataSID {
// Decode the XML into a Java Object // Decode the XML into a Java Object
JAXBElement<CollectedData> element = (JAXBElement<CollectedData>) unmarshaller.unmarshal(is); JAXBElement<CollectedData> element = (JAXBElement<CollectedData>) unmarshaller.unmarshal(is);
CollectedData collected = element.getValue(); CollectedData collected = element.getValue();
// contact_date = current date
Calendar cal = Calendar.getInstance();
java.sql.Date contactDate = new java.sql.Date(cal.getTimeInMillis());
PreparedStatement st = createInventoryStatement(con, collected); PreparedStatement st = createInventoryStatement(con, collected, contactDate);
st.executeUpdate(); st.executeUpdate();
List<User> users = collected.getUserHistory().getUser();
String superid = collected.getTelecentroInfo().getSuperid();
List<Interface> interfaces = collected.getInterfaces().getInterface();
org.postgresql.util.PGobject macaddr = new org.postgresql.util.PGobject();
macaddr.setType("macaddr");
macaddr.setValue(interfaces.get(0).getMacAddress());
for(User user: users) {
st = createUserHistoryStatement(con, contactDate, superid, macaddr, user.getName(), user.getLogin(), user.getLogout());
st.executeUpdate();
}
con.close(); con.close();
return "Success"; return "Success";
...@@ -190,11 +205,11 @@ public class DataSID { ...@@ -190,11 +205,11 @@ public class DataSID {
} }
} }
private static PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData) throws SQLException { private static PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData, java.sql.Date contactDate) throws SQLException {
final String query = "INSERT INTO " + SA_INVENTORY + " " + final String query = "INSERT INTO " + SA_INVENTORY + " " +
"(contact_date, telecentro_id, versao, machine, machine_type, " + "(contact_date, telecentro_id, versao, machine, machine_type, " +
"admin_name, admin_phone, tl_name, " + "admin_name, tl_conection, tl_name, tl_beneficiary, " +
"tl_phone, state, city, " + "users_count, state, city, " +
"tl_street, tl_number, zipcode, " + "tl_street, tl_number, zipcode, " +
"tl_neighborhood, geolocation, mirrors_timestamp, " + "tl_neighborhood, geolocation, mirrors_timestamp, " +
"hd_model, hd_size, hd_used, " + "hd_model, hd_size, hd_used, " +
...@@ -202,7 +217,7 @@ public class DataSID { ...@@ -202,7 +217,7 @@ public class DataSID {
"extra_hds, memory_size, processor, " + "extra_hds, memory_size, processor, " +
"os_type, os_distro, kernel) VALUES " + "os_type, os_distro, kernel) VALUES " +
"(?, ?, ?, ?, ?, " + "(?, ?, ?, ?, ?, " +
"?, ?, ?, " + "?, ?, ?, ?, " +
"?, ?, ?, " + "?, ?, ?, " +
"?, ?, ?, " + "?, ?, ?, " +
"?, ?, ?, " + "?, ?, ?, " +
...@@ -219,12 +234,10 @@ public class DataSID { ...@@ -219,12 +234,10 @@ public class DataSID {
List<Disk> disks = inventory.getDisks().getDisk(); List<Disk> disks = inventory.getDisks().getDisk();
TeleCentroInfo teleCentroInfo = collectedData.getTelecentroInfo(); TeleCentroInfo teleCentroInfo = collectedData.getTelecentroInfo();
// contact_date = current date st.setDate(1, contactDate);
Calendar cal = Calendar.getInstance();
st.setDate(1, new java.sql.Date(cal.getTimeInMillis()));
// telecentro_id // telecentro_id
st.setString(2, teleCentroInfo.getDatasid()); st.setString(2, teleCentroInfo.getSuperid());
// machine // machine
org.postgresql.util.PGobject macaddr = new org.postgresql.util.PGobject(); org.postgresql.util.PGobject macaddr = new org.postgresql.util.PGobject();
...@@ -244,86 +257,111 @@ public class DataSID { ...@@ -244,86 +257,111 @@ public class DataSID {
// admin_name // admin_name
st.setString(6, teleCentroInfo.getAdminName()); st.setString(6, teleCentroInfo.getAdminName());
// admin_phone // tl_conection
st.setString(7, teleCentroInfo.getAdminPhone()); st.setString(7, teleCentroInfo.getTlConnection());
// tl_name // tl_name
st.setString(8, teleCentroInfo.getTlName()); st.setString(8, teleCentroInfo.getTlName());
// tl_phone // tl_beneficiary
st.setString(9, teleCentroInfo.getTlPhone()); st.setString(9, teleCentroInfo.getTlBeneficiary());
// user_count
st.setInt(10, teleCentroInfo.getUserCount().intValue());
// state // state
st.setString(10, teleCentroInfo.getState()); st.setString(11, teleCentroInfo.getState());
// city // city
st.setString(11, teleCentroInfo.getCity()); st.setString(12, teleCentroInfo.getCity());
// tl_street // tl_street
st.setString(12, teleCentroInfo.getTlStreet()); st.setString(13, teleCentroInfo.getTlStreet());
// tl_number // tl_number
st.setString(13, teleCentroInfo.getTlNumber()); st.setString(14, teleCentroInfo.getTlNumber());
// tl_zipcode // tl_zipcode
st.setString(14, teleCentroInfo.getTlZipcode()); st.setString(15, teleCentroInfo.getTlZipcode());
// tl_neighborhood // tl_neighborhood
st.setString(15, teleCentroInfo.getTlNeighborhood()); st.setString(16, teleCentroInfo.getTlNeighborhood());
// geolocation // geolocation
st.setString(16, teleCentroInfo.getGeolocation()); st.setString(17, teleCentroInfo.getGeolocation());
// mirrors_timestamp // mirrors_timestamp
st.setString(17, collectedData.getMirrorsTimestamp()); st.setString(18, collectedData.getMirrorsTimestamp());
// hd_model // hd_model
st.setString(18, disks.get(0).getModel()); st.setString(19, disks.get(0).getModel());
// hd_size // hd_size
st.setInt(19, disks.get(0).getSize().intValue()); st.setInt(20, disks.get(0).getSize().intValue());
// hd_used // hd_used
st.setInt(20, disks.get(0).getUsed().intValue()); st.setInt(21, disks.get(0).getUsed().intValue());
if (disks.size() > 1) { if (disks.size() > 1) {
// hd2_model // hd2_model
st.setString(18, disks.get(1).getModel()); st.setString(19, disks.get(1).getModel());
// hd2_size // hd2_size
st.setInt(19, disks.get(1).getSize().intValue()); st.setInt(20, disks.get(1).getSize().intValue());
// hd2_used // hd2_used
st.setInt(20, disks.get(1).getUsed().intValue()); st.setInt(21, disks.get(1).getUsed().intValue());
} }
else { else {
// hd2_model // hd2_model
st.setNull(18, Types.VARCHAR); st.setNull(19, Types.VARCHAR);
// hd2_size // hd2_size
st.setNull(19, Types.INTEGER); st.setNull(20, Types.INTEGER);
// hd2_used // hd2_used
st.setNull(20, Types.INTEGER); st.setNull(21, Types.INTEGER);
} }
// extra_hds // extra_hds
st.setInt(21, (disks.size() > 2) ? (disks.size() - 2) : 0); st.setInt(22, (disks.size() > 2) ? (disks.size() - 2) : 0);
// memory_size // memory_size
st.setInt(22, inventory.getMemory().intValue()); st.setInt(23, inventory.getMemory().intValue());
// processor // processor
st.setString(23, inventory.getProcessor()); st.setString(24, inventory.getProcessor());
// os_type // os_type
st.setString(24, inventory.getOs()); st.setString(25, inventory.getOs());
// os_distro // os_distro
st.setString(25, inventory.getDistro()); st.setString(26, inventory.getDistro());
// kernel // kernel
st.setString(26, inventory.getKernel()); st.setString(27, inventory.getKernel());
return st;
}
private static PreparedStatement createUserHistoryStatement(Connection con, java.sql.Date contactDate, String m_superid, Object macaddr, String name, String login, String logout) throws SQLException {
final String query = "INSERT INTO " + SA_USER_HISTORY + " " +
"(contact_date, m_superid, macaddr, name, login, logout) VALUES " +
"(?, ?, ?, ?, ?, ?);";
PreparedStatement st = con.prepareStatement(query);
st.setDate(1, contactDate);
// m_superid = telecentro-id
st.setString(2, m_superid);
st.setObject(3, macaddr);
st.setString(4, name);
st.setString(5, login);
st.setString(6, logout);
return st; return st;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment