forked from HighTower1991/YouTrackRestApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModifyIssueField.java
43 lines (43 loc) · 1.63 KB
/
ModifyIssueField.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package youtrack.commands;
import com.sun.istack.internal.NotNull;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import youtrack.Error;
import youtrack.Issue;
import youtrack.commands.base.RunningCommand;
import youtrack.exceptions.AuthenticationErrorException;
import youtrack.exceptions.CommandExecutionException;
import youtrack.util.Service;
/**
* Created by egor.malyshev on 02.04.2014.
*/
public class ModifyIssueField extends RunningCommand<Issue, String> {
public ModifyIssueField(@NotNull Issue owner) {
super(owner);
}
@Override
public String getResult() throws CommandExecutionException, AuthenticationErrorException {
try {
if(method.getStatusCode() != 200) {
final Error e = new Error();
e.setMessage(method.getStatusText());
e.setCode(method.getStatusCode());
throw new CommandExecutionException(this, e);
} else {
return Service.readStream(method.getResponseBodyAsStream());
}
} catch(CommandExecutionException e) {
throw e;
} catch(Exception e) {
throw new CommandExecutionException(this, e);
}
}
@Override
public void createCommandMethod() {
final PostMethod postMethod = new PostMethod(owner.getYouTrack().getHostAddress() + "issue/" + owner.getId() + "/execute");
postMethod.setRequestBody(new NameValuePair[]{
new NameValuePair("command", parameters.get("field") + " " + parameters.get("value"))
});
method = postMethod;
}
}