From 275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Oct 2014 17:30:41 +0200 Subject: Huge exception overhaul: Merged ClusterStorageException with PersistencyException. Replaced MembershipException with InvalidCollectionModification CORBA Exception. Made all predef steps throw more accurate exceptions when they go wrong, and let more exceptions bubble through from underneath. --- .../com/c2kernel/entity/imports/ImportItem.java | 54 +++++++++------------- 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/imports/ImportItem.java') diff --git a/src/main/java/com/c2kernel/entity/imports/ImportItem.java b/src/main/java/com/c2kernel/entity/imports/ImportItem.java index ba24289..74362d5 100644 --- a/src/main/java/com/c2kernel/entity/imports/ImportItem.java +++ b/src/main/java/com/c2kernel/entity/imports/ImportItem.java @@ -29,12 +29,13 @@ import org.custommonkey.xmlunit.XMLUnit; import com.c2kernel.collection.Aggregation; import com.c2kernel.collection.CollectionArrayList; import com.c2kernel.collection.Dependency; -import com.c2kernel.collection.MembershipException; -import com.c2kernel.common.CannotManageException; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.CannotManage; +import com.c2kernel.common.InvalidCollectionModification; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.ObjectAlreadyExists; import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.TraceableEntity; import com.c2kernel.events.Event; import com.c2kernel.events.History; @@ -44,7 +45,6 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.outcome.Outcome; import com.c2kernel.persistency.outcome.Viewpoint; import com.c2kernel.process.Gateway; @@ -90,7 +90,7 @@ public class ImportItem extends ModuleImport { if (existingItem.exists()) { try { itemPath = existingItem.getItemPath(); - } catch (ObjectNotFoundException ex) { } + } catch (ObjectNotFound ex) { } } } if (itemPath == null) itemPath = new ItemPath(); @@ -109,12 +109,12 @@ public class ImportItem extends ModuleImport { } @Override - public void create(AgentPath agentPath, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException { + public void create(AgentPath agentPath, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFound, CannotManage, ObjectAlreadyExists, InvalidCollectionModification { DomainPath domPath = new DomainPath(new DomainPath(initialPath), name); if (domPath.exists()) { ItemPath domItem = domPath.getItemPath(); if (!getItemPath().equals(domItem)) - throw new CannotManageException("Item "+domPath+" was found with the wrong itemPath ("+domPath.getItemPath()+" vs "+getItemPath()+")", ""); + throw new CannotManage("Item "+domPath+" was found with the wrong itemPath ("+domPath.getItemPath()+" vs "+getItemPath()+")"); } TraceableEntity newItem; @@ -139,32 +139,22 @@ public class ImportItem extends ModuleImport { else usedWfVer = workflowVer.intValue(); try { compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, usedWfVer); - } catch (ObjectNotFoundException ex) { - throw new CannotManageException("Could not find workflow "+workflow+"v"+usedWfVer+" for item "+domPath, ""); - } catch (InvalidDataException e) { - throw new CannotManageException("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid", ""); + } catch (ObjectNotFound ex) { + throw new CannotManage("Could not find workflow "+workflow+"v"+usedWfVer+" for item "+domPath); + } catch (InvalidData e) { + throw new CannotManage("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid"); } // create collections CollectionArrayList colls = new CollectionArrayList(); for (ImportDependency element: dependencyList) { - try { - Dependency newDep = element.create(); - colls.put(newDep); - } catch (MembershipException ex) { - Logger.error(ex); - throw new CannotManageException("A specified member is not of the correct type in "+element.name, ""); - } + Dependency newDep = element.create(); + colls.put(newDep); } for (ImportAggregation element : aggregationList) { - try { - Aggregation newAgg = element.create(); - colls.put(newAgg); - } catch (MembershipException ex) { - Logger.error(ex); - throw new CannotManageException("A specified member is not of the correct type in "+element.name, ""); - } + Aggregation newAgg = element.create(); + colls.put(newAgg); } // (re)initialise the new item with properties, workflow and collections @@ -177,7 +167,7 @@ public class ImportItem extends ModuleImport { } catch (Exception ex) { Logger.error("Error initialising new item "+name ); Logger.error(ex); - throw new CannotManageException("Problem initialising new item. See server log.", ""); + throw new CannotManage("Problem initialising new item. See server log."); } // import outcomes @@ -202,12 +192,12 @@ public class ImportItem extends ModuleImport { continue; } } - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { Logger.msg(3, "View "+thisOutcome.schema+"/"+thisOutcome.viewname+" not found in "+name+". Creating."); impView = new Viewpoint(getItemPath(), thisOutcome.schema, thisOutcome.viewname, thisOutcome.version, -1); - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { throw new ObjectCannotBeUpdated("Could not check data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name); - } catch (InvalidDataException e) { + } catch (InvalidData e) { throw new ObjectCannotBeUpdated("Could not check previous event for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name); } @@ -219,7 +209,7 @@ public class ImportItem extends ModuleImport { try { Gateway.getStorage().put(getItemPath(), newOutcome, null); Gateway.getStorage().put(getItemPath(), impView, null); - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { throw new ObjectCannotBeUpdated("Could not store data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name); } } -- cgit v1.2.3