Search in sources :

Example 1 with KheopsAlbumsEntity

use of org.karnak.backend.data.entity.KheopsAlbumsEntity in project karnak by OsiriX-Foundation.

the class GatewaySetUpService method addDestinationNode.

private void addDestinationNode(List<ForwardDestination> dstList, ForwardDicomNode fwdSrcNode, DestinationEntity dstNode) {
    try {
        List<AttributeEditor> editors = new ArrayList<>();
        if (!dstNode.getCondition().isEmpty()) {
            editors.add(new ConditionEditor(dstNode.getCondition()));
        }
        final boolean filterBySOPClassesEnable = dstNode.isFilterBySOPClasses();
        if (filterBySOPClassesEnable) {
            editors.add(new FilterEditor(dstNode.getSOPClassUIDEntityFilters()));
        }
        final List<KheopsAlbumsEntity> kheopsAlbumEntities = dstNode.getKheopsAlbumEntities();
        SwitchingAlbum switchingAlbum = new SwitchingAlbum();
        if (kheopsAlbumEntities != null && !kheopsAlbumEntities.isEmpty()) {
            editors.add((Attributes dcm, AttributeEditorContext context) -> {
                kheopsAlbumEntities.forEach(kheopsAlbums -> {
                    switchingAlbum.apply(dstNode, kheopsAlbums, dcm);
                });
            });
        }
        StreamRegistryEditor streamRegistryEditor = new StreamRegistryEditor();
        editors.add(streamRegistryEditor);
        boolean deidentificationEnable = dstNode.isDesidentification();
        boolean profileDefined = dstNode.getProjectEntity() != null && dstNode.getProjectEntity().getProfileEntity() != null;
        if (deidentificationEnable && profileDefined) {
            // TODO add an option in destination model
            editors.add(new DeIdentifyEditor(dstNode));
        }
        DicomProgress progress = new DicomProgress();
        if (dstNode.isActivate()) {
            if (dstNode.getDestinationType() == DestinationType.stow) {
                // parse headers to hashmap
                HashMap<String, String> map = new HashMap<>();
                String headers = dstNode.getHeaders();
                Document doc = Jsoup.parse(headers);
                String key = doc.getElementsByTag("key").text();
                String value = doc.getElementsByTag("value").text();
                if (StringUtil.hasText(key)) {
                    map.put(key, value);
                }
                WebForwardDestination fwd = new WebForwardDestination(dstNode.getId(), fwdSrcNode, dstNode.getUrl(), map, progress, editors, dstNode.getTransferSyntax(), dstNode.isTranscodeOnlyUncompressed());
                if (kheopsAlbumEntities != null && !kheopsAlbumEntities.isEmpty()) {
                    progress.addProgressListener((DicomProgress dicomProgress) -> {
                        Attributes dcm = dicomProgress.getAttributes();
                        kheopsAlbumEntities.forEach(kheopsAlbums -> {
                            switchingAlbum.applyAfterTransfer(kheopsAlbums, dcm);
                        });
                    });
                }
                dstList.add(fwd);
            } else {
                DicomNode destinationNode = new DicomNode(dstNode.getAeTitle(), dstNode.getHostname(), dstNode.getPort());
                DicomForwardDestination dest = new DicomForwardDestination(dstNode.getId(), getDefaultAdvancedParameters(), fwdSrcNode, destinationNode, dstNode.getUseaetdest(), progress, editors, dstNode.getTransferSyntax(), dstNode.isTranscodeOnlyUncompressed());
                dstList.add(dest);
            }
        }
    } catch (IOException e) {
        LOGGER.error("Cannot build ForwardDestination", e);
    }
}
Also used : HashMap(java.util.HashMap) ConditionEditor(org.karnak.backend.model.editor.ConditionEditor) ArrayList(java.util.ArrayList) Attributes(org.dcm4che3.data.Attributes) FilterEditor(org.karnak.backend.model.editor.FilterEditor) IOException(java.io.IOException) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Document(org.jsoup.nodes.Document) StreamRegistryEditor(org.karnak.backend.model.editor.StreamRegistryEditor) DicomProgress(org.weasis.dicom.param.DicomProgress) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) DeIdentifyEditor(org.karnak.backend.model.editor.DeIdentifyEditor) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) AttributeEditor(org.weasis.dicom.param.AttributeEditor) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode)

