@Override public String toString() { return getDirectTypeNames().toString(); }
@Override public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException { if (checkThisNode && effective.isMandatoryChildNode(name)) { constraintViolation(26, "Mandatory child node " + name + " can not be removed"); } return null; // no further checking needed for the removed subtree }
@NotNull Set<String> getMandatoryProperties() { return getNameSet(REP_MANDATORY_PROPERTIES); }
private void checkNodeTypeConstraints(NodeState after) throws CommitFailedException { EffectiveType effective = getEffective(); Set<String> properties = effective.getMandatoryProperties(); for (PropertyState ps : after.getProperties()) { properties.remove(ps.getName()); checkPropertyTypeConstraints(ps); } // verify the presence of all mandatory items if (!properties.isEmpty()) { constraintViolation(21, "Mandatory property " + properties.iterator().next() + " not found in a new node"); } List<String> names = Lists.newArrayList(after.getChildNodeNames()); for (String child : effective.getMandatoryChildNodes()) { if (!names.remove(child)) { constraintViolation(25, "Mandatory child node " + child + " not found in a new node"); } } if (!names.isEmpty()) { for (String name : names) { NodeState child = after.getChildNode(name); String primary = child.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = child.getNames(JCR_MIXINTYPES); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, false); if (!effective.isValidChildNode(name, editor.getEffective())) { constraintViolation(25, "Unexpected child node " + name + " found in a new node"); } } } }
@Test(expected = CommitFailedException.class) public void removeMandatoryChildNode() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryChildNode("mandatory")).andReturn(true); expect(effective.getDirectTypeNames()).andReturn(Collections.emptyList()); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.childNodeDeleted("mandatory", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void removeMandatoryProperty() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryProperty("mandatory")).andReturn(true); expect(effective.getDirectTypeNames()).andReturn(Collections.emptyList()); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.propertyDeleted(PropertyStates.createProperty("mandatory", "")); }
private void checkPropertyTypeConstraints(PropertyState after) throws CommitFailedException { if (NodeStateUtils.isHidden(after.getName())) { return; } NodeState definition = effective.getDefinition(after); if (definition == null) { constraintViolation(4, "No matching property definition found for " + after); } else if (JCR_UUID.equals(after.getName()) && effective.isNodeType(MIX_REFERENCEABLE)) { // special handling for the jcr:uuid property of mix:referenceable // TODO: this should be done in a pluggable extension if (!isValidUUID(after.getValue(Type.STRING))) { constraintViolation(12, "Invalid UUID value in the jcr:uuid property"); } } else { int requiredType = getRequiredType(definition); if (requiredType != PropertyType.UNDEFINED) { checkRequiredType(after, requiredType); checkValueConstraints(definition, after, requiredType); } } }
@Override public TypeEditor childNodeChanged( String name, NodeState before, NodeState after) throws CommitFailedException { String primary = after.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = after.getNames(JCR_MIXINTYPES); if (primary == null && effective != null) { // no primary type defined, find and apply a default type primary = effective.getDefaultType(name); if (primary != null) { builder.setProperty(JCR_PRIMARYTYPE, primary, NAME); } else { constraintViolation( 4, "No default primary type available " + " for child node " + name); } } // if node type didn't change no need to validate child node boolean validate = primaryChanged(before, primary) || mixinsChanged(before, mixins); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, validate); if (checkThisNode && validate && !effective.isValidChildNode(name, editor.getEffective())) { constraintViolation( 1, "No matching definition found for child node " + name + " with effective type " + editor.getEffective()); } return editor; }
} else { if (type.getBoolean(JCR_IS_ABSTRACT)) { if (parent != null && name != null && primary.equals(parent.getDefaultType(name))) { return new EffectiveType(list);
String name = dropIndexFromName(nameWithIndex); boolean sns = !name.equals(nameWithIndex); Set<String> typeNames = effective.getTypeNames(); if (definition.exists() && snsMatch(sns, definition)) { return true; for (String typeName : typeNames) { NodeState definition = residual.getChildNode(typeName); if (definition.exists() && snsMatch(sns, definition)) { return true;
@Override public void propertyDeleted(PropertyState before) throws CommitFailedException { String name = before.getName(); if (checkThisNode && effective.isMandatoryProperty(name)) { constraintViolation( 22, "Mandatory property " + name + " can not be removed"); } }
private void checkNodeTypeConstraints(NodeState after) throws CommitFailedException { EffectiveType effective = getEffective(); Set<String> properties = effective.getMandatoryProperties(); for (PropertyState ps : after.getProperties()) { properties.remove(ps.getName()); checkPropertyTypeConstraints(ps); } // verify the presence of all mandatory items if (!properties.isEmpty()) { constraintViolation(21, "Mandatory property " + properties.iterator().next() + " not found in a new node"); } List<String> names = Lists.newArrayList(after.getChildNodeNames()); for (String child : effective.getMandatoryChildNodes()) { if (!names.remove(child)) { constraintViolation(25, "Mandatory child node " + child + " not found in a new node"); } } if (!names.isEmpty()) { for (String name : names) { NodeState child = after.getChildNode(name); String primary = child.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = child.getNames(JCR_MIXINTYPES); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, false); if (!effective.isValidChildNode(name, editor.getEffective())) { constraintViolation(25, "Unexpected child node " + name + " found in a new node"); } } } }
private void checkPropertyTypeConstraints(PropertyState after) throws CommitFailedException { if (NodeStateUtils.isHidden(after.getName())) { return; } NodeState definition = effective.getDefinition(after); if (definition == null) { constraintViolation(4, "No matching property definition found for " + after); } else if (JCR_UUID.equals(after.getName()) && effective.isNodeType(MIX_REFERENCEABLE)) { // special handling for the jcr:uuid property of mix:referenceable // TODO: this should be done in a pluggable extension if (!isValidUUID(after.getValue(Type.STRING))) { constraintViolation(12, "Invalid UUID value in the jcr:uuid property"); } } else { int requiredType = getRequiredType(definition); if (requiredType != PropertyType.UNDEFINED) { checkRequiredType(after, requiredType); checkValueConstraints(definition, after, requiredType); } } }
@Override public TypeEditor childNodeChanged( String name, NodeState before, NodeState after) throws CommitFailedException { String primary = after.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = after.getNames(JCR_MIXINTYPES); if (primary == null && effective != null) { // no primary type defined, find and apply a default type primary = effective.getDefaultType(name); if (primary != null) { builder.setProperty(JCR_PRIMARYTYPE, primary, NAME); } else { constraintViolation( 4, "No default primary type available " + " for child node " + name); } } // if node type didn't change no need to validate child node boolean validate = primaryChanged(before, primary) || mixinsChanged(before, mixins); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, validate); if (checkThisNode && validate && !effective.isValidChildNode(name, editor.getEffective())) { constraintViolation( 1, "No matching definition found for child node " + name + " with effective type " + editor.getEffective()); } return editor; }
} else { if (type.getBoolean(JCR_IS_ABSTRACT)) { if (parent != null && name != null && primary.equals(parent.getDefaultType(name))) { return new EffectiveType(list);
String name = dropIndexFromName(nameWithIndex); boolean sns = !name.equals(nameWithIndex); Set<String> typeNames = effective.getTypeNames(); if (definition.exists() && snsMatch(sns, definition)) { return true; for (String typeName : typeNames) { NodeState definition = residual.getChildNode(typeName); if (definition.exists() && snsMatch(sns, definition)) { return true;
@Override public void propertyDeleted(PropertyState before) throws CommitFailedException { String name = before.getName(); if (checkThisNode && effective.isMandatoryProperty(name)) { constraintViolation( 22, "Mandatory property " + name + " can not be removed"); } }
private void checkNodeTypeConstraints(NodeState after) throws CommitFailedException { EffectiveType effective = getEffective(); Set<String> properties = effective.getMandatoryProperties(); for (PropertyState ps : after.getProperties()) { properties.remove(ps.getName()); checkPropertyTypeConstraints(ps); } // verify the presence of all mandatory items if (!properties.isEmpty()) { constraintViolation(21, "Mandatory property " + properties.iterator().next() + " not found in a new node"); } List<String> names = Lists.newArrayList(after.getChildNodeNames()); for (String child : effective.getMandatoryChildNodes()) { if (!names.remove(child)) { constraintViolation(25, "Mandatory child node " + child + " not found in a new node"); } } if (!names.isEmpty()) { for (String name : names) { NodeState child = after.getChildNode(name); String primary = child.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = child.getNames(JCR_MIXINTYPES); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, false); if (!effective.isValidChildNode(name, editor.getEffective())) { constraintViolation(25, "Unexpected child node " + name + " found in a new node"); } } } }
@Override public String toString() { return getDirectTypeNames().toString(); }
private void checkPropertyTypeConstraints(PropertyState after) throws CommitFailedException { if (NodeStateUtils.isHidden(after.getName())) { return; } NodeState definition = effective.getDefinition(after); if (definition == null) { constraintViolation(4, "No matching property definition found for " + after); } else if (JCR_UUID.equals(after.getName()) && effective.isNodeType(MIX_REFERENCEABLE)) { // special handling for the jcr:uuid property of mix:referenceable // TODO: this should be done in a pluggable extension if (!isValidUUID(after.getValue(Type.STRING))) { constraintViolation(12, "Invalid UUID value in the jcr:uuid property"); } } else { int requiredType = getRequiredType(definition); if (requiredType != PropertyType.UNDEFINED) { checkRequiredType(after, requiredType); checkValueConstraints(definition, after, requiredType); } } }