I am trying to create work item in RTC through java application using the jazz api's.
My connection to the repository is successful. Now i need to set all the required fields through java code in order to save/run the workitem. Really dont know how to set those values in below codes.
String repositoryURI= args[0];
String userId= args[1];
String password= args[2];
String projectAreaName= args[3];
String typeIdentifier= args[4];
String summary= args[5];
String categoryName= args[6];
ITeamRepository teamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(null);
IProcessClientService processClient= (IProcessClientService) teamRepository.getClientLibrary(IProcessClientService.class);
IAuditableClient auditableClient= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
URI uri= URI.create(projectAreaName.replaceAll(" ", "%20"));
IProjectAreaHandle projectArea= (IProjectAreaHandle) processClient.findProcessArea(uri, null, null);
//IProjectAreaHandle projectArea = teamArea.getProjectArea();
if (projectArea == null) {
System.out.println("Project area not found.");
return false;
}
//IWorkItemType workItemType = service.findWorkItemType(projectArea, "defect", monitor);
IWorkItemType workItemType= workItemClient.findWorkItemType((IProjectAreaHandle) projectArea, typeIdentifier, null);
// findWorkItemType(projectArea, typeIdentifier, null);
if (workItemType == null) {
System.out.println("Work item type not found.");
return false;
}
System.out.println("Category not found.: " + categoryName );
List path= Arrays.asList(categoryName.split("/"));
System.out.println("Category not found.: " + path );
ICategoryHandle category= workItemClient.findCategoryByNamePath((IProjectAreaHandle) projectArea, path, null);
//ICategoryHandle category=
if (category == null) {
System.out.println("Category not found.: " + category );
return false;
}
WorkItemInitialization operation= new WorkItemInitialization(summary, category);
IWorkItemHandle handle= operation.run(workItemType, null);
IWorkItem workItem= auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, null);
System.out.println("Created work item " + workItem.getId() + ".");
teamRepository.logout();
While running the codes i am receiving the below errors. Because of mandatory fields are not assigned. Can any one help me to pass the attribute values (Contact Phone) from java to jazz.
ERROR received:
Severity: ERROR
Summary: Attribute 'Contact Phone #' not set
Description: The 'Contact Phone #' attribute needs to be set (work item <09:13:03>).
Related
I need to create a dummy string for my application on when a user search for an existing mail and if it is tagged as "erased" it will return an error message "user erased"
here is my wod file.
WOD:
<WebObject name=form2>
Customer email address:
<WebObject name=emailField></WebObject>
<WebObject name=submitEmailButton></WebObject>
</WebObject>
submitEmailButton : WOSubmitButton {
action = submitEmail;
value = "Search";
}
java:
NSArray persons = Person.personsWithEmail(email, session().defaultEditingContext());
if ( (persons == null) || (persons.count() == 0) ) {
errorMessage = "customer email \"" + email + "\" could not be found.";
return null;
}
this is how submitemail look like in wod.
<WebObject name=form2>
Customer email address: <WebObject name=emailField></WebObject>
<WebObject name=submitEmailButton></WebObject>
</WebObject>
<br>
submitEmailButton : WOSubmitButton {
action = submitEmail;
value = "Search";
I need to add a condition that will check once a flag is tagged as erased it will show the error message.
A very strange porblem. I'm tring to update contacts name by this rule:
- if a contact's name start with "bit" + space ("bit ") so -> update the contact's name to name.substring(4, name.length()), and that means that the contact name will update without the "bit ".
when I use name.substring from number that lower them 4 (I think until the space in contact's name) its working perfectly. When I use from the 4 character onwards the contact's name multiply. For exmaple, when i use name = name.substring(4, name.length()) while name equal to "bit Lili" its update to:
Lili Lili.
private void updateContact(String name) {
ContentResolver cr = getContentResolver();
String where = ContactsContract.Data.DISPLAY_NAME + " = ?";
String[] params = new String[] {name};
Cursor phoneCur = managedQuery(ContactsContract.Data.CONTENT_URI,null,where,params,null);
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
if ((null == phoneCur)) {//createContact(name, phone);
Toast.makeText(this, "no contact with this name", Toast.LENGTH_SHORT).show();
return;} else {ops.add(ContentProviderOperation.newUpdate(android.provider.ContactsContract.Data.CONTENT_URI)
.withSelection(where, params)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name.substring(4,name.length()))
.build());
}
phoneCur.close();
try {cr.applyBatch(ContactsContract.AUTHORITY, ops);}
catch (RemoteException e) {e.printStackTrace();}
catch (OperationApplicationException e) {e.printStackTrace();}}
Thanks!
Not a certain answer but it suppose to work the issue you have is with the
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME //This specific part has a problem with the new update function
,name.substring(4,name.length()))
So my fix proposal is to change it to family name and given name change these as you need based on your question you want to remove the given name so it's a fix for that
public static boolean updateContactName(#NonNull Context context, #NonNull String name) {
if (name.length() < 4) return true;
String givenNameKey = ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME;
String familyNameKey = ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME;
String changedName = name.substring(4, name.length());
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
String where = ContactsContract.Data.DISPLAY_NAME + " = ?";
String[] params = new String[]{name};
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(where, params)
.withValue(givenNameKey, changedName)
.withValue(familyNameKey, "")
.build());
try {
context.getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
Problem
I want to see if user "john" is in group "Calltaker". I can't seem to get the syntax right on my search filter to check for a specific user in a specific group. I can list all users in a group to verify the desired user is there.
Questions
What is the right syntax for a ldap search filter to determine if a specific user is in a specific group(in Tivoli Access Manager)?
What should I check on the returned LDAPEntry object given by that search string to see that the user is, or isn't, in the group?
Info
john is defined in "cn=users,dc=ldap,dc=net"
Calltaker is defined in "cn=groups,dc=ldap,dc=net"
I'm querying against TAM's ldap, from java
Using the searchfilter to be "cn=Calltaker" I can print out the search results such that calling nextEntry.toString contains the list of users. See Example 1 below
Here's a few searchfilters I've tried that don't work (aka searchResults.next() throws an error):
(&(objectclass=groupOfUniqueName)(uniquemember=uid="+ username + ",cn=groups,dc=ldap,dc=net))
(&(objectclass=groupOfUniqueName)(uniquemember=uid="+ username + ",cn=users,dc=ldap,dc=net))
(uniquemember=uid="+ username + ",cn=users,dc=ldap,dc=net)
Example 1) only search group, using searchFilter="cn=Calltaker", verify it contains users:
System.out.println(nextEntry.toString()); //added newlines for readability
nextEntry:
LDAPEntry:
cn=Calltaker,cn=groups,dc=ldap,dc=net;
LDAPAttributeSet:
LDAPAttribute: {type='objectclass', values='groupOfUniqueNames','top'}
LDAPAttribute: {type='uniquemember',
values=
'uid=placeholder,cn=users,dc=ldap,dc=net',
'secAuthority=default',
'uid=john,cn=users,dc=ldap,dc=net',
'uid=sally,cn=users,dc=ldap,dc=net', ....etc
Code:
public boolean isUserInGroup(username){
boolean userInGroup = false;
String loginDN = "uid=" + admin_username + "," + "cn=users,dc=ldap,dc=net";
String searchBase = "cn=groups,dc=ldap,dc=net";
int searchScope = LDAPConnection.SCOPE_SUB;
searchFilter = "(&(objectclass=ePerson)(uniquemember=uid="+ username + ",cn=users,dc=ldap,dc=net))";
//Connect
LDAPConnection lc = connect(hosts);
lc.bind(LDAPConnection.LDAP_V3, loginDN, admin_password.getBytes("UTF8"));
lc.getAuthenticationDN();
LDAPSearchResults searchResults = lc.search(searchBase,
searchScope,
searchFilter,
null, // return all attributes
false); // return attrs and values
while (searchResults.hasMore()) {
LDAPEntry nextEntry = null;
try {
nextEntry = searchResults.next();
} catch (LDAPException e) {
// Exception is thrown, go for next entry
if (e.getResultCode() == LDAPException.LDAP_TIMEOUT || e.getResultCode() == LDAPException.CONNECT_ERROR)
break;
else
continue;
}
//TODO some check to verify nextEntry shows the user in the group
userInGroup = true;
LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
Iterator<LDAPAttribute> allAttributes = attributeSet.iterator();
while (allAttributes.hasNext()) {
LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
String attributeName = attribute.getName();
System.out.println("found attribute '" + attributeName + "' with value '" + attribute.getStringValue() + "'");
}
}
lc.disconnect();
return userInGroup;
}
** EDIT **
Implemented answer from EJP, changed searchBase to include group
Code that works:
private static final String admin_username = "foo";
private static final String[] hosts = new String[]{"foohost.net"};
public boolean isUserInGroup(String username, String group){
boolean userInGroup = false;
String loginDN = "uid=" + admin_username + "," + "cn=users,dc=ldap,dc=net";
String searchBase = "cn=" + group + "," + "cn=groups,dc=ldap,dc=net";
int searchScope = LDAPConnection.SCOPE_SUB;
searchFilter = "(&(objectclass=groupOfUniqueNames)(uniquemember=uid="+ username + ",cn=users,dc=ldap,dc=net))";
//Connect
LDAPConnection lc = connect(hosts);
lc.bind(LDAPConnection.LDAP_V3, loginDN, admin_password.getBytes("UTF8"));
lc.getAuthenticationDN();
LDAPSearchResults searchResults = lc.search(searchBase,
searchScope,
searchFilter,
null, // return all attributes
false); // return attrs and values
while (searchResults.hasMore()) {
LDAPEntry nextEntry = null;
try {
nextEntry = searchResults.next();
} catch (LDAPException e) {
// Exception is thrown, go for next entry
if (e.getResultCode() == LDAPException.LDAP_TIMEOUT || e.getResultCode() == LDAPException.CONNECT_ERROR)
break;
else
continue;
}
//A result was found, therefore the user is in the group
userInGroup = true;
}
lc.disconnect();
return userInGroup;
}
What is the right syntax for a ldap search filter to determine if a specific user is in a specific group(in Tivoli Access Manager)?
Either of the filters you used, but the objectClass to search on is groupofUniqueNames (plural).
What should I check on the returned LDAPEntry object given by that search string to see that the user is, or isn't, in the group?
Nothing. He will be, otherwise the group won't be returned in the search. All you need to do is check that the search result is non-empty.
Here's a few searchfilters I've tried that don't work (aka searchResults.next() throws an error):
Throws what error?
(&(objectclass=groupOfUniqueName)(uniquemember=uid="+ username + ",cn=groups,dc=ldap,dc=net))
Nothing wrong with this except for groupOfUniqueName. You should use search filter arguments like {0} rather than building them into the search string.
(&(objectclass=groupOfUniqueName)(uniquemember=uid="+ username + ",cn=users,dc=ldap,dc=net))
This one will search the cn=users subtree for a group. It won't work unless you have groups under cn=users, which doesn't seem likely.
(uniquemember=uid="+ username + ",cn=users,dc=ldap,dc=net)
This will select non-groups. You don't want that: you need the objectClass part.
I am using ApacheDS as directory server & UnboundID as LDAP SDK for entering user and its related groups. I am following a link
http://ldapwiki.willeke.com/wiki/Tips%20using%20UnboundID%20LDAP%20SDK
in which they have used CompareRequest method to find out whether user is a member of a particular group or not?
The code i have written against this method is as such
//input ---- uid = "rohit.joshi" and groupName = "Java"
public boolean isUserMemberOfGroup(String uid, String groupName) {
boolean answ = false;
LDAPConnection connection = connect();
try {
//userDN -- uid=rohit.joshi,ou=users,o=wipro
String userDN = "uid=" + uid + ",ou=users," + LDAP_BASE_DN;
//groupDN -- cn=Java,ou=groups,o=wipro
String groupDN = "cn=" + groupName + ",ou=groups," + LDAP_BASE_DN;
CompareRequest compareRequest = new CompareRequest(userDN, "uniqueMember", groupDN);
CompareResult compareResult = connection.compare(compareRequest);
if (compareResult.compareMatched()) {
// The user is a member of the group.
System.out.println("user is a member of group");
}
else {
// The user is not a member of the group.
System.out.println("user is not a member of group");
}
} catch (LDAPException e) {
e.printStackTrace();
}
return answ;
}
CREATING LDAP CONNECTOR
Connection with LDAP Server Established : true
LDAPException(resultCode=16 (no such attribute), errorMessage='NO_SUCH_ATTRIBUTE: failed for MessageType : COMPARE_REQUEST
Message ID : 1
Compare request
Entry : 'uid=mahesh.joshi,ou=users,o=wipro'
Attribute description : 'uniqueMember'
Attribute value : 'cn=Java,ou=groups,o=wiproorg.apache.directory.api.ldap.model.message.CompareRequestImpl#1d9123e1: null', diagnosticMessage='NO_SUCH_ATTRIBUTE: failed for MessageType : COMPARE_REQUEST
Message ID : 1
Compare request
Entry : 'uid=mahesh.joshi,ou=users,o=wipro'
Attribute description : 'uniqueMember'
Attribute value : 'cn=Java,ou=groups,o=wiproorg.apache.directory.api.ldap.model.message.CompareRequestImpl#1d9123e1: null')
at com.unboundid.ldap.sdk.LDAPConnection.compare(LDAPConnection.java:2236)
at com.LdapServiceImpl.isUserMemberOfGroup(LdapServiceImpl.java:380)
at com.App.main(App.java:102)
But running this method I am getting error in console as shown above. While I am able to check user and group existence individually.But checking them in a single query operation is still not possible. Any suggests in this regard would be a great help.
Apparently there is 'NO_SUCH_ATTRIBUTE' of 'uniqueMember' within ApacheDS.
LDAPException(resultCode=16 (no such attribute), errorMessage='NO_SUCH_ATTRIBUTE: failed for MessageType : COMPARE_REQUEST
Message ID : 1
Compare request
Entry : 'uid=mahesh.joshi,ou=users,o=wipro'
Attribute description : 'uniqueMember'
Try using 'member' rather than 'uniqueMember'.
WORKING Example:
public static void main(String[] args)
{
LDAPConnection connection = new LDAPConnection();
try
{
connection.connect("localhost", 10389);
}
catch (LDAPException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String attributeName = "uniqueMember";
String assertionValue = "uid=mahesh.joshi,ou=users,ou=sevenSeas,dc=example,dc=com";
String entryDN = "cn=Java,ou=groups,ou=sevenSeas,dc=example,dc=com";
CompareRequest compareRequest = new CompareRequest(entryDN, attributeName, assertionValue);
CompareResult compareResult = null;
try
{
compareResult = connection.compare(compareRequest);
if (compareResult.compareMatched())
{
System.out.println("The user: " + assertionValue + " is a member of the group: " + entryDN);
}
else
{
System.out.println("The user: " + assertionValue + " is NOT a member of the group: " + entryDN);
}
}
catch (LDAPException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Setup an example as closely as I could to your scenario.
-jim
I am trying to update nickname of a contact but not able to do so.
Below is the code which I have written
ArrayList<android.content.ContentProviderOperation> ops = new ArrayList<android.content.ContentProviderOperation>();
String selectArgs1 = Data.CONTACT_ID + " = ? AND " + Data.MIMETYPE + " = ? ";
String[] selectArgs2 = new String[]{ContactId, "vnd.android.cursor.item/nickname"};
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withSelection(selectArgs1, selectArgs2)
.withValue(ContactsContract.CommonDataKinds.Nickname.NAME, nickname)
.build());
ContentProviderResult [] cpResArr = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
int j=cpResArr.length;
System.out.println(j);
Toast.makeText(getApplicationContext(), "value is updated", Toast.LENGTH_LONG).show();**
I got it worked, below is the piece of code which worked for me.
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, ContactId)
.withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
.withValue(Nickname.NAME, "Sister")
.withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
.withValue(Nickname.LABEL, "Sister")
.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
We need to obtain builder object and than add it to arraylist before calling applybatch.
Refer the following link for further info: http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Nickname.html