How to get commitMessage from gerrit REST API use JAVA - java

I want to use java connect Gerrit REST API, so i find the opensource gerrit-rest-java-client. But i don't know how to query the changes commitMessage.
My simple code is as follows
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritAuthData.Basic authData = new GerritAuthData.Basic("Gerrit", "User", "password");
GerritApi gerritApi = gerritRestApiFactory.create(authData);
List<ChangeInfo> changes = gerritApi.changes().query("status:merged").withLimit(1).get();
for (ChangeInfo cc : changes) {
System.out.println("subject:" + cc.subject);
System.out.println("changeId:" + cc.changeId);
System.out.println("commitMessage:");
}

You need to query changes adding the "&o=CURRENT_REVISION" to get commit SHA-1 of the current revision (see more details here). Then you need to use the Get Commit endpoint to finally get the commit message.

Related

Is it possible to get Direct Messages from Twitter by a specific user using the Twitter4j library?

I'm using the Twitter4j library to develop a proyect that works with Twitter, one of the things what I need is to get the Direct messages, I'm using the following code:
try{
List<DirectMessage> loStatusList = loTwitter.getDirectMessages();
for (DirectMessage loStatus : loStatusList) {
System.out.println(loStatus.getId() + ",#" + loStatus.getSenderScreenName() + "," + loStatus.getText() + "|");
}
}
catch(Exception e)
It works fine, but what the code returns is a list of the most recent messages in general. What I want is to get those direct messages using some kind of filter that allows finding them by a user that I indicate.
For example, I need to see the DM only from user #TwitterUser.
Is this posible with this library?
All kinds of suggestions are accepted, even if I should use another library I would be grateful if you let me know.
It looks like the actual Twitter API doesn't support a direct filter on that API, by username anyway. (See Twitter API doc: GET direct_messages.)
Which means, you'd have to make multiple calls to the API with pagination enabled, and cache the responses into a list.
Here is an example of pagination wtih Twitter4J getDirectMessages().
In that example, use the existing:
List<DirectMessage> messages;
But inside the loop, do:
messages.addAll(twitter.getDirectMessages(paging));
Note: you only would have to do this once. And in fact, you should persist these to a durable local cache like Redis or something. Because once you have the last message id, you can ask the Twitter API to only return "messages since id" with the since_id param.
Anyway, then on the client side you'd just do your filtering with the usual means in Java. For example:
// Joe is on twitter as #joe
private static final String AT_JOE = "Joe";
// Java 8 Lambda to filter by screen name
List<DirectMessage> messagesFromJoe = messages.stream()
.filter(message -> message.getSenderScreenName().equals(AT_JOE))
.collect(Collectors.toList());
Above, getSenderScreenName() was discovered by reading the Twitter4J API doc for DirectMessage.

How To Add A User Alias Using Google Admin SDK Java API

