All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bonitasoft.engine.profile.persistence.SelectDescriptorBuilder Maven / Gradle / Ivy

/**
 * Copyright (C) 2012 BonitaSoft S.A.
 * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301, USA.
 **/
package org.bonitasoft.engine.profile.persistence;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bonitasoft.engine.persistence.OrderByOption;
import org.bonitasoft.engine.persistence.OrderByType;
import org.bonitasoft.engine.persistence.PersistentObject;
import org.bonitasoft.engine.persistence.QueryOptions;
import org.bonitasoft.engine.persistence.SelectByIdDescriptor;
import org.bonitasoft.engine.persistence.SelectListDescriptor;
import org.bonitasoft.engine.persistence.SelectOneDescriptor;
import org.bonitasoft.engine.profile.model.SProfile;
import org.bonitasoft.engine.profile.model.SProfileEntry;
import org.bonitasoft.engine.profile.model.SProfileMember;

/**
 * @author Matthieu Chaffotte
 * @author Elias Ricken de Medeiros
 */
public class SelectDescriptorBuilder {

    private static final String ROLE_ID = "roleId";

    private static final String GROUP_ID = "groupId";

    private static final String USER_ID = "userId";

    private static final String PROFILE_ID = "profileId";

    private static final String PARENT_ID = "parentId";

    public static  SelectByIdDescriptor getElementById(final Class clazz, final String elementName, final long id) {
        return new SelectByIdDescriptor("get" + elementName + "ById", clazz, id);
    }

    public static SelectOneDescriptor getNumberOfElement(final String elementName, final Class clazz) {
        final Map parameters = Collections.emptyMap();
        return new SelectOneDescriptor("getNumberOf" + elementName, parameters, clazz, Long.class);
    }

    public static  SelectOneDescriptor getElementByNameDescriptor(final Class clazz, final String elementName,
            final String name) {
        final Map parameters = Collections.singletonMap("name", (Object) name);
        return new SelectOneDescriptor("get" + elementName + "ByName", parameters, clazz);
    }

