自定义在Alfresco

时间:2016-03-08 11:16:16

标签: spring javabeans alfresco alfresco-share alfresco-webscripts

如何制作自定义用户个人资料?我想在Alfresco中为用户添加一个新字段... 我尝试使用此代码:http://ecmarchitect.com/archives/2012/02/27/1555,代码:http://ecmarchitect.com/images/articles/alfresco-people/someco-people.zip ...

重要代码:

  

SignUserFactory.java

package com.someco.share;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Map;

import org.alfresco.web.site.SlingshotUserFactory;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.surf.FrameworkUtil;
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.exception.ConnectorServiceException;
import org.springframework.extensions.surf.exception.UserFactoryException;
import org.springframework.extensions.surf.site.AlfrescoUser;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
import org.springframework.extensions.surf.util.StringBuilderWriter;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.connector.Connector;
import org.springframework.extensions.webscripts.connector.ConnectorContext;
import org.springframework.extensions.webscripts.connector.HttpMethod;
import org.springframework.extensions.webscripts.connector.Response;
import org.springframework.extensions.webscripts.json.JSONWriter;

public class SomeCoUserFactory extends SlingshotUserFactory {

    public static final String SCP_BIRTH_DATE = "{http://www.someco.com/model/people/1.0}birthDate";
    public static String SCP_SHIRT_SIZE = "{http://www.someco.com/model/people/1.0}shirtSize"; 
    public static String SCP_SIGNIFICANT_OTHER = "{http://www.someco.com/model/people/1.0}significantOther";
    public static String SCP_LIKES_NEIL_DIAMOND = "{http://www.someco.com/model/people/1.0}likesNeilDiamond";
    public static String PROP_SCP_BIRTH_DATE = "birthDate";
    public static String PROP_SCP_SHIRT_SIZE = "shirtSize";
    public static String PROP_SCP_SIGNIFICANT_OTHER = "significantOther";
    public static String PROP_SCP_LIKES_NEIL_DIAMOND = "likesNeilDiamond";


    @Override
    protected AlfrescoUser constructUser(JSONObject properties, Map<String, Boolean> capabilities,
            Map<String, Boolean> immutability) throws JSONException {
        AlfrescoUser user = super.constructUser(properties, capabilities, immutability);
        user.setProperty(PROP_SCP_BIRTH_DATE, properties.has(SCP_BIRTH_DATE) ? properties.getString(SCP_BIRTH_DATE) : null);
        user.setProperty(PROP_SCP_SHIRT_SIZE, properties.has(SCP_SHIRT_SIZE) ? properties.getString(SCP_SHIRT_SIZE) : null);
        user.setProperty(PROP_SCP_SIGNIFICANT_OTHER, properties.has(SCP_SIGNIFICANT_OTHER) ? properties.getString(SCP_SIGNIFICANT_OTHER) : null);
        user.setProperty(PROP_SCP_LIKES_NEIL_DIAMOND, properties.has(SCP_LIKES_NEIL_DIAMOND) ? properties.getString(SCP_LIKES_NEIL_DIAMOND) : null);
        return user;
    }

