diff --git a/config/pathologies.json b/config/pathologies.json new file mode 100644 index 0000000000000000000000000000000000000000..2019dbeead083ff750d9f84fca46666a847f1251 --- /dev/null +++ b/config/pathologies.json @@ -0,0 +1,24 @@ +[{ + "code": "dementia", + "datasets": [{ + "code": "adni" + }, { + "code": "ppmi" + }, { + "code": "edsd" + } + + ] + }, { + "code": "neuropathology", + "datasets": [{ + "code": "neuro1" + }, { + "code": "neuro2" + }, { + "code": "neuro3" + } + + ] + } +] diff --git a/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java b/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java new file mode 100644 index 0000000000000000000000000000000000000000..59511de85016213a66eb576e8ea7f8410d5d6b0f --- /dev/null +++ b/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java @@ -0,0 +1,61 @@ +/** + * 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()); + + } +} diff --git a/src/main/java/eu/hbp/mip/utils/CustomResourceLoader.java b/src/main/java/eu/hbp/mip/utils/CustomResourceLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..b7365762468eb400aaec9172e13ae3960986a773 --- /dev/null +++ b/src/main/java/eu/hbp/mip/utils/CustomResourceLoader.java @@ -0,0 +1,20 @@ +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