Search in sources :

Example 6 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeController method buildEmptyDataNode.

protected DataNode buildEmptyDataNode() {
    DataNode dataNode = new DataNode();
    dataNode.setVirtual(false);
    dataNode.setName(null);
    dataNode.setPublished(false);
    return dataNode;
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode)

Example 7 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode in project ArachneCentralAPI by OHDSI.

the class BaseUserController method unlinkUserToDataNode.

@ApiOperation("Unlink User to DataNode")
@RequestMapping(value = "/api/v1/user-management/datanodes/{datanodeId}/users", method = RequestMethod.DELETE)
public JsonResult unlinkUserToDataNode(@PathVariable("datanodeId") Long datanodeId, @RequestBody CommonLinkUserToDataNodeDTO linkUserToDataNode) throws NotExistException {
    final DN datanode = Optional.ofNullable(baseDataNodeService.getById(datanodeId)).orElseThrow(() -> new NotExistException(String.format(DATA_NODE_NOT_FOUND_EXCEPTION, datanodeId), DataNode.class));
    final U user = userService.getByUsernameInAnyTenant(linkUserToDataNode.getUserName());
    baseDataNodeService.unlinkUserToDataNode(datanode, user);
    return new JsonResult(NO_ERROR);
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode 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;
}
Also used : CommonListEntityRequest(com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest) AtlasService(com.odysseusinc.arachne.portal.service.AtlasService) ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) IAtlas(com.odysseusinc.arachne.portal.model.IAtlas) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ObjectMessage(javax.jms.ObjectMessage) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) Collectors(java.util.stream.Collectors) JMSException(javax.jms.JMSException) CommonEntityDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) List(java.util.List) DataNode(com.odysseusinc.arachne.portal.model.DataNode) Map(java.util.Map) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) MessagingUtils.getRequestQueueName(com.odysseusinc.arachne.commons.service.messaging.MessagingUtils.getRequestQueueName) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) ObjectMessage(javax.jms.ObjectMessage) List(java.util.List) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) IAtlas(com.odysseusinc.arachne.portal.model.IAtlas) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode in project ArachneCentralAPI by OHDSI.

the class AuthenticationSystemTokenFilter method doFilter.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    String token = request.getHeader(tokenHeader);
    if (token != null) {
        DataNode dataNode = baseDataNodeService.findByToken(token).orElseThrow(() -> new BadCredentialsException("dataNode not found"));
        if (SecurityContextHolder.getContext().getAuthentication() == null) {
            GrantedAuthority dataNodeAuthority = new SimpleGrantedAuthority("ROLE_" + Roles.ROLE_DATA_NODE);
            Collection<GrantedAuthority> authorityCollection = new ArrayList<>();
            authorityCollection.add(dataNodeAuthority);
            DataNodeAuthenticationToken authentication = new DataNodeAuthenticationToken(token, dataNode, authorityCollection);
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }
    }
    filterChain.doFilter(servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) DataNode(com.odysseusinc.arachne.portal.model.DataNode) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Example 10 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode 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());
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) Date(java.util.Date) LinkedList(java.util.LinkedList) AchillesFile(com.odysseusinc.arachne.portal.model.achilles.AchillesFile) Characterization(com.odysseusinc.arachne.portal.model.achilles.Characterization) DataNode(com.odysseusinc.arachne.portal.model.DataNode) JsonReader(com.google.gson.stream.JsonReader) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) JsonParser(com.google.gson.JsonParser) Async(org.springframework.scheduling.annotation.Async) Transactional(javax.transaction.Transactional)

Aggregations

DataNode (com.odysseusinc.arachne.portal.model.DataNode)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ApiOperation (io.swagger.annotations.ApiOperation)5 ObjectMessage (javax.jms.ObjectMessage)4 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)3 IUser (com.odysseusinc.arachne.portal.model.IUser)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 CommonEntityDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO)2 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)2 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)2 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)2 Study (com.odysseusinc.arachne.portal.model.Study)2 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)2 List (java.util.List)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1