@Override public boolean apply(PropertyDefinition propertyDefinition) { return propertyDefinition.isAutoCreated(); } });
@Override public boolean apply(PropertyDefinition propertyDefinition) { return propertyDefinition.isAutoCreated(); } });
@Override public boolean apply(PropertyDefinition propertyDefinition) { return propertyDefinition.isAutoCreated(); } });
private void processPropertyDefinition( Node nodeTypeNode, PropertyDefinition propertyDefinition ) throws RepositoryException { Node propertyDefinitionNode = nodeTypeNode.addNode(PROPERTY_DEFINITION, PROPERTY_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(propertyDefinition.getName())) { propertyDefinitionNode.setProperty(NAME, propertyDefinition.getName()); } propertyDefinitionNode.setProperty(AUTO_CREATED, propertyDefinition.isAutoCreated()); propertyDefinitionNode.setProperty(MANDATORY, propertyDefinition.isMandatory()); propertyDefinitionNode.setProperty(MULTIPLE, propertyDefinition.isMultiple()); propertyDefinitionNode.setProperty(PROTECTED, propertyDefinition.isProtected()); propertyDefinitionNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(propertyDefinition.getOnParentVersion())); propertyDefinitionNode.setProperty(REQUIRED_TYPE, org.modeshape.jcr.api.PropertyType.nameFromValue(propertyDefinition.getRequiredType()) .toUpperCase()); String[] availableQueryOperators = propertyDefinition.getAvailableQueryOperators(); propertyDefinitionNode.setProperty(AVAILABLE_QUERY_OPERATORS, availableQueryOperators != null ? availableQueryOperators : new String[0]); Value[] defaultValues = propertyDefinition.getDefaultValues(); propertyDefinitionNode.setProperty(DEFAULT_VALUES, defaultValues != null ? defaultValues : new Value[0]); String[] valueConstraints = propertyDefinition.getValueConstraints(); propertyDefinitionNode.setProperty(VALUE_CONSTRAINTS, valueConstraints != null ? valueConstraints : new String[0]); propertyDefinitionNode.setProperty(IS_FULL_TEXT_SEARCHABLE, propertyDefinition.isFullTextSearchable()); propertyDefinitionNode.setProperty(IS_QUERY_ORDERABLE, propertyDefinition.isQueryOrderable()); }
private void processPropertyDefinition( Node nodeTypeNode, PropertyDefinition propertyDefinition ) throws RepositoryException { Node propertyDefinitionNode = nodeTypeNode.addNode(PROPERTY_DEFINITION, PROPERTY_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(propertyDefinition.getName())) { propertyDefinitionNode.setProperty(NAME, propertyDefinition.getName()); } propertyDefinitionNode.setProperty(AUTO_CREATED, propertyDefinition.isAutoCreated()); propertyDefinitionNode.setProperty(MANDATORY, propertyDefinition.isMandatory()); propertyDefinitionNode.setProperty(MULTIPLE, propertyDefinition.isMultiple()); propertyDefinitionNode.setProperty(PROTECTED, propertyDefinition.isProtected()); propertyDefinitionNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(propertyDefinition.getOnParentVersion())); propertyDefinitionNode.setProperty(REQUIRED_TYPE, org.modeshape.jcr.api.PropertyType.nameFromValue(propertyDefinition.getRequiredType()) .toUpperCase()); String[] availableQueryOperators = propertyDefinition.getAvailableQueryOperators(); propertyDefinitionNode.setProperty(AVAILABLE_QUERY_OPERATORS, availableQueryOperators != null ? availableQueryOperators : new String[0]); Value[] defaultValues = propertyDefinition.getDefaultValues(); propertyDefinitionNode.setProperty(DEFAULT_VALUES, defaultValues != null ? defaultValues : new Value[0]); String[] valueConstraints = propertyDefinition.getValueConstraints(); propertyDefinitionNode.setProperty(VALUE_CONSTRAINTS, valueConstraints != null ? valueConstraints : new String[0]); propertyDefinitionNode.setProperty(IS_FULL_TEXT_SEARCHABLE, propertyDefinition.isFullTextSearchable()); propertyDefinitionNode.setProperty(IS_QUERY_ORDERABLE, propertyDefinition.isQueryOrderable()); }
/** * Tests if auto create properties are not a residual set definition * (getName() does not return "*") */ public void testIsAutoCreate() throws RepositoryException { NodeTypeIterator types = manager.getAllNodeTypes(); // loop all node types while (types.hasNext()) { NodeType type = types.nextNodeType(); PropertyDefinition defs[] = type.getPropertyDefinitions(); for (int i = 0; i < defs.length; i++) { if (defs[i].isAutoCreated()) { assertFalse("An auto create property must not be a " + "residual set definition.", defs[i].getName().equals("*")); } } } }
public boolean isPropertyProtectedOrNewAutoCreated(final Object n, final String name) throws PersistenceException { final Node node = (Node)n; try { final PropertyDefinition pd = this.searchPropertyDefinition(node, name); if ( pd != null ) { // SLING-2877 (autocreated check is only required for new nodes) if ( (node.isNew() && pd.isAutoCreated()) || pd.isProtected() ) { return true; } } } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re); } return false; }
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"); } } } }
property.setAutoCreated(pd.isAutoCreated()); property.setMultiple(pd.isMultiple()); property.setProtected(pd.isProtected());
private static void assertAutoCreatedItems(@NotNull Tree authorizableTree, @NotNull String ntName, @NotNull Root root) throws Exception { NodeType repUser = ReadOnlyNodeTypeManager.getInstance(root, NamePathMapper.DEFAULT).getNodeType(ntName); for (NodeDefinition cnd : repUser.getChildNodeDefinitions()) { if (cnd.isAutoCreated()) { assertTrue(authorizableTree.hasChild(cnd.getName())); } } for (PropertyDefinition pd : repUser.getPropertyDefinitions()) { if (pd.isAutoCreated()) { assertTrue(authorizableTree.hasProperty(pd.getName())); } } } }
assertThat(propDefn.getRequiredType(), is(jcrPropertyType(requiredType))); assertThat(propDefn.isMandatory(), is(options.contains(PropertyOptions.Mandatory))); assertThat(propDefn.isAutoCreated(), is(options.contains(PropertyOptions.Autocreated))); assertThat(propDefn.isProtected(), is(options.contains(PropertyOptions.Protected))); assertThat(propDefn.isMultiple(), is(options.contains(PropertyOptions.Multiple)));
/** * 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(); }
/** * Creates a new property definition based on <code>propDef</code>. * * @param propDef the JCR property definition. * @param resolver the name/path resolver of the session that provided * the property definition. * @param qValueFactory the QValue factory. * @throws RepositoryException if an error occurs while reading from * <code>propDef</code>. */ public QPropertyDefinitionImpl(PropertyDefinition propDef, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException { this(propDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(propDef.getName()), resolver.getQName(propDef.getDeclaringNodeType().getName()), propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), convertValues(propDef.getDefaultValues(), resolver, qValueFactory), propDef.isMultiple(), propDef.getRequiredType(), ValueConstraint.create(propDef.getRequiredType(), propDef.getValueConstraints(), resolver), propDef.getAvailableQueryOperators(), propDef.isFullTextSearchable(), propDef.isQueryOrderable()); }
/** * Creates a new property definition based on <code>propDef</code>. * * @param propDef the JCR property definition. * @param resolver the name/path resolver of the session that provided * the property definition. * @param qValueFactory the QValue factory. * @throws RepositoryException if an error occurs while reading from * <code>propDef</code>. */ public QPropertyDefinitionImpl(PropertyDefinition propDef, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException { this(propDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(propDef.getName()), resolver.getQName(propDef.getDeclaringNodeType().getName()), propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), convertValues(propDef.getDefaultValues(), resolver, qValueFactory), propDef.isMultiple(), propDef.getRequiredType(), ValueConstraint.create(propDef.getRequiredType(), propDef.getValueConstraints(), resolver), propDef.getAvailableQueryOperators(), propDef.isFullTextSearchable(), propDef.isQueryOrderable()); }
propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(),
propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(),
@Override protected void setUp() throws Exception { super.setUp(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType); NodeDefinition[] ndefs = nt.getChildNodeDefinitions(); for (int i = 0; i < ndefs.length; i++) { if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated()) { childNodeDef = ndefs[i]; break; } } PropertyDefinition[] pdefs = nt.getPropertyDefinitions(); for (int i = 0; i < pdefs.length; i++) { if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated()) { childPropDef = pdefs[i]; break; } } if (childPropDef == null && childNodeDef == null) { cleanUp(); throw new NotExecutableException(); } }
private JcrPropertyDefinition propertyDefinitionFrom( PropertyDefinition propDefn ) throws RepositoryException { Name propertyName = nameFactory.create(propDefn.getName()); int onParentVersionBehavior = propDefn.getOnParentVersion(); int requiredType = propDefn.getRequiredType(); boolean mandatory = propDefn.isMandatory(); boolean multiple = propDefn.isMultiple(); boolean autoCreated = propDefn.isAutoCreated(); boolean isProtected = propDefn.isProtected(); boolean fullTextSearchable = propDefn.isFullTextSearchable(); boolean queryOrderable = propDefn.isQueryOrderable(); Value[] defaultValues = propDefn.getDefaultValues(); JcrValue[] jcrDefaultValues = null; if (defaultValues != null) { jcrDefaultValues = new JcrValue[defaultValues.length]; for (int i = 0; i != defaultValues.length; ++i) { Value value = defaultValues[i]; jcrDefaultValues[i] = new JcrValue(this.context.getValueFactories(), value); } } String[] valueConstraints = propDefn.getValueConstraints(); String[] queryOperators = propDefn.getAvailableQueryOperators(); if (valueConstraints == null) valueConstraints = new String[0]; NodeKey prototypeKey = repository.repositoryCache().getSystemKey(); return new JcrPropertyDefinition(this.context, null, prototypeKey, propertyName, onParentVersionBehavior, autoCreated, mandatory, isProtected, jcrDefaultValues, requiredType, valueConstraints, multiple, fullTextSearchable, queryOrderable, queryOperators); }
private JcrPropertyDefinition propertyDefinitionFrom( PropertyDefinition propDefn ) throws RepositoryException { Name propertyName = nameFactory.create(propDefn.getName()); int onParentVersionBehavior = propDefn.getOnParentVersion(); int requiredType = propDefn.getRequiredType(); boolean mandatory = propDefn.isMandatory(); boolean multiple = propDefn.isMultiple(); boolean autoCreated = propDefn.isAutoCreated(); boolean isProtected = propDefn.isProtected(); boolean fullTextSearchable = propDefn.isFullTextSearchable(); boolean queryOrderable = propDefn.isQueryOrderable(); Value[] defaultValues = propDefn.getDefaultValues(); JcrValue[] jcrDefaultValues = null; if (defaultValues != null) { jcrDefaultValues = new JcrValue[defaultValues.length]; for (int i = 0; i != defaultValues.length; ++i) { Value value = defaultValues[i]; jcrDefaultValues[i] = new JcrValue(this.context.getValueFactories(), value); } } String[] valueConstraints = propDefn.getValueConstraints(); String[] queryOperators = propDefn.getAvailableQueryOperators(); if (valueConstraints == null) valueConstraints = new String[0]; NodeKey prototypeKey = repository.repositoryCache().getSystemKey(); return new JcrPropertyDefinition(this.context, null, prototypeKey, propertyName, onParentVersionBehavior, autoCreated, mandatory, isProtected, jcrDefaultValues, requiredType, valueConstraints, multiple, fullTextSearchable, queryOrderable, queryOperators); }