eu.ciechanowiec.sling.rocket.jcr.ConditionalProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sling.rocket.commons Show documentation
Show all versions of sling.rocket.commons Show documentation
Common utilities used by Sling Rocket
package eu.ciechanowiec.sling.rocket.jcr;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import javax.jcr.Node;
import javax.jcr.Property;
import java.util.Optional;
@Slf4j
record ConditionalProperty(String propertyName) {
@SneakyThrows
Optional retrieveFrom(Node node) {
log.trace("Retrieving property of name '{}' from {}", propertyName, node);
boolean hasProperty = node.hasProperty(propertyName);
if (hasProperty) {
Property property = node.getProperty(propertyName);
log.trace("Property found and will be returned: {}. Node: {}", property, node);
return Optional.of(property);
} else {
log.trace("No property of name '{}' found for {}", propertyName, node);
return Optional.empty();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy