Feedback on PR-2376

This commit is contained in:
Ben Bosman
2019-04-09 15:16:17 +02:00
parent 2ed91c616c
commit a23a8821e6
11 changed files with 30 additions and 22 deletions

View File

@@ -730,17 +730,16 @@ public class MetadataImport {
} }
if (acceptableRelationshipTypes.size() > 1) { if (acceptableRelationshipTypes.size() > 1) {
System.out.println("Ambiguous relationship_types were found");
log.error("Ambiguous relationship_types were found"); log.error("Ambiguous relationship_types were found");
return; return;
} }
if (acceptableRelationshipTypes.size() == 0) { if (acceptableRelationshipTypes.size() == 0) {
System.out.println("no relationship_types were found");
log.error("no relationship_types were found"); log.error("no relationship_types were found");
return; return;
} }
buildRelationObject(c, item, value, left, acceptableRelationshipTypes); //There is exactly one
buildRelationObject(c, item, value, left, acceptableRelationshipTypes.get(0));
} }
/** /**
@@ -749,16 +748,15 @@ public class MetadataImport {
* @param item The item for which this relationship will be constructed * @param item The item for which this relationship will be constructed
* @param value The value for the relationship * @param value The value for the relationship
* @param left A boolean indicating whether the item is the leftItem or the rightItem * @param left A boolean indicating whether the item is the leftItem or the rightItem
* @param acceptableRelationshipTypes The acceptable relationship types * @param acceptedRelationshipType The acceptable relationship type
* @throws SQLException If something goes wrong * @throws SQLException If something goes wrong
* @throws AuthorizeException If something goes wrong * @throws AuthorizeException If something goes wrong
*/ */
private void buildRelationObject(Context c, Item item, String value, boolean left, private void buildRelationObject(Context c, Item item, String value, boolean left,
List<RelationshipType> acceptableRelationshipTypes) RelationshipType acceptedRelationshipType)
throws SQLException, AuthorizeException { throws SQLException, AuthorizeException {
Item leftItem = null; Item leftItem = null;
Item rightItem = null; Item rightItem = null;
RelationshipType acceptedRelationshipType = acceptableRelationshipTypes.get(0);
if (left) { if (left) {
leftItem = item; leftItem = item;
rightItem = itemService.findByIdOrLegacyId(c, value); rightItem = itemService.findByIdOrLegacyId(c, value);

View File

@@ -124,7 +124,6 @@ public class InitializeEntities {
relationshipTypeService.update(context, relationshipTypeFromDb); relationshipTypeService.update(context, relationshipTypeFromDb);
} }
} }
context.commit();
context.complete(); context.complete();
} }
@@ -187,7 +186,7 @@ public class InitializeEntities {
} }
return relationshipTypes; return relationshipTypes;
} catch (ParserConfigurationException | SAXException | IOException | SQLException e) { } catch (ParserConfigurationException | SAXException | IOException | SQLException e) {
log.error(e, e); log.error("An error occurred while parsing the XML file to relations", e);
} }
return null; return null;
} }

View File

@@ -59,7 +59,7 @@ public class EntityServiceImpl implements EntityService {
List<Relationship> fullList = this.getAllRelations(context, entity); List<Relationship> fullList = this.getAllRelations(context, entity);
List<Relationship> listToReturn = new LinkedList<>(); List<Relationship> listToReturn = new LinkedList<>();
for (Relationship relationship : fullList) { for (Relationship relationship : fullList) {
if (relationship.getLeftItem() == entity.getItem()) { if (relationship.getLeftItem().getID() == entity.getItem().getID()) {
listToReturn.add(relationship); listToReturn.add(relationship);
} }
} }
@@ -70,7 +70,7 @@ public class EntityServiceImpl implements EntityService {
List<Relationship> fullList = this.getAllRelations(context, entity); List<Relationship> fullList = this.getAllRelations(context, entity);
List<Relationship> listToReturn = new LinkedList<>(); List<Relationship> listToReturn = new LinkedList<>();
for (Relationship relationship : fullList) { for (Relationship relationship : fullList) {
if (relationship.getRightItem() == entity.getItem()) { if (relationship.getRightItem().getID() == entity.getItem().getID()) {
listToReturn.add(relationship); listToReturn.add(relationship);
} }
} }
@@ -94,8 +94,8 @@ public class EntityServiceImpl implements EntityService {
EntityType entityType = this.getType(context, entity); EntityType entityType = this.getType(context, entity);
List<RelationshipType> listToReturn = new LinkedList<>(); List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context)) { for (RelationshipType relationshipType : relationshipTypeService.findAll(context)) {
if (relationshipType.getLeftType() == entityType || if (relationshipType.getLeftType().getID() == entityType.getID() ||
relationshipType.getRightType() == entityType) { relationshipType.getRightType().getID() == entityType.getID()) {
listToReturn.add(relationshipType); listToReturn.add(relationshipType);
} }
} }
@@ -106,7 +106,7 @@ public class EntityServiceImpl implements EntityService {
EntityType entityType = this.getType(context, entity); EntityType entityType = this.getType(context, entity);
List<RelationshipType> listToReturn = new LinkedList<>(); List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context)) { for (RelationshipType relationshipType : relationshipTypeService.findAll(context)) {
if (relationshipType.getLeftType() == entityType) { if (relationshipType.getLeftType().getID() == entityType.getID()) {
listToReturn.add(relationshipType); listToReturn.add(relationshipType);
} }
} }
@@ -117,7 +117,7 @@ public class EntityServiceImpl implements EntityService {
EntityType entityType = this.getType(context, entity); EntityType entityType = this.getType(context, entity);
List<RelationshipType> listToReturn = new LinkedList<>(); List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context)) { for (RelationshipType relationshipType : relationshipTypeService.findAll(context)) {
if (relationshipType.getRightType() == entityType) { if (relationshipType.getRightType().getID() == entityType.getID()) {
listToReturn.add(relationshipType); listToReturn.add(relationshipType);
} }
} }

