/*******************************************************************************
* Copyright 2012 Christian Ternes and Thorsten Volland
*
* 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 org.businessmanager.domain;
import java.util.Calendar;
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 org.businessmanager.i18n.ResourceBundleAccessor;
@Entity
public class Activity extends AbstractEntity {
public enum ActivityType {
CONTACT("activitytype_contact")
, INVOICE("activitytype_invoice");
private String label;
private ActivityType(String label) {
this.label = label;
}
public String getLabel() {
return ResourceBundleAccessor.getString(label);
}
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@Column
private Long userId;
@Column
private Long sourceId;
@Column
@Enumerated(EnumType.STRING)
private ActivityType type;
@Column
private String data;
@Column
private Calendar creationDate;
Activity() {
}
public Activity(Long userId, ActivityType activityType) {
this.userId = userId;
this.type = activityType;
this.creationDate = Calendar.getInstance();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getSourceId() {
return sourceId;
}
public void setSourceId(Long sourceId) {
this.sourceId = sourceId;
}
public ActivityType getType() {
return type;
}
public void setType(ActivityType type) {
this.type = type;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((data == null) ? 0 : data.hashCode());
result = prime * result
+ ((sourceId == null) ? 0 : sourceId.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((userId == null) ? 0 : userId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Activity other = (Activity) obj;
if (data == null) {
if (other.data != null)
return false;
} else if (!data.equals(other.data))
return false;
if (sourceId == null) {
if (other.sourceId != null)
return false;
} else if (!sourceId.equals(other.sourceId))
return false;
if (type != other.type)
return false;
if (userId == null) {
if (other.userId != null)
return false;
} else if (!userId.equals(other.userId))
return false;
return true;
}
@Override
public String toString() {
return "Activity [userId=" + userId + ", sourceId=" + sourceId
+ ", type=" + type + ", data=" + data + "]";
}
public void setCreationDate(Calendar creationDate) {
this.creationDate = creationDate;
}
public Calendar getCreationDate() {
return creationDate;
}
}