-
Notifications
You must be signed in to change notification settings - Fork 86
/
ResourceAPI.java
180 lines (147 loc) · 5.76 KB
/
ResourceAPI.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* $This file is distributed under the terms of the license in LICENSE$ */
package edu.cornell.mannlib.vitro.webapp.dynapi.components;
import java.util.LinkedList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
public class ResourceAPI extends AbstractPoolComponent implements Versionable<ResourceAPIKey> {
private String name;
private String versionMin;
private String versionMax;
private String procedureUriOnGet;
private String procedureUriOnGetAll;
private String procedureUriOnPost;
private String procedureUriOnDelete;
private String procedureUriOnPut;
private String procedureUriOnPatch;
private List<CustomRESTAction> customRESTActions = new LinkedList<CustomRESTAction>();
@Override
public void dereference() {
// TODO Auto-generated method stub
}
@Override
public String getVersionMin() {
return versionMin;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#minAPIVersion", minOccurs = 0, maxOccurs = 1)
public void setVersionMin(String versionMin) {
this.versionMin = versionMin;
}
@Override
public String getVersionMax() {
return versionMax;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#maxAPIVersion", maxOccurs = 1)
public void setVersionMax(String versionMax) {
this.versionMax = versionMax;
}
public String getName() {
return name;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1)
public void setName(String name) {
this.name = name;
}
@Override
public ResourceAPIKey getKey() {
return ResourceAPIKey.of(name, versionMin);
}
@Override
public boolean isValid() {
return true;
}
public String getProcedureUriOnGet() {
return procedureUriOnGet;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#onGet", minOccurs = 0, maxOccurs = 1,
asString = true)
public void setProcedureUrionGet(String procedureOnGet) {
this.procedureUriOnGet = procedureOnGet;
}
public String getProcedureUriOnGetAll() {
return procedureUriOnGetAll;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#onGetAll", minOccurs = 0, maxOccurs = 1,
asString = true)
public void setProcedureUriOnGetAll(String procedureOnGetAll) {
this.procedureUriOnGetAll = procedureOnGetAll;
}
public String getProcedureUriOnPost() {
return procedureUriOnPost;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#onPost", minOccurs = 0, maxOccurs = 1,
asString = true)
public void setProcedureUriOnPost(String procedureOnPost) {
this.procedureUriOnPost = procedureOnPost;
}
public String getProcedureUriOnDelete() {
return procedureUriOnDelete;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#onDelete", minOccurs = 0, maxOccurs = 1,
asString = true)
public void setProcedureUriOnDelete(String procedureOnDelete) {
this.procedureUriOnDelete = procedureOnDelete;
}
public String getProcedureUriOnPut() {
return procedureUriOnPut;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#onPut", minOccurs = 0, maxOccurs = 1,
asString = true)
public void setProcedureUriOnPut(String procedureOnPut) {
this.procedureUriOnPut = procedureOnPut;
}
public String getProcedureUriOnPatch() {
return procedureUriOnPatch;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#onPatch", minOccurs = 0, maxOccurs = 1,
asString = true)
public void setProcedureUriOnPatch(String procedureOnPatch) {
this.procedureUriOnPatch = procedureOnPatch;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasCustomRESTAction")
public void addCustomRESTAction(CustomRESTAction customRESTAction) {
customRESTActions.add(customRESTAction);
}
public List<CustomRESTAction> getCustomRESTActions() {
return customRESTActions;
}
public String getProcedureUri(String method, boolean isResourceRequest) {
String procedureUri = getProcedureUriByMethod(method, isResourceRequest);
if (procedureUri != null) {
return procedureUri;
}
throw new UnsupportedOperationException("Unsupported method");
}
private String getProcedureUriByMethod(String method, boolean isResourceRequest) {
switch (method.toUpperCase()) {
case "POST":
return procedureUriOnPost;
case "GET":
return isResourceRequest ? procedureUriOnGet : procedureUriOnGetAll;
case "DELETE":
return procedureUriOnDelete;
case "PUT":
return procedureUriOnPut;
case "PATCH":
return procedureUriOnPatch;
default:
return null;
}
}
public String getProcedureUriByActionName(String method, String actionName) {
String uri = getProcedureUriByCustomActionName(method, actionName);
if (uri != null) {
return uri;
}
throw new UnsupportedOperationException("Unsupported custom action");
}
private String getProcedureUriByCustomActionName(String method, String name) {
String uri = null;
for (CustomRESTAction customRestAction : customRESTActions) {
if (customRestAction.getName().equals(name) && method.equals(customRestAction.getHttpMethodName())) {
uri = customRestAction.getTargetProcedureUri();
break;
}
}
return uri;
}
}