Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removing unneeded JcrPropertyFunctions class
  • Loading branch information
ajs6f committed Apr 17, 2015
1 parent 51f952a commit c4cf788
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 197 deletions.
Expand Up @@ -19,13 +19,12 @@
import static java.lang.System.clearProperty;
import static java.lang.System.getProperty;
import static java.lang.System.setProperty;
import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static org.fcrepo.kernel.FedoraJcrTypes.CONTENT_SIZE;
import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_BINARY;
import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_NON_RDF_SOURCE_DESCRIPTION;
import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.HAS_MESSAGE_DIGEST;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.nodetype2name;
import static org.fcrepo.kernel.utils.ContentDigest.asURI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -67,6 +66,7 @@
import org.fcrepo.kernel.services.BinaryService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.ContainerService;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -202,7 +202,7 @@ public void testGetFederatedObject() throws RepositoryException {
final Node node = object.getNode();
final NodeType[] mixins = node.getMixinNodeTypes();
assertEquals(2, mixins.length);
final boolean found = asList(mixins).stream().map(nodetype2name).anyMatch(FEDORA_CONTAINER::equals);
final boolean found = stream(mixins).map(NodeType::getName).anyMatch(FEDORA_CONTAINER::equals);
assertTrue("Mixin not found: " + FEDORA_CONTAINER, found);

session.save();
Expand All @@ -221,7 +221,7 @@ public void testGetFederatedDatastream() throws RepositoryException {
final NodeType[] mixins = node.getMixinNodeTypes();
assertEquals(2, mixins.length);
final boolean found =
asList(mixins).stream().map(nodetype2name).anyMatch(FEDORA_NON_RDF_SOURCE_DESCRIPTION::equals);
stream(mixins).map(NodeType::getName).anyMatch(FEDORA_NON_RDF_SOURCE_DESCRIPTION::equals);
assertTrue("Mixin not found: " + FEDORA_NON_RDF_SOURCE_DESCRIPTION, found);

session.save();
Expand All @@ -237,7 +237,7 @@ public void testGetFederatedContent() throws RepositoryException {

final NodeType[] mixins = node.getMixinNodeTypes();
assertEquals(2, mixins.length);
final boolean found = asList(mixins).stream().map(nodetype2name).anyMatch(FEDORA_BINARY::equals);
final boolean found = stream(mixins).map(NodeType::getName).anyMatch(FEDORA_BINARY::equals);
assertTrue("Mixin not found: " + FEDORA_BINARY, found);

final File file = fileForNode(node);
Expand Down
Expand Up @@ -19,14 +19,12 @@
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static com.hp.hpl.jena.update.UpdateAction.execute;
import static com.hp.hpl.jena.update.UpdateFactory.create;
import static java.util.Arrays.stream;
import static java.util.function.Function.identity;
import static org.apache.commons.codec.digest.DigestUtils.shaHex;
import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeConverter;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isFrozenNode;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isInternalNode;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.isFrozen;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.property2values;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.value2string;
import static org.fcrepo.kernel.utils.Streams.fromIterator;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;
Expand Down Expand Up @@ -324,9 +322,10 @@ public Date getLastModifiedDate() {
@Override
public boolean hasType(final String type) {
try {
if (isFrozen.test(node) && hasProperty(FROZEN_MIXIN_TYPES)) {
final Stream<Value> values = fromIterator(property2values.apply(getProperty(FROZEN_MIXIN_TYPES)));
return values.map(value2string).anyMatch(type::equals);
if (node.isNodeType(FROZEN_NODE) && hasProperty(FROZEN_MIXIN_TYPES)) {
final Property p = node.getProperty(FROZEN_MIXIN_TYPES);
final Stream<Value> values = p.isMultiple() ? stream(p.getValues()) : Stream.of(p.getValue());
return values.map(Value::toString).anyMatch(type::equals);
}
return node.isNodeType(type);
} catch (final PathNotFoundException e) {
Expand Down
Expand Up @@ -27,7 +27,6 @@

import java.util.Collection;
import java.util.HashSet;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
Expand Down
Expand Up @@ -18,17 +18,13 @@
import static java.util.Collections.disjoint;
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.observation.Event;

import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.observer.EventFilter;

import org.slf4j.Logger;

import java.util.Collections;
import java.util.Set;

/**
Expand Down
Expand Up @@ -17,10 +17,11 @@


import static java.util.Arrays.asList;
import static javax.jcr.PropertyType.BINARY;
import static javax.jcr.PropertyType.REFERENCE;
import static javax.jcr.PropertyType.UNDEFINED;
import static javax.jcr.PropertyType.WEAKREFERENCE;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.isBinaryContentProperty;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Arrays;
Expand Down Expand Up @@ -127,8 +128,8 @@ public abstract class FedoraTypesUtils implements FedoraJcrTypes {
/**
* Check whether a property is an internal property that should be suppressed from external output.
*/
public static Predicate<Property> isInternalProperty = p -> isBinaryContentProperty.test(p) ||
isProtectedAndShouldBeHidden.test(p);
public static Predicate<Property> isInternalProperty = UncheckedPredicate.uncheck(p -> p.getType() == BINARY &&
p.getName().equals(JCR_DATA) || isProtectedAndShouldBeHidden.test(p));

/**
* Check if a node is "internal" and should not be exposed e.g. via the REST API
Expand Down
Expand Up @@ -32,17 +32,18 @@
import javax.jcr.Value;

import com.hp.hpl.jena.rdf.model.Resource;

import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.exception.IdentifierConversionException;
import org.fcrepo.kernel.exception.NoSuchPropertyDefinitionException;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.services.functions.JcrPropertyFunctions;
import org.modeshape.jcr.IsExternal;
import org.slf4j.Logger;

/**
* Tools for replacing, appending and deleting JCR node properties
* @author Chris Beer
* @author ajs6f
* @since May 10, 2013
*/
public class NodePropertiesTools {
Expand Down Expand Up @@ -206,7 +207,7 @@ public Property removeNodeProperty(final Node node, final String propertyName, f

property = node.getProperty(propertyName);

if (JcrPropertyFunctions.isMultipleValuedProperty.test(property)) {
if (property.isMultiple()) {

final List<Value> newValues = new ArrayList<>();

Expand Down
Expand Up @@ -20,25 +20,20 @@
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.getReferencePropertyName;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isSkolemNode;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isReferenceProperty;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.isBinaryContentProperty;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isInternalReferenceProperty;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isInternalProperty;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isNonRdfSourceDescription;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isContainer;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isInternalNode;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.isMultipleValuedProperty;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.value2string;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import java.io.InputStream;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyType;
Expand All @@ -60,7 +55,6 @@
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionManager;

import org.fcrepo.kernel.services.functions.JcrPropertyFunctions;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;

import org.junit.Before;
Expand Down Expand Up @@ -151,37 +145,6 @@ public void setUp() {
initMocks(this);
}

@Test
public void testIsMultipleValuedProperty() throws RepositoryException {
final Property mockYes = mock(Property.class);
when(mockYes.isMultiple()).thenReturn(true);
final Property mockNo = mock(Property.class);
try {
isMultipleValuedProperty.test(null);
fail("Null values should throw a NullPointerException");
} catch (final NullPointerException e) {
// expected
}
boolean actual = isMultipleValuedProperty.test(mockYes);
assertEquals(true, actual);
actual = isMultipleValuedProperty.test(mockNo);
assertEquals(false, actual);
when(mockYes.isMultiple()).thenThrow(new RepositoryException());
try {
isMultipleValuedProperty.test(mockYes);
fail("Unexpected completion after RepositoryException!");
} catch (final RuntimeException e) {
// expected
}
}

@Test
public void testIsBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.BINARY);
when(mockProperty.getName()).thenReturn(JcrConstants.JCR_DATA);
assertTrue(isBinaryContentProperty.test(mockProperty));
}

@Test
public void testIsInternalReferenceProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.REFERENCE);
Expand Down Expand Up @@ -237,19 +200,6 @@ public void testIsInternalProperty() throws RepositoryException {
assertTrue(isInternalProperty.test(mockProperty));
}

@Test
public void testIsNotBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.STRING);
assertFalse(isBinaryContentProperty.test(mockProperty));
}

@Test
public void testContentButNotBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.STRING);
when(mockProperty.getName()).thenReturn(JcrConstants.JCR_DATA);
assertFalse(isBinaryContentProperty.test(mockProperty));
}

@Test
public void testIsBlanknode() throws RepositoryException {
when(mockNode.isNodeType(FEDORA_SKOLEMNODE)).thenReturn(true);
Expand Down Expand Up @@ -302,45 +252,6 @@ public void testPredicateExceptionHandling() throws RepositoryException {
}
}

@Test
public void testValue2String() throws RepositoryException {
// test a valid Value
when(mockValue.getString()).thenReturn("foo");
assertEquals("foo", value2string.apply(mockValue));
when(mockValue.getString()).thenThrow(new RepositoryException());
try {
value2string.apply(mockValue);
fail("Unexpected FedoraTypesUtils.value2string" +
" completion after RepositoryException!");
} catch (final RuntimeException e) {
// expected
}
try {
value2string.apply(null);
fail("Unexpected FedoraTypesUtils.value2string" +
" completion with null argument!");
} catch (final NullPointerException e) {
// expected
}
}

@Test
public void testProperty2values() throws RepositoryException {
// single-valued
when(mockProperty.isMultiple()).thenReturn(false);
when(mockProperty.getValue()).thenReturn(mockValue);
assertEquals("Found wrong Value!", JcrPropertyFunctions.property2values
.apply(mockProperty).next(), mockValue);
// multi-valued
when(mockProperty.isMultiple()).thenReturn(true);
when(mockProperty.getValues()).thenReturn(
new Value[] {mockValue, mockValue2});
final Iterator<Value> testIterator = JcrPropertyFunctions.property2values.apply(mockProperty);
assertEquals("Found wrong Value!", testIterator.next(), mockValue);
assertEquals("Found wrong Value!", testIterator.next(), mockValue2);

}

@Test
public void testGetClosestExistingAncestorRoot() throws RepositoryException {
when(mockSession.getRootNode()).thenReturn(mockRootNode);
Expand Down
Expand Up @@ -15,18 +15,17 @@
*/
package org.fcrepo.kernel.services.functions;

import static java.util.Arrays.stream;
import static org.fcrepo.kernel.FedoraJcrTypes.FROZEN_MIXIN_TYPES;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.isFrozen;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.property2values;
import static org.fcrepo.kernel.services.functions.JcrPropertyFunctions.value2string;
import static org.fcrepo.kernel.utils.Streams.fromIterator;
import static org.fcrepo.kernel.FedoraJcrTypes.FROZEN_NODE;

import java.util.Arrays;
import java.util.Collection;
import java.util.function.Predicate;
import java.util.stream.Stream;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;

Expand Down Expand Up @@ -54,9 +53,10 @@ public BooleanTypesPredicate(final String... types) {
@Override
public boolean test(final Node input) {
try {
if (isFrozen.test(input) && input.hasProperty(FROZEN_MIXIN_TYPES)) {
final Stream<Value> values = fromIterator(property2values.apply(input.getProperty(FROZEN_MIXIN_TYPES)));
return test((int) values.map(value2string).filter(nodeTypes::contains).count());
if (input.isNodeType(FROZEN_NODE) && input.hasProperty(FROZEN_MIXIN_TYPES)) {
final Property p = input.getProperty(FROZEN_MIXIN_TYPES);
final Stream<Value> values = p.isMultiple() ? stream(p.getValues()) : Stream.of(p.getValue());
return test((int) values.map(Value::toString).filter(nodeTypes::contains).count());
}
return test((int) nodeTypes.stream().filter(UncheckedPredicate.uncheck(n->input.isNodeType(n))).count());
} catch (final RepositoryException e) {
Expand Down

0 comments on commit c4cf788

Please sign in to comment.