例如,我需要评估器,我可以使用它来显示 Share 中的操作。如果当前用户是文档的作者,那么我将显示操作。
项目结构如下图(alf221-action-share
):
C:\EclipseWorkspaces\alfresco\alf221-action-share>tree /F
...
├───build
│ ├───classes
│ │ └───com
│ │ └───firm
│ │ └───alfresco
│ │ └───alf221
│ │ └───evaluators
│ │ UsersCompareEvaluator.class
│ │
│ ├───dist
│ └───lib
│ alf221-action-share.jar
│
└───src
└───main
├───com
│ └───firm
│ └───alfresco
│ └───alf221
│ └───evaluators
│ UsersCompareEvaluator.java
│
└───resources
├───alfresco
│ └───web-extension
│ │ alf221-action-share-slingshot-application-context.x
│ │
│ └───messages
│ alf221-action-share.properties
│
└───META-INF
│ share-config-custom.xml
│
└───resources
└───components
└───documentlibrary
└───actions
firm-exclude-participant-16.png
在UsersCompareEvaluator
课堂上,我只是想确定当前用户:
package com.firm.alfresco.alf221.evaluators;
import org.alfresco.web.ui.common.component.evaluator.BaseEvaluator;
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
import org.springframework.extensions.webscripts.connector.User;
public class UsersCompareEvaluator extends BaseEvaluator {
@Override
public boolean evaluate() {
RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();
User user = requestContext.getUser();
System.out.println("CURRENT USER IS ... " + user.getName());
return true;
}
}
我的alf221-action-share-slingshot-application-context.xml
:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN'
'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="com.firm.alf221-action-share.resources"
class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.web-extension.messages.alf221-action-share</value>
</list>
</property>
</bean>
<bean id="evaluator.doclib.action.isDocumentOnApproval"
parent="evaluator.doclib.metadata.value">
<property name="accessor" value="node.properties.idocs:documentStatus" />
<property name="comparator">
<bean class="org.alfresco.web.evaluator.StringEqualsComparator">
<property name="value" value="onApproval" />
</bean>
</property>
</bean>
<bean id="evaluator.doclib.action.isCurrentUserAuthor"
class="com.firm.alfresco.alf221.evaluators.UsersCompareEvaluator" />
</beans>
我的share-config-custom.xml
:
<alfresco-config>
<config evaluator="string-compare" condition="DocLibActions">
<actions>
<action id="firm-exclude-participant"
type="javascript"
label="actions.firm.exclude-participant"
icon="document-change-type">
<param name="function">onActionTkbFormDialog</param>
<permissions>
<permission allow="true">Write</permission>
</permissions>
<param name="itemKind">action</param>
<param name="itemId">exclude-participant</param>
<param name="mode">create</param>
<param name="successMessage">message.exclude-participant.success</param>
<param name="failureMessage">message.exclude-participant.failure</param>
<evaluator>evaluator.doclib.action.isDocumentOnApproval</evaluator>
<evaluator>evaluator.doclib.action.isCurrentUserAuthor</evaluator>
</action>
</actions>
<actionGroups>
<actionGroup id="document-details">
<action index="500" id="firm-exclude-participant" />
</actionGroup>
</actionGroups>
</config>
</alfresco-config>
我放在以下路径中的 jar 文件:/opt/tomcat7/webapps/share/WEB-INF/lib
一切都很完美,除了我的自定义评估器。在此配置中,共享不起作用...在日志中,我看到以下内容:
[aleksey@alfresco01 tomcat7]$ sudo vi share.log
...
Caused by: java.lang.NoClassDefFoundError: org/alfresco/web/ui/common/component/evaluator/BaseEvaluator
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2928)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1174)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1669)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1271)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1242)
... 22 more
Caused by: java.lang.ClassNotFoundException: org.alfresco.web.ui.common.component.evaluator.BaseEvaluator
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 33 more
如果在评估器中我实现了ActionEvaliator
接口并尝试如下识别当前用户......
public class UsersCompareEvaluator implements ActionEvaluator {
private Map<Object, Object> registeredBeans =
Context.getProcessEngineConfiguration().getBeans();
private ServiceRegistry registry =
(ServiceRegistry)registeredBeans.get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
private AuthenticationService authenticationService =
registry.getAuthenticationService();
@Override
public boolean evaluate(Node node) {
System.out.println("CURRENT USER IS ... " +
authenticationService.getCurrentUserName());
return true;
}
@Override
public boolean evaluate(Object object) {
if(object instanceof Node) {
return evaluate((Node)object);
}
return false;
}
}
...并将我的 jar 文件放在同一个地方(/opt/tomcat7/webapps/share/WEB-INF/lib
) - 然后我得到以下异常:
...
Caused by: java.lang.ClassNotFoundException: org.alfresco.web.action.ActionEvaluator
...
我试图将我的自定义评估器打包到单独的 jar 中并将其放置在此处:/opt/tomcat7/webapps/alfresco/WEB-INF/lib
. 但是我如何从 Share 中引用这个评估者呢?
例如,我有一个单独的项目(alf221-custom-evaluator
):
C:\EclipseWorkspaces\alfresco\alf221-custom-evaluator>tree /F
...
└───src
└───main
├───com
│ └───firm
│ └───alfresco
│ └───alf221
│ └───evaluators
│ UsersCompareEvaluator.java
│
└───resources
└───alfresco
└───web-extension
alf221-custom-evaluator-slingshot-application-context.xml
在alf221-custom-evaluator-slingshot-application-context.xml
我指定以下内容:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN'
'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="evaluator.doclib.action.runtime.user"
class="com.firm.alfresco.alf221.evaluators.UsersCompareEvaluator" />
</beans>
然后,在share-config-custom.xml
中alf221-action-share
,我指定以下内容:
...
<evaluator>evaluator.doclib.action.runtime.user</evaluator>
...
在这种情况下,我收到以下警告消息:
...
2018-01-03 12:10:59,956 WARN [web.scripts.ActionEvaluatorHelper] [http-bio-8888-exec-8] Evaluator 'evaluator.doclib.action.runtime.user' not found.
...
而且我的自定义评估器不起作用。
如何在 Alfresco 4.2.2 中为 Share 编写自定义评估器?
我将非常感谢您提供的信息。谢谢大家。