de.kaiserpfalzEdv.piracc.backend.auth.RoleQuery.java Source code

Java tutorial

Introduction

Here is the source code for de.kaiserpfalzEdv.piracc.backend.auth.RoleQuery.java

Source

/*
 * Copyright 2015 Kaiserpfalz EDV-Service, Roland T. 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.piracc.backend.auth;

import de.kaiserpfalzEdv.piracc.backend.db.auth.Role;
import de.kaiserpfalzEdv.vaadin.backend.auth.User;
import de.kaiserpfalzEdv.vaadin.backend.db.EntityQuery;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.sql.Timestamp;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
 * @author klenkes
 * @version 2015Q1
 * @since 16.09.15 20:41
 */
public class RoleQuery implements EntityQuery<Role> {
    private static final long serialVersionUID = 1002686833696737477L;

    private Long id;
    private Timestamp created;
    private Timestamp modified;

    private String name;
    private String commonName;

    @Override
    public boolean valid() {
        return id != null || created != null || modified != null || name != null || commonName != null;
    }

    public String getName() {
        return name;
    }

    public RoleQuery setName(String name) {
        this.name = name;
        return this;
    }

    public String getCommonName() {
        return commonName;
    }

    public RoleQuery setCommonName(String commonName) {
        this.commonName = commonName;
        return this;
    }

    @Override
    public long getId() {
        return id;
    }

    public RoleQuery setId(Long id) {
        this.id = id;
        return this;
    }

    @Override
    public Timestamp getCreated() {
        return created;
    }

    public void setCreated(final Timestamp timestamp) {
        this.created = timestamp;
    }

    @Override
    public Timestamp getLastModified() {
        return modified;
    }

    public void setLastModified(final Timestamp timestamp) {
        this.modified = timestamp;
    }

    @Override
    public User getCreatedBy() {
        throw new UnsupportedOperationException("Role does not know a createdBy attribute");
    }

    @Override
    public User getLastModifiedBy() {
        throw new UnsupportedOperationException("Role does not know a modifiedBy attribute");
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }
        RoleQuery rhs = (RoleQuery) obj;
        return new EqualsBuilder().append(this.id, rhs.id).append(this.created, rhs.created)
                .append(this.modified, rhs.modified).append(this.name, rhs.name)
                .append(this.commonName, rhs.commonName).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(id).append(created).append(modified).append(name).append(commonName)
                .toHashCode();
    }

    @Override
    public String toString() {
        ToStringBuilder result = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);

        if (id != null)
            result.append("id", id);
        if (created != null)
            result.append("created", created);
        if (modified != null)
            result.append("modified", modified);
        if (isNotBlank(name))
            result.append("name", name);
        if (isNotBlank(commonName))
            result.append("commonName", commonName);

        return result.toString();
    }
}