@Override @SneakyThrows(RepositoryException.class) public boolean hasChildren() { return getValue().isMultiple(); }
private List<String> getValues() throws RepositoryException { if (property.isMultiple()) { final List<String> values = new ArrayList<>(); for (Value value : property.getValues()) { values.add(value.getString()); } return values; } else { return Arrays.asList(property.getString()); } }
private void storeProperty(final Collection<FieldValue> values, final Property property) throws RepositoryException { if (property.isMultiple()) { for (final Value v : property.getValues()) { values.add(getFieldValue(v.getString())); } } else { values.add(getFieldValue(property.getString())); } }
@Override @SneakyThrows(RepositoryException.class) public String getValueAsString() { if (getValue().isMultiple()) { return getName(); } else { return getValue().getString(); } }
private Object getValue(final Property property) { try { if (property.isMultiple()) { return getMultipleValues(property); } else { return getSingleValue(property); } } catch (RepositoryException ignore) {} return null; }
@Override @SneakyThrows(RepositoryException.class) public String getDescription() { return getValue().isMultiple() ? String.valueOf(getValue().getValues().length) : getName(); }
private Value[] getPropertyValues(PropertyValue operand, Node node) throws RepositoryException { Property property = getProperty(operand, node); if (property == null) { return new Value[0]; } else if (property.isMultiple()) { return property.getValues(); } else { return new Value[] { property.getValue() }; } }
public static void moveProperty(Property source, Node targetNode) throws RepositoryException { // JCR props can't be moved, we gotta recreate w/ same value and delete if (source.isMultiple()) { targetNode.setProperty(source.getName(), source.getValues()); } else { targetNode.setProperty(source.getName(), source.getValue()); } source.remove(); }
public Object getValue(Property property) throws RepositoryException { if (property.isMultiple()) { return multiValueGetter.getValue(property.getValues()); } else { return singleValueGetter.getValue(property.getValue()); } }
private void forStringCodecProperties(final Node node, final PropertyVisitor visitor) throws RepositoryException { final PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { final Property property = properties.nextProperty(); if (!property.isMultiple() && property.getType() == PropertyType.STRING && !property.getName().contains(":")) { visitor.visit(property); } } }
protected void verifyProperty( Node node, String propertyName, String expectedValue ) throws RepositoryException { Property property = node.getProperty(propertyName); Value value = property.isMultiple() ? property.getValues()[0] : property.getValue(); assertEquals(expectedValue, value.getString()); }
@Override protected boolean matchesSafely(Property item) { try { final V valueObject = (V) (item.isMultiple() ? Arrays.stream(item.getValues()).map(value -> PropertyUtil.getValueObject(value)).toArray() : PropertyUtil.getValueObject(item.getValue())); return propertyValueMatcher.matches(valueObject); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } }
@Test public void setMultiValueProperty() throws Exception { // GIVEN String[] values = { "Art", "Dan", "Jen" }; JcrNodeAdapter adapter = new JcrNodeAdapter(node); Property<HashSet> property = new ObjectProperty<>(new HashSet<>(Arrays.asList(values))); adapter.addItemProperty("multiple", property); // WHEN Node res = adapter.applyChanges(); // THEN assertTrue(res.getProperty("multiple").isMultiple()); }
private RestProperty createRestProperty( Session session, Property property, String baseUrl ) throws RepositoryException { List<String> values = restPropertyValues(property, baseUrl, session); String url = RestHelper.urlFrom(baseUrl, ITEMS_METHOD_NAME, encodedPath(property.getPath())); String parentUrl = RestHelper.urlFrom(baseUrl, ITEMS_METHOD_NAME, encodedPath(property.getParent().getPath())); boolean multiValued = property.isMultiple(); return new RestProperty(property.getName(), url, parentUrl, values, multiValued); }
@Test public void testIsMultiple() throws RepositoryException { Property property = new MockProperty("test", "test", null); assertTrue(!property.isMultiple()); }
public void testEmptyValues() throws Exception { superuser.importXML(targetPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); superuser.save(); Node n = superuser.getNode(targetPath).getNode(nodeName4); Property p = n.getNode(nodeName3).getProperty("test:multiProperty"); assertTrue(p.isMultiple()); assertTrue(p.getDefinition().isMultiple()); Assert.assertArrayEquals(new String[0], p.getValues()); } }
public void testSingleValues() throws Exception { superuser.importXML(targetPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); superuser.save(); Node n = superuser.getNode(targetPath).getNode(nodeName4); Property p = n.getNode(nodeName1).getProperty("test:multiProperty"); assertTrue(p.isMultiple()); assertTrue(p.getDefinition().isMultiple()); Assert.assertArrayEquals(new Value[]{vf.createValue("v1")}, p.getValues()); }
@Test public void testGetMultiValuedWithSingleValue() throws Exception { // GIVEN final String firstString = "one"; final MockValue first = new MockValue(firstString); // WHEN final Property property = new MockProperty("test", new Value[]{first}, null); // THEN assertTrue(property.isMultiple()); assertEquals(firstString, property.getValues()[0].getString()); }
public void testMultiValues() throws Exception { superuser.importXML(targetPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); superuser.save(); Node n = superuser.getNode(targetPath).getNode(nodeName4); Property p = n.getNode(nodeName2).getProperty("test:multiProperty"); assertTrue(p.isMultiple()); assertTrue(p.getDefinition().isMultiple()); Value[] expected = new Value[] {vf.createValue("v1"), vf.createValue("v2")}; Assert.assertArrayEquals(expected, p.getValues()); }
private static void checkLength(Property p) throws RepositoryException { if (p.isMultiple()) { Value[] vals = p.getValues(); long[] lengths = p.getLengths(); for (int i = 0; i < lengths.length; i++) { assertTrue("Wrong property length", lengths[i] == getValueLength(vals[i])); } } else { assertTrue("Wrong property length", p.getLength() == getValueLength(p.getValue())); } }