changeset 50:5bf964077567

small cleanup.
author casties
date Fri, 28 Oct 2016 18:20:06 +0200
parents 2d669fdd0a8b
children d2833ab25c54
files src/main/java/org/mpi/openmind/repository/bo/Entity.java
diffstat 1 files changed, 31 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/repository/bo/Entity.java	Thu Oct 27 20:21:19 2016 +0200
+++ b/src/main/java/org/mpi/openmind/repository/bo/Entity.java	Fri Oct 28 18:20:06 2016 +0200
@@ -376,52 +376,44 @@
     }
     
     public void addSourceRelation(Relation srcRel) {
-    	//@TODO
-    	 /*  big problem definition:
-    	 * example TEXT is_version_of TEXT
-    	 * the relation is_version_of is saved twice in the DB
-    	 */
-    	Relation oldRel = this.containsSrcRel(srcRel);
-    	if(oldRel != null){
-    		
-    		Exception ex = new Exception(
-    				"This entity has already this (source) relation [\n" +
-					toString() + "\n" +
-					"NewRel=" + srcRel + "\n" +
-					"OldRel=" + oldRel + "]");
-    		logger.error(ex.getMessage(), ex);
-    		//logger.error(ex.getMessage());
-    		this.removeSourceRelation(srcRel.getOwnValue(), srcRel.getTargetId());
-    	}
-    	srcRel.setType(getType());
+        // @TODO
+        /*
+         * big problem definition: example TEXT is_version_of TEXT the relation
+         * is_version_of is saved twice in the DB
+         */
+        Relation oldRel = this.containsSrcRel(srcRel);
+        if (oldRel != null) {
+            logger.error("This entity has already this (source) relation [\n" + toString() + "\n"
+                    + "NewRel=" + srcRel + "\n" + "OldRel=" + oldRel + "]");
+            // remove new relation(?)
+            this.removeSourceRelation(srcRel.getOwnValue(), srcRel.getTargetId());
+        }
+        srcRel.setType(getType());
         this.sourceRelations.add(srcRel);
     }
     
     public void addTargetRelation(Relation tarRel) {
-    	Relation oldRel = this.containsTarRel(tarRel);
-    	if(oldRel != null){
-    		Exception ex = new Exception(
-    				"This entity has already this (target) relation [\n" +
-					toString() + "\n" +
-					"NewRel=" + tarRel + "\n" +
-					"OldRel=" + oldRel + "]");
-    		logger.error(ex.getMessage(), ex);
-    		//logger.error(ex.getMessage());
-    		this.removeTargetRelation(tarRel.getOwnValue(), tarRel.getSourceId());
-    	}
-    	tarRel.setType(this.getType());
+        Relation oldRel = this.containsTarRel(tarRel);
+        if (oldRel != null) {
+            logger.error("This entity has already this (target) relation [\n" + toString() + "\n" + "NewRel=" + tarRel
+                    + "\n" + "OldRel=" + oldRel + "]");
+            this.removeTargetRelation(tarRel.getOwnValue(), tarRel.getSourceId());
+        }
+        tarRel.setType(this.getType());
         this.targetRelations.add(tarRel);
-        
     }
     
-    private void testLightweightState(){
-    	try {
-        	if (this.lightweight) {
-        		throw new IllegalAccessException("This Entity is lightweight, so its relations and attributes were not loaded from the DB. " + this.toString());
-	        }
-        }catch (Exception e) {
-			logger.error(e.getMessage(), e);
-		}
+    private void testLightweightState() {
+        // FIXME: should this just be a logger call?
+        try {
+            if (this.lightweight) {
+                throw new IllegalAccessException(
+                        "This Entity is lightweight, so its relations and attributes were not loaded from the DB. "
+                                + this.toString());
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+        }
     }
 
     public List<Relation> getSourceRelations() {