-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDocument.java
More file actions
49 lines (37 loc) · 1.49 KB
/
Copy pathCreateDocument.java
File metadata and controls
49 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package turing;
import java.io.IOException;
import java.nio.channels.SocketChannel;
import turing.Message.OPERATION;
import turing.Message.RESULT;
public class CreateDocument implements Runnable {
private SocketChannel client;
private Message received;
public CreateDocument (SocketChannel client, Message received){
this.client = client;
this.received = received;
}
public void run() {
Message toSend = new Message();
Message.RESULT result;
try {
String usernameOnline = received.getUsername();
String document = received.getDocumentName();
int numSection = received.getNumOfSection();
result = Turing.databaseDocuments.addDocumentDB(new Document(document,usernameOnline,numSection)); //aggiunge documento al database documenti
if (result == RESULT.OP_OK){
//aggiunge il documento nella lista documenti dell'utente e l'utente nella lista degli utenti autorizzati del documento
result = Turing.databaseUsers.addDocumentToUser(usernameOnline, usernameOnline, document,Turing.databaseDocuments);
if (result == RESULT.OP_OK)
System.out.println("Documento "+received.getDocumentName()+ " creato.");
}
toSend.setMessageResult(OPERATION.CREATE_DOC,result);
Message.sendMessage(client, toSend);
System.out.println("Server-CreateDocument ["+ received.getUsername()+", document: "+received.getDocumentName() +"]: " +result);
client.close();
} catch (IOException e){
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
}
}