001/*
002 *  Copyright 2018 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.datasourcesexplorer;
017
018import java.util.HashMap;
019import java.util.List;
020import java.util.Map;
021
022import org.apache.avalon.framework.component.Component;
023import org.apache.avalon.framework.service.ServiceException;
024import org.apache.avalon.framework.service.ServiceManager;
025import org.apache.avalon.framework.service.Serviceable;
026import org.apache.cocoon.ProcessingException;
027
028import org.ametys.core.ui.Callable;
029
030/**
031 * Component to get ldap data
032 */
033public class GetLDAPData implements Component, Serviceable
034{
035    private LDAPConnector _ldapConnector;
036
037    public void service(ServiceManager smanager) throws ServiceException
038    {
039        _ldapConnector = (LDAPConnector) smanager.lookup(LDAPConnector.ROLE);
040    }
041
042    /**
043     * Get the attributes for this DN
044     * @param datasourceId The ldap datasource id
045     * @param dn The ldap dn
046     * @return The attributes of this ldap node
047     * @throws ProcessingException If an error occurred with ldap
048     */
049    @Callable
050    public Map <String, List<Map<String, String>>> getData(String datasourceId, String dn) throws ProcessingException
051    {
052        Map<String, List<Map<String, String>>> result = new HashMap<>();
053        result.put("data", _ldapConnector.getAttributes(datasourceId, dn));
054        
055        return result;
056    }
057}