use of com.odysseusinc.arachne.portal.model.achilles.AchillesFile in project ArachneCentralAPI by OHDSI.
the class AchillesImportServiceImpl method importData.
@Override
@Async(value = "importAchillesReportsExecutor")
@Transactional
public void importData(IDataSource dataSource, File archivedData) throws IOException {
Characterization characterization = new Characterization();
characterization.setDataSource(dataSource);
final Long dataSourceId = dataSource.getId();
final String dataSourceName = dataSource.getName();
final DataNode dataNode = dataSource.getDataNode();
final Long dataNodeId = dataNode.getId();
final String dataNodeName = dataNode.getName();
LOGGER.info(IMPORT_ACHILLES_RESULT_LOG, "Started", dataSourceId, dataSourceName, dataNodeId, dataNodeName);
Timestamp now = new Timestamp(new Date().getTime());
characterization.setDate(now);
Path tempDir = Files.createTempDirectory("achilles_");
entityManager.setFlushMode(FlushModeType.COMMIT);
batch.set(new ArrayList<>());
try {
unzipData(archivedData, tempDir);
List<AchillesFile> files = new LinkedList<>();
JsonParser parser = new JsonParser();
final Characterization result = characterizationRepository.save(characterization);
Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
AchillesFile achillesFile = new AchillesFile();
achillesFile.setFilePath(tempDir.relativize(file).toString());
try (JsonReader reader = new JsonReader(new InputStreamReader(Files.newInputStream(file, READ)))) {
JsonObject jsonObject = parser.parse(reader).getAsJsonObject();
achillesFile.setData(jsonObject);
}
achillesFile.setCharacterization(result);
saveAsBatch(achillesFile);
return CONTINUE;
}
});
flush();
LOGGER.info(IMPORT_ACHILLES_RESULT_LOG, "Finished", dataSourceId, dataSourceName, dataNodeId, dataNodeName);
} finally {
FileUtils.deleteQuietly(tempDir.toFile());
}
}
use of com.odysseusinc.arachne.portal.model.achilles.AchillesFile in project ArachneCentralAPI by OHDSI.
the class AchillesControllerTest method getFile.
@WithUserDetails(value = "admin@odysseusinc.com")
@DatabaseSetup(value = { "/data/achilles/datanode.xml", "/data/achilles/users.xml", "/data/achilles/studies.xml", "/data/achilles/datasources.xml", "/data/achilles/reports.xml", "/data/achilles/characterizations.xml", "/data/achilles/permissions.xml", "/data/achilles/study-participants.xml" })
public void getFile() throws Exception {
Bootstrap bootstrap = new Bootstrap();
AchillesFile observationFile = achillesFileRepository.findOne(11L);
assertThat(observationFile, is(notNullValue()));
observationFile.setData(bootstrap.observationJson());
AchillesFile dashboardFile = achillesFileRepository.findOne(4L);
assertThat(dashboardFile, is(notNullValue()));
dashboardFile.setData(bootstrap.dashboardJson());
achillesFileRepository.save(Arrays.asList(observationFile, dashboardFile));
mvc.perform(get(String.format(API_FILES, PUBLIC_DS, "dashboard.json")).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.result.SUMMARY.ATTRIBUTE_NAME[0]", is("Source name")));
mvc.perform(get(String.format(API_FILES, PUBLIC_DS, "observations/observation_3051227.json")).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.result.OBSERVATIONS_BY_TYPE.CONCEPT_NAME", is("Lab observation numeric result")));
}
use of com.odysseusinc.arachne.portal.model.achilles.AchillesFile in project ArachneCentralAPI by OHDSI.
the class BaseAchillesController method getFile.
@ApiOperation("Get file contents")
@RequestMapping(value = { "datasource/{id}/files/{filename:.*}", "datasource/{id}/files/{filepath:.*}/{filename:.*}" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JsonResult<JsonNode> getFile(@PathVariable("id") Long datasourceId, @RequestParam(name = "char", required = false) Long characterizationId, @PathVariable(value = "filepath", required = false) String path, @PathVariable("filename") String filename) throws NotExistException, IOException {
final String filepath = StringUtils.isBlank(path) ? filename : path + File.separator + filename;
DS dataSource = checkDataSource(datasourceId);
if (characterizationId == null) {
characterizationId = achillesService.getLatestCharacterizationId(dataSource);
}
AchillesFile file = achillesService.getAchillesFile(characterizationId, filepath).orElseThrow(() -> new NotExistException(String.format("File %s not found", filepath), AchillesFile.class));
JsonObject jsonObject = file.getData();
JsonNode node = objectMapper.readTree(new Gson().toJson(jsonObject));
return new JsonResult<>(NO_ERROR, node);
}
Aggregations