Neil McErlean d1db3663e4 Fix for ALF-5373 Renditions being generated to the same location (e.g. through use of paths/templates) can lead to incorrect renditions/exceptions.
Added new policy to aspect rn:rendition. Rendition nodes, before deletion, have their non-primary parent assocs removed.  Otherwise the deletion of rendition nodes (which just moves them to the archive store) means that renditionService.getRenditions() returns those deleted assocs.
     Enabled HTMLRenderingEngineTest.testImagesSameFolder test case. Changed it slightly so that it deletes renditions/extracted images between test runs to prevent unwanted overwriting of renditions
     Enabled RenditionServiceIntegrationTest.testRenditionPlacements test case. Fixed the test path to point to /.../filename.txt as it should.
           Rewrote the end of the test to cover the cases where a rendition is attempting to overwrite another.
     Refactoring: renamed numerous private variables to aid readability
     Changes to RenditionNodeManager. If:
           a rendition is to an existing node that is not a rendition OR
           a rendition is to an existing rendition node whose source is not the same as the current one OR
           a rendition is to an existing rendition node whose renditionDef's name has changed
     Then throw an exception. We explicitly disallow these use cases now. We may support them in the future with a "forceOverwrite" option somewhere.
     StandardRenditionLocationResolverImpl now uses a RepositoryHelper to locate CompanyHome rather than a Lucene search
     Extensive debug logging added to the service.
     Added some javadoc


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@23330 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2010-10-28 21:00:32 +00:00

117 lines
3.9 KiB
Java

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.rendition;
import java.util.List;
import org.alfresco.model.RenditionModel;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Rendition aspect behaviour bean.
* <p/>
* When any rendition node is deleted, its parent association back to the source
* node must be predeleted also. Otherwise a child-association remains from the
* source node to the rendition node in the archive store.
*
* @author Neil McErlean
* @since 3.4
*/
public class RenditionAspect implements NodeServicePolicies.BeforeDeleteNodePolicy
{
/** logger */
private static final Log log = LogFactory.getLog(RenditionAspect.class);
/** Services */
private PolicyComponent policyComponent;
private NodeService nodeService;
/**
* Set the policy component
*
* @param policyComponent policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* Set the node service
*
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Initialise method
*/
public void init()
{
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
RenditionModel.ASPECT_RENDITION,
new JavaBehaviour(this, "beforeDeleteNode", Behaviour.NotificationFrequency.EVERY_EVENT));
}
@Override
public void beforeDeleteNode(NodeRef nodeRef)
{
if (!nodeService.exists(nodeRef))
{
return;
}
if (log.isDebugEnabled())
{
log.debug("Predeleting rendition assoc to " + nodeRef);
}
List<ChildAssociationRef> parents = nodeService.getParentAssocs(nodeRef, RenditionModel.ASSOC_RENDITION, RegexQNamePattern.MATCH_ALL);
// There should in fact only be one parent of type rn:rendition to a rendition node.
final int parentCount = parents.size();
if (parents.size() > 1 && log.isDebugEnabled())
{
log.debug("Unexpectedly found " + parentCount + " source nodes. Removing all parent assocs.");
}
for (ChildAssociationRef chAssRef : parents)
{
// Initially only for non-primary child-associations
if (chAssRef.isPrimary() == false)
{
nodeService.removeChildAssociation(chAssRef);
}
}
}
}