nl.vpro.domain.user.Editors Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of user-domain Show documentation
Show all versions of user-domain Show documentation
Domain classes and interfaces related to accountability, users and organizations.
package nl.vpro.domain.user;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import jakarta.validation.*;
/**
* @author Michiel Meeuwissen
* @since 5.6
*/
@Slf4j
public class Editors {
private Editors() {
}
private static final Validator VALIDATOR;
static {
Validator validator;
try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
validator = factory.getValidator();
} catch (Exception e) {
log.warn(e.getMessage());
validator = null;
}
VALIDATOR = validator;
}
public static Editor mapWorksFor(List organizations, Editor user) {
if (organizations != null) {
for (Organization organization : organizations) {
if (VALIDATOR != null && !VALIDATOR.validate(organization).isEmpty()) {
log.warn("The organization {} for {} is not valid. Ignoring", organization, user);
continue;
}
if (organization.getDisplayName() == null) {
organization.setDisplayName(organization.getId());
}
user.addOrganization(organization);
}
log.debug("User works for : {}", user.getOrganizations());
}
return user;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy