KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > ActionableAspect


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.action;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.alfresco.model.ContentModel;
23 import org.alfresco.repo.policy.Behaviour;
24 import org.alfresco.repo.policy.JavaBehaviour;
25 import org.alfresco.repo.policy.PolicyComponent;
26 import org.alfresco.repo.policy.PolicyScope;
27 import org.alfresco.service.cmr.repository.ChildAssociationRef;
28 import org.alfresco.service.cmr.repository.NodeRef;
29 import org.alfresco.service.cmr.repository.NodeService;
30 import org.alfresco.service.cmr.repository.StoreRef;
31 import org.alfresco.service.namespace.NamespaceService;
32 import org.alfresco.service.namespace.QName;
33
34 /**
35  * Class containing behaviour for the auditable aspect
36  *
37  * @author Roy Wetherall
38  */

39 public class ActionableAspect
40 {
41     public static final QName ASSOC_NAME_SAVEDACTIONFOLDER = QName.createQName(ContentModel.ACTION_MODEL_URI, "savedActionFolder");
42     public static final QName ASSOC_NAME_SAVEDRULESFOLDER = QName.createQName(ContentModel.ACTION_MODEL_URI, "savedRuleFolder");
43     
44     private Behaviour onAddAspectBehaviour;
45     
46     private PolicyComponent policyComponent;
47     
48     private NodeService nodeService;
49     
50     public void setPolicyComponent(PolicyComponent policyComponent)
51     {
52         this.policyComponent = policyComponent;
53     }
54     
55     public void setNodeService(NodeService nodeService)
56     {
57         this.nodeService = nodeService;
58     }
59     
60     public void init()
61     {
62         this.policyComponent.bindClassBehaviour(
63                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
64                 ContentModel.ASPECT_ACTIONABLE,
65                 new JavaBehaviour(this, "onCopyNode"));
66         this.policyComponent.bindClassBehaviour(
67                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"),
68                 ContentModel.ASPECT_ACTIONABLE,
69                 new JavaBehaviour(this, "onCopyComplete"));
70         
71         this.onAddAspectBehaviour = new JavaBehaviour(this, "onAddAspect");
72         this.policyComponent.bindClassBehaviour(
73                 QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
74                 this,
75                 onAddAspectBehaviour);
76     }
77     
78     /**
79      * On add aspect policy behaviour
80      * @param nodeRef
81      * @param aspectTypeQName
82      */

83     public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
84     {
85         if (ContentModel.ASPECT_ACTIONABLE.equals(aspectTypeQName) == true)
86         {
87             List JavaDoc<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(nodeRef, ASSOC_NAME_SAVEDACTIONFOLDER);
88             if (assocs.size() == 0)
89             {
90                 // Create the saved action folder used by this service
91
this.nodeService.createNode(nodeRef,
92                         ContentModel.ASSOC_SAVED_ACTION_FOLDERS,
93                         ASSOC_NAME_SAVEDACTIONFOLDER,
94                         ContentModel.TYPE_SAVED_ACTION_FOLDER);
95             }
96             
97             List JavaDoc<ChildAssociationRef> assocs2 = this.nodeService.getChildAssocs(nodeRef, ASSOC_NAME_SAVEDRULESFOLDER);
98             if (assocs2.size() == 0)
99             {
100                 // Create the saved action folder used by this service
101
this.nodeService.createNode(nodeRef,
102                         ContentModel.ASSOC_SAVED_ACTION_FOLDERS,
103                         ASSOC_NAME_SAVEDRULESFOLDER,
104                         ContentModel.TYPE_SAVED_ACTION_FOLDER);
105             }
106         }
107     }
108     
109     public void onCopyNode(
110             QName classRef,
111             NodeRef sourceNodeRef,
112             StoreRef destinationStoreRef,
113             boolean copyToNewNode,
114             PolicyScope copyDetails)
115     {
116         copyDetails.addAspect(ContentModel.ASPECT_ACTIONABLE);
117         
118         List JavaDoc<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(sourceNodeRef);
119         for (ChildAssociationRef assoc : assocs)
120         {
121             if (assoc.getTypeQName().equals(ContentModel.ASSOC_SAVED_ACTION_FOLDERS) == true)
122             {
123                 copyDetails.addChildAssociation(classRef, assoc, true);
124             }
125         }
126         
127         this.onAddAspectBehaviour.disable();
128     }
129     
130     public void onCopyComplete(
131             QName classRef,
132             NodeRef sourceNodeRef,
133             NodeRef destinationRef,
134             Map JavaDoc<NodeRef, NodeRef> copyMap)
135     {
136         this.onAddAspectBehaviour.enable();
137     }
138 }
139
Popular Tags