Java tutorial
/* * South Face Software * Copyright 2012, South Face Software, Inc. and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This 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; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package com.sfs.captor.model; import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.Lob; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; import javax.persistence.Table; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.apache.commons.lang.StringUtils; import org.hibernate.envers.Audited; import org.hibernate.search.annotations.Analyze; import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Index; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Store; import com.sfs.captor.data.Constants; import com.sfs.captor.data.Literal; import com.sfs.captor.data.StatusType; import com.sfs.captor.util.ModelUtils; /** * Business Process * * @author lbbishop * */ @Entity @Indexed @Audited @Table(name = "businessprocess") public class BusinessProcess extends EntityBase implements Serializable { private static final long serialVersionUID = 1L; @Id @DocumentId @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES) @NotNull(message = "Event is required") @Size(max = 100) @Column(name = "event", length = 100, nullable = false) private String event; @NotNull(message = "Goal is required") @Size(max = 255) @Column(name = "goal", length = 255, nullable = false) private String goal; @Lob @Column(name = "activities", columnDefinition = "TEXT NULL", nullable = true) private String activities; @NotNull(message = "Status is required") @Enumerated(EnumType.STRING) @Column(name = "status_type") private StatusType statusType; @OneToOne @JoinColumn(name = "productrelease_id", nullable = true) private ProductRelease productRelease; @Lob @Column(name = "issues", columnDefinition = "TEXT NULL", nullable = true) private String issues; @ManyToOne private Project project; /** * Default constructor */ public BusinessProcess() { super(); init(); } /** * Identifier constructor */ public BusinessProcess(int identifier) { super(); this.identifier = Integer.valueOf(identifier); init(); } /** * class init method */ private void init() { } /** * PrePersist method */ @PrePersist public void prePersist() { if (this.modifiedBy == null) { this.modifiedBy = Literal.APPNAME.toString(); } this.modifiedDate = new Date(); } /** * PreUpdate method */ @PreUpdate public void preUpdate() { if (this.modifiedBy == null) { this.modifiedBy = Literal.APPNAME.toString(); } this.modifiedDate = new Date(); } /** * @return the id */ public Long getId() { return id; } /** * @param id * the id to set */ public void setId(Long id) { this.id = id; } /** * @return the event */ public String getEvent() { return event; } /** * @param event * the event to set */ public void setEvent(String event) { this.event = event; } /** * @return the goal */ public String getGoal() { return goal; } /** * @return the goal abbreviated */ public String getGoalAbbrv() { return StringUtils.abbreviate(this.goal, Constants.ABBRV_DESC_LEN); } /** * @param goal * the goal to set */ public void setGoal(String goal) { this.goal = goal; } /** * @return the activities */ public String getActivities() { return activities; } /** * @param activities * the activities to set */ public void setActivities(String activities) { this.activities = activities; } /** * @return the productRelease */ public ProductRelease getProductRelease() { return productRelease; } /** * @param productRelease * the productRelease to set */ public void setProductRelease(ProductRelease productRelease) { this.productRelease = productRelease; } /** * @return the project */ public Project getProject() { return project; } /** * @param project * the project to set */ public void setProject(Project project) { this.project = project; } /** * @return the issues */ public String getIssues() { return issues; } /** * @param issues * the issues to set */ public void setIssues(String issues) { this.issues = issues; } /** * @return the statusType */ public StatusType getStatusType() { return statusType; } /** * @param statusType * the statusType to set */ public void setStatusType(StatusType statusType) { this.statusType = statusType; } /** * @return the identifier string (PREFIX concatenated with identifier) */ public String getArtifact() { return ModelUtils.buildArtifactIdentifier(Literal.PREFIX_BUSINESSPROCESS.toString(), this.identifier); } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("BusinessProcess [id="); builder.append(id); builder.append(", event="); builder.append(event); builder.append(", goal="); builder.append(goal); builder.append(", activities="); builder.append(activities); builder.append(", productRelease="); builder.append(productRelease); builder.append("]"); return builder.toString(); } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((event == null) ? 0 : event.hashCode()); return result; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BusinessProcess other = (BusinessProcess) obj; if (event == null) { if (other.event != null) return false; } else if (!event.equals(other.event)) return false; return true; } }