Skip to content
Snippets Groups Projects
Commit 7c960dbb authored by ThanKarab's avatar ThanKarab
Browse files

Pathologies endpoint added.

parent 0e9c093c
No related branches found
No related tags found
No related merge requests found
[{
"code": "dementia",
"datasets": [{
"code": "adni"
}, {
"code": "ppmi"
}, {
"code": "edsd"
}
]
}, {
"code": "neuropathology",
"datasets": [{
"code": "neuro1"
}, {
"code": "neuro2"
}, {
"code": "neuro3"
}
]
}
]
/**
* Created by mirco on 04.12.15.
*/
package eu.hbp.mip.controllers;
import com.fasterxml.jackson.core.type.TypeReference;
import eu.hbp.mip.utils.CustomResourceLoader;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping(value = "/pathologies", produces = {APPLICATION_JSON_VALUE})
@Api(value = "/pathologies")
public class PathologiesApi {
@RequestMapping(name = "/pathologies", method = RequestMethod.GET)
public String getPathologies() {
return loadPathologies();
}
@Autowired
private CustomResourceLoader resourceLoader;
private String loadPathologies() {
Resource resource = resourceLoader.getResource("file:/opt/portal/api/pathologies.json");
String result;
try {
result = convertInputStreamToString(resource.getInputStream());
} catch (IOException e) {
result = "{\"error\" : \"The pathologies.json file could not be read.\"}";
}
return result;
}
// Pure Java
private static String convertInputStreamToString(InputStream inputStream) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
}
package eu.hbp.mip.utils;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
@Component
public class CustomResourceLoader implements ResourceLoaderAware {
private ResourceLoader resourceLoader;
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
public Resource getResource(String resourceLocation) {
return resourceLoader.getResource(resourceLocation);
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment