Skip to content

Commit c8ad06b

Browse files
authored
Merge pull request #152 from juanjemdIos/main
Get methods. Description and ID
2 parents 92e5adf + 4bed00e commit c8ad06b

File tree

3 files changed

+90
-35
lines changed

3 files changed

+90
-35
lines changed

src/main/java/fair/Constants.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public class Constants {
4444

4545
public static final String OM42_URL = "https://w3id.org/foops/test/OM4.2";
4646

47-
public static final String OM5_1_URL = "https://w3id.org/foops/test/OM5_1";
47+
public static final String OM5_1_URL = "https://w3id.org/foops/test/OM5.1";
4848

49-
public static final String OM5_2_URL = "https://w3id.org/foops/test/OM5_2";
49+
public static final String OM5_2_URL = "https://w3id.org/foops/test/OM5.2";
5050

5151
public static final String PURL1_URL = "https://w3id.org/foops/test/PURL1";
5252

@@ -182,14 +182,14 @@ public class Constants {
182182
public static final String OM4_2_EXPLANATION_ERROR = "The license used could not be resolved";
183183

184184
//provenance
185-
public static final String OM5_1 = "OM5_1";
185+
public static final String OM5_1 = "OM5.1";
186186
public static final String OM5_1_TITLE = "Basic provenance metadata";
187187
public static final String OM5_1_DESC = "This check verifies if basic provenance is available for the ontology: " +
188188
"[author, creation date]. This check also verifies whether [contributor, previous version] are present" +
189189
", but with no penalty (as no all ontologies may have a previous version or a contributor)";
190190
public static final String OM5_1_EXPLANATION = "The following provenance information was not found: ";
191191

192-
public static final String OM5_2 = "OM5_2";
192+
public static final String OM5_2 = "OM5.2";
193193
public static final String OM5_2_TITLE = "Detailed provenance metadata";
194194
public static final String OM5_2_DESC = "This check verifies if detailed provenance information is available " +
195195
"for the ontology: [issued date, publisher]";

src/main/java/fair/FOOPS.java

+25-16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import com.google.gson.Gson;
2222
import com.google.gson.GsonBuilder;
23+
import com.google.gson.JsonObject;
24+
import com.google.gson.JsonParser;
2325
import entities.Check;
2426
import entities.checks.*;
2527
import entities.Ontology;
@@ -38,7 +40,8 @@
3840
import java.nio.file.Path;
3941
import java.util.ArrayList;
4042
import java.util.Optional;
41-
43+
import java.util.HashMap;
44+
import java.util.Map;
4245

4346
public class FOOPS {
4447
private static final Logger logger = LoggerFactory.getLogger(FOOPS.class);
@@ -90,22 +93,28 @@ public void fairTest(){
9093
* @param name Name test.
9194
* @return ????????
9295
*/
93-
public Optional<Check> getTestByName(String name) {
94-
logger.info("------ Get test -----");
95-
// Gson gson = new GsonBuilder().
96-
// excludeFieldsWithoutExposeAnnotation().
97-
// setPrettyPrinting().
98-
// create();
99-
100-
// checks.forEach(check -> {
101-
// logger.info("Objeto completo del check: " + check);
102-
// String jsonCheck = gson.toJson(check);
103-
// logger.info("JSON completo del check: " + jsonCheck);
104-
// });
96+
public Optional<Map<String, String>> getTestByName(String name) {
97+
98+
Gson gson = new GsonBuilder()
99+
.excludeFieldsWithoutExposeAnnotation()
100+
.setPrettyPrinting()
101+
.create();
102+
105103
return checks.stream()
106-
.peek(check -> logger.info("Verificando check: " + check.getClass().getSimpleName()))
107-
.filter(check -> check.getClass().getSimpleName().equals(name))
108-
.findFirst();
104+
.map(check -> {
105+
String jsonCheck = gson.toJson(check);
106+
JsonObject jsonObject = JsonParser.parseString(jsonCheck).getAsJsonObject();
107+
return jsonObject;
108+
})
109+
.filter(jsonObject -> jsonObject.get("abbreviation").getAsString().equals(name))
110+
.map(jsonObject -> {
111+
Map<String, String> details = new HashMap<>();
112+
details.put("description", jsonObject.get("description").getAsString());
113+
details.put("id", jsonObject.get("id").getAsString());
114+
details.put("title", jsonObject.get("title").getAsString());
115+
return details;
116+
})
117+
.findFirst();
109118
}
110119
/**
111120
* In construction

src/main/java/server/FOOPSController.java

+61-15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import io.swagger.annotations.ApiOperation;
3636
import io.swagger.annotations.ApiParam;
3737
import java.util.Optional;
38+
import java.util.Map;
39+
import java.nio.file.Files;
40+
import java.util.HashMap;
3841

3942
@RestController
4043
public 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

Comments
 (0)