    @Override
    public void saveUser(AlfrescoUser user) throws UserFactoryException {
        RequestContext context = (RequestContext)ThreadLocalRequestContext.getRequestContext();
        if (!context.getUserId().equals(user.getId())) {
            throw new UserFactoryException("Unable to persist user with different Id that current Id.");
        }

        StringBuilderWriter buf = new StringBuilderWriter(512);
        JSONWriter writer = new JSONWriter(buf);

        try {
            writer.startObject();

            writer.writeValue("username", user.getId());

            writer.startValue("properties");
            writer.startObject();
            writer.writeValue(CM_FIRSTNAME, user.getFirstName());
            writer.writeValue(CM_LASTNAME, user.getLastName());
            writer.writeValue(CM_JOBTITLE, user.getJobTitle());
            writer.writeValue(CM_ORGANIZATION, user.getOrganization());
            writer.writeValue(CM_LOCATION, user.getLocation());
            writer.writeValue(CM_EMAIL, user.getEmail());
            writer.writeValue(CM_TELEPHONE, user.getTelephone());
            writer.writeValue(CM_MOBILE, user.getMobilePhone());
            writer.writeValue(CM_SKYPE, user.getSkype());
            writer.writeValue(CM_INSTANTMSG, user.getInstantMsg());
            writer.writeValue(CM_GOOGLEUSERNAME, user.getGoogleUsername());
            writer.writeValue(CM_COMPANYADDRESS1, user.getCompanyAddress1());
            writer.writeValue(CM_COMPANYADDRESS2, user.getCompanyAddress2());
            writer.writeValue(CM_COMPANYADDRESS3, user.getCompanyAddress3());
            writer.writeValue(CM_COMPANYPOSTCODE, user.getCompanyPostcode());
            writer.writeValue(CM_COMPANYFAX, user.getCompanyFax());
            writer.writeValue(CM_COMPANYEMAIL, user.getCompanyEmail());
            writer.writeValue(CM_COMPANYTELEPHONE, user.getCompanyTelephone());

            // START SomeCo Specific properties
            writer.writeValue(SCP_BIRTH_DATE, user.getStringProperty(PROP_SCP_BIRTH_DATE));
            writer.writeValue(SCP_SHIRT_SIZE, user.getStringProperty(PROP_SCP_SHIRT_SIZE));
            writer.writeValue(SCP_SIGNIFICANT_OTHER, user.getStringProperty(PROP_SCP_SIGNIFICANT_OTHER));
            writer.writeValue(SCP_LIKES_NEIL_DIAMOND, user.getStringProperty(PROP_SCP_LIKES_NEIL_DIAMOND));
            // END SomeCo Specific properties

            writer.endObject();
        writer.endValue();

        writer.startValue("content");
        writer.startObject();
        writer.writeValue(CM_PERSONDESCRIPTION, user.getBiography());
        writer.endObject();
        writer.endValue();

        writer.endObject();

        Connector conn = FrameworkUtil.getConnector(context, ALFRESCO_ENDPOINT_ID);
        ConnectorContext c = new ConnectorContext(HttpMethod.POST);
        c.setContentType("application/json");
        Response res = conn.call("/slingshot/profile/userprofile", c,
                new ByteArrayInputStream(buf.toString().getBytes()));
        if (Status.STATUS_OK != res.getStatus().getCode()) {
            throw new UserFactoryException("Remote error during User save: " + res.getStatus().getMessage());
        }
    } catch (IOException ioErr) {
        throw new UserFactoryException("IO error during User save: " + ioErr.getMessage(), ioErr);
    } catch (ConnectorServiceException cse) {
        throw new UserFactoryException("Configuration error during User save: " + cse.getMessage(), cse);
    }
    }
}
  

份额-CONFIG-custom.xml

<config evaluator="string-compare" condition="WebFramework" replace="true">
    <web-framework>
        <defaults>
            <user-factory>webframework.factory.user.someco</user-factory>
        </defaults>
    </web-framework>
</config>
  

定制弹弓应用context.xml中

      <bean id="webscripts.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>webscripts.messages.webscripts</value>
            <value>alfresco.messages.common</value>
            <value>alfresco.messages.slingshot</value>
            <value>alfresco.web-extension.messages.somecoPeople</value>
         </list>
      </property>
   </bean>

   <bean id="webframework.factory.user.someco" class="com.someco.share.SomeCoUserFactory" parent="webframework.factory.base" />

当我尝试在Alfresco登录时,它给了我这个错误:

  

SEVERE:Servlet的Servlet.service()[Spring Surf Dispatcher Servlet]   在路径[/ share]的上下文中抛出异常[请求处理   失败;嵌套异常是带有root的java.lang.NullPointerException]   导致java.lang.NullPointerException   org.springframework.extensions.surf.ObjectPersistenceService.getObject(ObjectPersistenceService.java:128)     在   org.springframework.extensions.surf.ModelObjectService.getObject(ModelObjectService.java:552)     在   org.springframework.extensions.surf.ModelObjectService.getConfiguration(ModelObjectService.java:157)     在   org.springframework.extensions.surf.site.SiteUtil.getSiteConfiguration(SiteUtil.java:104)     在   org.springframework.extensions.surf.site.SiteUtil.getRootPage(SiteUtil.java:53)     在   org.springframework.extensions.surf.support.AbstractRequestContext.getRootPage(AbstractRequestContext.java:320)     在   org.springframework.extensions.surf.mvc.PageViewResolver.canHandle(PageViewResolver.java:109)     在   org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:386)     在   org.springframework.extensions.webscripts.servlet.mvc.AbstractWebScriptViewResolver.resolveViewName(AbstractWebScriptViewResolver.java:64)     在   org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1240)     在   org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1181)     在   org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)     在   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:620)at   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)     在   org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)     在   org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)     在   org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.SecurityHeadersFilter.doFilter(SecurityHeadersFilter.java:168)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.CSRFFilter.doFilter(CSRFFilter.java:322)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:447)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:611)     在   org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2466)     在   org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2455)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:745)

     

