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;
}
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;
}
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;
}
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));
}
}
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());
}
Aggregations