/************************************************************************** * ItemProxy.java * * $Revision: 1.25 $ * $Date: 2005/05/10 11:40:09 $ * * Copyright (C) 2001 CERN - European Organization for Nuclear Research * All rights reserved. **************************************************************************/ package com.c2kernel.entity.proxy; import java.util.ArrayList; import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionMember; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.Item; import com.c2kernel.entity.ItemHelper; import com.c2kernel.entity.ManageableEntity; import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.agent.JobArrayList; import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; /****************************************************************************** * It is a wrapper for the connection and communication with Item * It caches data loaded from the Item to reduce communication * * @version $Revision: 1.25 $ $Date: 2005/05/10 11:40:09 $ * @author $Author: abranson $ ******************************************************************************/ public class ItemProxy extends EntityProxy { /************************************************************************** * **************************************************************************/ protected ItemProxy( org.omg.CORBA.Object ior, int systemKey) throws ObjectNotFoundException { super(ior, systemKey); } @Override public ManageableEntity narrow() throws ObjectNotFoundException { try { return ItemHelper.narrow(mIOR); } catch (org.omg.CORBA.BAD_PARAM ex) { } throw new ObjectNotFoundException("CORBA Object was not an Item, or the server is down."); } /************************************************************************** * * **************************************************************************/ public void initialise( int agentId, String itemProps, String workflow ) throws AccessRightsException, InvalidDataException, PersistencyException, ObjectNotFoundException { Logger.msg(7, "ItemProxy::initialise - started"); ((Item)getEntity()).initialise( agentId, itemProps, workflow ); } public void setProperty(AgentProxy agent, String name, String value) throws AccessRightsException, PersistencyException { String[] params = new String[2]; params[0] = name; params[1] = value; try { agent.execute(this, "WriteProperty", params); } catch (AccessRightsException e) { throw (e); } catch (PersistencyException e) { throw (e); } catch (Exception e) { Logger.error(e); throw new PersistencyException("Could not store property"); } } /************************************************************************** * **************************************************************************/ protected void requestAction( Job thisJob ) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException { String outcome = thisJob.getOutcomeString(); // check fields that should have been filled in if (outcome==null) if (thisJob.requiresOutcome()) throw new InvalidDataException("Outcome is required.", ""); else outcome=""; if (thisJob.getAgentId() == -1) throw new InvalidDataException("No Agent specified.", ""); Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName()); requestAction (thisJob.getAgentId(), thisJob.getStepPath(), thisJob.getPossibleTransition(), outcome); } //requestData is xmlString public void requestAction( int agentId, String stepPath, int transitionID, String requestData ) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException { ((Item)getEntity()).requestAction( agentId, stepPath, transitionID, requestData ); } /************************************************************************** * **************************************************************************/ public String queryLifeCycle( int agentId, boolean filter ) throws AccessRightsException, ObjectNotFoundException, PersistencyException { return ((Item)getEntity()).queryLifeCycle( agentId, filter ); } /************************************************************************** * **************************************************************************/ private ArrayList getJobList(int agentId, boolean filter) throws AccessRightsException, ObjectNotFoundException, PersistencyException { JobArrayList thisJobList; try { String jobs = queryLifeCycle(agentId, filter); thisJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(jobs); } catch (Exception e) { Logger.error(e); throw new PersistencyException("Exception::ItemProxy::getJobList() - Cannot unmarshall the jobs", null); } return thisJobList.list; } public ArrayList getJobList(AgentProxy agent) throws AccessRightsException, ObjectNotFoundException, PersistencyException { return getJobList(agent.getSystemKey()); } private ArrayList getJobList(int agentId) throws AccessRightsException, ObjectNotFoundException, PersistencyException { return getJobList(agentId, true); } private Job getJobByName(String actName, int agentId) throws AccessRightsException, ObjectNotFoundException, PersistencyException { ArrayList jobList = getJobList(agentId); for (Job job : jobList) { int transition = job.getPossibleTransition(); if (job.getStepName().equals(actName)) if (transition == Transitions.COMPLETE || transition == Transitions.DONE) return job; } return null; } public Collection getCollection(String collName) throws ObjectNotFoundException { return (Collection)getObject("Collection/"+collName); } public Job getJobByName(String actName, AgentProxy agent) throws AccessRightsException, ObjectNotFoundException, PersistencyException { return getJobByName(actName, agent.getSystemKey()); } }