Editing resolution of JIRA issue using Transition throws exception - jira

I have two JIRA project for eg. DEV and CLIENT. I want to set the resolution of issue in CLIENT project to DONE when the resolution of issue in DEV project changes to DONE.
For this I have done following code :
public void changeTransition(com.atlassian.jira.issue.Issue devIssue, Issue clientIssue, JiraRestClient restClient) {
IssueRestClient issueClient = restClient.getIssueClient();
Iterable<Transition> transitions = issueClient.getTransitions(clientIssue.getTransitionsUri()).claim();
final Transition doneIssueTransition = getTransitionByName(transitions, "Done"); //this returns done Transition
if (doneIssueTransition != null) {
ImmutableList.Builder<FieldInput> builder = ImmutableList.builder();
builder.add(new FieldInput(IssueFieldId.RESOLUTION_FIELD, ComplexIssueInputFieldValue.with("name", devIssue.getResolution().getName())));
ImmutableList<FieldInput> fieldInputs = builder.build();
TransitionInput transitionInput = new TransitionInput(doneIssueTransition.getId(), fieldInputs, prepareComment(devIssue));
issueClient.transition(clientIssue.getTransitionsUri(), transitionInput).claim();
}
}
The exception that I get is :
Field 'resolution' cannot be set. It is not on the appropriate screen, or unknown.
is there anything wrong with the code? what this exception signifies? what changes should I make to get this resolved?

Related

Missing Test Points using .Net sdk GetPointsByQueryAsync

I am using the method "GetPointsByQueryAsync" when I use it for a small number of test cases (as input) it is working fine but when I use it for a large number of test cases (as input), it messes up like some test points will miss, when I try to get miss points separately, it works fine. I have posted this issue on the Visual studio community, they refuse to fix it and said it is not our policy to look into this issue. I have a test case count of 3000 and a test point count of 15000.
https://developercommunity.visualstudio.com/t/Missing-Test-Points-using-Net-sdk/10215409
using Microsoft.TeamFoundation.TestManagement.WebApi;
public List<TestPoint> GetTestPoints(Uri uri, string oAuthAccessToken, List<int> testcaseIds)
{
TestPointsQuery outputQuery= null;
try
{
VssOAuthAccessTokenCredential mCredential = new VssOAuthAccessTokenCredential(oAuthAccessToken);
VssConnection connection =
new VssConnection(uri, mCredential);
TestManagementHttpClient testManagementHttpClient = connection.GetClient<TestManagementHttpClient>();
TestPointsQuery query = new TestPointsQuery();
PointsFilter filter = new PointsFilter();
filter.TestcaseIds = testcaseIds;
query.PointsFilter = filter;
outputQuery = testManagementHttpClient.GetPointsByQueryAsync(query, WIProject.Id).Result;
}
catch (Exception e)
{
Console.WriteLine(e);
}
return outputQuery.Points;
}

Unable to move jira support ticket to Done status using Rest Client

I am using Java rest client with following maven dependency:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-app</artifactId>
<version>5.2.0</version>
</dependency>
And the following code:
void markDuplicateAndClose(IssueRestClient client, ...) {
...
Iterable<Transition> transitions = client.getTransitions(duplicateIssue.getTransitionsUri()).claim();
Transition doneTransition = getTransitionByName(transitions, "Done");
String requiredFieldId = null;
for (Field f : doneTransition.getFields()) {
if (f.isRequired())
requiredFieldId = f.getId();
};
Collection<FieldInput> fieldInputs = Arrays.asList(new FieldInput(requiredFieldId, "Duplicate"));
TransitionInput ti = new TransitionInput(doneTransition.getId(), fieldInputs);
promise = client.transition(keyToIssuesMap.get(duplicate), ti).claim();
...
}
private Transition getTransitionByName(Iterable<Transition> transitions, String stateName) {
for (Transition t: transitions) {
if (t.getName().equals(stateName))
return t;
}
return null;
}
However, I get the following error:
Exception in thread "main" RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={customfield_10212=Could not find valid 'id' or 'value' in the Parent Option object.}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:45)
at com.xyz.jira_accessor.jira.Util.markDuplicates(Util.java:109)
at com.xyz.jira_accessor.jira.Util.main(Util.java:132)
Caused by: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={customfield_10212=Could not find valid 'id' or 'value' in the Parent Option object.}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:176)
What is wrong with my code?
As discussed in below comments, I tried to see the underlying codes for the option:
Option shown as compulsory on the UI
HTML from Chrome Debugger for the same:
And so I changed the above code to:
Collection<FieldInput> fieldInputs = Arrays.asList(new FieldInput("customfield_11607", "12091"));
TransitionInput ti = new TransitionInput(doneTransition.getId(), fieldInputs);
promise = client.transition(keyToIssuesMap.get(duplicate), ti).claim();
But it still did not work.
Just that the error message changed to:
errors={customfield_11607=Could not find valid 'id' or 'value' in the Parent Option object.}
(To Jira Team) Can you make the error messages bit more meaningful and simplify the API please? It is very hard to figure out things. Or at least, provide some more examples which are easily searchable on the Internet.

