Mercurial > hg > openmind
changeset 80:4c9ceb28cfd0
fix some NPEs with refreshRelations
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 16 Jun 2017 15:41:39 +0200 |
parents | b0aebac0780a |
children | 4845dff46ad9 |
files | src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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<Entity> 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<Entity> 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.