2016-03-25 38 views
0

我使用的是5.1的Alfresco社区,我试图让记录例如当前人物的属性值,在用户,我有:找人露天的财产JAVA

"{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发现,在积极方面

帮帮我!

回答

1

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


编辑:你需要注入的bean的服务注册!

+0

但我想获取当前用户的参数记录,没有提供任何信息(用户,通过)。在这种情况下,您创建一个人,并通过它获得nodeRef。但是如果我想要当前用户,我该如何做到这一点? –

2

可以使用CMIS查询露天和调用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; 
    } 

} 
+0

但我想获取当前用户的参数记录,而不提供任何信息(用户,通过)。我怎样才能做到这一点? –

+1

@PetterS我会尽快答复 –

+0

谢谢@AndreaGirardi! :) –

0
String name = AuthenticationUtil.getFullyAuthenticatedUser() 

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

+0

对于当前用户是。但是,财产? –

0

这会给你当前登录的用户名和详细信息。

 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()); 
     }