-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSMSManagerClient.java
131 lines (105 loc) · 3.54 KB
/
DSMSManagerClient.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package a3;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Date;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceRef;
public class DSMSManagerClient {
String managerID;
String store;
File log;
WebInterface service;
public DSMSManagerClient(String[] args, String ID) {
if(ID.charAt(2) != 'M') {
System.out.println("Manager IDs must be in the format: [provinceAcronym]M[4-digit ID]");
return;
}
managerID = ID;
store = ID.substring(0,2);
try {
log = new File(ID + "log.txt");
QName compQName = new QName("http://a3/", "DSMSImplService");
if(store.equals("QC")) {
URL compURL = new URL("http://localhost:8080/a3/WebInterfaceQC?wsdl");
Service compService = Service.create(compURL, compQName);
service = compService.getPort(WebInterface.class);
} else if(store.equals("ON")) {
URL compURL = new URL("http://localhost:8080/a3/WebInterfaceON?wsdl");
Service compService = Service.create(compURL, compQName);
service = compService.getPort(WebInterface.class);
}
else if(store.equals("BC")) {
URL compURL = new URL("http://localhost:8080/a3/WebInterfaceBC?wsdl");
Service compService = Service.create(compURL, compQName);
service = compService.getPort(WebInterface.class);
}
if(log.createNewFile()) {
System.out.println("File created for manager #" + ID);
}
} catch (IOException e) {
e.printStackTrace();
}
// corba stuff used to be here
}
public boolean add(String itemID, String itemName, short quantity, double price) throws RemoteException {
boolean status = false;
// corba invoke method
status = service.addItem(this.managerID, itemID, itemName, quantity, price);
// Write to file
synchronized(log) {
try {
FileWriter writeManager = new FileWriter(log, true);
writeManager.append("\nREQUEST:\n" + "\tDate: " + new Date()
+ "\n\tType: add" + "\n\tSubmitted by: " + managerID
+ "\n\tItem ID: " + itemID
+ "\n\tItem name: " + itemName
+ "\n\tItem quantity: " + quantity
+ "\n\tItem price: " + price);
writeManager.append(status?"\n\tStatus: successful":"\n\tStatus: unsuccessful\n");
writeManager.close();
}catch (IOException e) {
e.printStackTrace();
}
}
return status;
}
public boolean remove(String itemID, short quantity) throws RemoteException {
boolean status = false;
// corba invoke method
status = service.removeItem(this.managerID, itemID, quantity);
// Write to file
synchronized(log) {
try {
FileWriter writeManager = new FileWriter(log, true);
writeManager.append("\nREQUEST:\n" + "\tDate: " + new Date()
+ "\n\tType: remove" + "\n\tSubmitted by: " + managerID
+ "\n\tItem ID: " + itemID
+ "\n\tItem quantity: " + quantity);
writeManager.append(status?"\n\tStatus: successful":"\n\tStatus: unsuccessful\n");
writeManager.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return status;
}
public void list() throws RemoteException {
// corba invoke method
System.out.println(service.listItemAvailability(this.managerID));
// Write to file
synchronized(log) {
try {
FileWriter writeManager = new FileWriter(log, true);
writeManager.append("\nREQUEST:\n" + "\tDate: " + new Date()
+ "\n\tType: list inventory" + "\n\tSubmitted by: " + managerID);
writeManager.close();
} catch (IOException e) {
e.printStackTrace();
}}
}
}