I am using the service account model and Google's Admin SDK Java API to retrieve and modify users.
The goal is to add an alias for an existing user.
Alias newAlias = new Alias();
newAlias.setId(userID);
newAlias.setAlias(alias);
Directory.Users.Aliases.Insert request = directory.users().aliases().insert(userID, newAlias);
request.execute();
execute() fails 100% of the time with the error message:
"Value set through a parameter is inconsistent with a value set in the request"
but of course does not identify the problem parameter or value, or provide a suggestion.
I tried all 8 combinations of scoped (or not scoped) userID and alias in newAlias, and userID in the request, with the same result. By all 8 combinations, I mean:
newAlias.setId(userID);
newAlias.setAlias(alias);
insert(userID, newAlias);
newAlias.setId(userID#domain.com);
newAlias.setAlias(alias#domain.com);
insert(userID#domain.com, newAlias);
and so on...
Any ideas greatly appreciated.
I think it is worth adding that, while I believe the above approach is correct (using Directory.Aliases.Insert) and that I am missing some critical information or made a mistake, I also attempted to add the alias by updating the User object instead of Aliases, something like this:
List<String> aliases = new ArrayList<String>();
aliases.add(scopedAlias); //userid#domain.com
User user = new User();
user = retrieveUser(uid); //Gets current record from Google
user.setAliases(aliases);
Directory.Users.Update request
= directory.users().update(uid, user);
request.execute();
That did not work either.
Anyone have an example of working code?
I've gotten aliases inserted using the following:
Alias alias = new Alias();
alias.setAlias(aliasString);
directory.users().aliases().insert(userId, alias).execute();
I don't have anything in the way of insight as to why your approach isn't working or why my approach works, but there you go.
S. McKinley's suggestion worked.
The key difference:
I had been including the call:
alias.setId(userId);
or
alias.setId(scopedUserId); //userId#domain
Either one resulted in the "parameter is inconsistent with a value" error. Leave it out and the alias gets created.
I was able to find the customerId as follows
Go to admin.google.com
Security -> Set up single sign-on (SSO)
You will see URLs like this:
https://accounts.google.com/o/saml2/idp?idpid=Cxxxxxxxx
That Cxxxxxxxx is your customerId

get all issues stored in jira

hi i want to get all issues stored in jira from java using jql or any othere way.
i try to use this code:
for(String name:getProjectsNames()){
String jqlRequest = "project = \""+name+"\"";
SearchResult result = restClient.getSearchClient().searchJql(
jqlRequest, 10000,0, pm);
final Iterable<BasicIssue> issues = result.getIssues();
for (BasicIssue is : issues) {
Issue issue = restClient.getIssueClient().getIssue(is.getKey(), pm);
...........
}
it give me the result but it take a very long time.
is there a query or a rest API URL or any other way that give me all issues?
please help me
The JIRA REST API will give you all the info from each issue at a rate of a few issues/second. The Inquisitor add-on at https://marketplace.atlassian.com/plugins/com.citrix.jira.inquisitor will give you thousands of issues per second but only the standard JIRA fields.
There is one other way. There is one table in JIRA database named "dbo.jiraissue". If you have access to that database then you can fetch all the ids of all issues. After fetching this data you can send this REST request "**localhost/rest/api/2/issue/issue_id" and get JSON response. Of course you have to write some code for this but this is one way I know to get all issues.

How to get the id of commit using JavaGit library?

I use this code from the JavaGit example:
File repositoryDirectory = new File("Library\\build\\jar\\");
DotGit dotGit = DotGit.getInstance(repositoryDirectory);
// Print commit messages of the current branch
for (Commit c : dotGit.getLog()) {
System.out.println(c.getMessage());
}
How could I get the id of commit this way?
Or it might be more appropriate library to interact with git?
According to the documentation (I don't know very much this library), you should invoke the getCommitName() method and use the returned Ref object to get the information you want (I think the SHA1 hash or the tag).

Get all calendar entries for a given date using Notes.jar

I am working on a simple Java code to extract all calendar entries for a given date. I know it's possible using Domingo but I would like to use only Notes.jar for this purpose. It is possible for me to create a session based on a given credentials and get the calendar object. I am looking to extract the current running Notes session and use that session object to open the calendar view in the mail file and start playing with it. But I am not able to get it working. Anybody have any idea or links on this?
Well I have done with the default notes API and here's the code.
NotesAPITest nat = new NotesAPITest();
NotesThread.sinitThread();
Session sess1 = NotesFactory.createSession();
System.out.println(sess1.getUserName());
Database database = sess1.getDatabase("", "mailfile");
View calendarView = database.getView("($Calendar)");
DateTime dt = sess1.createDateTime("today");
ViewEntryCollection vec = calendarView.getAllEntriesByKey(dt, true);
ViewEntry entry = vec.getFirstEntry();
while (entry != null)
{
Document caldoc = entry.getDocument();
System.out.println("Subject: " + caldoc.getItemValueString("Subject"));
System.out.println("Chair Person: " + caldoc.getItemValueString("Chair"));
System.out.println("Start Time: " + nat.getStartEndTimes(caldoc, "StartDateTime") );
System.out.println("Start Time: " + nat.getStartEndTimes(caldoc, "EndDateTime") );
System.out.println("Required: " + caldoc.getItemValueString("RequiredAttendees"));
entry = vec.getNextEntry();
}
The only drawback i see is that, whenever the session is extracte, notes pops up a password dialog box. In my searches so far I have not seen a solution for that. Apparently a security arrangement in LN i guess.
Just by googling I have found this article. They create an Eclispe plugin there for Notes. And the example code for getting employee brithdays is also there (I guess Calendar works in a similar way):
s = NotesFactory.createSession();
// Get the local address book
Database nab = s.getDatabase("",s.getAddressBooks().elementAt(0).toString());
if (nab.isOpen() == false) nab.open();
// Get the Birthdays & Anniversaries view
View baview = nab.getView("BA");
ViewEntryCollection eba = baview.getAllEntries();
ViewEntry entry = eba.getFirstEntry();
list = new String[eba.getCount()];
int count = 0;
while (entry != null) {
Vector vals = entry.getColumnValues();
list[count]= vals.elementAt(1).toString() + " " + vals.elementAt(2).toString();
entry = eba.getNextEntry();
count++;
}
EDIT: Also look at this link for some documentation on Notes.jar.
The NotesFactory.createSession() method is what you can use to get a handle to the current session. Notes will automatically share the current client session. If this method is failing, there may be something wrong with your basic configuration. Be sure that:
You have the Notes Client fully installed on the machine running the Java app, and be sure there is a valid Notes ID file. (For example, be sure you can open the Notes client on this machine successfully).
Also, be sure that the the nnotes.dll file is accessible on your machine's path (different than the Java CLASSPATH).
And, confirm that the Notes.ini file is also on the machine's PATH.
#vikramjb, try doing NotesFactory.createSession((String) null, (String) null, password); to prevent the notes password popup from prompting you each time you do something with the session that needs security.
Found out about this from here: http://lekkimworld.com/2006/07/10/java_in_notes_domino_explained_domino_session_tester.html

Categories

Resources