Added JavaDoc to public methods in new classes where necessary

This commit is contained in:
Raf Ponsaerts
2018-10-25 14:55:21 +02:00
parent 031642ddc1
commit af94859404
32 changed files with 655 additions and 5 deletions

View File

@@ -21,6 +21,10 @@ import org.dspace.content.service.RelationshipService;
import org.dspace.content.service.RelationshipTypeService;
import org.dspace.core.Context;
/**
* This script is used to populate the database with specific objects (see UUIDs) with a set of
* relationships so that various functionalities can be tested properly.
*/
public class AdditionalRelationshipScript {
private RelationshipTypeService relationshipTypeService;
@@ -35,6 +39,14 @@ public class AdditionalRelationshipScript {
itemService = ContentServiceFactory.getInstance().getItemService();
}
/**
* The main method for this script
*
* @param argv The commandline arguments given with this command, though nothing will be done with them
* @throws SQLException If something goes wrong with the database
* @throws AuthorizeException If something goes wrong with permissions
* @throws ParseException If something goes wrong with the parsing
*/
public static void main(String[] argv) throws SQLException, AuthorizeException, ParseException {
AdditionalRelationshipScript additionalRelationshipScript = new AdditionalRelationshipScript();
additionalRelationshipScript.execute();

View File

@@ -38,6 +38,11 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
* This script is used to initialize the database with a set of relationshiptypes that are written
* in an xml file that is given to this script.
* This XML file needs to have a proper XML structure and needs to define the variables of the RelationshipType object
*/
public class InitializeEntities {
private final static Logger log = Logger.getLogger(InitializeEntities.class);
@@ -53,6 +58,14 @@ public class InitializeEntities {
}
/**
* The main method for this script
*
* @param argv The commandline arguments given with this command
* @throws SQLException If something goes wrong with the database
* @throws AuthorizeException If something goes wrong with permissions
* @throws ParseException If something goes wrong with the parsing
*/
public static void main(String[] argv) throws SQLException, AuthorizeException, ParseException {
InitializeEntities initializeEntities = new InitializeEntities();
CommandLineParser parser = new PosixParser();

View File

@@ -9,28 +9,59 @@ package org.dspace.content;
import java.util.List;
/**
* This class represents an Entity object. An Entity object has an Item that it describes with a list
* of relationships that it includes as well.
*/
public class Entity {
/**
* The Item that is being described by this Entity
*/
private Item item;
/**
* The relationships for the Item that is included in this Entity
*/
private List<Relationship> relationships;
/**
* constructor for the Entity object
* @param item The Item to be included in this Entity object as a property
* @param relationshipList The list of relationships
*/
public Entity(Item item,List<Relationship> relationshipList) {
setItem(item);
setRelationships(relationshipList);
}
/**
* Standard getter for the Item for this Entity object
* @return The Item that is described in this Entity object
*/
public Item getItem() {
return item;
}
/**
* Standard setter for the Item for this Entity object
* @param item The Item to be set
*/
public void setItem(Item item) {
this.item = item;
}
/**
* Standard getter for the list of relationships for the Item in this Entity object
* @return the list of relationships
*/
public List<Relationship> getRelationships() {
return relationships;
}
/**
* Standard setter for the list of relationships for the Item in this Entity object
* @param relationships The list of relationships to be set
*/
public void setRelationships(List<Relationship> relationships) {
this.relationships = relationships;
}

View File

@@ -15,32 +15,60 @@ import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
* Class representing an EntityType
* This class contains an Integer ID that will be the unique value for this class and also the primary key
* This also has a label that will be used to identify what kind of EntityType this object is
*/
@Entity
@Table(name = "entity_type")
public class EntityType {
/**
* The Integer ID used as a primary key for this database object.
* This is generated by a sequence
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "entity_type_id_seq")
@SequenceGenerator(name = "entity_type_id_seq", sequenceName = "entity_type_id_seq", allocationSize = 1)
@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = false)
protected Integer id;
/**
* The String label field for the entity type
* This cannot be null
*/
@Column(name = "label", nullable = false)
private String label;
/**
* The standard getter for the ID of this EntityType
* @return The ID for this EntityType
*/
public Integer getId() {
return id;
}
/**
* The standard setter for the ID of this EntityType
* @param id The ID that this EntityType's ID will be set to
*/
public void setId(Integer id) {
this.id = id;
}
/**
* The standard getter for the label of this EntityType
* @return The label for this EntityType
*/
public String getLabel() {
return label;
}
/**
* The standard setter for the label of this EntityType
* @param label The label that this EntityType's label will be set to
*/
public void setLabel(String label) {
this.label = label;
}

View File

@@ -20,82 +20,162 @@ import javax.persistence.Table;
import org.dspace.core.ReloadableEntity;
/**
* This class represents a relationship
* It has a leftItem and a rightItem which are both DSpaceObjects
* that have a specified RelationshipType that links them together
* It also has a left and right place column that works just like a normal DSpace metadata place column
*/
@Entity
@Table(name = "relationship")
public class Relationship implements ReloadableEntity<Integer> {
/**
* The Integer ID field for this object
* This is automatically generated
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "relationship_id_seq")
@SequenceGenerator(name = "relationship_id_seq", sequenceName = "relationship_id_seq", allocationSize = 1)
@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = false)
protected Integer id;
/**
* The leftItem property for the Relationship object.
* This leftItem is a DSpaceObject and is stored as an ID
*/
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "left_id", nullable = false)
private Item leftItem;
/**
* The relationshipType property for this Relationship object
* This is stored as an ID in the database
*/
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "type_id", nullable = false)
private RelationshipType relationshipType;
/**
* The rightItem property for the Relationship object.
* This rightItem is a DSpaceObject and is stored as an ID
*/
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "right_id", nullable = false)
private Item rightItem;
/**
* An Integer to describe the left place for this relationship
*/
@Column(name = "left_place")
private int leftPlace;
/**
* An Integer to describe the right place for this relationship
*/
@Column(name = "right_place")
private int rightPlace;
/**
* Standard getter for the ID field
* @return the ID
*/
public Integer getId() {
return id;
}
/**
* Standard setter for the ID field
* @param id The ID to be set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Standard getter for the leftItem field
* @return The leftItem Item object in this relationship
*/
public Item getLeftItem() {
return leftItem;
}
/**
* Standard setter for the leftItem field
* @param leftItem The leftItem Item object that the leftItem field should be set to
*/
public void setLeftItem(Item leftItem) {
this.leftItem = leftItem;
}
/**
* Standard getter for the relationshipType field
* @return The relationshipType RelationshipType object in this relationship
*/
public RelationshipType getRelationshipType() {
return relationshipType;
}
/**
* Standard setter for the relationshipType field for the Relationship
* @param relationshipType The relationshipType that will be set in this Relationship
*/
public void setRelationshipType(RelationshipType relationshipType) {
this.relationshipType = relationshipType;
}
/**
* Standard getter for the rightItem Item object in this Relationship
* @return the rightItem Item object
*/
public Item getRightItem() {
return rightItem;
}
/**
* Standard setter for the rightItem Item object in this Relationship
* @param rightItem The rightItem Item object that will be used in this relationship
*/
public void setRightItem(Item rightItem) {
this.rightItem = rightItem;
}
/**
* Standard getter for the leftPlace Integer in this Relationship
* @return The leftPlace integer for this relationship
*/
public int getLeftPlace() {
return leftPlace;
}
/**
* Standard setter for the leftPlace Integer in this Relationship
* @param leftPlace the leftPlace Integer that will be used in this relationship
*/
public void setLeftPlace(int leftPlace) {
this.leftPlace = leftPlace;
}
/**
* Standard getter for the rightPlace Integer in this Relationship
* @return the rightPlace integer for this relationship
*/
public int getRightPlace() {
return rightPlace;
}
/**
* Standard setter for the rightPlace Integer in this Relationship
* @param rightPlace the rightPlace Integer that will be used in this relationship
*/
public void setRightPlace(int rightPlace) {
this.rightPlace = rightPlace;
}
/**
* Standard getter for the ID for this Relationship
* @return The ID of this relationship
*/
public Integer getID() {
return id;
}

View File

@@ -19,112 +19,226 @@ import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
* Class representing a RelationshipType
* This class contains an Integer ID that will be the unique value and primary key in the database.
* This key is automatically generated
* It also has a leftType and rightType EntityType that describes the relationshipType together with a leftLabel and
* rightLabel.
* The cardinality properties describe how many of each relations this relationshipType can support
*/
@Entity
@Table(name = "relationship_type")
public class RelationshipType {
/**
* The Integer ID used as a primary key for this database object.
* This is generated by a sequence
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "relationship_type_id_seq")
@SequenceGenerator(name = "relationship_type_id_seq", sequenceName = "relationship_type_id_seq", allocationSize = 1)
@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = false)
protected Integer id;
/**
* The leftType EntityType field for the relationshipType
* This is stored as an ID and cannot be null
*/
@ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
@JoinColumn(name = "left_type", nullable = false)
private EntityType leftType;
/**
* The rightType EntityType field for the relationshipType
* This is stored as an ID and cannot be null
*/
@ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
@JoinColumn(name = "right_type", nullable = false)
private EntityType rightType;
/**
* The leftLabel String field for the relationshipType
* This is stored as a String and cannot be null
* This is a textual representation of the name of the relationship that this RelationshipType is connected to
*/
@Column(name = "left_label", nullable = false)
private String leftLabel;
/**
* The rightLabel String field for the relationshipType
* This is stored as a String and cannot be null
* This is a textual representation of the name of the relationship that this RelationshipType is connected to
*/
@Column(name = "right_label", nullable = false)
private String rightLabel;
/**
* The minimum amount of relations for the leftItem that need to be present at all times
* This is stored as an Integer
*/
@Column(name = "left_min_cardinality")
private int leftMinCardinality;
/**
* The maximum amount of relations for the leftItem that can to be present at all times
* This is stored as an Integer
*/
@Column(name = "left_max_cardinality")
private int leftMaxCardinality;
/**
* The minimum amount of relations for the rightItem that need to be present at all times
*/
@Column(name = "right_min_cardinality")
private int rightMinCardinality;
/**
* Tha maximum amount of relations for the rightItem that can be present at all times
*/
@Column(name = "right_max_cardinality")
private int rightMaxCardinality;
/**
* Standard getter for the ID of this RelationshipType
* @return The ID of this RelationshipType
*/
public Integer getId() {
return id;
}
/**
* Standard getter for the ID of this RelationshipType
* @param id The ID that this RelationshipType should receive
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Standard getter for The leftType EntityType for this RelationshipType
* @return The leftType EntityType of this RelationshipType
*/
public EntityType getLeftType() {
return leftType;
}
/**
* Standard setter for the leftType EntityType for this RelationshipType
* @param leftType The leftType EntityType that this RelationshipType should receive
*/
public void setLeftType(EntityType leftType) {
this.leftType = leftType;
}
/**
* Standard getter for The rightType EntityType for this RelationshipType
* @return The rightType EntityType of this RelationshipType
*/
public EntityType getRightType() {
return rightType;
}
/**
* Standard setter for the rightType EntityType for this RelationshipType
* @param rightType The rightType EntityType that this RelationshipType should receive
*/
public void setRightType(EntityType rightType) {
this.rightType = rightType;
}
/**
* Standard getter for the leftLabel String for this RelationshipType
* @return The leftLabel String of this RelationshipType
*/
public String getLeftLabel() {
return leftLabel;
}
/**
* Standard setter for the leftLabel String for this RelationshipType
* @param leftLabel The leftLabel String that this RelationshipType should receive
*/
public void setLeftLabel(String leftLabel) {
this.leftLabel = leftLabel;
}
/**
* Standard getter for the rightLabel String for this RelationshipType
* @return The rightLabel String of this RelationshipType
*/
public String getRightLabel() {
return rightLabel;
}
/**
* Standard setter for the rightLabel String for this RelationshipType
* @param rightLabel The rightLabel String that this RelationshipType should receive
*/
public void setRightLabel(String rightLabel) {
this.rightLabel = rightLabel;
}
/**
* Standard getter for the leftMinCardinality Integer for this RelationshipType
* @return the leftMinCardinality Integer of this RelationshipType
*/
public int getLeftMinCardinality() {
return leftMinCardinality;
}
/**
* Standard setter for the leftMinCardinality Integer for this RelationshipType
* @param leftMinCardinality The leftMinCardinality Integer that this RelationshipType should recieve
*/
public void setLeftMinCardinality(int leftMinCardinality) {
this.leftMinCardinality = leftMinCardinality;
}
/**
* Standard getter for the leftMaxCardinality Integer for this RelationshipType
* @return the leftMaxCardinality Integer of this RelationshipType
*/
public int getLeftMaxCardinality() {
return leftMaxCardinality;
}
/**
* Standard setter for the leftMaxCardinality Integer for this RelationshipType
* @param leftMaxCardinality The leftMaxCardinality Integer that this RelationshipType should recieve
*/
public void setLeftMaxCardinality(int leftMaxCardinality) {
this.leftMaxCardinality = leftMaxCardinality;
}
/**
* Standard getter for the rightMinCardinality Integer for this RelationshipType
* @return the rightMinCardinality Integer of this RelationshipType
*/
public int getRightMinCardinality() {
return rightMinCardinality;
}
/**
* Standard setter for the rightMinCardinality Integer for this RelationshipType
* @param rightMinCardinality The rightMinCardinality Integer that this RelationshipType should recieve
*/
public void setRightMinCardinality(int rightMinCardinality) {
this.rightMinCardinality = rightMinCardinality;
}
/**
* Standard getter for the rightMaxCardinality Integer for this RelationshipType
* @return the rightMaxCardinality Integer of this RelationshipType
*/
public int getRightMaxCardinality() {
return rightMaxCardinality;
}
/**
* Standard setter for the rightMaxCardinality Integer for this RelationshipType
* @param rightMaxCardinality The rightMaxCardinality Integer that this RelationshipType should recieve
*/
public void setRightMaxCardinality(int rightMaxCardinality) {
this.rightMaxCardinality = rightMaxCardinality;
}

View File

@@ -13,6 +13,12 @@ import org.dspace.content.EntityType;
import org.dspace.core.Context;
import org.dspace.core.GenericDAO;
/**
* Database Access Object Interface class for the EntityType object
* The implementation of this class is responsible for all database calls for the EntityType object and is autowired by
* spring
* This class should only be accessed from a single service and should never be exposed outside of the API
*/
public interface EntityTypeDAO extends GenericDAO<EntityType> {
public EntityType findByEntityType(Context context, String entityType) throws SQLException;

View File

@@ -15,6 +15,12 @@ import org.dspace.content.Relationship;
import org.dspace.core.Context;
import org.dspace.core.GenericDAO;
/**
* Database Access Object Interface class for the Relationship object
* The implementation of this class is responsible for all
* database calls for the Relationship object and is autowired by spring
* This class should only be accessed from a single service and should never be exposed outside of the API
*/
public interface RelationshipDAO extends GenericDAO<Relationship> {
List<Relationship> findByItem(Context context,Item item) throws SQLException;

View File

@@ -14,6 +14,12 @@ import org.dspace.content.RelationshipType;
import org.dspace.core.Context;
import org.dspace.core.GenericDAO;
/**
* Database Access Object Interface class for the RelationshipType object
* The implementation of this class is responsible for all
* database calls for the RelationshipType object and is autowired by spring
* This class should only be accessed from a single service and should never be exposed outside of the API
*/
public interface RelationshipTypeDAO extends GenericDAO<RelationshipType> {
RelationshipType findbyTypesAndLabels(Context context,

View File

@@ -17,17 +17,119 @@ import org.dspace.content.Relationship;
import org.dspace.content.RelationshipType;
import org.dspace.core.Context;
/**
* This Service provides us with a few methods to return objects based on the Entity object.
* Since the Entity object isn't a database object, this method mostly outsources to getters for other services
* to return the wanted objects to then check for properties on either the list of relationships or the item included
* in the Entity.
*/
public interface EntityService {
/**
* This will construct an Entity object that will be returned with the Item that matches the ItemID that was
* passed along
* as well as a list of relationships for that Item.
* @param context The relevant DSpace context
* @param itemId The ItemID for the Item that is to be used in the Entity object
* @return The constructed Entity object with the Item and the list of relationships
* @throws SQLException If something goes wrong
*/
Entity findByItemId(Context context, UUID itemId) throws SQLException;
/**
* Returns the EntityType for the Item that is attached to the Entity that is passed along to this method.
* The EntityType String logic is in the Metadata for that Item and will be searched on in the EntityTypeService
* to retrieve the actual EntityType object
* @param context The relevant DSpace context
* @param entity The Entity object which contains the Item
* @return The EntityType that belongs to this Item
* @throws SQLException If something goes wrong
*/
EntityType getType(Context context, Entity entity) throws SQLException;
/**
* Returns the list of relations for the given Entity object
* @param context The relevant DSpace context
* @param entity The Entity object for which the list of relationships will be returned
* @return The list of relationships for the given Entity object
*/
List<Relationship> getAllRelations(Context context, Entity entity);
/**
* Retrieves the list of relationships, which are attached to the Entity object that is passed along, where the
* left item object of each relationship is equal to the Item object of the Entity object that is passed along
* @param context The relevant DSpace context
* @param entity The Entity object to be returned
* @return The list of relationships that have the Item in the Entity object as their left item
*/
List<Relationship> getLeftRelations(Context context, Entity entity);
/**
* Retrieves the list of relationships, which are attached to the Entity object that is passed along, where the
* right item object of each relationship is equal to the Item object of the Entity object that is passed along
* @param context The relevant DSpace context
* @param entity The Entity object to be returned
* @return The list of relationships that have the Item in the Entity object as their right item
*/
List<Relationship> getRightRelations(Context context, Entity entity);
/**
* Retrieves the list of relationships for which their relationshiptype has a left or right label that is
* equal to the passed along label String
* @param context The relevant DSpace context
* @param label The label that needs to be in the relationshiptype of the relationship
* @return The list of relationships that have a relationshiptype with a left or right label
* that is equal to the label param
* @throws SQLException If something goes wrong
*/
List<Relationship> getRelationsByLabel(Context context, String label) throws SQLException;
/**
* Retrieves the list of relationships that have a relationshiptype that contains the EntityType for the given
* Entity
* in either the leftEntityType or the rightEntityType variables
* @param context The relevant DSpace context
* @param entity The Entity for which the EntityType should be checked for relationships
* @return The list of relationships that each contain a relationshiptype in which there is a right or left
* entity type that
* is equal to the entity type for the given entity
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getAllRelationshipTypes(Context context, Entity entity) throws SQLException;
/**
* Retrieves the list of relationships that have a relationshiptype that contains the EntityType for the given
* Entity
* in the leftEntityType
* @param context The relevant DSpace context
* @param entity The Entity for which the EntityType should be checked for relationships
* @return The list of relationships that each contain a relationshiptype in which there is a left entity type that
* is equal to the entity type for the given entity
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getLeftRelationshipTypes(Context context, Entity entity) throws SQLException;
/**
* Retrieves the list of relationships that have a relationshiptype that contains the EntityType for the given
* Entity
* in the rightEntityType
* @param context The relevant DSpace context
* @param entity The Entity for which the EntityType should be checked for relationships
* @return The list of relationships that each contain a relationshiptype in which there is a right entity type that
* is equal to the entity type for the given entity
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getRightRelationshipTypes(Context context, Entity entity) throws SQLException;
/**
* Retrieves a list of RelationshipType objects for which either their left or right label is equal to the
* label parameter that's being passed along
* @param context The relevant DSpace context
* @param label The label for which the relationshiptype's labels must be checked
* @return The list of relationshiptypes that each contain a left or right label that is equal
* to the given label parameter
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getRelationshipTypesByLabel(Context context, String label) throws SQLException;
}

View File

@@ -15,11 +15,35 @@ import org.dspace.content.EntityType;
import org.dspace.core.Context;
import org.dspace.service.DSpaceCRUDService;
/**
* This Service is used to access the data for EntityTypes through the DAO objects
*/
public interface EntityTypeService extends DSpaceCRUDService<EntityType> {
/**
* Retrieves the EntityType that has the entityType String parameter as label
* @param context The relevant DSpace context
* @param entityType The String label that has to match
* @return The EntityType that has a String
* @throws SQLException If something goes wrong
*/
public EntityType findByEntityType(Context context,String entityType) throws SQLException;
/**
* Retrieves all the EntityType objects currently in the system
* @param context The relevant DSpace context
* @return A list of all EntityType objects
* @throws SQLException If something goes wrong
*/
public List<EntityType> findAll(Context context) throws SQLException;
/**
* This method creates an EntityType object in the database with the given entityTypeString as it's label
* @param context The relevant DSpace context
* @param entityTypeString The label for the newly created EntityType
* @return The newly created EntityType
* @throws SQLException If something goes wrong
* @throws AuthorizeException If something geos wrong with authorizations
*/
public EntityType create(Context context, String entityTypeString) throws SQLException, AuthorizeException;
}

View File

@@ -16,14 +16,59 @@ import org.dspace.content.Relationship;
import org.dspace.core.Context;
import org.dspace.service.DSpaceCRUDService;
/**
* This Service will use the DAO classes to access the information about Relationships from the database
*/
public interface RelationshipService extends DSpaceCRUDService<Relationship> {
/**
* Retrieves the list of Relationships currently in the system for which the given Item is either
* a leftItem or a rightItem object
* @param context The relevant DSpace context
* @param item The Item that has to be the left or right item for the relationship to be included in the list
* @return The list of relationships for which each relationship adheres to the above listed constraint
* @throws SQLException If something goes wrong
*/
public List<Relationship> findByItem(Context context,Item item) throws SQLException;
/**
* Retrieves the full list of relationships currently in the system
* @param context The relevant DSpace context
* @return The list of all relationships currently in the system
* @throws SQLException If something goes wrong
*/
public List<Relationship> findAll(Context context) throws SQLException;
/**
* This method creates a relationship object in the database equal to the given relationship param
* if this is a valid relationship
* @param context The relevant DSpace context
* @param relationship The relationship that will be created in the database if it is valid
* @return The created relationship with updated place variables
* @throws SQLException If something goes wrong
* @throws AuthorizeException If something goes wrong with authorizations
*/
public Relationship create(Context context, Relationship relationship) throws SQLException, AuthorizeException;
/**
* Retrieves the highest integer value for the leftplace property of a Relationship for all relationships
* that have the given item as a left item
* @param context The relevant DSpace context
* @param item The item that has to be the leftItem of a relationship for it to qualify
* @return The integer value of the highest left place property of all relationships
* that have the given item as a leftitem property
* @throws SQLException If something goes wrong
*/
int findLeftPlaceByLeftItem(Context context, Item item) throws SQLException;
/**
* Retrieves the highest integer value for the rightplace property of a Relationship for all relationships
* that have the given item as a right item
* @param context The relevant DSpace context
* @param item The item that has to be the rightitem of a relationship for it to qualify
* @return The integer value of the highest right place property of all relationships
* that have the given item as a rightitem property
* @throws SQLException If something goes wrong
*/
int findRightPlaceByRightItem(Context context, Item item) throws SQLException;
}

View File

@@ -16,12 +16,40 @@ import org.dspace.content.RelationshipType;
import org.dspace.core.Context;
import org.dspace.service.DSpaceCRUDService;
/**
* This Service uses DAOs to access information on the database objects for the RelationshipTypes
*/
public interface RelationshipTypeService extends DSpaceCRUDService<RelationshipType> {
/**
* This method creates the given RelationshipType object in the database and returns it
* @param context The relevant DSpace context
* @param relationshipType The RelationshipType to be created in the database
* @return The newly created RelationshipType
* @throws SQLException If something goes wrong
* @throws AuthorizeException If something goes wrong with authorizations
*/
RelationshipType create(Context context,RelationshipType relationshipType) throws SQLException, AuthorizeException;
/**
* Retrieves a RelationshipType for which the given parameters all match the one in the returned RelationshipType
* @param context The relevant DSpace context
* @param leftType The rightType EntityType that needs to match for the returned RelationshipType
* @param rightType The rightType EntityType that needs to match for the returned RelationshipType
* @param leftLabel The leftLabel String that needs to match for the returned RelationshipType
* @param rightLabel The rightLabel String that needs to match for the returned RelationshipType
* @return
* @throws SQLException If something goes wrong
*/
RelationshipType findbyTypesAndLabels(Context context,EntityType leftType,EntityType rightType,
String leftLabel,String rightLabel)
throws SQLException;
/**
* Retrieves all RelationshipType objects currently in the system
* @param context The relevant DSpace context
* @return The list of all RelationshipType objects currently in the system
* @throws SQLException If something goes wrong
*/
List<RelationshipType> findAll(Context context) throws SQLException;
}

View File

@@ -9,22 +9,49 @@ package org.dspace.content.virtual;
import java.util.Map;
/**
* This service offers a way to convert EntityType String labels to a filter query which is defined in the
* bean config for this service
*/
public class EntityTypeToFilterQueryService {
/**
* This map contains the mapping between the String label and the String for the filter query
* e.g. <entry key="Person" value="f.entityType=Person,equals"/>
*/
private Map<String, String> map;
/**
* Standard setter for this map
* @param map The map that should be set in this service
*/
public void setMap(Map map) {
this.map = map;
}
/**
* Standard getter for the map
* @return the map
*/
public Map getMap() {
return map;
}
/**
* Retrieves the filterQuery for the key that's given as a parameter. It looks in the map for the value
* @param key The key for which we'll find the value in the map
* @return The filter query representation for the given key
*/
public String getFilterQueryForKey(String key) {
return map.get(key);
}
/**
* Returns a boolean depending on whether a key is present in the map or not
* @param key The key to be checked for
* @return The boolean indicating whether this key is present in the map or not
*/
public boolean hasKey(String key) {
return map.containsKey(key);
}

View File

@@ -9,14 +9,30 @@ package org.dspace.content.virtual;
import java.util.Map;
/**
* This class is responsible for holding the representation of how a certain relationshipType label has to be
* translated to the virtual metadata added onto the items that belong to the relationships that these
* relationshipTypes belong to
*/
public class VirtualMetadataPopulator {
/**
* The map that holds this representation
*/
private Map map;
/**
* Standard setter for the map
* @param map The map to be used in the VirtualMetadataPopulator
*/
public void setMap(Map map) {
this.map = map;
}
/**
* Standard getter for the map
* @return The map that is used in the VirtualMetadataPopulator
*/
public Map getMap() {
return map;
}

View File

@@ -11,9 +11,19 @@ import org.dspace.app.rest.model.EntityTypeRest;
import org.dspace.content.EntityType;
import org.springframework.stereotype.Component;
/**
* This converter is responsible for transforming the model representation of an EntityType to the REST
* representation of an EntityType and vice versa
*/
@Component
public class EntityTypeConverter extends DSpaceConverter<org.dspace.content.EntityType, EntityTypeRest> {
/**
* This method converts the EntityType model object that is passed along in the params to the
* REST representation of this object
* @param obj The EntityType model object to be converted
* @return The EntityType REST object that is made from the model object
*/
public EntityTypeRest fromModel(EntityType obj) {
EntityTypeRest entityTypeRest = new EntityTypeRest();
entityTypeRest.setId(obj.getId());
@@ -21,6 +31,12 @@ public class EntityTypeConverter extends DSpaceConverter<org.dspace.content.Enti
return entityTypeRest;
}
/**
* This method converts the EntityType REST object that is passed along in the params to the model
* representation of this object
* @param obj The EntityType REST object to be converted
* @return The EntityType model object that is made from the REST object
*/
public EntityType toModel(EntityTypeRest obj) {
EntityType entityType = new EntityType();
entityType.setId(obj.getId());

View File

@@ -13,12 +13,23 @@ import org.dspace.content.virtual.EntityTypeToFilterQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* This converter takes an EntityType and converts it to a FilteredDiscoveryPageRest object to give a
* representation about the filter query that has to be used for the given EntityType
*/
@Component
public class FilteredDiscoveryPageConverter extends DSpaceConverter<org.dspace.content.EntityType,
FilteredDiscoveryPageRest> {
@Autowired
private EntityTypeToFilterQueryService entityTypeToFilterQueryService;
/**
* This method converts the EntityType object to a FilteredDiscoveryPageRest object to be passed along
* to the resource and endpoint so that callers can know what filter query they need to use to
* filter on a particular, given, EntityType
* @param obj The EntityType for which this filterQuery string will be looked up for
* @return The filterQuery String for the given EntityType
*/
public FilteredDiscoveryPageRest fromModel(EntityType obj) {
FilteredDiscoveryPageRest filteredDiscoveryPageRest = new FilteredDiscoveryPageRest();
filteredDiscoveryPageRest.setId(obj.getLabel());

View File

@@ -17,6 +17,10 @@ import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* This converter is responsible for transforming the model representation of an Relationship to the REST
* representation of an Relationship and vice versa
*/
@Component
public class RelationshipConverter extends DSpaceConverter<Relationship, RelationshipRest> {
@@ -29,6 +33,12 @@ public class RelationshipConverter extends DSpaceConverter<Relationship, Relatio
private RelationshipTypeConverter relationshipTypeConverter;
/**
* This method converts the Relationship model object that is passed along in the params to the
* REST representation of this object
* @param obj The Relationship model object to be converted
* @return The Relationship REST object that is made from the model object
*/
public RelationshipRest fromModel(Relationship obj) {
RelationshipRest relationshipRest = new RelationshipRest();
relationshipRest.setId(obj.getId());
@@ -40,6 +50,12 @@ public class RelationshipConverter extends DSpaceConverter<Relationship, Relatio
return relationshipRest;
}
/**
* This method converts the Relationship REST object that is passed along in the params to the model
* representation of this object
* @param obj The Relationship REST object to be converted
* @return The Relationship model object that is made from the REST object
*/
public Relationship toModel(RelationshipRest obj) {
Relationship relationship = new Relationship();
try {

View File

@@ -12,12 +12,22 @@ import org.dspace.content.RelationshipType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* This converter is responsible for transforming the model representation of an RelationshipType to the REST
* representation of an RelationshipType and vice versa
*/
@Component
public class RelationshipTypeConverter extends DSpaceConverter<RelationshipType, RelationshipTypeRest> {
@Autowired
private EntityTypeConverter entityTypeConverter;
/**
* This method converts the RelationshipType model object that is passed along in the params to the
* REST representation of this object
* @param obj The RelationshipType model object to be converted
* @return The RelationshipType REST object that is made from the model object
*/
public RelationshipTypeRest fromModel(RelationshipType obj) {
RelationshipTypeRest relationshipTypeRest = new RelationshipTypeRest();
@@ -34,6 +44,12 @@ public class RelationshipTypeConverter extends DSpaceConverter<RelationshipType,
return relationshipTypeRest;
}
/**
* This method converts the RelationshipType REST object that is passed along in the params to the model
* representation of this object
* @param obj The RelationshipType REST object to be converted
* @return The RelationshipType model object that is made from the REST object
*/
public RelationshipType toModel(RelationshipTypeRest obj) {
RelationshipType relationshipType = new RelationshipType();

View File

@@ -9,6 +9,11 @@ package org.dspace.app.rest.model;
import org.dspace.app.rest.RestResourceController;
/**
* This class is the REST representation of the EntityType model object and acts as a data object
* for the EntityTypeResource class.
* Refer to {@link org.dspace.content.EntityType} for explanation of the properties
*/
public class EntityTypeRest extends BaseObjectRest<Integer> {
public static final String NAME = "entitytype";

View File

@@ -10,6 +10,10 @@ package org.dspace.app.rest.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dspace.app.rest.RestResourceController;
/**
* This class acts as the REST representation of the converted EntityType objects to this logic. This class acts
* as a data holder for the FilteredDiscoveryPageResource
*/
public class FilteredDiscoveryPageRest extends BaseObjectRest<String> {
public static final String NAME = "filtered-discovery-page";
@@ -27,8 +31,14 @@ public class FilteredDiscoveryPageRest extends BaseObjectRest<String> {
return NAME;
}
/**
* The label of the filter
*/
@JsonProperty(value = "filter-name")
private String label;
/**
* The filterQuery string that can be used to filter on the label
*/
@JsonProperty(value = "discovery-query")
private String filterQueryString;

View File

@@ -12,6 +12,11 @@ import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.app.rest.RestResourceController;
/**
* This class acts as the REST representation of the Relationship model class.
* This class acts as a data holder for the RelationshipResource
* Refer to {@link org.dspace.content.Relationship} for explanation about the properties
*/
public class RelationshipRest extends BaseObjectRest<Integer> {
public static final String NAME = "relationship";
public static final String CATEGORY = "core";

View File

@@ -10,6 +10,11 @@ package org.dspace.app.rest.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.app.rest.RestResourceController;
/**
* This class is the REST representation of the RelationshipType model class.
* This class acts as a data holder for the RelationshipTypeResource class
* Refer to {@link org.dspace.content.RelationshipType} for an explanation of the properties
*/
public class RelationshipTypeRest extends BaseObjectRest<Integer> {
public static final String NAME = "relationshiptype";

View File

@@ -11,6 +11,10 @@ import org.dspace.app.rest.model.EntityTypeRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**
* EntityType HAL Resource. This resource adds the data from the REST object together with embedded objects
* and a set of links if applicable
*/
@RelNameDSpaceResource(EntityTypeRest.NAME)
public class EntityTypeResource extends DSpaceResource<EntityTypeRest> {
public EntityTypeResource(EntityTypeRest data, Utils utils, String... rels) {

View File

@@ -11,6 +11,10 @@ import org.dspace.app.rest.model.FilteredDiscoveryPageRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**
* FilteredDiscoveryPage HAL Resource. This resource adds the data from the REST object together with embedded objects
* and a set of links if applicable
*/
@RelNameDSpaceResource(FilteredDiscoveryPageRest.NAME)
public class FilteredDiscoveryPageResource extends DSpaceResource<FilteredDiscoveryPageRest> {
public FilteredDiscoveryPageResource(FilteredDiscoveryPageRest data, Utils utils,

View File

@@ -11,6 +11,10 @@ import org.dspace.app.rest.model.RelationshipRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**
* Relationship HAL Resource. This resource adds the data from the REST object together with embedded objects
* and a set of links if applicable
*/
@RelNameDSpaceResource(RelationshipRest.NAME)
public class RelationshipResource extends DSpaceResource<RelationshipRest> {
public RelationshipResource(RelationshipRest data, Utils utils, String... rels) {

View File

@@ -11,6 +11,10 @@ import org.dspace.app.rest.model.RelationshipTypeRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**
* RelationshipType HAL Resource. This resource adds the data from the REST object together with embedded objects
* and a set of links if applicable
*/
@RelNameDSpaceResource(RelationshipTypeRest.NAME)
public class RelationshipTypeResource extends DSpaceResource<RelationshipTypeRest> {
public RelationshipTypeResource(RelationshipTypeRest data, Utils utils, String... rels) {

View File

@@ -22,6 +22,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
/**
* This is the repository that is responsible to manage EntityType Rest objects
*/
@Component(EntityTypeRest.CATEGORY + "." + EntityTypeRest.NAME)
public class EntityTypeRestRepository extends DSpaceRestRepository<EntityTypeRest, Integer> {

View File

@@ -24,6 +24,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
/**
* This is the repository that is responsible to manage FilteredDiscoveryPage Rest objects
*/
@Component(FilteredDiscoveryPageRest.CATEGORY + "." + FilteredDiscoveryPageRest.NAME)
public class FilteredDiscoveryPageRestRepository extends DSpaceRestRepository<FilteredDiscoveryPageRest, String> {

View File

@@ -22,6 +22,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
/**
* This is the repository that is responsible to manage Relationship Rest objects
*/
@Component(RelationshipRest.CATEGORY + "." + RelationshipRest.NAME)
public class RelationshipRestRepository extends DSpaceRestRepository<RelationshipRest, Integer> {

View File

@@ -22,6 +22,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
/**
* This is the repository that is responsible to manage RelationshipType Rest objects
*/
@Component(RelationshipTypeRest.CATEGORY + "." + RelationshipTypeRest.NAME)
public class RelationshipTypeRestRepository extends DSpaceRestRepository<RelationshipTypeRest, Integer> {

View File

@@ -168,7 +168,7 @@ public class DiscoverQueryBuilderTest {
Arrays.asList(searchFilter), "item", page);
assertThat(discoverQuery.getFilterQueries(), containsInAnyOrder("archived:true", "subject:\"Java\""));
assertThat(discoverQuery.getQuery(), is("\"" + query + "\""));
assertThat(discoverQuery.getQuery(), is(query));
assertThat(discoverQuery.getDSpaceObjectFilter(), is(Constants.ITEM));
assertThat(discoverQuery.getSortField(), is("dc.title_sort"));
assertThat(discoverQuery.getSortOrder(), is(DiscoverQuery.SORT_ORDER.asc));
@@ -293,7 +293,7 @@ public class DiscoverQueryBuilderTest {
"subject");
assertThat(discoverQuery.getFilterQueries(), containsInAnyOrder("archived:true", "subject:\"Java\""));
assertThat(discoverQuery.getQuery(), is("\"" + query + "\""));
assertThat(discoverQuery.getQuery(), is(query));
assertThat(discoverQuery.getDSpaceObjectFilter(), is(Constants.ITEM));
assertThat(discoverQuery.getSortField(), isEmptyOrNullString());
assertThat(discoverQuery.getMaxResults(), is(0));