Search in sources :

Example 16 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit by apache.

the class NodeTypeDefinitionFactory method create.

/**
     * Create a new JCR property definition from the given <code>QPropertyDefinition</code>.
     *
     * @param qPd A SPI property definition.
     * @return the corresponding JCR property definition.
     * @throws RepositoryException if an error occurs.
     */
public PropertyDefinition create(QPropertyDefinition qPd) throws RepositoryException {
    PropertyDefinitionTemplate pt = ntMgr.createPropertyDefinitionTemplate();
    pt.setName(getJCRName(qPd.getName()));
    pt.setAutoCreated(qPd.isAutoCreated());
    pt.setMandatory(qPd.isMandatory());
    pt.setOnParentVersion(qPd.getOnParentVersion());
    pt.setProtected(qPd.isProtected());
    pt.setRequiredType(qPd.getRequiredType());
    pt.setMultiple(qPd.isMultiple());
    pt.setFullTextSearchable(qPd.isFullTextSearchable());
    pt.setValueConstraints(createValueConstraints(qPd.getRequiredType(), qPd.getValueConstraints()));
    pt.setAvailableQueryOperators(qPd.getAvailableQueryOperators());
    pt.setQueryOrderable(qPd.isQueryOrderable());
    pt.setDefaultValues(createValues(qPd.getDefaultValues()));
    return pt;
}
Also used : PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Example 17 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit-oak by apache.

the class NodeTypeUtils method createPropertyDefTemplate.

/**
     * Creates the property definition template.
     *
     * @param ntm the ntm
     * @param prop the prop
     * @return the property definition template
     * @throws RepositoryException the repository exception
     */
private static PropertyDefinitionTemplate createPropertyDefTemplate(NodeTypeManager ntm, String prop, int type) throws RepositoryException {
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    pdt.setName(prop);
    pdt.setOnParentVersion(OnParentVersionAction.IGNORE);
    pdt.setRequiredType(type);
    pdt.setValueConstraints(null);
    pdt.setDefaultValues(null);
    pdt.setFullTextSearchable(true);
    pdt.setValueConstraints(new String[0]);
    return pdt;
}
Also used : PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Example 18 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit-oak by apache.

the class NodeTypeTest method trivialUpdates.

@Test
public void trivialUpdates() throws Exception {
    // test various trivial updates that should not trigger repository scans
    // whether or not the repository scan happens can not be checked directly;
    // it requires inspecting the INFO level log 
    String[] types = new String[] { "trivial1", "trivial2" };
    ArrayList<NodeTypeTemplate> ntt = new ArrayList<NodeTypeTemplate>();
    // adding node types
    Session session = getAdminSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    for (String t : types) {
        NodeTypeTemplate nt = manager.createNodeTypeTemplate();
        nt.setName(t);
        ntt.add(nt);
    }
    manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), false);
    // adding an optional property
    ntt = new ArrayList<NodeTypeTemplate>();
    for (String t : types) {
        NodeTypeDefinition ntd = manager.getNodeType(t);
        PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
        opt.setMandatory(false);
        opt.setName("optional");
        opt.setRequiredType(PropertyType.STRING);
        PropertyDefinitionTemplate opts = manager.createPropertyDefinitionTemplate();
        opts.setMandatory(false);
        opts.setMultiple(true);
        opts.setName("optionals");
        opts.setRequiredType(PropertyType.STRING);
        NodeTypeTemplate nt = manager.createNodeTypeTemplate(ntd);
        List pdt = nt.getPropertyDefinitionTemplates();
        pdt.add(opt);
        pdt.add(opts);
        ntt.add(nt);
    }
    manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), true);
    // make one optional property mandatory
    ntt = new ArrayList<NodeTypeTemplate>();
    for (String t : types) {
        NodeTypeDefinition ntd = manager.getNodeType(t);
        PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
        opt.setMandatory("trivial2".equals(t));
        opt.setName("optional");
        opt.setRequiredType(PropertyType.STRING);
        PropertyDefinitionTemplate opts = manager.createPropertyDefinitionTemplate();
        opts.setMandatory("trivial2".equals(t));
        opts.setMultiple(true);
        opts.setName("optionals");
        opts.setRequiredType(PropertyType.STRING);
        NodeTypeTemplate nt = manager.createNodeTypeTemplate(ntd);
        List pdt = nt.getPropertyDefinitionTemplates();
        pdt.add(opt);
        pdt.add(opts);
        ntt.add(nt);
    }
    // but update both node types
    manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), true);
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ArrayList(java.util.ArrayList) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 19 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit-oak by apache.

