1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/**************************************************************************
* AddDomainPath
*
* Copyright (C) 2001 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
package com.c2kernel.lifecycle.instance.predefined;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.TransactionManager;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
/**************************************************************************
*
* $Revision: 1.21 $
* $Date: 2005/06/02 12:17:22 $
*
* Params: Schemaname_version:Viewpoint (optional), Outcome, Timestamp (optional
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
public class Import extends PredefinedStep
{
public Import()
{
super();
}
//requestdata is xmlstring
@Override
public void request( AgentPath agent, int transitionID, String requestData)
throws AccessRightsException,
InvalidTransitionException,
InvalidDataException
{
Logger.msg(8,"Import::request()");
Logger.msg(1,"Import::request() - Starting.");
checkAccessRights(agent);
String[] params = getDataList(requestData);
int split1 = params[0].indexOf('_');
int split2 = params[0].indexOf(':');
requestData = params[1];
String schemaName = params[0].substring(0, split1);
String viewpoint = null;
int schemaVersion;
if (split2 > -1) {
schemaVersion = Integer.parseInt(params[0].substring(split1+1, split2));
viewpoint = params[0].substring(split2+1);
}
else
schemaVersion = Integer.parseInt(params[0].substring(split1+1));
String timestamp;
if (params.length == 3)
timestamp = params[2];
else
timestamp = Event.timeToString(Event.getGMT());
// write event, outcome and viewpoints to storage
int syskey = getItemEntityPath().getSysKey();
TransactionManager storage = Gateway.getStorage();
History hist = new History(syskey, this);
Event event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), transitionID, getName(), getPath(), getType(), schemaName, schemaVersion, viewpoint, getCurrentState(), timestamp);
try {
storage.put(syskey, new Outcome(event.getID(), requestData, schemaName, schemaVersion), this);
storage.put(syskey, new Viewpoint(syskey, schemaName, viewpoint, schemaVersion, event.getID()), this);
if (!"last".equals(viewpoint))
storage.put(syskey, new Viewpoint(syskey, schemaName, "last", schemaVersion, event.getID()), this);
} catch (ClusterStorageException e) {
Logger.error(e);
storage.abort(this);
throw new InvalidDataException("Could not store imported outcome. Rolled back.");
}
storage.commit(this);
}
}
|