Source code: org/embl/ebi/escience/scufl/talisman/AddDataConstraint.java
1 /**
2 * This file is a component of the Taverna project,
3 * and is licensed under the GNU LGPL.
4 * Copyright Tom Oinn, EMBL-EBI
5 */
6 package org.embl.ebi.escience.scufl.talisman;
7
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import org.embl.ebi.escience.scufl.DataConstraint;
11 import org.embl.ebi.escience.scufl.DataConstraintCreationException;
12 import org.embl.ebi.escience.scufl.MalformedNameException;
13 import org.embl.ebi.escience.scufl.UnknownPortException;
14 import org.embl.ebi.escience.scufl.UnknownProcessorException;
15 import org.embl.ebi.escience.talisman.*;
16
17 import org.embl.ebi.escience.scufl.talisman.AbstractScuflAction;
18 import java.lang.String;
19
20
21
22 /**
23 * Adds a new data constraint to the ScuflModel contained within
24 * the field named by 'model' in the Talisman page. The required
25 * parameters are 'sourceprocessor', 'sourceport', 'sinkprocessor'
26 * and 'sinkport', all of which must contain names of the appropriate
27 * entities within the ScuflModel.
28 * @author Tom Oinn
29 */
30 public class AddDataConstraint extends AbstractScuflAction implements ActionWorker {
31
32 public void process(HttpServletRequest request , HttpServletResponse response, Action action)
33 throws AbortActionException, NodeResolutionException, UnknownResolutionProtocolException {
34 super.process(request, response, action);
35
36 Trigger trigger = (Trigger)action.getParent();
37
38 // Require the following parameters (model is redundant here,
39 // retained for clarity. The superclass has already checked it)
40 action.requireParameters("model,sourceport,sourceprocessor,sinkport,sinkprocessor");
41
42 // Build the description string for the source and sink ports
43 String sourcePortString =
44 Resolver.getFieldValue(action.props.getProperty("sourceprocessor"),action) + ":" +
45 Resolver.getFieldValue(action.props.getProperty("sourceport"),action);
46 String sinkPortString =
47 Resolver.getFieldValue(action.props.getProperty("sinkprocessor"),action) + ":" +
48 Resolver.getFieldValue(action.props.getProperty("sinkport"),action);
49
50 // Create a new data constraint and add it to the model.
51 try {
52 model.addDataConstraint(new DataConstraint(model,sourcePortString,sinkPortString));
53 }
54 catch (DataConstraintCreationException dcce) {
55 trigger.addError(dcce.getMessage());
56 throw new AbortActionException();
57 }
58 catch (UnknownPortException upe) {
59 trigger.addError(upe.getMessage());
60 throw new AbortActionException();
61 }
62 catch (UnknownProcessorException upre) {
63 trigger.addError(upre.getMessage());
64 throw new AbortActionException();
65 }
66 catch (MalformedNameException mne) {
67 trigger.addError(mne.getMessage());
68 throw new AbortActionException();
69 }
70 }
71
72 }