All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.ciechanowiec.sling.rocket.jcr.ConditionalProperty Maven / Gradle / Ivy

There is a newer version: 13.26.0
Show newest version
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