diff --git a/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java index 872217bf62..ee188dc144 100644 --- a/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java @@ -250,7 +250,8 @@ public abstract class DSpaceObjectServiceImpl implements } } MetadataValue metadataValue = metadataValueService.create(context, dso, metadataField); - //Set place to list length + //Set place to list length of all metadatavalues for the given schema.element.qualifier combination. + // Subtract one to adhere to the 0 as first element rule metadataValue.setPlace( this.getMetadata(dso, metadataField.getMetadataSchema().getName(), metadataField.getElement(), metadataField.getQualifier(), Item.ANY).size() - 1); diff --git a/dspace-api/src/main/java/org/dspace/content/RelationshipServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/RelationshipServiceImpl.java index d0f1f89895..793d9151ff 100644 --- a/dspace-api/src/main/java/org/dspace/content/RelationshipServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/RelationshipServiceImpl.java @@ -82,6 +82,8 @@ public class RelationshipServiceImpl implements RelationshipService { if (isRelationshipValidToCreate(context, relationship)) { if (authorizeService.authorizeActionBoolean(context, relationship.getLeftItem(), Constants.WRITE) || authorizeService.authorizeActionBoolean(context, relationship.getRightItem(), Constants.WRITE)) { + // This order of execution should be handled in the creation (create, updateplace, update relationship) + // for a proper place allocation Relationship relationshipToReturn = relationshipDAO.create(context, relationship); updatePlaceInRelationship(context, relationshipToReturn); update(context, relationshipToReturn); @@ -100,6 +102,8 @@ public class RelationshipServiceImpl implements RelationshipService { public void updatePlaceInRelationship(Context context, Relationship relationship) throws SQLException, AuthorizeException { Item leftItem = relationship.getLeftItem(); + // Max value is used to ensure that these will get added to the back of the list and thus receive the highest + // (last) place as it's set to a -1 for creation if (relationship.getLeftPlace() == -1) { relationship.setLeftPlace(Integer.MAX_VALUE); } diff --git a/dspace-api/src/main/java/org/dspace/content/dao/RelationshipDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/RelationshipDAO.java index c309715ad2..fbd5d32980 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/RelationshipDAO.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/RelationshipDAO.java @@ -37,23 +37,23 @@ public interface RelationshipDAO extends GenericDAO { List findByItem(Context context,Item item) throws SQLException; /** - * This method returns the highest leftplace integer for all the relationships where this - * item is the leftitem so that we can set a proper leftplace attribute on the next relationship + * This method returns the next leftplace integer to use for a relationship with this item as the leftItem + * * @param context The relevant DSpace context * @param item The item to be matched on leftItem - * @return The integer for the highest leftPlace value for all the relatonship objects - * that have the given item as leftItem + * @return The next integer to be used for the leftplace of a relationship with the given item + * as a left item * @throws SQLException If something goes wrong */ int findNextLeftPlaceByLeftItem(Context context, Item item) throws SQLException; /** - * This method returns the highest rightplace integer for all the relationships where this - * item is the rightitem so that we can set a proper rightplace attribute on the next relationship + * This method returns the next rightplace integer to use for a relationship with this item as the rightItem + * * @param context The relevant DSpace context * @param item The item to be matched on rightItem - * @return The integer for the highest rightPlace value for all the relatonship objects - * that have the given item as rightItem + * @return The next integer to be used for the rightplace of a relationship with the given item + * as a right item * @throws SQLException If something goes wrong */ int findNextRightPlaceByRightItem(Context context, Item item) throws SQLException; diff --git a/dspace-api/src/main/java/org/dspace/content/service/RelationshipService.java b/dspace-api/src/main/java/org/dspace/content/service/RelationshipService.java index 83032858e5..5e4f8eb733 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/RelationshipService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/RelationshipService.java @@ -52,23 +52,23 @@ public interface RelationshipService extends DSpaceCRUDService { 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 + * This method returns the next leftplace integer to use for a relationship with this item as the leftItem + * * @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 + * @return The next integer to be used for the leftplace of a relationship with the given item + * as a left item * @throws SQLException If something goes wrong */ int findNextLeftPlaceByLeftItem(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 + * This method returns the next rightplace integer to use for a relationship with this item as the rightItem + * * @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 + * @return The next integer to be used for the rightplace of a relationship with the given item + * as a right item * @throws SQLException If something goes wrong */ int findNextRightPlaceByRightItem(Context context, Item item) throws SQLException;