Example 2 with KheopsAlbumsEntity

use of org.karnak.backend.data.entity.KheopsAlbumsEntity in project karnak by OsiriX-Foundation.

the class KheopsAlbumsRepoTest method shouldFindAllRecords.

/**
 * Test find all.
 */
@Test
void shouldFindAllRecords() {
    // Create an entity to save
    // Destination
    DestinationEntity destinationEntity = new DestinationEntity();
    destinationEntity.setAeTitle("AeTitle");
    destinationEntity.setDestinationType(DestinationType.dicom);
    destinationEntity.setHostname("hostName");
    destinationEntity.setPort(1);
    destinationEntity = destinationRepo.saveAndFlush(destinationEntity);
    // Kheops Albums
    KheopsAlbumsEntity entity = new KheopsAlbumsEntity();
    entity.setCondition("Condition");
    entity.setDestinationEntity(destinationEntity);
    // Save the entity
    LOGGER.info("Saving entity with Condition [{}]", entity.getCondition());
    repository.saveAndFlush(entity);
    // Find all
    List<KheopsAlbumsEntity> all = repository.findAll();
    // Test find all
    assertNotNull(all);
    assertTrue(all.size() > 0);
    assertEquals(1, all.size());
    LOGGER.info("Number of entities found [{}]", all.size());
}
Also used : DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 3 with KheopsAlbumsEntity

use of org.karnak.backend.data.entity.KheopsAlbumsEntity in project karnak by OsiriX-Foundation.

the class KheopsAlbumsRepoTest method shouldSaveAndFindARecord.

/**
 * Test save and find record.
 */
@Test
void shouldSaveAndFindARecord() {
    // Create an entity to save
    KheopsAlbumsEntity entity = new KheopsAlbumsEntity();
    entity.setCondition("Condition");
    // Save the entity
    LOGGER.info("Saving entity with Condition [{}]", entity.getCondition());
    entity = repository.save(entity);
    // Test Save
    assertEquals("Condition", entity.getCondition());
    assertNotNull(entity.getId());
    LOGGER.info("Entity with Condition [{}] and id [{}] saved", entity.getCondition(), entity.getId());
    // Find By Id
    Optional<KheopsAlbumsEntity> foundByIdOpt = repository.findById(entity.getId());
    // Test Find by Id
    assertTrue(foundByIdOpt.isPresent());
    LOGGER.info("Entity found with Condition [{}] and id [{}]", foundByIdOpt.get().getCondition(), foundByIdOpt.get().getId());
    assertEquals(entity.getId(), foundByIdOpt.get().getId());
}
Also used : KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 4 with KheopsAlbumsEntity

use of org.karnak.backend.data.entity.KheopsAlbumsEntity in project karnak by OsiriX-Foundation.

the class TextFieldsBindSwitchingAlbum method buildBinder.

