Search in sources :

Example 1 with ProfileElementEntity

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

the class Profile method getProfileItems.

public static List<ProfileItem> getProfileItems(ProfileEntity profileEntity) {
    final Set<ProfileElementEntity> listProfileElementEntity = profileEntity.getProfileElementEntities();
    List<ProfileItem> profileItems = new ArrayList<>();
    for (ProfileElementEntity profileElementEntity : listProfileElementEntity) {
        ProfileItemType t = ProfileItemType.getType(profileElementEntity.getCodename());
        if (t == null) {
            LOGGER.error("Cannot find the profile codename: {}", profileElementEntity.getCodename());
        } else {
            Object instanceProfileItem;
            try {
                instanceProfileItem = t.getProfileClass().getConstructor(ProfileElementEntity.class).newInstance(profileElementEntity);
                profileItems.add((ProfileItem) instanceProfileItem);
            } catch (Exception e) {
                LOGGER.error("Cannot build the profile: {}", t.getProfileClass().getName(), e);
            }
        }
    }
    profileItems.sort(Comparator.comparing(ProfileItem::getPosition));
    return profileItems;
}
Also used : ProfileItem(org.karnak.backend.model.profiles.ProfileItem) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ArrayList(java.util.ArrayList) ProfileItemType(org.karnak.backend.enums.ProfileItemType)

Example 2 with ProfileElementEntity

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

the class ProfilePipeService method validateProfile.

public ArrayList<ProfileError> validateProfile(ProfilePipeBody profilePipeYml) {
    ProfileEntity newProfileEntity = createNewProfile(profilePipeYml, false);
    ArrayList<ProfileError> profileErrors = new ArrayList<>();
    for (ProfileElementEntity profileElementEntity : newProfileEntity.getProfileElementEntities()) {
        ProfileError profileError = new ProfileError(profileElementEntity);
        profileErrors.add(profileError);
        ProfileItemType t = ProfileItemType.getType(profileElementEntity.getCodename());
        if (t == null) {
            profileError.setError("Cannot find the profile codename: " + profileElementEntity.getCodename());
        } else {
            try {
                t.getProfileClass().getConstructor(ProfileElementEntity.class).newInstance(profileElementEntity);
            } catch (Exception e) {
                profileError.setError(e.getCause().getMessage());
                continue;
            }
        }
    }
    return profileErrors;
}
Also used : ProfileError(org.karnak.frontend.profile.component.errorprofile.ProfileError) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ArrayList(java.util.ArrayList) ProfileItemType(org.karnak.backend.enums.ProfileItemType) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity)

Example 3 with ProfileElementEntity

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

the class ProfileComponent method createStreamResource.

public static StreamResource createStreamResource(ProfileEntity profileEntity) {
    try {
        Set<ProfileElementEntity> profileElementEntities = profileEntity.getProfileElementEntities().stream().sorted(Comparator.comparing(ProfileElementEntity::getPosition)).collect(Collectors.toCollection(LinkedHashSet::new));
        profileEntity.setProfileElementEntities(profileElementEntities);
        // https://stackoverflow.com/questions/61506368/formatting-yaml-with-jackson
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
        String strYaml = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(profileEntity);
        return new StreamResource(String.format("%s.yml", profileEntity.getName()).replace(" ", "-"), () -> new ByteArrayInputStream(strYaml.getBytes()));
    } catch (final Exception e) {
        LOGGER.error("Cannot create the StreamResource for downloading the yaml profile", e);
    }
    return null;
}
Also used : StreamResource(com.vaadin.flow.server.StreamResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with ProfileElementEntity

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

the class ProfileElementMainView method profilesView.

private void profilesView() {
    removeAll();
    add(new HorizontalLayout(// new horizontalelayout because fix padding
    new H2("Profile element(s)")));
    for (ProfileElementEntity profileElementEntity : profilesOrder) {
        add(setProfileName((profileElementEntity.getPosition() + 1) + ". " + profileElementEntity.getName()));
        add(new ProfileElementView(profileElementEntity));
    }
}
Also used : ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) H2(com.vaadin.flow.component.html.H2) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 5 with ProfileElementEntity

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

the class ProfileElementRepoTest method shouldDeleteRecord.

/**
 * Test delete record.
 */
@Test
void shouldDeleteRecord() {
    // Create an entity to save
    ProfileElementEntity entity = new ProfileElementEntity();
    String name = "Name";
    entity.setName(name);
    // Save the entity
    LOGGER.info("Saving entity with name [{}]", entity.getName());
    entity = repository.save(entity);
    // Retrieve the entity
    Optional<ProfileElementEntity> foundByIdOpt = repository.findById(entity.getId());
    // Test Find by Id
    assertTrue(foundByIdOpt.isPresent());
    // Delete the entity
    entity = foundByIdOpt.get();
    Long id = entity.getId();
    LOGGER.info("Deleting entity with id [{}]", id);
    repository.delete(entity);
    // Test Delete
    foundByIdOpt = repository.findById(id);
    LOGGER.info("Is deleted entity with id [{}] present: [{}]", id, foundByIdOpt.isPresent());
    assertFalse(foundByIdOpt.isPresent());
}
Also used : ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)31 Test (org.junit.jupiter.api.Test)24 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)24 Attributes (org.dcm4che3.data.Attributes)18 IncludedTagEntity (org.karnak.backend.data.entity.IncludedTagEntity)14 Profile (org.karnak.backend.service.profilepipe.Profile)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 HashSet (java.util.HashSet)7 Sequence (org.dcm4che3.data.Sequence)7 ArgumentEntity (org.karnak.backend.data.entity.ArgumentEntity)6 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)6 ProjectEntity (org.karnak.backend.data.entity.ProjectEntity)3 ProfileItemType (org.karnak.backend.enums.ProfileItemType)3 H2 (com.vaadin.flow.component.html.H2)2 ArrayList (java.util.ArrayList)2 MaskEntity (org.karnak.backend.data.entity.MaskEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Div (com.vaadin.flow.component.html.Div)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1