1 package com.sri.emo.annotations; 2 3 import com.jcorporate.expresso.core.controller.*; 4 import com.jcorporate.expresso.core.db.DBException; 5 import com.jcorporate.expresso.core.security.ReadOnlyUser; 6 import com.sri.common.controller.StateHandler; 7 import com.sri.emo.controller.AddNodeAction; 8 import com.sri.emo.dbobj.Node; 9 10 /*** 11 * Prompts for deleting a tag. 12 * 13 * @author Michael Rimov 14 * @version 1.0 15 */ 16 public class PromptDeleteTag implements StateHandler { 17 18 19 public static final String NAME = "promptDeleteTag"; 20 21 public static final String DESCRIPTION = "Prompt Delete Tag"; 22 23 public static final String TAG_ID = DoDelete.PARAM_TAG; 24 25 public static final String TAG_VALUE = "TagValue"; 26 27 private final Controller myParent; 28 29 public PromptDeleteTag(Controller parent) { 30 myParent = parent; 31 } 32 33 34 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException, ControllerException { 35 36 NodeTag nt = new NodeTag(); 37 nt.setField(NodeTag.TAG_ID, request.getParameter(DoDelete.PARAM_TAG)); 38 nt.retrieve(); 39 40 ReadOnlyUser requestingUser = request.getRequestingUser(); 41 if (!(requestingUser.isAdmin() || requestingUser.getLoginName().equals(nt.getAddedBy()))) { 42 throw new ControllerException("Permission to delete not allowed for user: " + requestingUser.getLoginName()); 43 } 44 45 String nodeId = nt.getField(NodeTag.TAG_PARENT_NODE); 46 request.getSession().setAttribute(TAG_VALUE, nt); 47 48 Transition yes = new Transition("yes", "Yes", myParent.getClass(), DoDelete.NAME); 49 yes.addParam(DoDelete.PARAM_TAG, request.getParameter(DoDelete.PARAM_TAG)); 50 response.add(yes); 51 52 Transition no = new Transition("no", "No", AddNodeAction.class, AddNodeAction.VIEW_NODE); 53 no.addParam(Node.NODE_ID, nodeId); 54 response.add(no); 55 } 56 }