Search in sources :

Example 1 with ProfileItemType

use of org.karnak.backend.enums.ProfileItemType 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 ProfileItemType

use of org.karnak.backend.enums.ProfileItemType 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)

Aggregations

ArrayList (java.util.ArrayList)2 ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)2 ProfileItemType (org.karnak.backend.enums.ProfileItemType)2 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)1 ProfileItem (org.karnak.backend.model.profiles.ProfileItem)1 ProfileError (org.karnak.frontend.profile.component.errorprofile.ProfileError)1