/************************************************************************** * CreateNewAgent.java * * Copyright (C) 2001 CERN - European Organization for Nuclear Research * All rights reserved. **************************************************************************/ package com.c2kernel.lifecycle.instance.predefined.server; import java.util.Arrays; import com.c2kernel.common.CannotManageException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.lifecycle.instance.predefined.PredefinedStep; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.lookup.LookupManager; import com.c2kernel.lookup.RolePath; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; public class RemoveRole extends PredefinedStep { public RemoveRole() { super(); } //requestdata is xmlstring @Override protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData) throws InvalidDataException { String[] params = getDataList(requestData); if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); LookupManager lookup; try { lookup = Gateway.getLookupManager(); } catch (CannotManageException e) { throw new InvalidDataException(e.getMessage(), ""); } RolePath thisRole; try { thisRole = lookup.getRolePath(params[0]); } catch (ObjectNotFoundException e) { throw new InvalidDataException("Role "+params[0]+" not found.", ""); } AgentPath[] agents = thisRole.getAgentsWithRole(); if (agents.length > 0) throw new InvalidDataException("Cannot remove role. "+agents.length+" agents still hold it.", ""); try { lookup.removeRole(agent, thisRole); } catch (ObjectCannotBeUpdated e) { Logger.error(e); throw new InvalidDataException("Role "+params[0]+" could not be removed.", ""); } catch (ObjectNotFoundException e) { throw new InvalidDataException("Role "+params[0]+" not found.", ""); } return requestData; } }