Search in sources :

Example 71 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class MockNodeTypeGenerator method getCompleteChildNodeDef.

public NodeDefinition getCompleteChildNodeDef(String name) {
    NodeDefinition childNodeDef1 = mock(NodeDefinition.class);
    NodeType requiredPrimaryType1 = getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME1);
    NodeType requiredPrimaryType2 = getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME2);
    NodeType[] reqPrimaryTypes = { requiredPrimaryType1, requiredPrimaryType2 };
    when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes);
    when(childNodeDef1.getName()).thenReturn(name);
    when(childNodeDef1.getOnParentVersion()).thenReturn(OnParentVersionAction.VERSION);
    when(childNodeDef1.getDefaultPrimaryType()).thenReturn(requiredPrimaryType1);
    when(childNodeDef1.allowsSameNameSiblings()).thenReturn(Boolean.TRUE);
    when(childNodeDef1.isAutoCreated()).thenReturn(Boolean.TRUE);
    when(childNodeDef1.isMandatory()).thenReturn(Boolean.TRUE);
    when(childNodeDef1.isProtected()).thenReturn(Boolean.TRUE);
    return childNodeDef1;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 72 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class ChildNodeDefGenerationTest method testCompleteChildNodeDefinitions.

@Test
public void testCompleteChildNodeDefinitions() throws ServletException, IOException, JSONException {
    NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs");
    NodeDefinition childNodeDef1 = getCompleteChildNodeDef("childNodeDef1");
    NodeDefinition childNodeDef2 = getCompleteChildNodeDef("childNodeDef2");
    NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 };
    when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
    when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
    when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
    assertEqualsWithServletResult("testCompleteChildNodeDefinitions");
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Test(org.junit.Test)

Example 73 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class ChildNodeDefGenerationTest method testSimpleChildNodeDefinitions.

@Test
public void testSimpleChildNodeDefinitions() throws ServletException, IOException, JSONException {
    NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs");
    NodeDefinition childNodeDef1 = getSimpleChildNodeDef("childNodeDef1");
    NodeDefinition childNodeDef2 = getSimpleChildNodeDef("childNodeDef2");
    NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 };
    when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
    when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
    when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
    assertEqualsWithServletResult("testSimpleChildNodeDefinitions");
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Test(org.junit.Test)

Example 74 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class DefaultNodeTypeTest method testIfDefaultsAreOmittedWithServlet.

/**
	 * Simulates a node type in the repository that has only default values and checks if they are omitted in the generated
	 * JSON file. 
	 */
@Test
public void testIfDefaultsAreOmittedWithServlet() throws JSONException, ServletException, IOException, ValueFormatException, IllegalStateException, RepositoryException {
    NodeType nt1 = getSimpleNodeTypeWithName("testNodeType");
    when(nodeTypeIterator.nextNodeType()).thenReturn(nt1);
    when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
    NodeType ntBase = mock(NodeType.class);
    when(ntBase.getName()).thenReturn("nt:base");
    NodeDefinition childNodeDef1 = mock(NodeDefinition.class);
    NodeType[] reqPrimaryTypes = { ntBase };
    when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes);
    when(childNodeDef1.getName()).thenReturn("childNodeDef");
    NodeDefinition[] childNodeDefs = { childNodeDef1 };
    when(nt1.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
    String propertyName = "stringPropertyDef";
    PropertyDefinition propertyDef = mock(PropertyDefinition.class);
    when(propertyDef.getRequiredType()).thenReturn(PropertyType.STRING);
    when(propertyDef.getName()).thenReturn(propertyName);
    when(nt1.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef });
    assertEqualsWithServletResult("testIfDefaultsAreOmittedWithServlet");
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Test(org.junit.Test)

Example 75 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class NewNodeDialog method validateInput.

protected void validateInput() {
    final String firstInput = getText().getText();
    final String secondInput = comboSelection;
    try {
        if (secondInput == null || secondInput.length() == 0) {
            setErrorMessage("");
        } else if (ntManager == null) {
            setErrorMessage(null);
        } else if (ntManager.isAllowedPrimaryChildNodeType(parentNodeType, secondInput)) {
            // also check on the name, not only the type
            if (allChildNodeDefs == null) {
                setErrorMessage("No child node definitions found for " + parentNodeType);
            } else {
                boolean success = false;
                for (int i = 0; i < allChildNodeDefs.length; i++) {
                    NodeDefinition aChildNodeDef = allChildNodeDefs[i];
                    if (aChildNodeDef.getName() != null && aChildNodeDef.getName().length() > 0) {
                        if (firstInput.equals(aChildNodeDef.getName())) {
                            setErrorMessage(null);
                            return;
                        }
                    } else {
                        // mark success if there's a child node definition without a name
                        // (ie then it can be any name)
                        success = true;
                    }
                }
                if (success) {
                    setErrorMessage(null);
                    return;
                }
                StringBuffer details = new StringBuffer();
                for (NodeDefinition aChildNodeDef : allChildNodeDefs) {
                    if (details.length() != 0) {
                        details.append(", ");
                    }
                    details.append("(name=" + aChildNodeDef.getName() + ", required primary type(s)=");
                    String[] requiredPrimaryTypeNames = aChildNodeDef.getRequiredPrimaryTypeNames();
                    if (requiredPrimaryTypeNames == null) {
                        details.append("null");
                    } else {
                        for (int j = 0; j < requiredPrimaryTypeNames.length; j++) {
                            String rptn = requiredPrimaryTypeNames[j];
                            if (j > 0) {
                                details.append(",");
                            }
                            details.append(rptn);
                        }
                    }
                    details.append(")");
                }
                setErrorMessage("No matching child node definition found for " + parentNodeType + ". Expected one of: " + details);
            }
        } else {
            setErrorMessage("Error: Invalid child node type of " + parentNodeType);
        }
    } catch (RepositoryException e) {
        setErrorMessage("RepositoryException: " + e);
    }
}
Also used : NodeDefinition(javax.jcr.nodetype.NodeDefinition) RepositoryException(org.apache.sling.ide.transport.RepositoryException) Point(org.eclipse.swt.graphics.Point)

Aggregations

NodeDefinition (javax.jcr.nodetype.NodeDefinition)77 NodeType (javax.jcr.nodetype.NodeType)44 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)29 Node (javax.jcr.Node)17 ItemExistsException (javax.jcr.ItemExistsException)14 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)13 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)13 Version (javax.jcr.version.Version)12 Test (org.junit.Test)11 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 RepositoryException (javax.jcr.RepositoryException)7 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Name (org.apache.jackrabbit.spi.Name)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 ArrayList (java.util.ArrayList)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 Session (javax.jcr.Session)3