    public static  SelectListDescriptor getElements(final Class clazz, final String elementName, final int fromIndex,
            final int numberOfElements) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfElements);
        return getElements(clazz, elementName, queryOptions);
    }

    public static  SelectListDescriptor getElements(final Class clazz, final String elementName, final String field,
            final OrderByType order, final int fromIndex, final int numberOfElements) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfElements, clazz, field, order);
        return getElements(clazz, elementName, queryOptions);
    }

    public static  SelectListDescriptor getElements(final Class clazz, final String elementName,
            final QueryOptions queryOptions) {
        final Map parameters = Collections.emptyMap();
        return new SelectListDescriptor("get" + elementName + "s", parameters, clazz, queryOptions);
    }

    public static SelectOneDescriptor getNumberOfEntriesOfProfile(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectOneDescriptor("getNumberOfEntriesOfProfile", parameters, SProfileEntry.class);
    }

    public static SelectListDescriptor getEntriesOfProfile(final long profileId, final String field, final OrderByType order,
            final int fromIndex, final int numberOfProfileEntries) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfProfileEntries, SProfileEntry.class, field, order);
        return getEntriesOfProfile(profileId, queryOptions);
    }

    public static SelectListDescriptor getEntriesOfProfile(final long profileId, final int fromIndex, final int numberOfProfileEntries) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfProfileEntries);
        return getEntriesOfProfile(profileId, queryOptions);
    }

    public static SelectListDescriptor getEntriesOfProfile(final long profileId, final QueryOptions queryOptions) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectListDescriptor("getEntriesOfProfile", parameters, SProfileEntry.class, queryOptions);
    }

    public static SelectListDescriptor getEntriesOfProfile(final long profileId, final long parentId, final String field,
            final OrderByType order, final int fromIndex, final int numberOfProfileEntries) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfProfileEntries, SProfileEntry.class, field, order);
        return getEntriesOfProfile(profileId, parentId, queryOptions);
    }

    public static SelectListDescriptor getEntriesOfProfile(final long profileId, final long parentId, final QueryOptions queryOptions) {
        final Map parameters = new HashMap(2);
        parameters.put(PROFILE_ID, profileId);
        parameters.put(PARENT_ID, parentId);
        return new SelectListDescriptor("getEntriesOfProfileByParentId", parameters, SProfileEntry.class, queryOptions);
    }

    public static SelectListDescriptor serarchSProfileMembersForUser(final long profileId, final int fromIndex, final int numberOfUserProfiles,
            final List orderByOptions) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);

        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfUserProfiles, orderByOptions);
        return new SelectListDescriptor("searchSProfileMembersForUser", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectOneDescriptor getNumberOfSProfileMembersForUser(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectOneDescriptor("countSProfileMembersForUser", parameters, SProfileMember.class);
    }

    public static SelectListDescriptor getSProfileMembersForGroup(final long profileId, final int fromIndex, final int numberOfUserProfiles,
            final List orderByOptions) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);

        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfUserProfiles, orderByOptions);
        return new SelectListDescriptor("searchSProfileMembersForGroup", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectOneDescriptor getNumberOfSProfileMembersForGroup(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectOneDescriptor("countSProfileMembersForGroup", parameters, SProfileMember.class);
    }

    public static SelectListDescriptor getSProfileMembersForRole(final long profileId, final int fromIndex, final int numberOfUserProfiles,
            final List orderByOptions) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);

        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfUserProfiles, orderByOptions);
        return new SelectListDescriptor("searchSProfileMembersForRole", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectOneDescriptor getNumberOfSProfileMembersForRole(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectOneDescriptor("countSProfileMembersForRole", parameters, SProfileMember.class);
    }

    public static SelectListDescriptor getSProfileMembersForRoleAndGroup(final long profileId, final int fromIndex,
            final int numberOfUserProfiles, final List orderByOptions) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);

        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfUserProfiles, orderByOptions);
        return new SelectListDescriptor("searchSProfileMembersForRoleAndGroup", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectOneDescriptor getNumberOfSProfileMembersForRoleAndGroup(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectOneDescriptor("countSProfileMembersForRoleAndGroup", parameters, SProfileMember.class);
    }

    public static SelectListDescriptor getDirectProfileMembersOfUser(final long userId, final String field, final OrderByType order,
            final int fromIndex, final int numberOfElements) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfElements, SProfileMember.class, field, order);
        final Map parameters = new HashMap(1);
        parameters.put(USER_ID, userId);
        return new SelectListDescriptor("getDirectProfileMembersOfUser", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectListDescriptor getDirectProfileMembersOfGroup(final long groupId, final String field, final OrderByType order,
            final int fromIndex, final int numberOfElements) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfElements, SProfileMember.class, field, order);
        final Map parameters = new HashMap(1);
        parameters.put(GROUP_ID, groupId);
        return new SelectListDescriptor("getDirectProfileMembersOfGroup", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectListDescriptor getDirectProfileMembersOfRole(final long roleId, final String field, final OrderByType order,
            final int fromIndex, final int numberOfElements) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfElements, SProfileMember.class, field, order);
        final Map parameters = new HashMap(1);
        parameters.put(ROLE_ID, roleId);
        return new SelectListDescriptor("getDirectProfileMembersOfRole", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectListDescriptor getProfileMembers(final String field, final OrderByType order, final int fromIndex,
            final int numberOfElements) {
        final QueryOptions queryOptions = new QueryOptions(fromIndex, numberOfElements, SProfileMember.class, field, order);
        final Map parameters = new HashMap(1);
        return new SelectListDescriptor("getProfileMembers", parameters, SProfileMember.class, queryOptions);
    }

    public static SelectListDescriptor getProfilesOfUser(final long userId) {
        final Map parameters = Collections.singletonMap(USER_ID, (Object) userId);
        return new SelectListDescriptor("getProfilesOfUser", parameters, SProfile.class);
    }

    public static SelectListDescriptor getSProfileMembersWithoutDisplayName(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectListDescriptor("getSProfileMembersWithoutDisplayName", parameters, SProfileMember.class);
    }

    public static SelectOneDescriptor getNumberOfUsersOfProfile(final long profileId) {
        final Map parameters = Collections.singletonMap(PROFILE_ID, (Object) profileId);
        return new SelectOneDescriptor("getNumberOfProfileMembersOfProfile", parameters, SProfileMember.class);
    }

    public static SelectByIdDescriptor getProfileMemberWithoutDisplayName(final long profileMemberId) {
        return new SelectByIdDescriptor("getProfileMemberWithoutDisplayNameById", SProfileMember.class, profileMemberId);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy