@ -1,6 +1,8 @@
package ru.ulstu.ping.model ;
import com.fasterxml.jackson.annotation.JsonProperty ;
import org.hibernate.annotations.Any ;
import org.hibernate.annotations.AnyMetaDef ;
import org.hibernate.annotations.MetaValue ;
import org.springframework.format.annotation.DateTimeFormat ;
import ru.ulstu.conference.model.Conference ;
import ru.ulstu.core.model.BaseEntity ;
@ -10,7 +12,9 @@ import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project ;
import ru.ulstu.user.model.User ;
import javax.persistence.Column ;
import javax.persistence.Entity ;
import javax.persistence.FetchType ;
import javax.persistence.JoinColumn ;
import javax.persistence.ManyToOne ;
import javax.persistence.Table ;
@ -29,21 +33,24 @@ public class Ping extends BaseEntity {
@JoinColumn ( name = "users_id" )
private User user ;
@ManyToOne ( )
@JoinColumn ( name = "conference_id" )
private Conference conference ;
@ManyToOne ( )
@JoinColumn ( name = "paper_id" )
private Paper paper ;
@ManyToOne ( )
@JoinColumn ( name = "grant_id" )
private Grant grant ;
@ManyToOne ( )
@JoinColumn ( name = "project_id" )
private Project project ;
@Column ( name = "activity_type" , insertable = false , updatable = false )
private String activityType ;
@Any (
metaColumn = @Column ( name = "activity_type" ) ,
fetch = FetchType . LAZY
)
@AnyMetaDef (
idType = "integer" , metaType = "string" ,
metaValues = {
@MetaValue ( targetEntity = Conference . class , value = "CONFERENCE" ) ,
@MetaValue ( targetEntity = Paper . class , value = "PAPER" ) ,
@MetaValue ( targetEntity = Project . class , value = "PROJECT" ) ,
@MetaValue ( targetEntity = Grant . class , value = "GRANT" )
}
)
@JoinColumn ( name = "activity_id" )
private UserActivity activity ;
public Ping ( ) {
}
@ -53,16 +60,6 @@ public class Ping extends BaseEntity {
this . user = user ;
}
public Ping ( @JsonProperty ( "id" ) Integer id ,
@JsonProperty ( "date" ) Date date ,
@JsonProperty ( "user" ) User user ,
@JsonProperty ( "conference" ) Conference conference ) {
setId ( id ) ;
this . date = date ;
this . user = user ;
this . conference = conference ;
}
public Date getDate ( ) {
return date ;
}
@ -79,59 +76,11 @@ public class Ping extends BaseEntity {
this . user = user ;
}
public Conference getConference ( ) {
return conference ;
}
public void setConference ( Conference conference ) {
this . conference = conference ;
}
public Paper getPaper ( ) {
return paper ;
}
public void setPaper ( Paper paper ) {
this . paper = paper ;
}
public Grant getGrant ( ) {
return grant ;
}
public void setGrant ( Grant grant ) {
this . grant = grant ;
}
public Project getProject ( ) {
return project ;
}
public void setProject ( Project project ) {
this . project = project ;
}
public < T > void setActivity ( T object ) {
if ( object . getClass ( ) = = Conference . class ) {
this . conference = ( Conference ) object ;
} else if ( object . getClass ( ) = = Project . class ) {
this . project = ( Project ) object ;
} else if ( object . getClass ( ) = = Grant . class ) {
this . grant = ( Grant ) object ;
} else if ( object . getClass ( ) = = Paper . class ) {
this . paper = ( Paper ) object ;
}
public UserActivity getActivity ( ) {
return this . activity ;
}
public UserActivity getActivity ( ) {
if ( conference ! = null ) {
return conference ;
} else if ( project ! = null ) {
return project ;
} else if ( paper ! = null ) {
return paper ;
} else {
return grant ;
}
public void setActivity ( UserActivity activity ) {
this . activity = activity ;
}
}