3535import io .swagger .annotations .ApiOperation ;
3636import io .swagger .annotations .ApiParam ;
3737import java .util .Optional ;
38+ import java .util .Map ;
39+ import java .nio .file .Files ;
40+ import java .util .HashMap ;
3841
3942@ RestController
4043public class FOOPSController {
@@ -75,6 +78,7 @@ public String assessPOST(
7578 Response r = null ;
7679 FOOPS f = null ;
7780 Path ontologyPath = null ;
81+
7882 try {
7983 try { //has an onto URI been provided?
8084 Gson gson = new Gson ();
@@ -135,25 +139,62 @@ public String assessPOST(
135139 public String testByNamePOST (
136140 @ ApiParam (value = "Name of test" , required = true )
137141 @ 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);
139149 return "{ \" test\" : \" Not found\" }" ;
150+
140151 }
141152
142153 @ 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 ."
145156 )
146- @ GetMapping (path = "/test" , produces = "application/json " )
157+ @ GetMapping (path = "/test" , produces = "text/plainn " )
147158 public String testByNameGET (
148159 @ ApiParam (value = "Name of test" , required = true )
149160 @ RequestParam String name ) {
150161
151162 FOOPS f = null ;
152163 Path ontologyPath = null ;
153164 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+ }
157198 }
158199
159200 @ ApiOperation (
@@ -165,24 +206,29 @@ public String benchmarkByNamePOST(
165206 @ ApiParam (value = "Name of benchmark" , required = true )
166207 @ RequestBody String body ) {
167208
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);
168214 return "{ \" benchmark\" : \" Not found\" }" ;
215+
169216 }
170217
171218 @ 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 ."
174221 )
175222 @ GetMapping (path = "/benchmark" , produces = "application/json" )
176223 public String benchmarkByNamePost (
177224 @ ApiParam (value = "Name of benchmark" , required = true )
178225 @ RequestParam String name ) {
179226
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\" }\" " ;
186232 }
187233 /**
188234 *
0 commit comments