Java tutorial
/******************************************************************************* * Copyright 2014 Juan Diego Navarre Gonzalez * * 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 net.navasoft.madcoin.backend.model.entities.impl; import java.io.Serializable; import java.lang.reflect.Array; import java.util.Collection; import java.util.Date; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.JoinColumns; import javax.persistence.Lob; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; import net.navasoft.madcoin.backend.model.entities.NormalizedEntity; import net.navasoft.madcoin.backend.services.rest.impl.MasterLimiter; import org.apache.commons.lang.ArrayUtils; /** * net.navasoft.madcoin.backend.model.entities.impl Class class * ServiceProviders. Description: * * @author Juan Diego Navarre Gonzalez - (${authorMail}) * @version 1.0 * @since 31/08/2014 09:11:49 PM */ @Entity @Table(name = "service_providers", catalog = "clickndonedb", schema = "", uniqueConstraints = { @UniqueConstraint(columnNames = { "email" }), @UniqueConstraint(columnNames = { "app_username" }) }) @XmlRootElement @NamedQueries({ @NamedQuery(name = "ServiceProviders.findAll", query = "SELECT s FROM ServiceProviders s"), @NamedQuery(name = "ServiceProviders.findByIdServiceProvider", query = "SELECT s FROM ServiceProviders s WHERE s.serviceProvidersPK.idServiceProvider = :idServiceProvider"), @NamedQuery(name = "ServiceProviders." + NormalizedEntity.NAMED_QUERY_ID, query = "SELECT s FROM ServiceProviders s WHERE s.serviceProvidersPK.appUsername = :appUsername"), @NamedQuery(name = "ServiceProviders.findByName", query = "SELECT s FROM ServiceProviders s WHERE s.name = :name"), @NamedQuery(name = "ServiceProviders.findByLastName", query = "SELECT s FROM ServiceProviders s WHERE s.lastName = :lastName"), @NamedQuery(name = "ServiceProviders.findByApplicationPassword", query = "SELECT s FROM ServiceProviders s WHERE s.applicationPassword = :applicationPassword"), @NamedQuery(name = "ServiceProviders.findByEmail", query = "SELECT s FROM ServiceProviders s WHERE s.email = :email"), @NamedQuery(name = "ServiceProviders.findByLastLoggedOn", query = "SELECT s FROM ServiceProviders s WHERE s.lastLoggedOn = :lastLoggedOn"), @NamedQuery(name = "ServiceProviders.findByLastPasswordReset", query = "SELECT s FROM ServiceProviders s WHERE s.lastPasswordReset = :lastPasswordReset"), @NamedQuery(name = "ServiceProviders.findByAuthorizedOn", query = "SELECT s FROM ServiceProviders s WHERE s.authorizedOn = :authorizedOn"), @NamedQuery(name = "ServiceProviders.findByLastUpdatedOn", query = "SELECT s FROM ServiceProviders s WHERE s.lastUpdatedOn = :lastUpdatedOn") }) public class ServiceProviders implements NormalizedEntity, MasterLimiter { /** * Constant serialVersionUID. * * @since 31/08/2014, 09:11:49 PM */ private static final long serialVersionUID = 1L; /** * service providers pk. * * @since 31/08/2014, 09:11:49 PM */ @EmbeddedId protected ServiceProvidersPK serviceProvidersPK; /** * name. * * @since 31/08/2014, 09:11:49 PM */ @Basic(optional = false) @Column(name = "name", nullable = false, length = 80) private String name; /** * last name. * * @since 31/08/2014, 09:11:49 PM */ @Basic(optional = false) @Column(name = "last_name", nullable = false, length = 80) private String lastName; /** * application password. * * @since 31/08/2014, 09:11:49 PM */ @Column(name = "application_password", length = 100) private String applicationPassword; /** * email. * * @since 31/08/2014, 09:11:49 PM */ @Basic(optional = false) @Column(name = "email", nullable = false, length = 45) private String email; /** * worker picture. * * @since 31/08/2014, 09:11:49 PM */ @Lob @Column(name = "worker_picture") private byte[] workerPicture; /** * last logged on. * * @since 31/08/2014, 09:11:49 PM */ @Column(name = "last_logged_on") @Temporal(TemporalType.TIMESTAMP) private Date lastLoggedOn; /** * last password reset. * * @since 31/08/2014, 09:11:49 PM */ @Column(name = "last_password_reset") @Temporal(TemporalType.TIMESTAMP) private Date lastPasswordReset; /** * authorized on. * * @since 31/08/2014, 09:11:49 PM */ @Basic(optional = false) @Column(name = "authorized_on", nullable = false) @Temporal(TemporalType.TIMESTAMP) private Date authorizedOn; /** * last updated on. * * @since 31/08/2014, 09:11:49 PM */ @Column(name = "last_updated_on") @Temporal(TemporalType.TIMESTAMP) private Date lastUpdatedOn; /** * app users. * * @since 31/08/2014, 09:11:49 PM */ @JoinColumn(name = "id_service_provider", referencedColumnName = "id_application_users", nullable = false, insertable = false, updatable = false) @ManyToOne(optional = false) private AppUsers appUsers; /** * provider role. * * @since 31/08/2014, 09:11:49 PM */ @JoinColumn(name = "provider_role", referencedColumnName = "id_provider_type", nullable = false) @ManyToOne(optional = false) private ProviderTypes providerRole; /** * request for data collection. * * @since 31/08/2014, 09:11:49 PM */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "serviceProviders") private Collection<RequestForData> requestForDataCollection; /** * service provider rankings collection. * * @since 31/08/2014, 09:11:49 PM */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "serviceProviders") private Collection<ServiceProviderRankings> serviceProviderRankingsCollection; /** * service providers collection. * * @since 31/08/2014, 09:11:49 PM */ @OneToMany(mappedBy = "serviceProviders") private Collection<ServiceProviders> serviceProvidersCollection; /** * service providers. * * @since 31/08/2014, 09:11:49 PM */ @JoinColumns({ @JoinColumn(name = "last_updated_id_provider", referencedColumnName = "id_service_provider"), @JoinColumn(name = "last_updated_by_provider", referencedColumnName = "app_username") }) @ManyToOne private ServiceProviders serviceProviders; /** * administrators. * * @since 31/08/2014, 09:11:49 PM */ @JoinColumns({ @JoinColumn(name = "last_updated_by_admin", referencedColumnName = "admin_username"), @JoinColumn(name = "last_updated_id_admin", referencedColumnName = "id_administrators") }) @ManyToOne private Administrators administrators; /** * administrators1. * * @since 31/08/2014, 09:11:49 PM */ @JoinColumns({ @JoinColumn(name = "authorized_by", referencedColumnName = "admin_username", nullable = false), @JoinColumn(name = "authorized_id", referencedColumnName = "id_administrators", nullable = false) }) @ManyToOne(optional = false) private Administrators administrators1; /** * end user rankings collection. * * @since 31/08/2014, 09:11:49 PM */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "serviceProviders") private Collection<EndUserRankings> endUserRankingsCollection; /** * work requests x service providers collection. * * @since 31/08/2014, 09:11:49 PM */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "serviceProviders") private Collection<WorkRequestsXServiceProviders> workRequestsXServiceProvidersCollection; /** * Instantiates a new service providers. * * @since 31/08/2014, 09:11:49 PM */ public ServiceProviders() { } /** * Instantiates a new service providers. * * @param serviceProvidersPK * the service providers pk * @since 31/08/2014, 09:11:49 PM */ public ServiceProviders(ServiceProvidersPK serviceProvidersPK) { this.serviceProvidersPK = serviceProvidersPK; } /** * Instantiates a new service providers. * * @param serviceProvidersPK * the service providers pk * @param name * the name * @param lastName * the last name * @param email * the email * @param authorizedOn * the authorized on * @since 31/08/2014, 09:11:49 PM */ public ServiceProviders(ServiceProvidersPK serviceProvidersPK, String name, String lastName, String email, Date authorizedOn) { this.serviceProvidersPK = serviceProvidersPK; this.name = name; this.lastName = lastName; this.email = email; this.authorizedOn = authorizedOn; } /** * Instantiates a new service providers. * * @param idServiceProvider * the id service provider * @param appUsername * the app username * @since 31/08/2014, 09:11:49 PM */ public ServiceProviders(long idServiceProvider, String appUsername) { this.serviceProvidersPK = new ServiceProvidersPK(idServiceProvider, appUsername); } /** * Gets the service providers pk. * * @return the service providers pk * @since 31/08/2014, 09:11:50 PM */ public ServiceProvidersPK getServiceProvidersPK() { return serviceProvidersPK; } /** * Sets the service providers pk. * * @param serviceProvidersPK * the new service providers pk * @since 31/08/2014, 09:11:50 PM */ public void setServiceProvidersPK(ServiceProvidersPK serviceProvidersPK) { this.serviceProvidersPK = serviceProvidersPK; } /** * Gets the name. * * @return the name * @since 31/08/2014, 09:11:50 PM */ public String getName() { return name; } /** * Sets the name. * * @param name * the new name * @since 31/08/2014, 09:11:50 PM */ public void setName(String name) { this.name = name; } /** * Gets the last name. * * @return the last name * @since 31/08/2014, 09:11:50 PM */ public String getLastName() { return lastName; } /** * Sets the last name. * * @param lastName * the new last name * @since 31/08/2014, 09:11:50 PM */ public void setLastName(String lastName) { this.lastName = lastName; } /** * Gets the application password. * * @return the application password * @since 31/08/2014, 09:11:50 PM */ public String getApplicationPassword() { return applicationPassword; } /** * Sets the application password. * * @param applicationPassword * the new application password * @since 31/08/2014, 09:11:50 PM */ public void setApplicationPassword(String applicationPassword) { this.applicationPassword = applicationPassword; } /** * Gets the email. * * @return the email * @since 31/08/2014, 09:11:50 PM */ public String getEmail() { return email; } /** * Sets the email. * * @param email * the new email * @since 31/08/2014, 09:11:50 PM */ public void setEmail(String email) { this.email = email; } /** * Gets the worker picture. * * @return the worker picture * @since 31/08/2014, 09:11:50 PM */ public byte[] getWorkerPicture() { return workerPicture; } /** * Sets the worker picture. * * @param workerPicture * the new worker picture * @since 31/08/2014, 09:11:50 PM */ public void setWorkerPicture(byte[] workerPicture) { this.workerPicture = workerPicture; } /** * Gets the last logged on. * * @return the last logged on * @since 31/08/2014, 09:11:50 PM */ public Date getLastLoggedOn() { return lastLoggedOn; } /** * Sets the last logged on. * * @param lastLoggedOn * the new last logged on * @since 31/08/2014, 09:11:50 PM */ public void setLastLoggedOn(Date lastLoggedOn) { this.lastLoggedOn = lastLoggedOn; } /** * Gets the last password reset. * * @return the last password reset * @since 31/08/2014, 09:11:50 PM */ public Date getLastPasswordReset() { return lastPasswordReset; } /** * Sets the last password reset. * * @param lastPasswordReset * the new last password reset * @since 31/08/2014, 09:11:50 PM */ public void setLastPasswordReset(Date lastPasswordReset) { this.lastPasswordReset = lastPasswordReset; } /** * Gets the authorized on. * * @return the authorized on * @since 31/08/2014, 09:11:50 PM */ public Date getAuthorizedOn() { return authorizedOn; } /** * Sets the authorized on. * * @param authorizedOn * the new authorized on * @since 31/08/2014, 09:11:50 PM */ public void setAuthorizedOn(Date authorizedOn) { this.authorizedOn = authorizedOn; } /** * Gets the last updated on. * * @return the last updated on * @since 31/08/2014, 09:11:50 PM */ public Date getLastUpdatedOn() { return lastUpdatedOn; } /** * Sets the last updated on. * * @param lastUpdatedOn * the new last updated on * @since 31/08/2014, 09:11:50 PM */ public void setLastUpdatedOn(Date lastUpdatedOn) { this.lastUpdatedOn = lastUpdatedOn; } /** * Gets the request for data collection. * * @return the request for data collection * @since 31/08/2014, 09:11:50 PM */ @XmlTransient public Collection<RequestForData> getRequestForDataCollection() { return requestForDataCollection; } /** * Sets the request for data collection. * * @param requestForDataCollection * the new request for data collection * @since 31/08/2014, 09:11:50 PM */ public void setRequestForDataCollection(Collection<RequestForData> requestForDataCollection) { this.requestForDataCollection = requestForDataCollection; } /** * Gets the service provider rankings collection. * * @return the service provider rankings collection * @since 31/08/2014, 09:11:50 PM */ @XmlTransient public Collection<ServiceProviderRankings> getServiceProviderRankingsCollection() { return serviceProviderRankingsCollection; } /** * Sets the service provider rankings collection. * * @param serviceProviderRankingsCollection * the new service provider rankings collection * @since 31/08/2014, 09:11:50 PM */ public void setServiceProviderRankingsCollection( Collection<ServiceProviderRankings> serviceProviderRankingsCollection) { this.serviceProviderRankingsCollection = serviceProviderRankingsCollection; } /** * Gets the service providers collection. * * @return the service providers collection * @since 31/08/2014, 09:11:50 PM */ @XmlTransient public Collection<ServiceProviders> getServiceProvidersCollection() { return serviceProvidersCollection; } /** * Sets the service providers collection. * * @param serviceProvidersCollection * the new service providers collection * @since 31/08/2014, 09:11:50 PM */ public void setServiceProvidersCollection(Collection<ServiceProviders> serviceProvidersCollection) { this.serviceProvidersCollection = serviceProvidersCollection; } /** * Gets the service providers. * * @return the service providers * @since 31/08/2014, 09:11:50 PM */ public ServiceProviders getServiceProviders() { return serviceProviders; } /** * Sets the service providers. * * @param serviceProviders * the new service providers * @since 31/08/2014, 09:11:50 PM */ public void setServiceProviders(ServiceProviders serviceProviders) { this.serviceProviders = serviceProviders; } /** * Gets the administrators. * * @return the administrators * @since 31/08/2014, 09:11:50 PM */ public Administrators getAdministrators() { return administrators; } /** * Sets the administrators. * * @param administrators * the new administrators * @since 31/08/2014, 09:11:50 PM */ public void setAdministrators(Administrators administrators) { this.administrators = administrators; } /** * Gets the administrators1. * * @return the administrators1 * @since 31/08/2014, 09:11:50 PM */ public Administrators getAdministrators1() { return administrators1; } /** * Sets the administrators1. * * @param administrators1 * the new administrators1 * @since 31/08/2014, 09:11:50 PM */ public void setAdministrators1(Administrators administrators1) { this.administrators1 = administrators1; } /** * Gets the end user rankings collection. * * @return the end user rankings collection * @since 31/08/2014, 09:11:50 PM */ @XmlTransient public Collection<EndUserRankings> getEndUserRankingsCollection() { return endUserRankingsCollection; } /** * Sets the end user rankings collection. * * @param endUserRankingsCollection * the new end user rankings collection * @since 31/08/2014, 09:11:50 PM */ public void setEndUserRankingsCollection(Collection<EndUserRankings> endUserRankingsCollection) { this.endUserRankingsCollection = endUserRankingsCollection; } /** * Gets the work requests x service providers collection. * * @return the work requests x service providers collection * @since 31/08/2014, 09:11:50 PM */ @XmlTransient public Collection<WorkRequestsXServiceProviders> getWorkRequestsXServiceProvidersCollection() { return workRequestsXServiceProvidersCollection; } /** * Sets the work requests x service providers collection. * * @param workRequestsXServiceProvidersCollection * the new work requests x service providers collection * @since 31/08/2014, 09:11:50 PM */ public void setWorkRequestsXServiceProvidersCollection( Collection<WorkRequestsXServiceProviders> workRequestsXServiceProvidersCollection) { this.workRequestsXServiceProvidersCollection = workRequestsXServiceProvidersCollection; } /** * Gets the provider role. * * @return the provider role * @since 7/09/2014, 06:51:17 PM */ public ProviderTypes getProviderRole() { return providerRole; } /** * Sets the provider role. * * @param providerRole * the new provider role * @since 31/08/2014, 09:11:50 PM */ public void setProviderRole(ProviderTypes providerRole) { this.providerRole = providerRole; } /** * Gets the app users. * * @return the app users * @since 31/08/2014, 09:11:50 PM */ public AppUsers getAppUsers() { return appUsers; } /** * Sets the app users. * * @param appUsers * the new app users * @since 31/08/2014, 09:11:50 PM */ public void setAppUsers(AppUsers appUsers) { this.appUsers = appUsers; } /** * {@inheritDoc Object#hashCode()}. * * @return the int * @see Object#hashCode() * @since 31/08/2014, 09:11:50 PM */ @Override public int hashCode() { int hash = 0; hash += (serviceProvidersPK != null ? serviceProvidersPK.hashCode() : 0); return hash; } /** * {@inheritDoc Object#equals(Object)}. * * @param object * the object * @return true, if equals * @see Object#equals(Object) * @since 31/08/2014, 09:11:50 PM */ @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are // not set if (!(object instanceof ServiceProviders)) { return false; } ServiceProviders other = (ServiceProviders) object; if ((this.serviceProvidersPK == null && other.serviceProvidersPK != null) || (this.serviceProvidersPK != null && !this.serviceProvidersPK.equals(other.serviceProvidersPK))) { return false; } return true; } /** * {@inheritDoc Object#toString()}. * * @return the string * @see Object#toString() * @since 31/08/2014, 09:11:50 PM */ @Override public String toString() { return "entities.ServiceProviders[ serviceProvidersPK=" + serviceProvidersPK + " ]"; } /** * Gets the normalized id. * * @return the normalized id * @since 31/08/2014, 09:11:50 PM */ @Override public Serializable getNormalizedId() { return getServiceProvidersPK(); } /** * Gets the id class. * * @return the id class * @since 31/08/2014, 09:11:50 PM */ @Override public Class<? extends Serializable> getIdClass() { return ServiceProvidersPK.class; } /** * Gets the named query id. * * @return the named query id * @since 31/08/2014, 09:11:50 PM */ @Override public String getNamedQueryId() { NamedQueries qs = getClass().getAnnotation(NamedQueries.class); for (NamedQuery q : qs.value()) { if (q.name().equalsIgnoreCase(getClass().getSimpleName() + "." + NAMED_QUERY_ID)) { return q.name(); } } return null; } /** * Gets the common name. * * @return the common name * @since 7/09/2014, 06:51:44 PM */ @Override @Transient public String getCommonName() { return getServiceProvidersPK().getAppUsername(); } /** * Gets the conditions. * * @return the conditions * @since 7/09/2014, 06:51:59 PM */ @Override @Transient public Object[] getConditions() { Object[] result = (Object[]) Array.newInstance(Object.class, 0); for (WorkRequestsXServiceProviders scheduled : workRequestsXServiceProvidersCollection) { if (scheduled.getWorkRequests().getEstimatedClosing() != null) { result = ArrayUtils.add(result, scheduled.getWorkRequests().getEstimatedArrival()); result = ArrayUtils.add(result, scheduled.getWorkRequests().getEstimatedClosing()); } } result = ArrayUtils.add(result, getProviderRole().getProviderScope()); // TODO obtener token de logueo result = ArrayUtils.add(result, "df75a122 60b499a0 ae60c94f 4040330d 2e10a37d ba657451 c4df2120 fca8ad25"); return result; } /** * Checks if is valid. * * @return true, if is valid * @since 7/09/2014, 06:52:06 PM */ @Override @Transient public boolean isValid() { boolean auxiliar = false; for (AppUserXStatus status : getAppUsers().getAppUserXStatusCollection()) { auxiliar |= status.getIdUserStatus().getStatusAppName().equalsIgnoreCase("ACTIVE"); } return auxiliar; } }