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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations