/** * Metodo per la lettura e il salvataggio in DB dei dati relativi alla prima configurazione del * cinema multisala * * @throws Exception */ public static void readInitialConfig() throws Exception { // Lettura del file config.xml MySQLAccess msa = new MySQLAccess(); msa.readDB(); Document config = loadDocument(CONFIG_FILE); // Creazione della lista di sale NodeList cinemaHalls = findCinemaHall(config); for (int i = 0; i < cinemaHalls.getLength(); i++) { NamedNodeMap attr = cinemaHalls.item(i).getAttributes(); String[] s = attr.getNamedItem("id").toString().split("\""); // ID della sala i char id = s[1].toCharArray()[0]; s = attr.getNamedItem("name").toString().split("\""); // Nome sala i String name = s[1]; s = attr.getNamedItem("specialseat").toString().split("\""); // Numero posti speciali int specialSeats = Integer.parseInt(s[1]); NodeList rows = readRows((Element) cinemaHalls.item(i)); // Numero file della sala i int n_rows = rows.getLength(); // Numero posti totali int seats = 0; for (int j = 0; j < n_rows; j++) { // Numero posti della fila j int r_seats = Integer.parseInt(rows.item(j).getTextContent().toString().trim()); seats += r_seats; } // Invoca l'inserimento in DB msa.insertCinemaHall(id, name, n_rows, seats, specialSeats); for (int j = 0; j < n_rows; j++) { NamedNodeMap r_attr = rows.item(j).getAttributes(); s = r_attr.getNamedItem("number").toString().split("\""); int number = Integer.parseInt(s[1]); // Numero posti della fila j int r_seats = Integer.parseInt(rows.item(j).getTextContent().toString().trim()); msa.insertRow(id, number, r_seats); } } msa.closeDB(); }
@Override public void run() { try { aes = new AESEncryptDecrypt(); while (bConnected) { String MsgFromClient = br.readLine(); if (MsgFromClient != null) { // Request for log in System.out.println(MsgFromClient); if (MsgFromClient.equals(LOGINREQUESTLABEL)) { userIdStr = br.readLine(); passwordStr = br.readLine(); passwordFromDB = DBAccess.getPasswordFromDB(userIdStr); priorityFromDB = DBAccess.getPriorityFromDB(userIdStr); System.out.println("password from db: " + passwordFromDB); // sent the LOGINRESPONSELABLE to client bw.write(LOGINRESPONSELABEL); bw.newLine(); bw.flush(); System.out.println(userIdStr); System.out.println(passwordStr); // System.out.println(passwordFromDB); // sent the log in result to client, fail or successful if (passwordFromDB != null && passwordStr.equals(passwordFromDB)) { if (priorityFromDB.equals("guest")) { bw.write(USERLOGINRESULT); bw.newLine(); bw.flush(); } else if (priorityFromDB.equals("admin")) { bw.write(ADMINLOGINRESULT); bw.newLine(); bw.flush(); } } else { bw.write(LOGINFAIL); bw.newLine(); bw.flush(); } } // Request for the MedRecordsPackage else if (MsgFromClient.equals(REQUESTMEDRECORDSPACKAGE)) { MedRecordsPackage MRP = DBAccess.getAllMedRecords(); oos = new ObjectOutputStream(socket.getOutputStream()); if (MRP != null) { oos.writeObject(MRP); oos.flush(); } } // Request for one MedRecord else if (MsgFromClient.equals(REQUESTONEMEDRECORD)) { MedRecord MR = DBAccess.getOneMedRecord(userIdStr); oos = new ObjectOutputStream(socket.getOutputStream()); if (MR != null) { oos.writeObject(MR); oos.flush(); } } // Request for update user's info else if (MsgFromClient.equals(REQUESTUPDATE)) { MedRecord mr = null; // wait to get the MedRecordsPackage try { ois = new ObjectInputStream(socket.getInputStream()); mr = (MedRecord) ois.readObject(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } if (mr != null) { DBAccess.updateMedRecord(mr); } } // App log out request else if (MsgFromClient.equals(APPLOGOUT)) { bConnected = false; } } } } catch (EOFException e) { e.printStackTrace(); System.out.println("Client disconnect!"); } catch (IOException e) { e.printStackTrace(); } finally { try { if (socket != null) socket.close(); if (br != null) br.close(); if (bw != null) bw.close(); if (ois != null) ois.close(); if (oos != null) oos.close(); // if (DBAccess != null) DBAccess.DBclose(); } catch (IOException e) { e.printStackTrace(); } } }