* Terms - Prepared support for rename * ObjectType.java - Added ID for serialization - Added RELATIONSHIP class constant * struts.xml - Added Relationship actions * General - Relationships between two terms can be added and listed - Clean-up: + Renamed methods according to their purpose + Fixed RDM and corresponding properties/annotations + RelationShipTypeAction.java
/trunk/src/ch/ffhs/webE/dao/RelationshipDAOImpl.java |
---|
File deleted |
\ No newline at end of file |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: ffhs/webE/dao/TermDAO.java |
=================================================================== |
--- ffhs/webE/dao/TermDAO.java (revision 34) |
+++ ffhs/webE/dao/TermDAO.java (revision 33) |
@@ -14,7 +14,7 @@ |
/** |
* @return |
*/ |
- List<Term> getTerms(); |
+ List<Term> listTerm(); |
/** |
* Delete a term |
/trunk/src/ch/ffhs/webE/dao/TermDAOImpl.java |
---|
31,13 → 31,13 |
Transaction transaction; |
/** |
* Returns a list of all terms |
* Creates a list of all terms |
* |
* @return an ArrayList with all the terms - in case of a problem, an empty |
* @return an ArrayList with all the users - in case of a problem, an empty |
* list is returned |
*/ |
@SuppressWarnings("unchecked") |
public List<Term> getTerms() |
public List<Term> listTerm() |
{ |
List<Term> term = null; |
try |
/trunk/src/ch/ffhs/webE/dao/RelationshipTypeDAO.java |
---|
6,11 → 6,11 |
public interface RelationshipTypeDAO { |
List<RelationshipType> getRelTypes(); |
List<RelationshipType> listRelationshipTypes(); |
boolean deleteRelationshipType(int relTypeID); |
RelationshipType getRelTypeById(int relTypeID); |
RelationshipType listRelTypeById(int relTypeID); |
boolean saveOrUpdateRelType(RelationshipType relType); |
} |
/trunk/src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java |
---|
26,7 → 26,7 |
*/ |
@SuppressWarnings("unchecked") |
@Override |
public List<RelationshipType> getRelTypes() |
public List<RelationshipType> listRelationshipTypes() |
{ |
List<RelationshipType> relType = null; |
100,7 → 100,7 |
* Used to get a relationship type by ID |
*/ |
@Override |
public RelationshipType getRelTypeById(int relTypeID) |
public RelationshipType listRelTypeById(int relTypeID) |
{ |
RelationshipType relType = null; |
try |
/trunk/src/ch/ffhs/webE/domain/Relationship.java |
---|
12,9 → 12,7 |
import javax.persistence.OneToOne; |
import javax.persistence.PrimaryKeyJoinColumn; |
import javax.persistence.Table; |
import javax.persistence.Transient; |
import javax.persistence.UniqueConstraint; |
import org.hibernate.annotations.GenericGenerator; |
import org.hibernate.annotations.Parameter; |
23,91 → 21,76 |
*/ |
@Entity |
@Table(name = "relationship", catalog = "webengineering", uniqueConstraints = @UniqueConstraint(columnNames = { |
"term_from", "term_to", "type_id" })) |
public class Relationship implements java.io.Serializable |
{ |
private int objectId; |
"term_from", "term_to", "type" })) |
public class Relationship implements java.io.Serializable { |
@Transient |
private ObjectEntity object; |
private int objectId; |
private Term termByTermTo; |
private ObjectEntity object; |
private RelationshipType relationshipType; |
private Term termByTermFrom; |
private Term termFrom; |
private Term termTo; |
private RelationshipType relationshipType; |
public Relationship() { |
} |
public Relationship() |
{ |
} |
public Relationship(Term termByTermTo, ObjectEntity object, |
RelationshipType relationshipType, Term termByTermFrom) { |
this.termByTermTo = termByTermTo; |
this.object = object; |
this.relationshipType = relationshipType; |
this.termByTermFrom = termByTermFrom; |
} |
public Relationship(Term termByTermTo, ObjectEntity object, |
RelationshipType relationshipType, Term termByTermFrom) |
{ |
this.termTo = termByTermTo; |
this.object = object; |
this.relationshipType = relationshipType; |
this.termFrom = termByTermFrom; |
} |
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "object")) |
@Id |
@GeneratedValue(generator = "generator") |
@Column(name = "object_id", unique = true, nullable = false) |
public int getObjectId() { |
return this.objectId; |
} |
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "object")) |
@Id |
@GeneratedValue(generator = "generator") |
@Column(name = "object_id", unique = true, nullable = false) |
public int getObjectId() |
{ |
return this.objectId; |
} |
public void setObjectId(int objectId) { |
this.objectId = objectId; |
} |
public void setObjectId(int objectId) |
{ |
this.objectId = objectId; |
} |
@ManyToOne(fetch = FetchType.LAZY) |
@JoinColumn(name = "term_to", nullable = false) |
public Term getTermByTermTo() { |
return this.termByTermTo; |
} |
@ManyToOne(fetch = FetchType.LAZY) |
@JoinColumn(name = "term_to", nullable = false) |
public Term getTermTo() |
{ |
return this.termTo; |
} |
public void setTermByTermTo(Term termByTermTo) { |
this.termByTermTo = termByTermTo; |
} |
public void setTermTo(Term termByTermTo) |
{ |
this.termTo = termByTermTo; |
} |
@OneToOne(fetch = FetchType.LAZY) |
@PrimaryKeyJoinColumn |
public ObjectEntity getObject() { |
return this.object; |
} |
@OneToOne(fetch = FetchType.LAZY) |
@PrimaryKeyJoinColumn |
public ObjectEntity getObject() |
{ |
return this.object; |
} |
public void setObject(ObjectEntity object) { |
this.object = object; |
} |
public void setObject(ObjectEntity object) |
{ |
this.object = object; |
} |
@ManyToOne(fetch = FetchType.LAZY) |
@JoinColumn(name = "type", nullable = false) |
public RelationshipType getRelationshipType() { |
return this.relationshipType; |
} |
@ManyToOne(fetch = FetchType.LAZY) |
@JoinColumn(name = "type_id", nullable = false) |
public RelationshipType getRelationshipType() |
{ |
return this.relationshipType; |
} |
public void setRelationshipType(RelationshipType relationshipType) { |
this.relationshipType = relationshipType; |
} |
public void setRelationshipType(RelationshipType relationshipType) |
{ |
this.relationshipType = relationshipType; |
} |
@ManyToOne(fetch = FetchType.LAZY) |
@JoinColumn(name = "term_from", nullable = false) |
public Term getTermByTermFrom() { |
return this.termByTermFrom; |
} |
@ManyToOne(fetch = FetchType.LAZY) |
@JoinColumn(name = "term_from", nullable = false) |
public Term getTermFrom() |
{ |
return this.termFrom; |
} |
public void setTermByTermFrom(Term termByTermFrom) { |
this.termByTermFrom = termByTermFrom; |
} |
public void setTermFrom(Term termByTermFrom) |
{ |
this.termFrom = termByTermFrom; |
} |
} |
/trunk/src/ch/ffhs/webE/domain/Term.java |
---|
45,12 → 45,6 |
0); |
/** |
* @var <code>true</code> if the term is edited/renamed, <code>false</code> |
* otherwise |
*/ |
public boolean edit = false; |
/** |
* No-op constructor |
*/ |
public Term() |
136,7 → 130,7 |
this.name = name; |
} |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "termTo") |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "termByTermTo") |
public Set<Relationship> getRelationshipsForTermTo() |
{ |
return this.relationshipsForTermTo; |
153,7 → 147,7 |
/** |
* @return |
*/ |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "termFrom") |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "termByTermFrom") |
public Set<Relationship> getRelationshipsForTermFrom() |
{ |
return this.relationshipsForTermFrom; |
/trunk/src/ch/ffhs/webE/domain/ObjectType.java |
---|
21,21 → 21,11 |
public class ObjectType implements java.io.Serializable |
{ |
/** |
* Version ID for serialization |
*/ |
private static final long serialVersionUID = 1L; |
/** |
* ObjectEntity type ID for a term |
*/ |
public static final int TERM = 1; |
/** |
* ObjectEntity type ID for a relationship |
*/ |
public static final int RELATIONSHIP = 2; |
private int id; |
private int objectTypeId; |
private String name; |
private Set<ObjectEntity> objects = new HashSet<ObjectEntity>(0); |
43,28 → 33,28 |
{ |
} |
public ObjectType(int id) |
public ObjectType(int objectTypeId) |
{ |
this.id = id; |
this.objectTypeId = objectTypeId; |
} |
public ObjectType(int id, String name, Set<ObjectEntity> objects) |
public ObjectType(int objectTypeId, String name, Set<ObjectEntity> objects) |
{ |
this.id = id; |
this.objectTypeId = objectTypeId; |
this.name = name; |
this.objects = objects; |
} |
@Id |
@Column(name = "id", unique = true, nullable = false) |
public int getId() |
@Column(name = "object_type_id", unique = true, nullable = false) |
public int getObjectTypeId() |
{ |
return this.id; |
return this.objectTypeId; |
} |
public void setId(int objectTypeId) |
public void setObjectTypeId(int objectTypeId) |
{ |
this.id = objectTypeId; |
this.objectTypeId = objectTypeId; |
} |
@Column(name = "name", unique = true, length = 45) |
/trunk/src/ch/ffhs/webE/domain/RelationshipType.java |
---|
2,15 → 2,13 |
// Generated 19.12.2010 14:46:08 by Hibernate Tools 3.4.0.Beta1 |
import static javax.persistence.GenerationType.IDENTITY; |
import java.util.HashSet; |
import java.util.Set; |
import javax.persistence.Column; |
import javax.persistence.Entity; |
import javax.persistence.FetchType; |
import javax.persistence.GeneratedValue; |
import static javax.persistence.GenerationType.IDENTITY; |
import javax.persistence.Id; |
import javax.persistence.OneToMany; |
import javax.persistence.Table; |
21,76 → 19,64 |
*/ |
@Entity |
@Table(name = "relationship_type", catalog = "webengineering", uniqueConstraints = @UniqueConstraint(columnNames = "name_from")) |
public class RelationshipType implements java.io.Serializable |
{ |
public class RelationshipType implements java.io.Serializable { |
private Integer id; |
private String nameFrom; |
private String nameTo; |
private Set<Relationship> relationships = new HashSet<Relationship>(0); |
private Integer relationshipId; |
private String nameFrom; |
private String nameTo; |
private Set<Relationship> relationships = new HashSet<Relationship>(0); |
public RelationshipType() |
{ |
} |
public RelationshipType() { |
} |
public RelationshipType(String nameFrom, String nameTo) |
{ |
this.nameFrom = nameFrom; |
this.nameTo = nameTo; |
} |
public RelationshipType(String nameFrom, String nameTo) { |
this.nameFrom = nameFrom; |
this.nameTo = nameTo; |
} |
public RelationshipType(String nameFrom, String nameTo, |
Set<Relationship> relationships) |
{ |
this.nameFrom = nameFrom; |
this.nameTo = nameTo; |
this.relationships = relationships; |
} |
public RelationshipType(String nameFrom, String nameTo, |
Set<Relationship> relationships) { |
this.nameFrom = nameFrom; |
this.nameTo = nameTo; |
this.relationships = relationships; |
} |
@Id |
@GeneratedValue(strategy = IDENTITY) |
@Column(name = "id", unique = true, nullable = false) |
public Integer getId() |
{ |
return this.id; |
} |
@Id |
@GeneratedValue(strategy = IDENTITY) |
@Column(name = "relationship_id", unique = true, nullable = false) |
public Integer getRelationshipId() { |
return this.relationshipId; |
} |
public void setId(Integer id) |
{ |
this.id = id; |
} |
public void setRelationshipId(Integer relationshipId) { |
this.relationshipId = relationshipId; |
} |
@Column(name = "name_from", unique = true, nullable = false) |
public String getNameFrom() |
{ |
return this.nameFrom; |
} |
@Column(name = "name_from", unique = true, nullable = false) |
public String getNameFrom() { |
return this.nameFrom; |
} |
public void setNameFrom(String nameFrom) |
{ |
this.nameFrom = nameFrom; |
} |
public void setNameFrom(String nameFrom) { |
this.nameFrom = nameFrom; |
} |
@Column(name = "name_to", nullable = false) |
public String getNameTo() |
{ |
return this.nameTo; |
} |
@Column(name = "name_to", nullable = false) |
public String getNameTo() { |
return this.nameTo; |
} |
public void setNameTo(String nameTo) |
{ |
this.nameTo = nameTo; |
} |
public void setNameTo(String nameTo) { |
this.nameTo = nameTo; |
} |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "relationshipType") |
public Set<Relationship> getRelationships() |
{ |
return this.relationships; |
} |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "relationshipType") |
public Set<Relationship> getRelationships() { |
return this.relationships; |
} |
public void setRelationships(Set<Relationship> relationships) |
{ |
this.relationships = relationships; |
} |
public void setRelationships(Set<Relationship> relationships) { |
this.relationships = relationships; |
} |
} |
/trunk/src/ch/ffhs/webE/action/RelationshipAction.java |
---|
File deleted |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: ffhs/webE/action/TermAction.java |
=================================================================== |
--- ffhs/webE/action/TermAction.java (revision 34) |
+++ ffhs/webE/action/TermAction.java (revision 33) |
@@ -40,9 +40,6 @@ |
*/ |
Map<String, Object> session = ActionContext.getContext().getSession(); |
- private final HttpServletRequest request = (HttpServletRequest) ActionContext |
- .getContext().get(StrutsStatics.HTTP_REQUEST); |
- |
/* |
* (non-Javadoc) |
* |
@@ -58,18 +55,13 @@ |
* |
* @return {@link Action#SUCCESS} |
*/ |
- public String save() |
+ public String add() |
{ |
- if (!"1".equals(this.request.getParameter("edit"))) |
- { |
- User user = this.userDAO.searchUsername((String) this.session |
- .get("username")); |
- ObjectEntity obj = new ObjectEntity(user, |
- new ObjectType(ObjectType.TERM), user, null, new Date(), false, |
- this.term, null, null); |
- this.term.setObject(obj); |
- } |
- |
+ User user = this.userDAO.searchUsername((String) this.session |
+ .get("username")); |
+ ObjectEntity obj = new ObjectEntity(user, new ObjectType(ObjectType.TERM), |
+ user, null, new Date(), false, this.term, null, null); |
+ this.term.setObject(obj); |
if (this.termDAO.saveOrUpdate(this.term)) |
{ |
return Action.SUCCESS; |
@@ -85,7 +77,7 @@ |
*/ |
public String list() |
{ |
- this.termList = this.termDAO.getTerms(); |
+ this.termList = this.termDAO.listTerm(); |
return Action.SUCCESS; |
} |
@@ -102,7 +94,6 @@ |
this.term = this.termDAO.getTermById(id); |
if (this.term != null) |
{ |
- this.term.edit = true; |
return Action.SUCCESS; |
} |
} |
@@ -117,10 +108,13 @@ |
*/ |
private int getIdParameter() |
{ |
+ HttpServletRequest request = (HttpServletRequest) ActionContext |
+ .getContext().get(StrutsStatics.HTTP_REQUEST); |
+ |
int id = -1; |
try |
{ |
- id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$ |
+ id = Integer.parseInt(request.getParameter("id")); //$NON-NLS-1$ |
} |
catch (Exception e) |
{ |
/trunk/src/ch/ffhs/webE/action/RelationshipTypeAction.java |
---|
5,126 → 5,125 |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts2.StrutsStatics; |
import org.apache.struts2.ServletActionContext; |
import ch.ffhs.webE.dao.RelationshipTypeDAO; |
import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
import ch.ffhs.webE.domain.RelationshipType; |
import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
public class RelationshipTypeAction extends ActionSupport implements |
ModelDriven<RelationshipType> |
ModelDriven<RelationshipType> |
{ |
private static final long serialVersionUID = -3644691864156792139L; |
private static final long serialVersionUID = -3644691864156792139L; |
private RelationshipType relType = new RelationshipType(); |
private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
private final RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
private RelationshipType relType = new RelationshipType(); |
private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
@Override |
public RelationshipType getModel() |
{ |
return this.relType; |
} |
@Override |
public RelationshipType getModel() |
{ |
return relType; |
} |
public String addOrUpdate() |
{ |
this.relTypeDAO.saveOrUpdateRelType(this.relType); |
return Action.SUCCESS; |
} |
public String addOrUpdate() |
{ |
relTypeDAO.saveOrUpdateRelType(relType); |
return SUCCESS; |
} |
public String list() |
{ |
this.relTypeList = this.relTypeDAO.getRelTypes(); |
return Action.SUCCESS; |
} |
public String edit() |
{ |
int id = this.getIdParameter(); |
if (id > 0) |
public String list() |
{ |
this.relType = this.relTypeDAO.getRelTypeById(id); |
return Action.SUCCESS; |
relTypeList = relTypeDAO.listRelationshipTypes(); |
return SUCCESS; |
} |
else |
public String edit() |
{ |
return Action.ERROR; |
int id = getIdParameter(); |
if (id > 0) |
{ |
relType = relTypeDAO.listRelTypeById(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
} |
/** |
* Gets the ID Parameter for update / delete requests |
* |
* @return int from the ID request. If not set or wrong, it gives back -1 |
*/ |
private int getIdParameter() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
/** |
* Gets the ID Parameter for update / delete requests |
* |
* @return int from the ID request. If not set or wrong, it gives back -1 |
*/ |
private int getIdParameter() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(StrutsStatics.HTTP_REQUEST); |
int id = -1; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
} |
catch (Exception e) |
{ |
// TODO: Logging - wrong parameter set |
} |
int id = -1; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
return id; |
} |
catch (Exception e) |
/** |
* deletes a relationshipType, gets the ID from the id parameter that was |
* submitted |
* |
* @return String - either success or error |
*/ |
public String delete() |
{ |
// TODO: Logging - wrong parameter set |
int id = getIdParameter(); |
// Check for malicious ID values |
if (id > 0) |
{ |
relTypeDAO.deleteRelationshipType(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
return id; |
} |
/* |
* Getters and setters |
*/ |
/** |
* deletes a relationshipType, gets the ID from the id parameter that was |
* submitted |
* |
* @return String - either success or error |
*/ |
public String delete() |
{ |
int id = this.getIdParameter(); |
public RelationshipType getRelType() |
{ |
return relType; |
} |
// Check for malicious ID values |
if (id > 0) |
public void setRelType(RelationshipType relType) |
{ |
this.relTypeDAO.deleteRelationshipType(id); |
return Action.SUCCESS; |
this.relType = relType; |
} |
else |
public List<RelationshipType> getRelTypeList() |
{ |
return Action.ERROR; |
return relTypeList; |
} |
} |
/* |
* Getters and setters |
*/ |
public RelationshipType getRelType() |
{ |
return this.relType; |
} |
public void setRelType(RelationshipType relType) |
{ |
this.relType = relType; |
} |
public List<RelationshipType> getRelTypeList() |
{ |
return this.relTypeList; |
} |
public void setRelTypeList(List<RelationshipType> relTypeList) |
{ |
this.relTypeList = relTypeList; |
} |
public void setRelTypeList(List<RelationshipType> relTypeList) |
{ |
this.relTypeList = relTypeList; |
} |
} |