-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathIdController.java
More file actions
57 lines (51 loc) · 1.77 KB
/
IdController.java
File metadata and controls
57 lines (51 loc) · 1.77 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
50
51
52
53
54
55
56
57
package controllers;
import java.io.IOException;
import java.util.ArrayList;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import models.Id;
import org.codehaus.jackson.map.ObjectMapper;
public class IdController {
Id myId;
public ArrayList<Id> getIds() {
ArrayList<Id> idsList = new ArrayList<Id>();
String json = TransactionController.MakeURLCall("/ids", "GET", "");
try {
ObjectMapper mapper = new ObjectMapper();
Id[] ids = mapper.readValue(json, Id[].class);
//parameter is json which takes in all url calls.
for(int i = 0; i < ids.length; i++){
idsList.add(ids[i]);
}
return idsList;
}catch (IOException i){
i.printStackTrace();
return null;
}
}
public Id postId(Id id) {
ObjectMapper mapper = new ObjectMapper();
try {
String json = mapper.writeValueAsString(id);
String response = TransactionController.MakeURLCall("/ids", "POST", json);
return mapper.readValue(response, Id.class);
}catch (IOException i){
i.printStackTrace();
return null;
}
}
public Id putId(Id id) {
ObjectMapper mapper = new ObjectMapper();
try {
String json = mapper.writeValueAsString(id);
String response = TransactionController.MakeURLCall("/ids", "PUT", json);
return mapper.readValue(response, Id.class);
}catch (IOException i){
i.printStackTrace();
return null;
}
}
public Id getIdByGit(String githubid){
return getIds().stream().filter(id -> id.getGithub().equals(githubid)).collect(Collectors.toList()).get(0);
}
}