@SuppressWarnings("static-access") public String addDatabaseSqlServer( String ip, String hostname, String dbInstance, String username, String password, String dbVendor, String dbName) { if (dbVendor.toUpperCase().equals("SQLSERVER")) { database.setQueryDate("SELECT GETDATE();"); database.setPort(1433); database.setIp(ip); database.setHostname(hostname); database.setDb_name(dbName); database.setUser(username); database.setVendor(dbVendor.toUpperCase()); database.setStatus("NOK"); database.setTrClass("error"); database.setInstance(dbInstance); try { // Encrypting the password database.setPass(encodePass.encode(password)); } catch (Exception e) { log.severe("{REST} Error: " + e); } try { log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Adding database: " + hostname); if (this.databaseDAO.insert_dataBase(database) == 0) { log.info("{REST} DataBase " + database.getHostname() + " was sucessfully registred."); return "SUCCESS"; } else { log.info( "{REST} DataBase " + database.getHostname() + " was not registred because it already exists."); return "DataBase " + database.getHostname() + " was not registred because it already exists."; } } catch (Exception e) { e.printStackTrace(); return "FAIL, check logs for details"; } } else { log.warning( " [ " + userInfo.getLoggedUsername() + " ]{REST} -> This method only allows SqlServer "); return "FAIL, check logs for details"; } }
public List<BancoDados> notFullDbVerification(HttpServletResponse response) { log.info( " [ " + userInfo.getLoggedUsername() + " ]{REST} -> Starting not full db verification: "); final List<BancoDados> listNOKbeforeVerification = this.databaseDAO.getdataBasesNOK(); final List<BancoDados> listdb = new ArrayList<BancoDados>(); try { if (!resource.islocked("notFullDBVerification")) { resource.lockRecurso("notFullDBVerification"); verification.databaseVerification(this.databaseDAO.getdataBasesNOK()); for (BancoDados db : listNOKbeforeVerification) { listdb.add(this.databaseDAO.getDataBaseByID(db.getId())); } resource.releaseLock("notFullDBVerification"); } return listdb; } catch (Exception e) { return null; } }
public List<BancoDados> bancodados() { try { log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Returning the database list."); return this.databaseDAO.listDataBases(); } catch (Exception e) { e.printStackTrace(); return null; } }
public List<BancoDados> fullDbVerification(HttpServletResponse response) { log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Starting full db verification: "); try { if (!resource.islocked("fullDbVerification")) { resource.lockRecurso("fullDbVerification"); verification.databaseVerification(this.databaseDAO.listDataBases()); resource.releaseLock("fullDbVerification"); } else { log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Recurso solicitado locado"); response.sendError(404); } return this.databaseDAO.listDataBases(); } catch (Exception e) { return null; } }
public String removeDatabase(int id) { try { log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Deleting database id: " + id); this.databaseDAO.deleteDataBase(this.databaseDAO.getDataBaseByID(id)); return "SUCCESS"; } catch (Exception e) { e.printStackTrace(); return "FAIL, check logs for details"; } }
@SuppressWarnings("static-access") public String addDatabase( String ip, String hostname, String dbInstance, String username, String password, String dbVendor) { if (dbVendor.toUpperCase().equals("MYSQL")) { database.setQueryDate("SELECT NOW() AS date;"); } if (dbVendor.toUpperCase().equals("ORACLE")) { database.setQueryDate("select sysdate from dual"); } if (dbVendor.toUpperCase().equals("SQLSERVER")) { database.setQueryDate("SELECT GETDATE();"); } if (dbVendor.toUpperCase().equals("POSTGRESQL")) { database.setQueryDate("SELECT now();"); } if (dbVendor.toUpperCase().equals("DB2")) { database.setQueryDate( "select VARCHAR_FORMAT(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MM:SS') FROM SYSIBM.SYSDUMMY1"); } if (dbVendor.toUpperCase().equals("MYSQL")) { database.setPort(3306); } if (dbVendor.toUpperCase().equals("ORACLE")) { database.setPort(1521); } if (dbVendor.toUpperCase().equals("SQLSERVER")) { database.setPort(1433); } if (dbVendor.toUpperCase().equals("POSTGRESQL")) { database.setPort(5432); } if (dbVendor.toUpperCase().equals("DB2")) { database.setPort(50000); } database.setIp(ip); database.setHostname(hostname); database.setDb_name(dbInstance); database.setUser(username); database.setVendor(dbVendor.toUpperCase()); database.setStatus("NOK"); database.setTrClass("error"); database.setInstance(dbInstance); try { // Encrypting the password database.setPass(encodePass.encode(password)); } catch (Exception e) { log.severe("{REST} Error: " + e); } try { log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Adding database: " + hostname); if (this.databaseDAO.insert_dataBase(database) == 0) { log.info("{REST} DataBase " + database.getHostname() + " was sucessfully registred."); return "SUCCESS"; } else { log.info( "{REST} DataBase " + database.getHostname() + " was not registred because it already exists."); return "DataBase " + database.getHostname() + " was not registred because it already exists."; } } catch (Exception e) { e.printStackTrace(); return "FAIL, check logs for details"; } }