Package com.spreadbible.ctlib

Source Code of com.spreadbible.ctlib.UserDBService

/*
* Author: Bo Maryniuk <bo@suse.de>
*
* Copyright (c) 2013 Bo Maryniuk. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*     1. Redistributions of source code must retain the above copyright notice,
*     this list of conditions and the following disclaimer.
*
*     2. Redistributions in binary form must reproduce the above copyright
*     notice, this list of conditions and the following disclaimer in the
*     documentation and/or other materials provided with the distribution.
*
*     3. The name of the author may not be used to endorse or promote products
*     derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY BO MARYNIUK "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.spreadbible.ctlib;

import com.spreadbible.ctlib.entities.CDBGroup;
import com.spreadbible.ctlib.entities.CDBPerson;
import com.spreadbible.ctlib.entities.ServiceEntitiesUtil;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
*
* @author bo
*/
public class UserDBService {
   
    /**
     * Get persons, filtered by the name.
     *
     * @param nameFilter
     * @return
     */
    public List getPersons(String nameFilter) throws Exception {
        List<CDBPerson> persons = new ArrayList<CDBPerson>();
        try {
            String template = "get-persons";
            HashMap params = new HashMap();
            if (nameFilter != null) {
                params.put("name", nameFilter);
            }

            ResultSet result = CTLib.getMapper().call("users." + template, params);
            while (result.next()) {               
                persons.add(ServiceEntitiesUtil.obtainCDBPerson(result));
            }

            CTLib.getMapper().close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        return persons;
    }

   
    public void setPerson(CDBPerson person) {
    }
   
    public void deletePerson(CDBPerson person) {
    }


    /**
     * Get groups.
     *
     * @param fillMembers.
     * @return
     */
    public List getGroups(Boolean fillMembers) throws Exception {
        List<CDBGroup> groups = new ArrayList<CDBGroup>();
        ResultSet result = CTLib.getMapper().call("users.get-groups", null);
        while (result.next()) {
            CDBGroup group = ServiceEntitiesUtil.obtainCDBGroup(result);
            if (fillMembers) {
                this.getGroupMembers(group);
            }
            groups.add(group);
        }

        return groups;
    }
   

    /**
     * Get group members.
     *
     * @param group
     * @return
     */
    public UserDBService getGroupMembers(CDBGroup group)
            throws Exception {
        HashMap params = new HashMap();
        params.put("gid", group.getId());

        ResultSet result = CTLib.getMapper().call("users.get-group", params);
        while (result.next()) {
            group.pushPerson(ServiceEntitiesUtil.obtainCDBPerson(result)).popNewPerson();
        }
       
        return this;
    }

    /**
     * Set group.
     *
     * @param group
     * @return
     */
    public UserDBService setGroup(CDBGroup group) {
        // Add new or update
        return this;
    }

    /**
     * Delete group.
     *
     * @param group
     * @return
     */
    public UserDBService deleteGroup(CDBGroup group) {
        return this;
    }
}
TOP

Related Classes of com.spreadbible.ctlib.UserDBService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.