Fixed AR-626: Default aspects not being checked for.

- The NodeService was preventing the removal of required aspects
 - This is now enforced by integrity


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3030 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-06-05 15:01:25 +00:00
parent 853e7d6cf1
commit 7c17d38207
4 changed files with 136 additions and 19 deletions

View File

@@ -595,20 +595,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// get the node
Node node = getNodeNotNull(nodeRef);
// check that the aspect may be removed
TypeDefinition nodeTypeDef = dictionaryService.getType(node.getTypeQName());
if (nodeTypeDef == null)
{
throw new InvalidNodeRefException("The node type is no longer valid: " + nodeRef, nodeRef);
}
List<AspectDefinition> defaultAspects = nodeTypeDef.getDefaultAspects();
if (defaultAspects.contains(aspectDef))
{
throw new InvalidAspectException(
"The aspect is a default for the node's type and cannot be removed: " + aspectTypeQName,
aspectTypeQName);
}
// remove the aspect, if present
boolean removed = node.getAspects().remove(aspectTypeQName);
// if the aspect was present, remove the associated properties

View File

@@ -0,0 +1,99 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.node.integrity;
import java.util.List;
import java.util.Set;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Event raised to check nodes' aspects
*
* @author Derek Hulley
*/
public class AspectsIntegrityEvent extends AbstractIntegrityEvent
{
private static Log logger = LogFactory.getLog(AspectsIntegrityEvent.class);
protected AspectsIntegrityEvent(
NodeService nodeService,
DictionaryService dictionaryService,
NodeRef nodeRef)
{
super(nodeService, dictionaryService, nodeRef, null, null);
}
public void checkIntegrity(List<IntegrityRecord> eventResults)
{
NodeRef nodeRef = getNodeRef();
if (!nodeService.exists(nodeRef))
{
// node has gone
if (logger.isDebugEnabled())
{
logger.debug("Event ignored - node gone: " + this);
}
eventResults.clear();
return;
}
else
{
checkMandatoryAspects(getNodeRef(), eventResults);
}
}
/**
* Checks that the node has the required mandatory aspects applied
*/
private void checkMandatoryAspects(NodeRef nodeRef, List<IntegrityRecord> eventResults)
{
Set<QName> aspects = nodeService.getAspects(nodeRef);
// get the node type
QName nodeTypeQName = nodeService.getType(nodeRef);
// get the aspects that should exist
TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName);
List<AspectDefinition> mandatoryAspectDefs = typeDef.getDefaultAspects();
// check
for (AspectDefinition aspect : mandatoryAspectDefs)
{
if (aspects.contains(aspect.getName()))
{
// it's fine
continue;
}
IntegrityRecord result = new IntegrityRecord(
"Mandatory aspect not set: \n" +
" Node: " + nodeRef + "\n" +
" Type: " + nodeTypeQName + "\n" +
" Aspect: " + aspect.getName());
eventResults.add(result);
// next one
continue;
}
// done
}
}

View File

@@ -278,19 +278,23 @@ public class IntegrityChecker
*/
public void onCreateNode(ChildAssociationRef childAssocRef)
{
NodeRef childRef = childAssocRef.getChildRef();
IntegrityEvent event = null;
// check properties on child node
event = new PropertiesIntegrityEvent(
nodeService,
dictionaryService,
childAssocRef.getChildRef());
childRef);
save(event);
// check that the multiplicity and other properties of the new association are allowed
onCreateChildAssociation(childAssocRef);
// check mandatory aspects
event = new AspectsIntegrityEvent(nodeService, dictionaryService, childRef);
save(event);
// check for associations defined on the new node (child)
NodeRef childRef = childAssocRef.getChildRef();
QName childNodeTypeQName = nodeService.getType(childRef);
ClassDefinition nodeTypeDef = dictionaryService.getClass(childNodeTypeQName);
if (nodeTypeDef == null)
@@ -370,10 +374,15 @@ public class IntegrityChecker
}
/**
* No checking performed: The property changes will be handled
* @see AspectsIntegrityEvent
*/
public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
{
IntegrityEvent event = null;
// check mandatory aspects
event = new AspectsIntegrityEvent(nodeService, dictionaryService, nodeRef);
save(event);
}
/**

View File

@@ -135,8 +135,22 @@ public class IntegrityTest extends TestCase
public void tearDown() throws Exception
{
authenticationComponent.clearCurrentSecurityContext();
txn.rollback();
try
{
authenticationComponent.clearCurrentSecurityContext();
}
catch (Throwable e)
{
e.printStackTrace();
}
try
{
txn.rollback();
}
catch (Throwable e)
{
e.printStackTrace();
}
}
/**
@@ -220,6 +234,15 @@ public class IntegrityTest extends TestCase
checkIntegrityNoFailure();
}
public void testRemoveMandatoryAspect() throws Exception
{
NodeRef nodeRef = createNode("abc", TEST_TYPE_WITH_ASPECT, allProperties);
// just remove the aspect
nodeService.removeAspect(nodeRef, TEST_ASPECT_WITH_PROPERTIES);
checkIntegrityExpectFailure("Failed to removal of mandatory aspect", 1);
}
public void testCreateTargetOfAssocsWithMandatorySourcesPresent() throws Exception
{
// this is the target of 3 assoc types where the source cardinality is 1..1