1

如何制作自定义用户配置文件?我想为 Alfresco 中的用户添加一个新字段...我尝试使用它:http ://ecmarchitect.com/archives/2012/02/27/1555 ,代码:http ://ecmarchitect.com/图片/文章/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);
    }
    }
}

共享配置-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>

自定义弹弓应用程序上下文.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 中登录时,它给了我这个错误:

严重:servlet [Spring Surf Dispatcher Servlet] 在路径 [/share] 的上下文中的 Servlet.service() 引发异常 [请求处理失败;嵌套异常是 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。

2016-03-09 18:47:06,039 错误 [alfresco.web.site] [http-apr-8080-exec-2] org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 java.lang.NullPointerException java.lang.NullPointerException at org.springframework.extensions.surf.ObjectPersistenceService.getObject(ObjectPersistenceService.java:128) at org.springframework.extensions.surf.ModelObjectService.getObject(ModelObjectService.java:552 ) 在 org.springframework.extensions.surf.site.SiteUtil.getSiteConfiguration(SiteUtil.java:104) 在 org.springframework.extensions.surf 的 org.springframework.extensions.surf.ModelObjectService.getConfiguration(ModelObjectService.java:157)。 site.SiteUtil.getRootPage(SiteUtil.java:53) 在 org.springframework.extensions.surf.support.AbstractRequestContext。

任何人都可以帮助我吗?也许当我将它添加到我的多合一扩展程序时,文件夹不正确。我需要帮助!

我正在使用露天社区 5

4

2 回答 2

4

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

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

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

您可以在此处下载 zip 格式的代码

该项目的主要变化是省略了文件userprofile.get.head.ftl,因为 .head.ftl WebScript 文件现在已从呈现共享组件的 WebScript 中弃用。现在通过使用主 .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"/>
</@>
于 2016-03-12T14:37:06.783 回答
1

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

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

您发布的大量代码/配置转储中的任何内容都无法帮助这里的任何人诊断问题所在,尤其是因为似乎没有一行代码是您的。

在查看 的来源之后,只需通过调用逐步调试,并且需要弄清楚如何制作它所抱怨的任何内容。ObjectPersistenceService.java:128null

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

于 2016-03-10T14:39:25.397 回答