@Override public boolean isRequired() { return this.propertyDef.isMandatory(); }
@Override public boolean apply(PropertyDefinition propertyDefinition) { return propertyDefinition.isMandatory(); } });
@Override public boolean apply(PropertyDefinition propertyDefinition) { return propertyDefinition.isMandatory(); } });
@Override public boolean apply(PropertyDefinition propertyDefinition) { return propertyDefinition.isMandatory(); } });
public boolean canRemoveProperty(String s) { boolean canRemovePrp = true; Iterator it = ntd.getPropertyDefinitionTemplates().iterator(); PropertyDefinition pd = null; while (it.hasNext()) { pd = (PropertyDefinitionTemplate) it.next(); if (((pd != null) && pd.getName().equals(s) && (pd.isProtected() || pd.isMandatory()))) { canRemovePrp = false; return canRemovePrp; } } return canRemovePrp; }
public boolean isPropertyMandatory(final Object node, final String name) throws PersistenceException { try { final Property prop = ((Node)node).getProperty(name); return prop.getDefinition().isMandatory(); } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re); } }
/** * Tests if removing a <code>InputStream</code> property with * <code>Node.setProperty(String, null)</code> works with * <code>parentNode.save()</code> */ public void testRemoveInputStreamPropertyParent() throws Exception { testNode.setProperty(propertyName1, is1); testRootNode.getSession().save(); Property property = testNode.getProperty(propertyName1); if (property.getDefinition().isMandatory() || property.getDefinition().isProtected()) { throw new NotExecutableException("property " + property.getName() + " can not be removed"); } testNode.setProperty(propertyName1, (InputStream) null); testRootNode.getSession().save(); assertFalse("Removing property with Node.setProperty(String, (InputStream)null) and parentNode.save() not working", testNode.hasProperty(propertyName1)); }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
public boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } else { return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * Test the deletion of a property by assigning it a null value, saved from * the Session */ public void testRemoveBinarySession() throws RepositoryException, NotExecutableException { if (property1.getDefinition().isMandatory() || property1.getDefinition().isProtected()) { throw new NotExecutableException("property " + property1.getName() + " can not be removed"); } property1.setValue((InputStream) null); superuser.save(); try { node.getProperty(propertyName1); fail("The property should not exist anymore, as a null Value has been assigned"); } catch (Exception e) { //success : the property has been deleted by assigning it a null value } }
@Override protected Item createRemoveItem() throws NotExecutableException, RepositoryException, LockException, ConstraintViolationException, ItemExistsException, NoSuchNodeTypeException, VersionException { Property removeProperty; if (testRootNode.hasProperty(propertyName1)) { removeProperty = testRootNode.getProperty(propertyName1); if (removeProperty.getDefinition().isProtected() || removeProperty.getDefinition().isMandatory()) { throw new NotExecutableException("Property to be remove must be mandatory nor protected '" + propertyName1 + "'."); } } else { removeProperty = testRootNode.setProperty(propertyName1, "anyString"); } // make sure the new node is persisted. testRootNode.save(); return removeProperty; }
/** * Remove all properties under the given node. */ private void removeProperties(Node node) throws RepositoryException { PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { Property property = properties.nextProperty(); if (property.getDefinition().isProtected() || property.getDefinition().isMandatory()) { continue; } try { property.remove(); } catch (ConstraintViolationException e) { log.debug("Property {} is a reserved property", property.getName()); } } }
private void checkProperty(Node objectNode, FieldDescriptor fieldDescriptor, Value value) throws RepositoryException { if (value == null) { PropertyDefinition definition = getPropertyDefinition(objectNode, fieldDescriptor.getJcrName()); if (definition != null) { if (definition.isMandatory() && !definition.isAutoCreated()) { throw new ObjectContentManagerException("Class of type:" + fieldDescriptor.getClassDescriptor().getClassName() + " has property: " + fieldDescriptor.getFieldName() + " declared as JCR property: " + fieldDescriptor.getJcrName() + " This property is mandatory but property in bean has value null"); } } } }
private void checkProperty(Node objectNode, FieldDescriptor fieldDescriptor, Value value) throws RepositoryException { if (value == null) { PropertyDefinition definition = getPropertyDefinition(objectNode, fieldDescriptor.getJcrName()); if (definition != null) { if (definition.isMandatory() && !definition.isAutoCreated()) { throw new ObjectContentManagerException("Class of type:" + fieldDescriptor.getClassDescriptor().getClassName() + " has property: " + fieldDescriptor.getFieldName() + " declared as JCR property: " + fieldDescriptor.getJcrName() + " This property is mandatory but property in bean has value null"); } } } }
/** * Creates a new property definition. * * @param definition a {@code non-null} {@link PropertyDefinition} */ public RestPropertyType( PropertyDefinition definition ) { this.name = definition.getName(); this.requiredType = org.modeshape.jcr.api.PropertyType.nameFromValue(definition.getRequiredType()); NodeType declaringNodeType = definition.getDeclaringNodeType(); this.declaringNodeTypeName = declaringNodeType == null ? null : declaringNodeType.getName(); this.isAutoCreated = definition.isAutoCreated(); this.isMandatory = definition.isMandatory(); this.isProtected = definition.isProtected(); this.isFullTextSearchable = definition.isFullTextSearchable(); this.onParentVersion = OnParentVersionAction.nameFromValue(definition.getOnParentVersion()); this.isMultiple = definition.isMultiple(); }
@Test public void testDefaultPropertyDefinition() throws Exception { // GIVEN // WHEN Property property = new MockProperty("test", new MockValue("value"), null); // THEN assertThat(property.getDefinition(), instanceOf(MockPropertyDefinition.class)); assertThat(property.getDefinition().isMultiple(), is(false)); assertThat(property.getDefinition().isMandatory(), is(false)); }
@Test public void testPropertyDefinition() throws Exception { // GIVEN final String propertyName = "test"; final MockPropertyDefinition propertyDefinition = new MockPropertyDefinition(propertyName); propertyDefinition.setMultiple(true); propertyDefinition.setMandatory(true); // WHEN Property property = new MockProperty(propertyName, new MockValue("value"), null, propertyDefinition); // THEN assertThat(property.getDefinition(), instanceOf(MockPropertyDefinition.class)); assertThat(property.getDefinition().isMultiple(), is(true)); assertThat(property.getDefinition().isMandatory(), is(true)); }