【问题标题】:Get property of person Alfresco in JAVA在JAVA中获取人Alfresco的财产
【发布时间】:2016-03-25 15:20:35
【问题描述】:

我正在使用 Alfresco 5.1 社区,并且我正在尝试获取当前登录人员的属性值,例如,在我拥有的用户中:

 "{http://www.someco.org/model/people/1.0}customProperty"

如何在 java 中获得这个?

是自定义属性,所以,在http://localhost:8080/alfresco/service/api/people 中不会出现。我该怎么做?

我尝试这样做以获得至少 nodeRef:

protected ServiceRegistry getServiceRegistry() {
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null) {
            // Fetch the registry that is injected in the activiti spring-configuration
            ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);

            if (registry == null) {
                throw new RuntimeException("Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" + ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
            }

            return registry;
        }
        throw new IllegalStateException("No ProcessEngineConfiguration found in active context");
    }

    public void writeToCatalina() {
        PersonService personService = getServiceRegistry().getPersonService();
        System.out.println("test");
        String name = AuthenticationUtil.getFullyAuthenticatedUser();
        System.out.println(name);
        NodeRef personRef = personService.getPerson(name);
        System.out.println(personRef);
    }

但我得到了:

在活动上下文中找不到 ProcessEngineConfiguration

帮帮我!

【问题讨论】:

    标签: alfresco alfresco-share alfresco-webscripts


    【解决方案1】:

    您可以使用CMIS查询Alfresco并调用API:

    GET /alfresco/service/api/people/{userName}.
    

    首先你可以定义创建会话 CmisSession 的方法:

    public Session getCmisSession() {
    
        logger.debug("Starting: getCmisSession()");
    
        // default factory implementation
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameter = new HashMap<String, String>();
    
        // connection settings
        parameter.put(SessionParameter.ATOMPUB_URL, url + ATOMPUB_URL);
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
        parameter.put(SessionParameter.AUTH_HTTP_BASIC, "true");
        parameter.put(SessionParameter.USER, username);
        parameter.put(SessionParameter.PASSWORD, password);
        parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
    
        List<Repository> repositories = factory.getRepositories(parameter);
    
        return repositories.get(0).createSession();
    }
    

    然后执行查询(此方法返回多个结果,你可能需要更改它):

    public void doQuery(String cql, int maxItems) {
    
        Session cmisSession = getCmisSession();
    
        OperationContext oc = new OperationContextImpl();
        oc.setMaxItemsPerPage(maxItems);
    
        ItemIterable<QueryResult> results = cmisSession.query(cql, false, oc);
    
        for (QueryResult result : results) {
            for (PropertyData<?> prop : result.getProperties()) {
                logger.debug(prop.getQueryName() + ": " + prop.getFirstValue());
            }
    
        }
    
    }
    

    如果你需要获取令牌,使用这个:

    public String getAuthenticationTicket() {
    
        try {   
    
            logger.info("ALFRESCO: Starting connection...");
    
            RestTemplate restTemplate = new RestTemplate();
            Map<String, String> params = new HashMap<String, String>();
            params.put("user", username);
            params.put("password", password);
            Source result = restTemplate.getForObject(url + AFMConstants.URL_LOGIN_PARAM, Source.class, params);
    
            logger.info("ALFRESCO: CONNECTED!");
    
            XPathOperations xpath = new Jaxp13XPathTemplate();          
            return xpath.evaluateAsString("//ticket", result);
        }
        catch (RestClientException ex) {
            logger.error("FATAL ERROR - Alfresco Authentication failed - getAuthenticationTicket() - "  + ex );
            return null;
        }       
        catch (Exception ex) {          
            logger.error("FATAL ERROR - Alfresco Authentication failed - getAuthenticationTicket() - "  + ex );
            return null;
        }
    
    }
    

    【讨论】:

    • 但我想获取当前用户的参数记录,而不提供任何信息(用户,通行证)。我怎样才能做到这一点?
    • @PetterS 我会尽快回复
    • 谢谢@AndreaGirardi! :)
    • 我怎样才能得到personService?我做了这样的事情......但不起作用。我输入了问题编辑。
    【解决方案2】:

    您需要使用this API 获取您的用户noderef,然后访问其属性this way


    编辑:您需要在您的 bean 上注入服务注册表!

    【讨论】:

    • 但我想获取当前用户的参数记录,而不提供任何信息(用户,通行证)。在这种情况下,您创建一个人并通过它获取 nodeRef。但是如果我想要当前用户,我该怎么做呢?
    【解决方案3】:
    String name = AuthenticationUtil.getFullyAuthenticatedUser()
    

    你可以使用它。让我知道它是否有效。

    【讨论】:

    • 对当前用户是。但是财产呢?
    【解决方案4】:

    这将为您提供当前登录的用户名和详细信息。

            String name = AuthenticationUtil.getFullyAuthenticatedUser();
            System.out.println("Current user:"+name);
            PersonService personService=serviceRegistry.getPersonService();
            NodeRef node=personService.getPerson(name);
            NodeService nodeService=serviceRegistry.getNodeService();
            Map<QName, Serializable> props=nodeService.getProperties(node);
    
            for (Entry<QName, Serializable> entry : props.entrySet())
            {
                System.out.println(entry.getKey() + "/" + entry.getValue());
            }
    

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多