mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-02 17:35:18 +00:00
- WARNING: this change requires a new DB as the WCM model has changed significantly, yes I have probably broken a few WCM things :) Previously the following statements were true: - Most of the model constants were defined in the ContentModel class - including web-client Application specific model items - WCMModel class was a mix of WCM repository and WCM application model constants - The applicationModel.xml definition file contained both web-client Application and WCM application model definitions - The wcmModel.xml definition file contained both WCM repository and WCM application model definitions The following statements are now true: - All web-client application specific model constants have been moved from ContentModel to a new model constants class ApplicationModel - A new WCM application model has been defined with the prefix "wca" and URI: http://www.alfresco.org/model/wcmappmodel/1.0 - All WCM application specific model constants have been renamed/moved from ContentModel/WCMModel to a new model constants class WCMAppModel - The mix of WCM application specific model definitions in contentModel.xml and applicationModel.xml has been moved to a new definition file wcmAppModel.xml - A patch is not required for standard Alfresco as only WCM definitions have actually changed . Fix to issue created during workflow id/name refactor . Fix to allow forms in the Available Content Forms panel to have correct sandbox/username context for action dialog git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4448 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
258 lines
10 KiB
Java
258 lines
10 KiB
Java
/*
|
|
* 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.forum;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.i18n.I18NUtil;
|
|
import org.alfresco.model.ApplicationModel;
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.model.ForumModel;
|
|
import org.alfresco.repo.policy.JavaBehaviour;
|
|
import org.alfresco.repo.policy.PolicyComponent;
|
|
import org.alfresco.repo.policy.PolicyScope;
|
|
import org.alfresco.service.cmr.coci.CheckOutCheckInServiceException;
|
|
import org.alfresco.service.cmr.model.FileExistsException;
|
|
import org.alfresco.service.cmr.model.FileFolderService;
|
|
import org.alfresco.service.cmr.model.FileNotFoundException;
|
|
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.cmr.repository.StoreRef;
|
|
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;
|
|
|
|
public class DiscussableAspect
|
|
{
|
|
private static final Log logger = LogFactory.getLog(DiscussableAspect.class);
|
|
|
|
/**
|
|
* Policy component
|
|
*/
|
|
private PolicyComponent policyComponent;
|
|
|
|
/**
|
|
* The node service
|
|
*/
|
|
private NodeService nodeService;
|
|
|
|
/**
|
|
* The file folder service
|
|
*/
|
|
private FileFolderService fileFolderService;
|
|
|
|
/**
|
|
* Sets the policy component
|
|
*
|
|
* @param policyComponent the policy component
|
|
*/
|
|
public void setPolicyComponent(PolicyComponent policyComponent)
|
|
{
|
|
this.policyComponent = policyComponent;
|
|
}
|
|
|
|
/**
|
|
* Set the node service
|
|
*
|
|
* @param nodeService the node service
|
|
*/
|
|
public void setNodeService(NodeService nodeService)
|
|
{
|
|
this.nodeService = nodeService;
|
|
}
|
|
|
|
/**
|
|
* Set the file folder service
|
|
*
|
|
* @param fileFolderService the file folder service
|
|
*/
|
|
public void setFileFolderService(FileFolderService fileFolderService)
|
|
{
|
|
this.fileFolderService = fileFolderService;
|
|
}
|
|
|
|
/**
|
|
* Initialise method
|
|
*/
|
|
public void init()
|
|
{
|
|
// Register copy behaviour for the discussable aspect
|
|
this.policyComponent.bindClassBehaviour(
|
|
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
|
|
ForumModel.ASPECT_DISCUSSABLE,
|
|
new JavaBehaviour(this, "onCopy"));
|
|
|
|
this.policyComponent.bindClassBehaviour(
|
|
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"),
|
|
ForumModel.ASPECT_DISCUSSABLE,
|
|
new JavaBehaviour(this, "onCopyComplete"));
|
|
}
|
|
|
|
/**
|
|
* onCopy policy behaviour
|
|
*
|
|
* @see org.alfresco.repo.copy.CopyServicePolicies.OnCopyNodePolicy#onCopyNode(QName, NodeRef, StoreRef, boolean, PolicyScope)
|
|
*/
|
|
public void onCopy(
|
|
QName sourceClassRef,
|
|
NodeRef sourceNodeRef,
|
|
StoreRef destinationStoreRef,
|
|
boolean copyToNewNode,
|
|
PolicyScope copyDetails)
|
|
{
|
|
// NOTE: we intentionally don't do anything in here, this stops the discussable
|
|
// aspect from being added to the new copied node - the behaviour we want.
|
|
}
|
|
|
|
public void onCopyComplete(
|
|
QName classRef,
|
|
NodeRef sourceNodeRef,
|
|
NodeRef destinationRef,
|
|
boolean copyNewNode,
|
|
Map<NodeRef, NodeRef> copyMap)
|
|
{
|
|
// if the copy is not a new node it is a checkin, we therefore
|
|
// need to copy any discussions from the working copy document
|
|
// to the document being checked in
|
|
if (copyNewNode == false)
|
|
{
|
|
List<ChildAssociationRef> sourceChildren = this.nodeService.getChildAssocs(sourceNodeRef,
|
|
ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
|
|
|
|
if (sourceChildren.size() != 1)
|
|
{
|
|
throw new CheckOutCheckInServiceException(
|
|
"The source node has the discussable aspect but does not have 1 child, it has " +
|
|
sourceChildren.size() + " children!");
|
|
}
|
|
|
|
NodeRef sourceForum = sourceChildren.get(0).getChildRef();
|
|
|
|
// get the forum for the destination node, it's created if necessary
|
|
NodeRef destinationForum = getDestinationForum(destinationRef);
|
|
|
|
// copy any topics from the source forum to the destination forum
|
|
int copied = 0;
|
|
List<ChildAssociationRef> sourceForums = this.nodeService.getChildAssocs(sourceForum);
|
|
for (ChildAssociationRef childRef : sourceForums)
|
|
{
|
|
String topicName = null;
|
|
NodeRef childNode = childRef.getChildRef();
|
|
if (this.nodeService.getType(childNode).equals(ForumModel.TYPE_TOPIC))
|
|
{
|
|
try
|
|
{
|
|
// work out the name for the copied topic
|
|
String childName = this.nodeService.getProperty(childNode,
|
|
ContentModel.PROP_NAME).toString();
|
|
Serializable labelProp = this.nodeService.getProperty(destinationRef,
|
|
ContentModel.PROP_VERSION_LABEL);
|
|
if (labelProp == null)
|
|
{
|
|
topicName = childName + " - " + new Date();
|
|
}
|
|
else
|
|
{
|
|
topicName = childName + " (" + labelProp.toString() + ")";
|
|
}
|
|
|
|
this.fileFolderService.copy(childNode, destinationForum, topicName);
|
|
copied++;
|
|
}
|
|
catch (FileNotFoundException fnfe)
|
|
{
|
|
throw new CheckOutCheckInServiceException(
|
|
"Failed to copy topic from working copy to checked out content", fnfe);
|
|
}
|
|
catch (FileExistsException fee)
|
|
{
|
|
throw new CheckOutCheckInServiceException("Failed to checkin content as a topic called " +
|
|
topicName + " already exists on the checked out content", fee);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("Copied " + copied + " topics from the working copy to the checked out content");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retrieves or creates the forum node for the given destination node
|
|
*
|
|
* @param destNodeRef The node to get the forum for
|
|
* @return NodeRef representing the forum
|
|
*/
|
|
private NodeRef getDestinationForum(NodeRef destNodeRef)
|
|
{
|
|
NodeRef destinationForum = null;
|
|
|
|
if (this.nodeService.hasAspect(destNodeRef, ForumModel.ASPECT_DISCUSSABLE))
|
|
{
|
|
List<ChildAssociationRef> destChildren = this.nodeService.getChildAssocs(destNodeRef,
|
|
ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
|
|
|
|
if (destChildren.size() != 1)
|
|
{
|
|
throw new IllegalStateException("Locked node has the discussable aspect but does not have 1 child, it has " +
|
|
destChildren.size() + " children!");
|
|
}
|
|
|
|
destinationForum = destChildren.get(0).getChildRef();
|
|
}
|
|
else
|
|
{
|
|
// create the forum - TODO: Move this to a repo discussion service so that it can
|
|
// be shared between here and the discussion wizard
|
|
|
|
// add the discussable aspect
|
|
this.nodeService.addAspect(destNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
|
|
|
|
// create a child forum space using the child association just introduced by
|
|
// adding the discussable aspect
|
|
String name = (String)this.nodeService.getProperty(destNodeRef,
|
|
ContentModel.PROP_NAME);
|
|
String forumName = I18NUtil.getMessage("coci_service.discussion_for", new Object[] {name});
|
|
|
|
Map<QName, Serializable> forumProps = new HashMap<QName, Serializable>(1);
|
|
forumProps.put(ContentModel.PROP_NAME, forumName);
|
|
|
|
ChildAssociationRef childRef = this.nodeService.createNode(destNodeRef,
|
|
ForumModel.ASSOC_DISCUSSION,
|
|
QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion"),
|
|
ForumModel.TYPE_FORUM, forumProps);
|
|
|
|
destinationForum = childRef.getChildRef();
|
|
|
|
// apply the uifacets aspect
|
|
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
|
|
uiFacetsProps.put(ApplicationModel.PROP_ICON, "forum");
|
|
this.nodeService.addAspect(destinationForum, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
|
|
}
|
|
|
|
return destinationForum;
|
|
}
|
|
}
|