2016-03-25 5 views
0

私はAlfrescoは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を使用してのAlfrescoを照会し、APIを呼び出すことができますクエリ(このメソッドのリターンを実行し

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

:あなたはセッションCmisSessionを作成する方法を定義することができます最初の場合

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

を複数の結果がある場合は、おそらくそれを変更する必要があります)。

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()); 
     } 
関連する問題