Search in sources :

Example 1 with Characterization

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());
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Timestamp(java.sql.Timestamp) Date(java.util.Date) AchillesFile(com.odysseusinc.arachne.portal.model.achilles.AchillesFile) Characterization(com.odysseusinc.arachne.portal.model.achilles.Characterization) ZipFile(java.util.zip.ZipFile) DataNode(com.odysseusinc.arachne.portal.model.DataNode) JsonReader(com.google.gson.stream.JsonReader) JsonParser(com.google.gson.JsonParser) Async(org.springframework.scheduling.annotation.Async) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Characterization

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;
}
Also used : Characterization(com.odysseusinc.arachne.portal.model.achilles.Characterization) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) CharacterizationDTO(com.odysseusinc.arachne.portal.api.v1.dto.CharacterizationDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Characterization (com.odysseusinc.arachne.portal.model.achilles.Characterization)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 CharacterizationDTO (com.odysseusinc.arachne.portal.api.v1.dto.CharacterizationDTO)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 DataNode (com.odysseusinc.arachne.portal.model.DataNode)1 AchillesFile (com.odysseusinc.arachne.portal.model.achilles.AchillesFile)1 ApiOperation (io.swagger.annotations.ApiOperation)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Path (java.nio.file.Path)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 Async (org.springframework.scheduling.annotation.Async)1 Transactional (org.springframework.transaction.annotation.Transactional)1