summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-10-03 17:30:41 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-10-03 17:30:41 +0200
commit275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 (patch)
treeddcc6b14077d90d1b970b67829f07120547dbb62 /src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
parenta139f95bfeca603333b8c0310ae09c6805e58584 (diff)
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.
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
index 054b2da..fdf852f 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
@@ -25,14 +25,15 @@ import java.util.Arrays;
import com.c2kernel.collection.Aggregation;
import com.c2kernel.collection.AggregationMember;
-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.ObjectCannotBeUpdated;
+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.Logger;
@@ -57,10 +58,14 @@ public class AssignItemToSlot extends PredefinedStep
* 0 - collection name
* 1 - slot number
* 2 - target entity key
+ * @throws ObjectNotFound
+ * @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
+ * @throws InvalidCollectionModification
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification {
String collName;
int slotNo;
@@ -76,20 +81,18 @@ public class AssignItemToSlot extends PredefinedStep
slotNo = Integer.parseInt(params[1]);
childItem = new ItemPath(params[2]);
} catch (Exception e) {
- throw new InvalidDataException("AssignItemToSlot: Invalid parameters "+Arrays.toString(params), "");
+ throw new InvalidData("AssignItemToSlot: 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("AssignItemToSlot: Collection '"+collName+"' not found in this Item", "");
- } catch (ClusterStorageException ex) {
+ } catch (PersistencyException ex) {
Logger.error(ex);
- throw new InvalidDataException("AssignItemToSlot: Error loading collection '\"+collName+\"': "+ex.getMessage(), "");
+ throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': "+ex.getMessage());
}
- if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.", "");
+ if (!(collObj instanceof Aggregation)) throw new InvalidData("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.");
agg = (Aggregation)collObj;
// find member and assign entity
@@ -97,25 +100,20 @@ public class AssignItemToSlot extends PredefinedStep
for (AggregationMember member : agg.getMembers().list) {
if (member.getID() == slotNo) {
if (member.getItemPath() != null)
- throw new InvalidDataException("AssignItemToSlot: Member slot "+slotNo+" not empty", "");
- try {
- member.assignItem(childItem);
- } catch (MembershipException e) {
- throw new InvalidDataException("AssignItemToSlot: Item "+childItem+" does not fit in slot "+slotNo, "");
- }
+ throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot "+slotNo+" not empty");
+ member.assignItem(childItem);
stored = true;
break;
}
}
if (!stored) {
- throw new InvalidDataException("AssignItemToSlot: Member slot "+slotNo+" not found.", "");
+ throw new ObjectNotFound("AssignItemToSlot: Member slot "+slotNo+" not found.");
}
-
try {
Gateway.getStorage().put(item, agg, null);
- } catch (ClusterStorageException e) {
- unknownException(e);
+ } catch (PersistencyException e) {
+ throw new PersistencyException("AssignItemToSlot: Error saving collection '"+collName+"': "+e.getMessage());
}
return requestData;
}