Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.ws.rest.params

File JobConstant.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

6
20
7
1
130
80
12
0.6
2.86
7
1.71

Classes

Class Line # Actions
JobConstant 43 20 12
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.ws.rest.params;
22   
23    import jalview.util.MessageManager;
24    import jalview.ws.params.OptionI;
25    import jalview.ws.rest.InputType;
26    import jalview.ws.rest.NoValidInputDataException;
27    import jalview.ws.rest.RestJob;
28   
29    import java.io.UnsupportedEncodingException;
30    import java.net.URLEncoder;
31    import java.util.ArrayList;
32    import java.util.List;
33   
34    import org.apache.http.entity.mime.content.ContentBody;
35    import org.apache.http.entity.mime.content.StringBody;
36   
37    /**
38    * defines a constant value always provided as a parameter.
39    *
40    * @author JimP
41    *
42    */
 
43    public class JobConstant extends InputType
44    {
45   
46    String value;
47   
48    /**
49    *
50    * @param param
51    * name of parameter
52    * @param val
53    * value of parameter
54    */
 
55  0 toggle public JobConstant(String param, String val)
56    {
57    // needs no data from the restJob
58  0 super(null);
59  0 this.token = param;
60  0 value = val;
61    }
62   
 
63  0 toggle @Override
64    public ContentBody formatForInput(RestJob rj)
65    throws UnsupportedEncodingException, NoValidInputDataException
66    {
67   
68  0 return new StringBody(value);
69    }
70   
 
71  0 toggle @Override
72    public List<String> getURLEncodedParameter()
73    {
74  0 ArrayList<String> prm = new ArrayList<String>();
75   
76  0 if (value != null && value.length() > 0)
77    {
78  0 try
79    {
80  0 prm.add(URLEncoder.encode(value, "UTF-8"));
81    } catch (UnsupportedEncodingException ex)
82    {
83  0 throw new Error(MessageManager
84    .formatMessage("error.couldnt_encode_as_utf8", new String[]
85    { value }), ex);
86   
87    }
88    }
89  0 return prm;
90    }
91   
 
92  0 toggle @Override
93    public String getURLtokenPrefix()
94    {
95  0 return "";
96    }
97   
 
98  0 toggle @Override
99    public boolean configureFromURLtokenString(List<String> tokenstring,
100    StringBuffer warnings)
101    {
102  0 if (tokenstring.size() > 1)
103    {
104  0 warnings.append(
105    "IMPLEMENTATION ERROR: Constant POST parameters cannot have more than one value.");
106  0 return false;
107    }
108  0 if (tokenstring.size() == 1)
109    {
110  0 value = tokenstring.get(0);
111    }
112  0 return true;
113    }
114   
 
115  0 toggle @Override
116    public boolean configureProperty(String tok, String val,
117    StringBuffer warnings)
118    {
119  0 warnings.append(
120    "IMPLEMENTATION ERROR: No Properties to configure for a Constant parameter.");
121  0 return false;
122    }
123   
 
124  0 toggle @Override
125    public List<OptionI> getOptions()
126    {
127    // empty list - this parameter isn't configurable, so don't try.
128  0 return new ArrayList<OptionI>();
129    }
130    }