use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.
the class TransferItem method importItem.
public void importItem(File dir) throws Exception {
// check if already exists
try {
Property name = (Property) Gateway.getStorage().get(itemPath, PROPERTY + "/" + NAME, null);
throw new Exception("Item " + itemPath + " already in use as " + name.getValue());
} catch (Exception ex) {
}
// retrieve objects
ArrayList<String> objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
ArrayList<C2KLocalObject> objects = new ArrayList<C2KLocalObject>();
for (String element : objectFiles) {
String xmlFile = FileStringUtility.file2String(element);
C2KLocalObject newObj;
String choppedPath = element.substring(dir.getCanonicalPath().length() + 1, element.length() - 4);
Logger.msg(choppedPath);
if (choppedPath.startsWith(OUTCOME.getName()))
newObj = new Outcome(choppedPath, xmlFile);
else
newObj = (C2KLocalObject) Gateway.getMarshaller().unmarshall(xmlFile);
objects.add(newObj);
}
// create item
TraceableEntity newItem = Gateway.getCorbaServer().createItem(itemPath);
Gateway.getLookupManager().add(itemPath);
PropertyArrayList props = new PropertyArrayList();
CollectionArrayList colls = new CollectionArrayList();
Workflow wf = null;
// put objects
for (C2KLocalObject obj : objects) {
if (obj instanceof Property)
props.list.add((Property) obj);
else if (obj instanceof Collection)
colls.list.add((Collection<?>) obj);
else if (obj instanceof Workflow)
wf = (Workflow) obj;
}
if (wf == null)
throw new Exception("No workflow found in import for " + itemPath);
// init item
newItem.initialise(importAgentId.getSystemKey(), Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(wf.search("workflow/domain")), Gateway.getMarshaller().marshall(colls));
// store objects
importByType(ClusterType.HISTORY, objects);
importByType(ClusterType.OUTCOME, objects);
importByType(ClusterType.VIEWPOINT, objects);
Gateway.getStorage().commit(this);
// add domPaths
for (String element : domainPaths) {
DomainPath newPath = new DomainPath(element, itemPath);
Gateway.getLookupManager().add(newPath);
}
}
use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.
the class TransferItem method exportItem.
public void exportItem(File dir, String path) throws Exception {
Logger.msg("Path " + path + " in " + itemPath);
String[] contents = Gateway.getStorage().getClusterContents(itemPath, path);
if (contents.length > 0) {
FileStringUtility.createNewDir(dir.getCanonicalPath());
for (String content : contents) {
exportItem(new File(dir, content), path + "/" + content);
}
} else {
// no children, try to dump object
try {
C2KLocalObject obj = Gateway.getStorage().get(itemPath, path, null);
Logger.msg("Dumping object " + path + " in " + itemPath);
File dumpPath = new File(dir.getCanonicalPath() + ".xml");
FileStringUtility.string2File(dumpPath, Gateway.getMarshaller().marshall(obj));
return;
}// not an object
catch (ObjectNotFoundException ex) {
}
}
}
use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.
the class ClusterStorageManager method clearCache.
public void clearCache(ItemPath itemPath) {
Logger.msg(5, "ClusterStorageManager.clearCache() - removing entire cache of " + itemPath);
if (memoryCache.containsKey(itemPath)) {
synchronized (memoryCache) {
if (Logger.doLog(6)) {
Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
int size = sysKeyMemCache.size();
Logger.msg(6, "ClusterStorageManager.clearCache() - " + size + " objects to remove.");
}
memoryCache.remove(itemPath);
}
} else
Logger.msg(6, "ClusterStorageManager.clearCache() - No objects cached");
}
use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.
the class ClusterStorageManager method get.
/**
* Internal get method. Retrieves clusters from ClusterStorages & maintains the memory cache.
* <br>
* There is a special case for Viewpoint. When path ends with /data it returns referenced Outcome instead of Viewpoint.
*
* @param itemPath current Iten
* @param path the cluster path
* @return the C2KObject located by path
*/
public C2KLocalObject get(ItemPath itemPath, String path) throws PersistencyException, ObjectNotFoundException {
// check cache first
Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
if (sysKeyMemCache != null) {
synchronized (sysKeyMemCache) {
C2KLocalObject obj = sysKeyMemCache.get(path);
if (obj != null) {
Logger.msg(7, "ClusterStorageManager.get() - found " + itemPath + "/" + path + " in memcache");
return obj;
}
}
}
// special case for Viewpoint- When path ends with /data it returns referenced Outcome instead of Viewpoint
if (path.startsWith(VIEWPOINT.getName()) && path.endsWith("/data")) {
StringTokenizer tok = new StringTokenizer(path, "/");
if (tok.countTokens() == 4) {
// to not catch viewpoints called 'data'
Viewpoint view = (Viewpoint) get(itemPath, path.substring(0, path.lastIndexOf("/")));
if (view != null)
return view.getOutcome();
else
return null;
}
}
C2KLocalObject result = null;
// deal out top level remote maps
if (path.indexOf('/') == -1) {
if (path.equals(HISTORY.getName())) {
result = new History(itemPath, null);
} else if (path.equals(JOB.getName())) {
if (itemPath instanceof AgentPath)
result = new JobList((AgentPath) itemPath, null);
else
throw new ObjectNotFoundException("Items do not have job lists");
}
}
if (result == null) {
// else try each reader in turn until we find it
ArrayList<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
for (ClusterStorage thisReader : readers) {
try {
result = thisReader.get(itemPath, path);
Logger.msg(7, "ClusterStorageManager.get() - reading " + path + " from " + thisReader.getName() + " for item " + itemPath);
// got it!
if (result != null)
break;
} catch (PersistencyException e) {
Logger.msg(7, "ClusterStorageManager.get() - reader " + thisReader.getName() + " could not retrieve " + itemPath + "/" + path + ": " + e.getMessage());
}
}
}
// No result was found after reading the list of ClusterStorages
if (result == null) {
throw new ObjectNotFoundException("ClusterStorageManager.get() - Path " + path + " not found in " + itemPath);
}
putInMemoryCache(itemPath, path, result);
return result;
}
use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.
the class UserCodeProcess method getJob.
/**
* @param jobs
* @param transition
* @return
*/
private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
for (C2KLocalObject c2kLocalObject : jobs.values()) {
Job thisJob = (Job) c2kLocalObject;
if (thisJob.getTransition().getId() == transition) {
Logger.msg(1, "=================================================================");
Logger.msg(5, "UserCodeProcess.getJob() - job:" + thisJob);
return thisJob;
}
}
return null;
}
Aggregations