2016-03-09 18:47:06,039错误[alfresco.web.site]   [HTTP-APR-8080-EXEC-2]   org.springframework.web.util.NestedServletException:Request   处理失败;嵌套异常是java.lang.NullPointerException   java.lang.NullPointerException at   org.springframework.extensions.surf.ObjectPersistenceService.getObject(ObjectPersistenceService.java:128)     在   org.springframework.extensions.surf.ModelObjectService.getObject(ModelObjectService.java:552)     在   org.springframework.extensions.surf.ModelObjectService.getConfiguration(ModelObjectService.java:157)     在   org.springframework.extensions.surf.site.SiteUtil.getSiteConfiguration(SiteUtil.java:104)     在   org.springframework.extensions.surf.site.SiteUtil.getRootPage(SiteUtil.java:53)     在   org.springframework.extensions.surf.support.AbstractRequestContext.getRootPage(AbstractRequestContext.java:320)     在   org.springframework.extensions.surf.mvc.PageViewResolver.canHandle(PageViewResolver.java:109)     在   org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:386)     在   org.springframework.extensions.webscripts.servlet.mvc.AbstractWebScriptViewResolver.resolveViewName(AbstractWebScriptViewResolver.java:64)     在   org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1240)     在   org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1181)     在   org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)     在   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:620)at   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)     在   org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)     在   org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)     在   org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.SecurityHeadersFilter.doFilter(SecurityHeadersFilter.java:168)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.CSRFFilter.doFilter(CSRFFilter.java:322)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:447)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:611)     在   org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2466)     在   org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2455)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:745)

任何人都可以帮我这个吗?也许当我将它添加到我的一体化扩展时,文件夹是不正确的。我需要帮助!

我正在使用Alfresco Community 5

2 个答案:

答案 0 :(得分:4)

您使用Jeff Potts作为参考的教程适用于Alfresco 3.4.d,它不能直接在Alfresco 5上使用。

抛出的错误似乎是由于您错过了部署内容模型的原因,即教程中引用的scPeopleModel.xml。

我已使用Alfresco SDK 2.2将上述教程转换为Alfresco 5.1,此项目位于here

您可以以zip格式here

下载代码

此项目的主要更改是省略了文件 userprofile.get.head.ftl ,原因是.head.ftl WebScript文件现已从WebScripts中弃用,以呈现共享组件。现在通过在主.html.ftl文件中使用@script和@link标记来加载依赖项。

因此,出于上述原因,您可以在userprofile.get.html.ftl中找到以下代码部分

<@markup id="css" >
   <#-- CSS Dependencies -->
   <@link href="${url.context}/res/components/profile/profile.css" group="profile"/>
</@>

<@markup id="js">
   <#-- JavaScript Dependencies -->
   <@script src="${url.context}/res/components/profile/profile.js" group="profile"/>
   <@script src="${url.context}/res/modules/simple-dialog.js" group="profile"/>
   <@script src="${url.context}/res/components/profile/sc-profile.js" group="profile"/>
</@>

答案 1 :(得分:1)

这是一个简单的NullPointerException,根据非常明确的错误消息,为您提供类和确切的行:

  

根本原因 java.lang.NullPointerException at at   org.springframework.extensions.surf.ObjectPersistenceService.getObject(ObjectPersistenceService.java:128)

您发布的大量代码/配置转储中没有任何内容可以帮助任何人诊断出错误,尤其是因为似乎没有一行代码是您的。

之后查看ObjectPersistenceService.java:128的来源,需要只是通过调用来调试,需要弄清楚如何抱怨null不是抱怨。

每个NPE都以完全相同的方式解决,使引用不为空。