# HG changeset patch # User Robert Casties # Date 1497620499 -7200 # Node ID 4c9ceb28cfd0a86bfde789021474da781270235d # Parent b0aebac0780aa6315e4753d0b81cce11b2fd8b55 fix some NPEs with refreshRelations diff -r b0aebac0780a -r 4c9ceb28cfd0 src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java --- a/src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java Fri Mar 03 18:59:20 2017 +0100 +++ b/src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java Fri Jun 16 15:41:39 2017 +0200 @@ -667,13 +667,16 @@ * @throws Exception */ private void refreshRelationTarget(Session session, Relation rel) throws Exception { - long targetModifOld = rel.getTargetModif(); + if(rel.getTargetId() == null){ + throw new Exception("Refreshing entity " + rel.getSourceId() + ", the system found a relation with empty target."); + } StringBuilder sb = new StringBuilder("refreshTarget of " + rel.toString() + " to "+rel.printTarget()); List entityList = this.getEntities(session, rel.getTargetId(), Node.SYS_STATUS_CURRENT_VERSION, rel.getType(), null, false); if(entityList.isEmpty()){ - throw new Exception("Saving entity " + rel.getSourceId() + ", the system found a relation without target. " + rel.toString()); + throw new Exception("Refreshing entity " + rel.getSourceId() + ", the system found a relation without target. " + rel.toString()); } Entity target = entityList.get(0); + long targetModifOld = rel.getTargetModif(); rel.setTarget(target); sb.append(" new "+rel.printTarget()); // the refresh is logged only if we detect a difference between the relation and the target entity. @@ -692,13 +695,16 @@ * @throws Exception */ private void refreshRelationSource(Session session, Relation rel) throws Exception { - long sourceModifOld = rel.getSourceModif(); + if(rel.getSourceId() == null){ + throw new Exception("Refreshing entity " + rel.getTargetId() + ", the system found a relation with emtpy source."); + } StringBuilder sb = new StringBuilder("refreshSource of " + rel.toString() + " to "+rel.printSource()); List entityList = this.getEntities(session, rel.getSourceId(), Node.SYS_STATUS_CURRENT_VERSION, rel.getType(), null, false); if(entityList.isEmpty()){ - throw new Exception("Saving entity " + rel.getTargetId() + ", the system found a relation without source. " + rel.toString()); + throw new Exception("Refreshing entity " + rel.getTargetId() + ", the system found a relation without source. " + rel.toString()); } Entity source = entityList.get(0); + long sourceModifOld = rel.getSourceModif(); rel.setSource(source); sb.append(" new "+rel.printSource()); // the refresh is logged only if we detect a difference between the relation and the source entity.