-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUploadServer.java
127 lines (100 loc) · 3.97 KB
/
UploadServer.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
import java.awt.Dimension;
import java.awt.Point;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.transform.TransformerFactoryConfigurationError;
import org.w3c.dom.Element;
import com.clusterpoint.api.CPSConnection;
import com.clusterpoint.api.request.CPSLookupRequest;
import com.clusterpoint.api.request.CPSRetrieveRequest;
import com.clusterpoint.api.request.CPSUpdateRequest;
import com.clusterpoint.api.response.CPSListLastRetrieveFirstResponse;
import com.clusterpoint.api.response.CPSLookupResponse;
import com.clusterpoint.api.response.CPSModifyResponse;
public class UploadServer {
private static CPSConnection conn;
public static void init() {
try {
conn = new CPSConnection("tcps://cloud-us-0.clusterpoint.com:9008", "Attendance", "USERNAME", "PASSWORD", "ID");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// public static void changeData(String id, int d1, int d2) throws TransformerFactoryConfigurationError, Exception {
// String doc = "<document><id>"+id+"</id><Correct>:"+d1+"</Correct><Incorrect>:"+d2+"</Incorrect></document>";
// CPSUpdateRequest update_req = new CPSUpdateRequest(doc);
// //CPSModifyResponse update_resp = (CPSModifyResponse)
// conn.sendRequest(update_req);
// //System.out.println("Updated ids: " + Arrays.toString(update_resp.getModifiedIds()));
// }
public static void changeData(String[] tags, String[] vals, int num, String dataBase) throws TransformerFactoryConfigurationError, Exception {
String doc = "<document>";
for(int i = 0; i < num; i++) {
doc = doc + "<" + tags[i].trim() +">:" + vals[i].trim() + "</" + tags[i].trim() + ">";
}
doc = doc + "</document>";
System.out.println(doc);
CPSUpdateRequest update_req = new CPSUpdateRequest(doc);
conn.sendRequest(update_req);
}
public static void changeDataWithoutBreak(String[] tags, String[] vals, int num, String dataBase) throws TransformerFactoryConfigurationError, Exception {
String doc = "<document>";
for(int i = 0; i < num; i++) {
doc = doc + "<" + tags[i].trim() +">" + vals[i].trim() + "</" + tags[i].trim() + ">";
}
doc = doc + "</document>";
System.out.println(doc);
CPSUpdateRequest update_req = new CPSUpdateRequest(doc);
conn.sendRequest(update_req);
}
public static String getData(String id) {
CPSRetrieveRequest retr_req = new CPSRetrieveRequest(id);
CPSListLastRetrieveFirstResponse retr_resp;
try {
retr_resp = (CPSListLastRetrieveFirstResponse) conn.sendRequest(retr_req);
List<Element> docs = retr_resp.getDocuments();
Iterator<Element> it = docs.iterator();
Element el = it.next();
return el.getTextContent();
//System.out.println();
//String[] vals = val.split(":");
//System.out.println(val + " [" + vals[1].charAt(0) + "] [" + vals[2].charAt(0) + "]");
} catch (TransformerFactoryConfigurationError | Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
return null;
}
public static void lookup(String id) {
//Set two ids to lookup
String ids[] = {id};
//Return just document id and title in found documents
Map<String, String> list = new HashMap<String, String>();
list.put("document/id", "yes");
list.put("document/title", "yes");
CPSLookupResponse resp = null;
CPSLookupRequest req;
try {
req = new CPSLookupRequest(ids, list);
resp = (CPSLookupResponse) conn.sendRequest(req);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Found " + resp.getFound());
List<Element> docs = resp.getDocuments();
Iterator<Element> it = docs.iterator();
//Iterate through found documents
while (it.hasNext())
{
Element el = it.next();
System.out.println(el.getTextContent());
//Here goes code that extracts data from DOM Element
}
}
}