com.infinities.skyport.entity.Organization.java Source code

Java tutorial

Introduction

Here is the source code for com.infinities.skyport.entity.Organization.java

Source

/*******************************************************************************
 * Copyright 2015 InfinitiesSoft Solutions Inc.
 *
 * 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 com.infinities.skyport.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.infinities.skyport.compute.entity.AbstractEntity;
import com.infinities.skyport.compute.entity.serializer.BasicSelfRecursiveSerializer;
import com.infinities.skyport.view.Views;

/**
 * User generated by hbm2java
 */
@Entity
@Table(name = "ORGANIZATIONS")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Organization extends AbstractEntity {

    private static final long serialVersionUID = 1L;

    private String name;
    @XmlTransient
    private Boolean enable;
    @XmlTransient
    private Organization parent;
    @JsonSerialize(using = BasicSelfRecursiveSerializer.class)
    @JsonView(Views.Full.class)
    @XmlElement(name = "user")
    private Set<User> users = new HashSet<User>(0);
    @JsonSerialize(using = BasicSelfRecursiveSerializer.class)
    @JsonView(Views.Full.class)
    @XmlElement(name = "role")
    private Set<Role> roles = new HashSet<Role>(0);
    @JsonSerialize(using = BasicSelfRecursiveSerializer.class)
    @JsonView(Views.Full.class)
    @XmlElement(name = "group")
    private Set<Organization> organizations = new HashSet<Organization>(0);

    public Organization() {
    }

    public Organization(String name, String desc, Boolean enable, Organization parent) {
        this.name = name;
        setDesc(desc);
        this.enable = enable;
        this.parent = parent;
    }

    @XmlElement(name = "groupid")
    @Transient
    public int getGroupId() {
        return getId().intValue();
    }

    @Column(name = "NAME", length = 40)
    public String getName() {
        return this.name;
    }

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

    @XmlTransient
    @Column(name = "ENABLE")
    public Boolean getEnable() {
        return this.enable;
    }

    @XmlTransient
    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "organization", cascade = CascadeType.REMOVE)
    public Set<User> getUsers() {
        return this.users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }

    @XmlTransient
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENTID")
    public Organization getParent() {
        return parent;
    }

    @XmlTransient
    public void setParent(Organization parent) {
        this.parent = parent;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "organization", cascade = CascadeType.REMOVE)
    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent", cascade = CascadeType.REMOVE)
    public Set<Organization> getOrganizations() {
        return organizations;
    }

    public void setOrganizations(Set<Organization> organizations) {
        this.organizations = organizations;
    }

    @XmlElement(name = "parentid")
    @Transient
    public int getParentid() {
        if (parent != null) {
            return parent.getId().intValue();
        } else {
            return -1;
        }
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((enable == null) ? 0 : enable.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Organization other = (Organization) obj;
        if (enable == null) {
            if (other.enable != null) {
                return false;
            }
        } else if (!enable.equals(other.enable)) {
            return false;
        }
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!name.equals(other.name)) {
            return false;
        }
        if (parent == null) {
            if (other.parent != null) {
                return false;
            }
        } else if (!parent.equals(other.parent)) {
            return false;
        }
        return true;
    }

}