C# - Xamarin - HttpClient - Operation is not valid due to the current state of the object - iOS

I'm working on a cross platform library that makes HTTP requests. It's working fine on Android, but when I try to use it on iOS I'm getting an exception and I can't figure out how to fix it.
Here is my code:
// method from cross platform library
Task.Factory.StartNew(delegate
{
try
{
var client = new HttpClient();
// some other setup stuff
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.post, "http://myurl.com...");
var task = client.SendAsync(request);
task.Wait(); // Exception thrown on this line
var response = task.Result;
var responseString = response.Content.ReadAsStringAsync().Result;
}
catch (Exception e)
{
}
}
On task.Wait(); I get a System.AggregateException with an inner exception of System.InvalidOperationException that says Operation is invalid due to the current state of the object.
Trying to find some solutions, I found that the issue could be cause by calling this on the UI thread. But that's the whole point of wrapping this all in Task.Factory.StartNew.
I've tried everything I know to do and have yet to solve the issue. Any help would be very appreciated.
Edit:
I decided to try my solution on an iPhone simulator. It's an iPhone 6 simulator running iOS 10. My physical device is the same. It works on the simulator, but not the physical device for some reason... very strange.
Edit 2:
Thanks to #YuriS for finding a solution.
From: https://forums.xamarin.com/discussion/36713/issue-with-microsoft-http-net-library-operation-is-not-valid-due-to-the-current-state-of-the-objec
What you can do is:
1) Go to References of ios Project
2) Edit References
3) Check 'System.Net.Http'
Behaviour for android is the same.
There can be few problems described here:
https://forums.xamarin.com/discussion/36713/issue-with-microsoft-http-net-library-operation-is-not-valid-due-to-the-current-state-of-the-objec
https://bugzilla.xamarin.com/show_bug.cgi?id=17936
"Operation is not valid" error at Xamarin.iOS project with HttpClient
http://motzcod.es/post/78863496592/portable-class-libraries-httpclient-so-happy
Seems all post pointing on System.Net.Http
Regardless of the problem there is a better ways doing this.One of them:
public static async Task PostRequest()
{
try
{
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://myuri");
//request.Headers.Add("", "");
var response = await client.SendAsync(request);
var responseString = await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
}
}
If you want to wait till function completes you call
await PostRequest();
If you don't need to wait then just omit "await" in the call or use
PostRequest.ContinueWith((t)=>
{
});
Also you need to handle an exception within the function, so probably returning just Task is not the best. I was just basing my answer on original function signature

accessing transition history via JIRA REST API

