use of com.odysseusinc.arachne.portal.model.achilles.Characterization 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);
try {
final Characterization result = characterizationRepository.save(characterization);
JsonParser parser = new JsonParser();
List<AchillesFile> files = new ArrayList<>(batchSize);
ZipFile zipFile = new ZipFile(archivedData);
for (ZipEntry entry : Collections.list(zipFile.entries())) {
String name = entry.getName();
if (!entry.isDirectory()) {
try (final InputStream in = zipFile.getInputStream(entry)) {
try (JsonReader reader = new JsonReader(new InputStreamReader(in))) {
JsonObject jsonObject = parser.parse(reader).getAsJsonObject();
AchillesFile achillesFile = new AchillesFile();
achillesFile.setData(jsonObject);
achillesFile.setFilePath(name);
achillesFile.setCharacterization(result);
files.add(achillesFile);
if (files.size() == batchSize) {
flush(files);
files = new ArrayList<>(batchSize);
}
}
}
}
}
flush(files);
LOGGER.info(IMPORT_ACHILLES_RESULT_LOG, "Finished", dataSourceId, dataSourceName, dataNodeId, dataNodeName);
} finally {
FileUtils.deleteQuietly(tempDir.toFile());
}
}
use of com.odysseusinc.arachne.portal.model.achilles.Characterization in project ArachneCentralAPI by OHDSI.
the class BaseAchillesController method getLatestCharacterization.
@ApiOperation("List latest characterization for given datasource")
@RequestMapping(value = "datasource/{id}", method = RequestMethod.GET)
public JsonResult<CharacterizationDTO> getLatestCharacterization(@PathVariable("id") Long datasourceId) throws NotExistException {
DS dataSource = checkDataSource(datasourceId);
Characterization characterization = achillesService.getLatestCharacterization(dataSource).orElseThrow(() -> new NotExistException(String.format("Characterization doesn't exist for dataSource: %s", datasourceId), Characterization.class));
JsonResult<CharacterizationDTO> result = new JsonResult<>();
result.setErrorCode(NO_ERROR.getCode());
CharacterizationDTO dto = conversionService.convert(characterization, CharacterizationDTO.class);
result.setResult(dto);
return result;
}
Aggregations