例如,我需要评估器,我可以使用它来显示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编写自定义评估程序?
我将非常感谢这些信息。谢谢大家。
答案 0 :(得分:4)
似乎我找到了解决方案......问题是我使用了Alfresco库中的alfresco-share-4.2.2.5.jar#uzip/org/alfresco/web/evaluator
类。共享库中表示相同的名称类。
即。有两个jar文件:
在package com.firm.alfresco.alf221.evaluators;
// was import org.alfresco.web.ui.common.component.evaluator.BaseEvaluator;
import org.alfresco.web.evaluator.BaseEvaluator;
import org.json.simple.JSONObject;
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(JSONObject jSONObject) {
RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();
User user = requestContext.getUser();
System.out.println("CURRENT USER IS ... " + user.getName());
return true;
}
}
我找到了我需要的一切。
此解决方案现在有效:
catalina.out
现在我可以在CURRENT USER IS ... admin
中看到:
BaseEvaluator
可以从JSONObject获取所有其他必要信息(也可以使用从String str = "POLYGON((39.4189453125 37.418708616699824,42.0556640625 37.418708616699824,43.4619140625 34.79181436843146,38.84765625 33.84817790215085,39.4189453125 37.418708616699824))";
String sp = "(([0-9]+[.])?[0-9]+[,]?\\s*)+";
Pattern p = Pattern.compile(sp);
Matcher matcher = p.matcher(str);
if (matcher.find()) {
System.out.println(matcher.group());
}
类继承的getUserId()
方法获取当前用户。)。