View File

@@ -48,7 +48,7 @@ public class RelationshipTypeServiceImpl implements RelationshipTypeService {
@Override @Override
public RelationshipType findbyTypesAndLabels(Context context,EntityType leftType,EntityType rightType, public RelationshipType findbyTypesAndLabels(Context context,EntityType leftType,EntityType rightType,
String leftLabel,String rightLabel) throws SQLException { String leftLabel,String rightLabel) throws SQLException {
return relationshipTypeDAO.findbyTypesAndLabels(context, leftType, rightType, leftLabel, rightLabel); return relationshipTypeDAO.findByTypesAndLabels(context, leftType, rightType, leftLabel, rightLabel);
} }
@Override @Override

View File

@@ -34,7 +34,7 @@ public interface RelationshipTypeDAO extends GenericDAO<RelationshipType> {
* @return The RelationshipType object that matches all the given parameters * @return The RelationshipType object that matches all the given parameters
* @throws SQLException If something goes wrong * @throws SQLException If something goes wrong
*/ */
RelationshipType findbyTypesAndLabels(Context context, RelationshipType findByTypesAndLabels(Context context,
EntityType leftType,EntityType rightType,String leftLabel,String rightLabel) EntityType leftType,EntityType rightType,String leftLabel,String rightLabel)
throws SQLException; throws SQLException;

View File

@@ -23,7 +23,7 @@ import org.dspace.core.Context;
public class RelationshipTypeDAOImpl extends AbstractHibernateDAO<RelationshipType> implements RelationshipTypeDAO { public class RelationshipTypeDAOImpl extends AbstractHibernateDAO<RelationshipType> implements RelationshipTypeDAO {
@Override @Override
public RelationshipType findbyTypesAndLabels(Context context, EntityType leftType, EntityType rightType, public RelationshipType findByTypesAndLabels(Context context, EntityType leftType, EntityType rightType,
String leftLabel, String rightLabel) String leftLabel, String rightLabel)
throws SQLException { throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context); CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);

View File

@@ -0,0 +1,13 @@
<!-- Build relationships from XML -->
<!ELEMENT relationships (type)*>
<!ELEMENT type (leftType|rightType|leftLabel|rightLabel|leftCardinality|rightCardinality)*>
<!ELEMENT leftType (#PCDATA)>
<!ELEMENT rightType (#PCDATA)>
<!ELEMENT leftLabel (#PCDATA)>
<!ELEMENT rightLabel (#PCDATA)>
<!ELEMENT leftCardinality (min|max)*>
<!ELEMENT min (#PCDATA)>
<!ELEMENT rightCardinality (min|max)*>
<!ELEMENT max (#PCDATA)>

View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE relationships SYSTEM "relationship-types.dtd">
<relationships> <relationships>
<type> <type>
<leftType>Publication</leftType> <leftType>Publication</leftType>

View File

@@ -41,8 +41,6 @@ public class RootRestResourceController {
@Autowired @Autowired
RootRestRepository rootRestRepository; RootRestRepository rootRestRepository;
private static Logger log = LogManager.getLogger();
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public RootResource listDefinedEndpoint(HttpServletRequest request) { public RootResource listDefinedEndpoint(HttpServletRequest request) {

View File

@@ -86,7 +86,7 @@ public class ItemConverter extends DSpaceObjectConverter<org.dspace.content.Item
try { try {
relationships = relationshipService.findByItem(new Context(), obj); relationships = relationshipService.findByItem(new Context(), obj);
} catch (SQLException e) { } catch (SQLException e) {
log.error(e, e); log.error("Error retrieving relationships for item " + item.getHandle(), e);
} }
List<RelationshipRest> relationshipRestList = new LinkedList<>(); List<RelationshipRest> relationshipRestList = new LinkedList<>();
for (Relationship relationship : relationships) { for (Relationship relationship : relationships) {

View File

@@ -1,2 +0,0 @@
id,collection,dc.title,relationship.type,relation.isAuthorOfPublication
636e440b-f554-4c27-9b9f-1696b18adbb2,123456789/674,Article,Publication,9cb4955a-abbd-40a0-b1aa-124e7ff83c1d||bb7053bf-7963-464a-bd70-2253d6b3cb37||77020ca8-f04e-4370-b259-d05b4939bab1
1 id collection dc.title relationship.type relation.isAuthorOfPublication
2 636e440b-f554-4c27-9b9f-1696b18adbb2 123456789/674 Article Publication 9cb4955a-abbd-40a0-b1aa-124e7ff83c1d||bb7053bf-7963-464a-bd70-2253d6b3cb37||77020ca8-f04e-4370-b259-d05b4939bab1