1 package info.mikethomas.fahweb.action;
2
3 /*
4 * #%L
5 * This file is part of FAHWeb.
6 * %%
7 * Copyright (C) 2012 - 2017 Michael Thomas <mikepthomas@outlook.com>
8 * %%
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/gpl-3.0.html>.
22 * #L%
23 */
24
25 import info.mikethomas.jfold.Connection;
26 import info.mikethomas.jfold.unit.Unit;
27 import com.opensymphony.xwork2.ActionSupport;
28
29 /**
30 * <p>ClientAction class.</p>
31 *
32 * @author Michael Thomas (mikepthomas@outlook.com)
33 * @version $Id: $Id
34 */
35 public class ClientAction extends ActionSupport {
36
37 private Unit unit;
38 private String control;
39 private Connection connection;
40
41 /** {@inheritDoc} */
42 @Override
43 public String execute() throws Exception {
44 this.unit = connection.queueInfo().get(0);
45 System.out.println(control);
46 return SUCCESS;
47 }
48
49 /**
50 * <p>getPageTitle.</p>
51 *
52 * @return a {@link java.lang.String} object.
53 */
54 public String getPageTitle() {
55 return "Folding@home Client Control";
56 }
57
58 /**
59 * <p>getPpd.</p>
60 *
61 * @return a {@link java.lang.String} object.
62 */
63 public String getPpd() {
64 return String.valueOf(unit.getPpd());
65 }
66
67 /**
68 * <p>getId.</p>
69 *
70 * @return a {@link java.lang.String} object.
71 */
72 public String getId() {
73 return unit.getId();
74 }
75
76 /**
77 * <p>getStatus.</p>
78 *
79 * @return a {@link java.lang.String} object.
80 */
81 public String getStatus() {
82 String status = unit.getState().toLowerCase();
83 return status.substring(0, 1).toUpperCase() + status.substring(1, status.length());
84 }
85
86 /**
87 * <p>getProgress.</p>
88 *
89 * @return a {@link java.lang.String} object.
90 */
91 public String getProgress() {
92 return unit.getPercentDone();
93 }
94
95 /**
96 * <p>getEta.</p>
97 *
98 * @return a {@link java.lang.String} object.
99 */
100 public String getEta() {
101 return unit.getEta();
102 }
103
104 /**
105 * <p>getCredit.</p>
106 *
107 * @return a {@link java.lang.String} object.
108 */
109 public String getCredit() {
110 return String.valueOf(unit.getCreditEstimate());
111 }
112
113 /**
114 * <p>getPrcg.</p>
115 *
116 * @return a {@link java.lang.String} object.
117 */
118 public String getPrcg() {
119 return unit.getProject() + " (" + unit.getRun() + ", " + unit.getClone() + ", " + unit.getGen() + ")";
120 }
121
122 /**
123 * <p>getDescription.</p>
124 *
125 * @return a {@link java.lang.String} object.
126 */
127 public String getDescription() {
128 return unit.getDescription().replace("\n", "<br/>");
129 }
130
131 /**
132 * <p>Getter for the field <code>control</code>.</p>
133 *
134 * @return a {@link java.lang.String} object.
135 */
136 public String getControl() {
137 return control;
138 }
139
140 /**
141 * <p>Setter for the field <code>control</code>.</p>
142 *
143 * @param control a {@link java.lang.String} object.
144 */
145 public void setControl(String control) {
146 this.control = control;
147 }
148
149 public void setConnection(Connection connection) {
150 this.connection = connection;
151 }
152 }