use of uk.ac.ebi.spot.goci.model.EnsemblRestcallHistory in project goci by EBISPOT.
the class EnsemblRestcallHistoryService method getEnsemblRestCallByTypeAndParamAndVersion.
// BEWARE:If the Ensembl release is valid, the system can try to retrieve the data from the table
public RestResponseResult getEnsemblRestCallByTypeAndParamAndVersion(String type, String param, String eRelease) {
RestResponseResult restResponseResult = null;
// Without release it is pointless stores the info.
if (eRelease != null) {
if (!(eRelease.isEmpty())) {
try {
Collection<EnsemblRestcallHistory> urls = ensemblRestcallHistoryRepository.findByRequestTypeAndEnsemblParamAndEnsemblVersion(type, param, eRelease);
if (urls.size() > 0) {
EnsemblRestcallHistory result = urls.iterator().next();
restResponseResult = new RestResponseResult();
restResponseResult.setUrl(result.getEnsemblUrl());
String restApiError = result.getEnsemblError();
if (restApiError != null && !restApiError.isEmpty()) {
restResponseResult.setError(restApiError);
} else {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.convertValue(result.getEnsemblResponse().toString(), JsonNode.class);
restResponseResult.setRestResult(jsonNode);
}
}
} catch (Exception e) {
// BEWARE: the following code MUST NOT block Ensembl Rest API Call
}
}
}
return restResponseResult;
}
use of uk.ac.ebi.spot.goci.model.EnsemblRestcallHistory in project goci by EBISPOT.
the class EnsemblRestcallHistoryService method create.
//Without release version, the data are not stored.
public EnsemblRestcallHistory create(RestResponseResult resultResponseResult, String type, String param, String eRelease) {
EnsemblRestcallHistory ensemblRestcallHistory = new EnsemblRestcallHistory();
String restApiError = resultResponseResult.getError();
if ((resultResponseResult.getStatus() == 200) || (resultResponseResult.getStatus() == 400)) {
if (eRelease != null) {
if (!(eRelease.isEmpty())) {
try {
ensemblRestcallHistory.setEnsemblUrl(resultResponseResult.getUrl());
ensemblRestcallHistory.setEnsemblParam(param);
ensemblRestcallHistory.setRequestType(type);
ensemblRestcallHistory.setEnsemblVersion(eRelease);
// Check for any errors
if (restApiError != null && !restApiError.isEmpty()) {
ensemblRestcallHistory.setEnsemblError(restApiError);
} else {
ensemblRestcallHistory.setEnsemblResponse(resultResponseResult.getRestResult().toString());
}
this.ensemblRestcallHistoryRepository.save(ensemblRestcallHistory);
} catch (Exception e) {
// BEWARE: the following code MUST NOT block Ensembl Rest API Call
}
}
}
}
return ensemblRestcallHistory;
}
Aggregations