use of com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeMessageServiceImpl method getDataList.
@Override
@PreAuthorize("hasPermission(#dataNode, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).IMPORT_FROM_DATANODE)")
public <T extends CommonEntityDTO> List<T> getDataList(DN dataNode, CommonAnalysisType analysisType) throws JMSException {
Long waitForResponse = messagingTimeout;
Long messageLifeTime = messagingTimeout;
// Get all Atlases available in user's tenant
List<IAtlas> atlasList = atlasService.findAll().stream().filter(a -> a.getVersion() != null).collect(Collectors.toList());
String baseQueue = MessagingUtils.EntitiesList.getBaseQueue(dataNode);
ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, new CommonEntityRequestObject(atlasList.stream().map(IAtlas::getId).collect(Collectors.toList()), analysisType), baseQueue, waitForResponse, messageLifeTime);
ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
List<T> entityList = (List<T>) responseMessage.getObject();
Map<Long, IAtlas> atlasMap = atlasList.stream().collect(Collectors.toMap(IAtlas::getId, a -> a));
entityList.forEach(e -> e.setName(atlasMap.get(e.getOriginId()).getName() + ": " + e.getName()));
return entityList;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method update.
@Override
@PreAuthorize("hasPermission(#analysis, 'Analysis', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public A update(A analysis) throws NotUniqueException, NotExistException, ValidationException {
A forUpdate = analysisRepository.findOne(analysis.getId());
if (forUpdate == null) {
throw new NotExistException("update: analysis with id=" + analysis.getId() + " not exist", Analysis.class);
}
if (analysis.getTitle() != null && !analysis.getTitle().equals(forUpdate.getTitle())) {
List<A> analyses = analysisRepository.findByTitleAndStudyId(analysis.getTitle(), forUpdate.getStudy().getId());
if (!analyses.isEmpty()) {
throw new NotUniqueException("title", "Not unique");
}
forUpdate.setTitle(analysis.getTitle());
}
if (analysis.getDescription() != null) {
forUpdate.setDescription(analysis.getDescription());
}
final CommonAnalysisType analysisType = analysis.getType();
if (analysisType != null) {
forUpdate.setType(analysisType);
}
final A saved = super.update(forUpdate);
solrService.indexBySolr(saved);
return saved;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method doAddCommonEntityToAnalysis.
protected void doAddCommonEntityToAnalysis(T analysis, DataReference dataReference, IUser user, CommonAnalysisType analysisType, List<MultipartFile> files) throws IOException {
files.stream().filter(f -> !CommonAnalysisType.COHORT.equals(analysisType) || !f.getName().endsWith(CommonFileUtils.OHDSI_JSON_EXT)).forEach(f -> {
try {
analysisService.saveFile(f, user, analysis, f.getName(), detectExecutable(analysisType, f), dataReference);
} catch (IOException e) {
LOGGER.error("Failed to save file", e);
}
});
if (analysisType.equals(CommonAnalysisType.COHORT)) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
class StringContainer {
String value = CommonAnalysisType.COHORT.getTitle();
}
final StringContainer generatedFileName = new StringContainer();
try (final ZipOutputStream zos = new ZipOutputStream(out)) {
files.forEach(file -> {
try {
if (file.getName().endsWith(CommonFileUtils.OHDSI_SQL_EXT)) {
String statement = org.apache.commons.io.IOUtils.toString(file.getInputStream(), "UTF-8");
String renderedSql = SqlRender.renderSql(statement, null, null);
DBMSType[] dbTypes = new DBMSType[] { DBMSType.POSTGRESQL, DBMSType.ORACLE, DBMSType.MS_SQL_SERVER, DBMSType.REDSHIFT, DBMSType.PDW };
String baseName = FilenameUtils.getBaseName(file.getOriginalFilename());
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
for (final DBMSType dialect : dbTypes) {
final String sql = SqlTranslate.translateSql(renderedSql, DBMSType.MS_SQL_SERVER.getOhdsiDB(), dialect.getOhdsiDB());
final String fileName = baseName + "." + dialect.getLabel().replaceAll(" ", "-") + "." + extension;
ZipUtil.addZipEntry(zos, fileName, new ByteArrayInputStream(sql.getBytes("UTF-8")));
}
final String shortBaseName = baseName.replaceAll("\\.ohdsi", "");
if (!generatedFileName.value.contains(shortBaseName)) {
generatedFileName.value += "_" + shortBaseName;
}
} else {
String fileName = file.getName();
ZipUtil.addZipEntry(zos, fileName, file.getInputStream());
}
} catch (IOException e) {
LOGGER.error("Failed to add file to archive", e);
throw new RuntimeIOException(e.getMessage(), e);
}
});
}
String fileName = generatedFileName.value + ".zip";
final MultipartFile sqlArchive = new MockMultipartFile(fileName, fileName, "application/zip", out.toByteArray());
analysisService.saveFile(sqlArchive, user, analysis, fileName, false, dataReference);
}
}
use of com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method updateCommonEntityInAnalysis.
@ApiOperation("update common entity in analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities/{fileUuid}", method = PUT)
public JsonResult updateCommonEntityInAnalysis(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String fileUuid, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws IOException, JMSException, PermissionDeniedException, URISyntaxException {
final IUser user = getUser(principal);
final AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, fileUuid);
T analysis = (T) analysisFile.getAnalysis();
final DataReference dataReference = analysisFile.getDataReference();
final DataReferenceDTO entityReference = new DataReferenceDTO(dataReference.getDataNode().getId(), dataReference.getGuid());
final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataReference.getDataNode(), analysisType);
analysisService.findAnalysisFilesByDataReference(analysis, dataReference).forEach(af -> {
analysisService.deleteAnalysisFile(analysis, af);
analysis.getFiles().remove(af);
});
doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
return new JsonResult(NO_ERROR);
}
use of com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType in project ArachneCentralAPI by OHDSI.
the class SubmissionHelper method updateSubmissionExtendedInfo.
public void updateSubmissionExtendedInfo(final Submission submission) {
final CommonAnalysisType analysisType = submission.getSubmissionGroup().getAnalysisType();
SubmissionExtendInfoAnalyzeStrategy strategy;
switch(analysisType) {
case COHORT:
{
strategy = new CohortSubmissionExtendInfoStrategy();
break;
}
case COHORT_CHARACTERIZATION:
{
strategy = new CohortCharacterizationSubmissionExtendInfoStrategy();
break;
}
case INCIDENCE:
{
strategy = new IncidenceSubmissionExtendInfoStrategy();
break;
}
case ESTIMATION:
{
strategy = new EstimationSubmissionExtendInfoStrategy();
break;
}
case PREDICTION:
{
strategy = new PredictionSubmissionExtendInfoStrategy();
break;
}
default:
{
strategy = new DefaultSubmissionExtendInfoStrategy();
}
}
strategy.updateExtendInfo(submission);
}
Aggregations