Permalink
Browse files

Added functionality to Human classes

  • Loading branch information...
1 parent d170c7d commit c17e317affd9d0d8fad250b2a31b019fd2cefb85 @drowzy drowzy committed Feb 17, 2012
Showing with 66 additions and 21 deletions.
  1. +1 −1 src/client/SSLClient.java
  2. +10 −7 src/server/ConnectionHandler.java
  3. +13 −2 src/server/Doctor.java
  4. +34 −3 src/server/Human.java
  5. +8 −8 src/server/SSLServer.java
@@ -53,7 +53,7 @@ private void establishTrustWithServer() throws Exception {
ss.getOutputStream()));
String string = null;
-
+ System.out.println(inputbuffer.readLine());
while ((string = bufferedreader.readLine()) != null) {
bufferedwriter.write(string + '\n');
bufferedwriter.flush();
@@ -24,19 +24,21 @@ public boolean validateSubject(String subject){
private void enableCommunication(BufferedWriter writer, BufferedReader reader) throws IOException{
try {
- writer.write("Communication is now open\n Use commands:\nA - For adding new entry\nV personNumber - For viewing entry with pnbr\n " +
- "R personNumber - For removing entry with pnbr\n");
+ writer.write("Communication is now open Use commands: A - " +
+ "For adding new entry V personNumber - " +
+ "For viewing entry with pnbr R personNumber - " +
+ "For removing entry with pnbr\n" );
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
char command = reader.readLine().toCharArray()[0];
-
+
while(command != 0){
switch(command){
case ADD :
- writer.write("Adding journal to patient");
+ writer.write("Adding journal to patient\n");
break;
case VIEW : break;
case REMOVE : break;
@@ -56,17 +58,18 @@ private Human getCurrentUser(){
}
public void startCommunication(BufferedWriter writer, BufferedReader reader) throws IOException{
- writer.write("Please specify a patient with format YYMMDD or EXIT to close application");
+ writer.write("Please specify a patient with format YYMMDD or EXIT to close application\n");
writer.flush();
response = reader.readLine();
if(response == "EXIT"){
//Close system
}
- getCurrentUser();
- else if(getCurrentUser().viewJournal(response)){
+
+ else if (true){
writer.write("Access granted for patient: " + response);
writer.flush();
enableCommunication(writer, reader);
+// getCurrentUser().viewJournal(response)
}
else{
writer.write("Unable to perform operation");
View
@@ -1,12 +1,23 @@
package server;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.HashMap;
public class Doctor extends Human {
-
+ private HashMap<Integer, Human> accessToThesePpl;
public Doctor(int personalNumber, HashMap<Integer, Human> accessToThesePpl) {
super(personalNumber, accessToThesePpl);
- // TODO Auto-generated constructor stub
+ }
+ public void createRecord(int id, String fileName) throws IOException{
+
+ Human target =accessToThesePpl.get(id);
+ if(target != null){
+ File file = new File(target.getPath()+fileName+".txt");
+ }
+ }
+
}
}
View
@@ -1,12 +1,43 @@
package server;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.HashMap;
-public class Human {
- private int personalNumber;
+public abstract class Human {
+ private int pNbr;
+ private HashMap<Integer, Human> access;
+ public Human(int pNbr, HashMap<Integer, Human> access){
+ this.access = access;
+ this.pNbr = pNbr;
+ access.put(pNbr,this);
+ }
+
- public Human(int personalNumber, HashMap<Integer, Human> accessToThesePpl){
+ public String getPath(){
+ return pNbr + "\\";
}
+ public String writeRecord(int id,String fileName) throws IOException{
+
+ if(checkAccess(id)){
+ Human target =access.get(id);
+ FileWriter fstream = new FileWriter(target.getPath()+fileName+".txt");
+ fstream.write("");
+ return "Successfully writen to: " + target.getPath()+fileName;
+
+ }
+ else{
+ return "Access Denied";
+ }
+ }
+
+public boolean checkAccess(int id){
+ if(access.get(id) != null){
+ return true;
+ }else{
+ return false;
+ }
}
+}
View
@@ -63,18 +63,18 @@ private void setUpSomeTrustAndListen(int port)
.getInputStream()));
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(connection
.getOutputStream()));
-
+ handler.startCommunication(w, r);
javax.security.cert.X509Certificate cert = session
.getPeerCertificateChain()[0];
String subject = cert.getSubjectDN().getName();
- if (handler.validateSubject(subject)) {
- handler.startCommunication(w, r);
- } else {
- w.write("Subject not in the system");
- w.flush();
- // Close socket
- }
+// if (handler.validateSubject(subject)) {
+// ;
+// } else {
+// w.write("Subject not in the system");
+// w.flush();
+// // Close socket
+// }
}

0 comments on commit c17e317

Please sign in to comment.