I found another person apparently having this issue but I thought I'd re-ask the question to see if I could make it more explicit.
I'm using the JIRA 6 REST web API and successfully pulling lots of data that matches our web cloud UI.
Now I'd like to see the transitions a given issue has been thru, preferably with info about who performed the transition.
I can see this transition history in our JIRA web UI but I haven't figured out how to access programmatically yet.
There's a promising sounding API:
http://example.com:8080/jira/rest/api/2/issue/{issueIdOrKey}/transitions [GET, POST]
And this is the API the previous asker seemed to have been using. From what I can tell it only returns the valid transitions you can ask for on the issue at a given point in time.
I would like a history of transitions, such as when the issue went to code review, QA, closed, etc.
I have done a expand=changelog but the change log does not correlate with the transitions that I can see.
Any tips would be appreciated. Thanks.
When you use expand=changelog, then all changes that have been done in issue are there. Exactly same info as in All tab in Activity section when viewing in web browser.
When I send:
http://jira.my.server.se/rest/api/2/issue/KEYF-42346?expand=changelog
Under changelogkey I find list of histories. Each historyhas list of items. Those items are changes performed on the certain field, with to and from values.
To find all status changes you need to do something like this:
for history in issue.changelog.histories:
for item in history.items:
if item.field == "status":
print item.toString # new value
print item.fromString # old value
Or use GET /rest/api/3/issue/{issueIdOrKey}/changelog like explained in the "get changelog" docs
You can try using the jql parameter for the REST API call.
So your call for,
JQL = project=XYZ and status was resolved
fields = key
will look like this,
http://example.com/rest/api/2/search?jql=project%3DXYZ%20and%20status%20was%20resolved&fields=key
where key will return only relevant information and not excessive for each issue.
public void changeStatus(IssueRestClient iRestClient,
List<Statuses> JiraStatuses, String key) {
String status = "To Do";
for (Statuses statuses : vOneToJiraStatuses) {
if (1 == statuses.compareTo(status)) {
try {
String _transition = statuses.getTransition();
Issue issue = iRestClient.getIssue(key).get();
Transition transition = getTransition(iRestClient, issue,
_transition);
if (!(isBlankOrNull(transition))) {
if (!(issue.getStatus().getName()
.equalsIgnoreCase(_transition)))
transition(transition, issue, null, iRestClient,
status);
}
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
}
break;
}
}
}
List is a pojo implementation where statuses and transitions defined in xml are injected through setter/constructor.
private void transition(Transition transition, Issue issue,
FieldInput fieldInput, IssueRestClient issueRestClient,
String status) throws Exception {
if (isBlankOrNull(fieldInput)) {
TransitionInput transitionInput = new TransitionInput(
transition.getId());
issueRestClient.transition(issue, transitionInput).claim();
Constants.REPORT.info("Status Updated for : " + issue.getKey());
} else {
TransitionInput transitionInput = new TransitionInput(
transition.getId());
issueRestClient.transition(issue, transitionInput).claim();
Constants.REPORT.info("Status Updated for : " + issue.getKey());
}
}
public Transition getTransition(IssueRestClient issueRestClient,
Issue issue, String _transition) {
Promise<Iterable<Transition>> ptransitions = issueRestClient
.getTransitions(issue);
Iterable<Transition> transitions = ptransitions.claim();
for (Transition transition : transitions) {
if (transition.getName().equalsIgnoreCase(_transition)) {
return transition;
}
}
return null;
}
In Short using Transition API of JIRA we can fetch all the transitions to set statuses

Windows service always writes to custom log and application log

I am using a custom EventLog for my Windows service. The service creates the event source after installtion. I don't have any problems.
However, I have setup my service so that I can run it from the IDE using the following mechanism:
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);
string firstArgument = string.Empty;
if (args.Length > 0)
firstArgument = args[0].ToUpperInvariant();
if (string.Compare(firstArgument, "-CONSOLE", true) == 0)
{
new SchedulerService().RunConsole(args);
}
else
{
ServiceBase[] services = new ServiceBase[] { new SchedulerService() };
ServiceBase.Run(services);
}
}
When writing to the event log, it seems to write my custom event log AND the application log. How can I prevent this from occurring?
Below is the code I am using to write to the event log: (The EventLog app setting is the same for the source and name)
using (System.Diagnostics.EventLog eventLog =
new EventLog(
System.Configuration.ConfigurationManager.AppSettings["EventLog"], ".",
System.Configuration.ConfigurationManager.AppSettings["EventLog"]))
{
eventLog.WriteEntry(msg, entryType);
}
It seems that a reboot of my machine has fixed this problem. I am not sure why yet, but I am going to assume the Event Viewer mechanism got in to some kind of weird state.

Resources