2016-03-25 77 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()); 
     }