35
35
import io .swagger .annotations .ApiOperation ;
36
36
import io .swagger .annotations .ApiParam ;
37
37
import java .util .Optional ;
38
+ import java .util .Map ;
39
+ import java .nio .file .Files ;
40
+ import java .util .HashMap ;
38
41
39
42
@ RestController
40
43
public class FOOPSController {
@@ -75,6 +78,7 @@ public String assessPOST(
75
78
Response r = null ;
76
79
FOOPS f = null ;
77
80
Path ontologyPath = null ;
81
+
78
82
try {
79
83
try { //has an onto URI been provided?
80
84
Gson gson = new Gson ();
@@ -135,25 +139,62 @@ public String assessPOST(
135
139
public String testByNamePOST (
136
140
@ ApiParam (value = "Name of test" , required = true )
137
141
@ RequestBody String body ) {
138
-
142
+
143
+ //hay que extraer el id del json del boy
144
+ // FOOPS f = null;
145
+ // Path ontologyPath = null;
146
+ // ontologyPath = Path.of("ontology");
147
+ // f = new FOOPS(String.valueOf(ontologyPath), true);
148
+ // Optional<Check> check = f.getTestByName(name);
139
149
return "{ \" test\" : \" Not found\" }" ;
150
+
140
151
}
141
152
142
153
@ ApiOperation (
143
- value = "IN CONSTRUCTION: Test by name" ,
144
- notes = "return JSON TEST obtained by FOOPS ."
154
+ value = "Test description by name" ,
155
+ notes = "return test description and id ."
145
156
)
146
- @ GetMapping (path = "/test" , produces = "application/json " )
157
+ @ GetMapping (path = "/test" , produces = "text/plainn " )
147
158
public String testByNameGET (
148
159
@ ApiParam (value = "Name of test" , required = true )
149
160
@ RequestParam String name ) {
150
161
151
162
FOOPS f = null ;
152
163
Path ontologyPath = null ;
153
164
ontologyPath = Path .of ("ontology" );
154
- f = new FOOPS (String .valueOf (ontologyPath ), true );
155
- Optional <Check > check = f .getTestByName (name );
156
- return "{ \" test\" : \" " + (check .isPresent () ? check .get ().toString () : "Not found" ) + "\" }" ;
165
+ Map <String , String > response = new HashMap <>();
166
+
167
+ try {
168
+ if (!Files .exists (ontologyPath )) {
169
+ logger .error ("El archivo ontology no existe en la ubicación especificada: " + ontologyPath .toString ());
170
+ // Proseguir sin cargar ontology
171
+ f = new FOOPS ("default_url_or_empty_string" , false ); // Asume alguna URL por defecto o deja vacío
172
+ } else {
173
+ f = new FOOPS (String .valueOf (ontologyPath ), true );
174
+ }
175
+ } catch (Exception e ) {
176
+ logger .error ("Error cargando la ontología: " + e .getMessage ());
177
+ // Proseguir sin ontology
178
+ f = new FOOPS ("default_url_or_empty_string" , false );
179
+ }
180
+ Optional <Map <String , String >> testDetails = f .getTestByName (name );
181
+
182
+ if (testDetails .isPresent ()) {
183
+ Map <String , String > details = testDetails .get ();
184
+ String description = details .get ("description" );
185
+ String id = details .get ("id" );
186
+ String title = details .get ("title" );
187
+
188
+ return "Test: " + name + "\n " +
189
+ "Title: " + title + "\n " +
190
+ "Description: " + description + "\n " +
191
+ "Please send a POST request to obtain a JSON. Example:\n " +
192
+ "curl -X POST \" https://foops.linkeddata.es/test/" + name + "\" -H \" accept: application/json; charset=UTF-8\" " +
193
+ "-H \" Content-Type: application/json;charset=UTF-8\" -d " +
194
+ "{ \" test\" : \" " + id + "\" }" ;
195
+ } else {
196
+ return "Description not found about: " + name ;
197
+ }
157
198
}
158
199
159
200
@ ApiOperation (
@@ -165,24 +206,29 @@ public String benchmarkByNamePOST(
165
206
@ ApiParam (value = "Name of benchmark" , required = true )
166
207
@ RequestBody String body ) {
167
208
209
+ // FOOPS f = null;
210
+ // Path ontologyPath = null;
211
+ // ontologyPath = Path.of("ontology");
212
+ // f = new FOOPS(String.valueOf(ontologyPath), true);
213
+ // Optional<Check> check = f.getBenchmarkByName(name);
168
214
return "{ \" benchmark\" : \" Not found\" }" ;
215
+
169
216
}
170
217
171
218
@ ApiOperation (
172
- value = "IN CONSTRUCTION: Benchmark by name" ,
173
- notes = "return JSON BENCHMARK obtained by FOOPS ."
219
+ value = "IN CONSTRUCTION: Benchmark description by name" ,
220
+ notes = "return benchmark description and id ."
174
221
)
175
222
@ GetMapping (path = "/benchmark" , produces = "application/json" )
176
223
public String benchmarkByNamePost (
177
224
@ ApiParam (value = "Name of benchmark" , required = true )
178
225
@ RequestParam String name ) {
179
226
180
- FOOPS f = null ;
181
- Path ontologyPath = null ;
182
- ontologyPath = Path .of ("ontology" );
183
- f = new FOOPS (String .valueOf (ontologyPath ), true );
184
- Optional <Check > check = f .getBenchmarkByName (name );
185
- return "{ \" benchmark\" : \" " + (check .isPresent () ? check .get ().toString () : "Not found" ) + "\" }" ;
227
+ return "Please send a POST request. Example: " +
228
+ "curl -X POST \" https://foops.linkeddata.es/benchmark\" -H \" accept: application/json;" +
229
+ "charset=UTF-8\" " +
230
+ "-H \" Content-Type: application/json;charset=UTF-8\" -d " +
231
+ "\" { \" benchmark\" : \" https://w3id.org/foops/test/CN1\" }\" " ;
186
232
}
187
233
/**
188
234
*
0 commit comments