de.kaiserpfalzEdv.iam.identity.IdentityQueryBuilder.java Source code

Java tutorial

Introduction

Here is the source code for de.kaiserpfalzEdv.iam.identity.IdentityQueryBuilder.java

Source

/*
 * Copyright (c) 2014 Kaiserpfalz EDV-Service, Roland Lichti
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.kaiserpfalzEdv.iam.identity;

import de.kaiserpfalzEdv.commons.IdentifiableReadable;
import de.kaiserpfalzEdv.commons.NameableReadable;
import de.kaiserpfalzEdv.tenant.Tenant;
import org.apache.commons.lang3.builder.Builder;

/**
 * @author klenkes
 * @since 2013Q
 */
public class IdentityQueryBuilder implements Builder<IdentityQuery> {
    private IdentityQuery query = new IdentityQuery();

    @Override
    public IdentityQuery build() {
        if (query.isValid())
            return query;

        throw new IllegalStateException("The IdentityQuery object could not be built.");
    }

    public IdentityQueryBuilder singleResultQuery() {
        query.setSingleIdentitySearch(true);

        return this;
    }

    public IdentityQueryBuilder multipleResultQuery() {
        query.setSingleIdentitySearch(false);

        return this;
    }

    public IdentityQueryBuilder withTenant(Tenant tenant) {
        query.setTenant(tenant);

        return this;
    }

    public IdentityQueryBuilder withTenant(IdentifiableReadable tenantId) {
        query.setTenantId(tenantId);

        return this;
    }

    public IdentityQueryBuilder withSubject(Subject subject) {
        query.setSubject(subject);

        return this;
    }

    public IdentityQueryBuilder withSubject(IdentifiableReadable subjectId) {
        query.setSubjectId(subjectId);

        return this;
    }

    public IdentityQueryBuilder withName(NameableReadable name) {
        query.setName(name.getName());
        query.setCode(name.getShortName());
        query.setCanonicalName(name.getCanonicalName());
        query.setDisplayName(name.getDisplayName());

        return this;
    }

    public IdentityQueryBuilder withId(IdentifiableReadable id) {
        query.setIdentityId(id);

        return this;
    }
}