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. --- .../instance/predefined/AddMemberToCollection.java | 48 +++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java index cbe812e..43316b2 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java @@ -24,14 +24,15 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays; import com.c2kernel.collection.Dependency; -import com.c2kernel.collection.MembershipException; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.InvalidCollectionModification; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.ObjectAlreadyExists; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.process.Gateway; import com.c2kernel.utils.CastorHashMap; import com.c2kernel.utils.Logger; @@ -58,10 +59,14 @@ public class AddMemberToCollection extends PredefinedStep * Params: * 0 - collection name * 1 - target entity key + * @throws ObjectAlreadyExists + * @throws PersistencyException + * @throws ObjectNotFound + * @throws InvalidCollectionModification */ @Override protected String runActivityLogic(AgentPath agent, ItemPath item, - int transitionID, String requestData) throws InvalidDataException { + int transitionID, String requestData) throws InvalidData, ObjectAlreadyExists, PersistencyException, ObjectNotFound, InvalidCollectionModification { String collName; ItemPath newChild; @@ -78,37 +83,22 @@ public class AddMemberToCollection extends PredefinedStep props = (CastorHashMap)Gateway.getMarshaller().unmarshall(params[2]); } catch (Exception e) { - throw new InvalidDataException("AddMemberToCollection: Invalid parameters "+Arrays.toString(params), ""); + throw new InvalidData("AddMemberToCollection: Invalid parameters "+Arrays.toString(params)); } // load collection C2KLocalObject collObj; - try { - collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); - } catch (ObjectNotFoundException ex) { - throw new InvalidDataException("AddMemberToCollection: Collection '"+collName+"' not found in this Item", ""); - } catch (ClusterStorageException ex) { - Logger.error(ex); - throw new InvalidDataException("AddMemberToCollection: Error loading collection '\"+collName+\"': "+ex.getMessage(), ""); - } - if (!(collObj instanceof Dependency)) throw new InvalidDataException("AddMemberToCollection: AddMemberToCollection operates on Dependency collections only.", ""); + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + if (!(collObj instanceof Dependency)) throw new InvalidData("AddMemberToCollection: AddMemberToCollection operates on Dependency collections only."); dep = (Dependency)collObj; - + // find member and assign entity - try { - if (props == null) - dep.addMember(newChild); - else - dep.addMember(newChild, props, null); - } catch (MembershipException e) { - throw new InvalidDataException("AddMemberToCollection: Item "+newChild+" is the wrong type for this collection", ""); - } + if (props == null) + dep.addMember(newChild); + else + dep.addMember(newChild, props, null); - try { - Gateway.getStorage().put(newChild, dep, null); - } catch (ClusterStorageException e) { - throw unknownException(e); - } + Gateway.getStorage().put(newChild, dep, null); return requestData; } } -- cgit v1.2.3