private Binder<KheopsAlbumsEntity> buildBinder() {
    Binder<KheopsAlbumsEntity> b = new BeanValidationBinder<>(KheopsAlbumsEntity.class);
    b.forField(textAuthorizationDestination).withValidator(StringUtils::isNotBlank, "Token destination is mandatory").withValidator(value -> {
        if (!textUrlAPI.getValue().isBlank()) {
            return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_DESTINATION);
        }
        return true;
    }, "Token can't be validate, minimum permissions: [write]").bind(KheopsAlbumsEntity::getAuthorizationDestination, KheopsAlbumsEntity::setAuthorizationDestination);
    b.forField(textAuthorizationSource).withValidator(StringUtils::isNotBlank, "Token source is mandatory").withValidator(value -> {
        if (!textUrlAPI.getValue().isBlank()) {
            return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_SOURCE);
        }
        return true;
    }, "Token can't be validate, minimum permissions: [read, send]").bind(KheopsAlbumsEntity::getAuthorizationSource, KheopsAlbumsEntity::setAuthorizationSource);
    b.forField(textUrlAPI).withValidator(StringUtils::isNotBlank, "Url API is mandatory").bind(KheopsAlbumsEntity::getUrlAPI, KheopsAlbumsEntity::setUrlAPI);
    b.forField(textCondition).withValidator(value -> {
        if (!textCondition.getValue().equals("")) {
            expressionError = ExpressionResult.isValid(textCondition.getValue(), new ExprCondition(), Boolean.class);
            textErrorConditionMsg.setText(expressionError.getMsg());
            return expressionError.isValid();
        }
        textErrorConditionMsg.setText("");
        return true;
    }, "Condition is not valid").bind(KheopsAlbumsEntity::getCondition, KheopsAlbumsEntity::setCondition);
    return b;
}
Also used : KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Binder(com.vaadin.flow.data.binder.Binder) StringUtils(org.apache.commons.lang3.StringUtils) List(java.util.List) JSONObject(org.json.JSONObject) ExpressionError(org.karnak.backend.model.expression.ExpressionError) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) KheopsApi(org.karnak.backend.api.KheopsApi) TextField(com.vaadin.flow.component.textfield.TextField) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) Span(com.vaadin.flow.component.html.Span) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) ExprCondition(org.karnak.backend.model.expression.ExprCondition) ExprCondition(org.karnak.backend.model.expression.ExprCondition) StringUtils(org.apache.commons.lang3.StringUtils) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity)

Example 5 with KheopsAlbumsEntity

use of org.karnak.backend.data.entity.KheopsAlbumsEntity in project karnak by OsiriX-Foundation.

the class SwitchingAlbumsView method setEventButtonAdd.

private void setEventButtonAdd() {
    newSwitchingAlbum.getButtonAdd().addClickListener(event -> {
        newSwitchingAlbum.getTextErrorConditionMsg().setText("");
        KheopsAlbumsEntity newKheopsAlbumsEntity = new KheopsAlbumsEntity();
        if (newSwitchingAlbumBinder.writeBeanIfValid(newKheopsAlbumsEntity)) {
            // Add only if not already existing in table
            if (!dataProviderSwitchingAlbums.getItems().contains(newKheopsAlbumsEntity)) {
                dataProviderSwitchingAlbums.getItems().add(newKheopsAlbumsEntity);
                dataProviderSwitchingAlbums.refreshAll();
                newSwitchingAlbum.clear();
            } else {
                // Otherwise error message already existing
                newSwitchingAlbum.getTextErrorConditionMsg().setText("Already existing");
            }
        }
    });
}
Also used : KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity)

Aggregations

KheopsAlbumsEntity (org.karnak.backend.data.entity.KheopsAlbumsEntity)15 Test (org.junit.jupiter.api.Test)10 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)8 ArrayList (java.util.ArrayList)7 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)5 List (java.util.List)3 ProjectEntity (org.karnak.backend.data.entity.ProjectEntity)3 Span (com.vaadin.flow.component.html.Span)2 TextField (com.vaadin.flow.component.textfield.TextField)2 Binder (com.vaadin.flow.data.binder.Binder)2 HashSet (java.util.HashSet)2 WeakHashMap (java.util.WeakHashMap)2 Attributes (org.dcm4che3.data.Attributes)2 JSONObject (org.json.JSONObject)2 KheopsApi (org.karnak.backend.api.KheopsApi)2 DicomSourceNodeEntity (org.karnak.backend.data.entity.DicomSourceNodeEntity)2 ForwardNodeEntity (org.karnak.backend.data.entity.ForwardNodeEntity)2 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)2 DicomForwardDestination (org.karnak.backend.dicom.DicomForwardDestination)2 ExprCondition (org.karnak.backend.model.expression.ExprCondition)2