gpt4 book ai didi

alfresco - 如何在 Alfresco 4.2.2 中为 Share 编写自定义评估器?

转载 作者:行者123 更新时间:2023-12-02 19:15:50 27 4
gpt4 key购买 nike

例如,我需要评估器,我可以用它来显示共享中的操作。如果当前用户是文档的作者,那么我将显示操作。

项目结构如下所示(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 接口(interface)并尝试按如下方式识别当前用户...

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。但我如何从共享中引用该评估器?

例如,我有一个单独的项目 (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>

然后,在位于 alf221-action-share 中的 share-config-custom.xml 中,我指定以下内容:

...
<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 编写自定义评估器?

如果您能提供这些信息,我将不胜感激。感谢大家。

最佳答案

看来我已经找到了解决方案...问题是我使用了 Alfresco 库中的 BaseEvaluator 类。相同名称的类在共享库中表示。

即有两个 jar 文件:

alfresco-share-4.2.2.5.jar#uzip/org/alfresco/web/evaluator 中,我找到了我需要的所有内容。

此解决方案现在有效:

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

所有其他必要的信息都可以从 JSONObject 获取(也可以使用继承自 BaseEvaluator 类的 getUserId() 方法获取当前用户。)。

关于alfresco - 如何在 Alfresco 4.2.2 中为 Share 编写自定义评估器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077051/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com