the class RepositoryUpgrade method createPropertyDefinitionTemplate.

private PropertyDefinitionTemplate createPropertyDefinitionTemplate(ValueFactory valueFactory, NodeTypeManager ntMgr, QPropertyDefinition def) throws RepositoryException {
    PropertyDefinitionTemplate tmpl = ntMgr.createPropertyDefinitionTemplate();
    Name name = def.getName();
    if (name != null) {
        tmpl.setName(getOakName(name));
    }
    tmpl.setAutoCreated(def.isAutoCreated());
    tmpl.setMandatory(def.isMandatory());
    tmpl.setOnParentVersion(def.getOnParentVersion());
    tmpl.setProtected(def.isProtected());
    tmpl.setRequiredType(def.getRequiredType());
    tmpl.setMultiple(def.isMultiple());
    tmpl.setAvailableQueryOperators(def.getAvailableQueryOperators());
    tmpl.setFullTextSearchable(def.isFullTextSearchable());
    tmpl.setQueryOrderable(def.isQueryOrderable());
    QValueConstraint[] qConstraints = def.getValueConstraints();
    if (qConstraints != null && qConstraints.length > 0) {
        String[] constraints = new String[qConstraints.length];
        for (int i = 0; i < qConstraints.length; i++) {
            constraints[i] = qConstraints[i].getString();
        }
        tmpl.setValueConstraints(constraints);
    }
    QValue[] qValues = def.getDefaultValues();
    if (qValues != null) {
        NamePathResolver npResolver = new DefaultNamePathResolver(source.getNamespaceRegistry());
        Value[] vs = new Value[qValues.length];
        for (int i = 0; i < qValues.length; i++) {
            vs[i] = ValueFormat.getJCRValue(qValues[i], npResolver, valueFactory);
        }
        tmpl.setDefaultValues(vs);
    }
    return tmpl;
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) QValue(org.apache.jackrabbit.spi.QValue) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)

Example 20 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit-oak by apache.

the class RepositoryUpgrade method createNodeTypeTemplate.

private NodeTypeTemplate createNodeTypeTemplate(ValueFactory valueFactory, NodeTypeManager ntMgr, String oakName, QNodeTypeDefinition def) throws RepositoryException {
    NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
    tmpl.setName(oakName);
    tmpl.setAbstract(def.isAbstract());
    tmpl.setMixin(def.isMixin());
    tmpl.setOrderableChildNodes(def.hasOrderableChildNodes());
    tmpl.setQueryable(def.isQueryable());
    Name primaryItemName = def.getPrimaryItemName();
    if (primaryItemName != null) {
        tmpl.setPrimaryItemName(getOakName(primaryItemName));
    }
    Name[] supertypes = def.getSupertypes();
    if (supertypes != null && supertypes.length > 0) {
        List<String> names = newArrayListWithCapacity(supertypes.length);
        for (Name supertype : supertypes) {
            names.add(getOakName(supertype));
        }
        tmpl.setDeclaredSuperTypeNames(names.toArray(new String[names.size()]));
    }
    List<PropertyDefinitionTemplate> propertyDefinitionTemplates = tmpl.getPropertyDefinitionTemplates();
    for (QPropertyDefinition qpd : def.getPropertyDefs()) {
        PropertyDefinitionTemplate pdt = createPropertyDefinitionTemplate(valueFactory, ntMgr, qpd);
        propertyDefinitionTemplates.add(pdt);
    }
    // + jcr:childNodeDefinition (nt:childNodeDefinition) = nt:childNodeDefinition protected sns
    List<NodeDefinitionTemplate> nodeDefinitionTemplates = tmpl.getNodeDefinitionTemplates();
    for (QNodeDefinition qnd : def.getChildNodeDefs()) {
        NodeDefinitionTemplate ndt = createNodeDefinitionTemplate(ntMgr, qnd);
        nodeDefinitionTemplates.add(ndt);
    }
    return tmpl;
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name)

Aggregations

PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)21 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)13 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 List (java.util.List)5 Node (javax.jcr.Node)5 Session (javax.jcr.Session)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)4 Test (org.junit.Test)4 Value (javax.jcr.Value)3 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 BigDecimal (java.math.BigDecimal)2 Binary (javax.jcr.Binary)2 NamespaceRegistry (javax.jcr.NamespaceRegistry)2 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)2 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)2 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)2