It's all about the answers!

Ask a question

Problem while reading custom attribute values from work item


Dashrath Kale (1542423) | asked Dec 10 '10, 7:55 a.m.
Hi,

We can fetch custom attributes values with below code using RTC client libraries:



		for (IAttributeHandle attribute1 : customeAttributes) {


IAttribute attribute = workItemClient.getAuditableCommon()
.resolveAuditable(attribute1, IAttribute.FULL_PROFILE,
monitor);



System.out.println("Attribute type : "
+ attribute.getAttributeType());

if (attribute.getAttributeType().equals("mediumString")) {
System.out.println("customAttribute name :"
+ attribute.getDisplayName() + ", value : "
+ itemToBeModified.getValue(attribute));

if ("Product Team Name".equals(attribute.getDisplayName())) {

teamname = (String) itemToBeModified
.getValue(attribute);
}
}

if (!attribute.getAttributeType().equals("mediumString")
&& !attribute.getAttributeType().equals(
"contributorList")) {
IWorkItemCommon workItemCommon = (IWorkItemCommon) teamRepository
.getClientLibrary(IWorkItemCommon.class);

IAuditableCommon auditableCommon = workItemCommon
.getAuditableCommon();

IEnumeration enumeration = workItemCommon
.resolveEnumeration(attribute, monitor);

ILiteral literal = enumeration
.findEnumerationLiteral((Identifier) itemToBeModified
.getValue(attribute));

String name = literal.getName();
System.out.println("name:" + name);
System.out.println("attribute details: "
+ attribute);

if ("Group Name".equals(attribute.getDisplayName())) {
groupname = name;

}
if ("SCM Region".equals(attribute.getDisplayName())) {
scmregion = name;
}
}


if (attribute.getAttributeType().equals("contributorList")) {

IAuditableClient auditableClient = (IAuditableClient) teamRepository
.getClientLibrary(IAuditableClient.class);
List<IContributorHandle> handles = (List<IContributorHandle>) itemToBeModified
.getValue(attribute);
List<IContributor> users = auditableClient
.resolveAuditables(handles,
ItemProfile.CONTRIBUTOR_DEFAULT, monitor);
System.out.println("Display Name : "
+ attribute.getDisplayName());
if ("Team Members".equals(attribute.getDisplayName())) {

for (Object object1 : users) {
IContributor contributor = (IContributor) object1;
teamMemberList.add(contributor);
}
}
if ("Build Engineers".equals(attribute.getDisplayName())) {

for (Object object1 : users) {
IContributor contributor = (IContributor) object1;
buildEngineerList.add(contributor);
}
}
if ("SCM Administrators"
.equals(attribute.getDisplayName())) {

for (Object object1 : users) {
IContributor contributor = (IContributor) object1;
scmAdminList.add(contributor);
}
}

}
}


but when using the service side RTC services we can't fetch the same custom attribute values (except custom atrribute "Product Team Name") , below is our server side code:


List<IAttributeHandle> customeAttributes = workingCopy
.getCustomAttributes();

for (IAttributeHandle attribute1 : customeAttributes) {

IAttribute attribute = wis
.getAuditableCommon()
.resolveAuditable(attribute1,
IAttribute.FULL_PROFILE,
monitor);

// get the value of attribute
// "Product Team Name"
if (attribute.getAttributeType().equals(
"mediumString")) {

if ("Product Team Name"
.equals(attribute
.getDisplayName())) {

teamname = (String) workingCopy
.getValue(attribute);

}
}

// get the values of attributes "Group Name"
// and
// "SCM Region"
if (!attribute.getAttributeType().equals(
"mediumString")
&& !attribute.getAttributeType()
.equals("contributorList")) {
IWorkItemCommon workItemCommon = (IWorkItemCommon) wis
.getWorkflowManager();

IEnumeration enumeration = workItemCommon
.resolveEnumeration(attribute,
monitor);

ILiteral literal = enumeration
.findEnumerationLiteral((Identifier) workingCopy
.getValue(attribute));
String name = literal.getName();
System.out.println("name:" + name);

if ("Group Name".equals(attribute
.getDisplayName())) {

groupname = name;

}
if ("SCM Region".equals(attribute
.getDisplayName())) {

scmregion = name;
}
}
// get the values of attributes
// "Build Engineers,Team Members and Product Administrators"
if (attribute.getAttributeType().equals(
"contributorList")) {

IWorkItemCommon workItemCommon = (IWorkItemCommon) wis
.getWorkflowManager();
IAuditableCommon auditableCommon = workItemCommon
.getAuditableCommon();
List<IContributorHandle> handles = (List<IContributorHandle>) workingCopy
.getValue(attribute);
List<IContributor> users = auditableCommon
.resolveAuditables(
handles,
ItemProfile.CONTRIBUTOR_DEFAULT,
monitor);
for (Object object1 : users) {
IContributor contributor = (IContributor) object1;
}
}

}
}


Is any one has any information/solution on this issue?

4 answers



permanent link
Patrick Streule (4.9k21) | answered Dec 14 '10, 8:23 a.m.
JAZZ DEVELOPER
Is any one has any information/solution on this issue?

In general, you have access to the same core API on the server and the
client. Could you elaborate more specifically on what didn't work?

On a side note, I would keep the code free of references to attribute
display names. They can change. I'd use the attribute identifier instead.

--
Regards,
Patrick
RTC Work Item Component Lead

permanent link
Dashrath Kale (1542423) | answered Dec 15 '10, 2:39 a.m.
Is any one has any information/solution on this issue?

In general, you have access to the same core API on the server and the
client. Could you elaborate more specifically on what didn't work?

On a side note, I would keep the code free of references to attribute
display names. They can change. I'd use the attribute identifier instead.

--
Regards,
Patrick
RTC Work Item Component Lead


Hi Patrick

Thanks for your information.

As mentioned earlier I can fetch the values of all the custom attributes using client side API's but can't fetch the same custom attribute values from the server side operation participant with the code given earlier.

Now I tried to get the values using attribute identifier as suggested by you and below is the my code:



List<IAttributeHandle> customeAttributes = workingCopy
.getCustomAttributes();

for (IAttributeHandle attribute1 : customeAttributes) {
System.out
.println("we are in -----------> for loop ");

IAttribute attribute = wis
.getAuditableCommon()
.resolveAuditable(attribute1,
IAttribute.FULL_PROFILE,
monitor);
IWorkItemCommon workItemCommon = (IWorkItemCommon) getService(IWorkItemCommon.class);

if (attribute.getIdentifier().equals(
"product_team_name")) {

teamname = (String) workingCopy
.getValue(attribute);
System.out.println("teamname:"
+ teamname);
}

if (attribute.getIdentifier().equals(
"group_name")
|| attribute.getIdentifier()
.equals("scm_region")) {

IEnumeration enumeration = workItemCommon
.resolveEnumeration(attribute,
monitor);
System.out.println("enumeration:"
+ enumeration);

ILiteral literal = enumeration
.findEnumerationLiteral((Identifier) workingCopy
.getValue(attribute));
System.out.println("literal:"
+ enumeration);

String name = literal.getName();

if ("group_name".equals(attribute
.getIdentifier())) {

groupname = name;
System.out.println("groupname:"
+ groupname);
}

if ("scm_region".equals(attribute
.getIdentifier())) {

scmregion = name;

System.out.println("scmregion:"
+ scmregion);

}
}

}


This code just print "we are in -----------> for loop" but does not print the values of cutom attributes.

permanent link
Monica Alarcón (11) | answered Aug 30 '11, 4:11 p.m.
Hello,

Im trying to getValue of Approvals's attribute but I obtained "" (empty string) when my workItem has text in this field. The WI is of type Component.

Im trying this in the server side, RTC v 3.0.1, here is my code:


...
service = getService(IWorkItemServer.class);
IWorkItem copy = (IWorkItem) wi.getWorkingCopy();

for(IAttributeHandle att : copy.getCustomAttributes()){
ATT = (IAttribute) RIS.fetchItem(att, IRepositoryItemService.COMPLETE);
IAttribute attribute = service.getAuditableCommon().resolveAuditable(att,IAttribute.FULL_PROFILE,null);

if (ATT.getIdentifier().equalsIgnoreCase(parsedConfig.idAtributo2)){
System.out.println("entro al if, encontr un att!!");
result = (String) wi.getValue(ATT);
result2 = (String) copy.getValue(attribute);

if (!result.equals("") || !result2.equals("")){
...


result and result2 are both empty strings.

Any idea?

mnka

permanent link
Zbynek Vavros (2834) | answered Oct 31 '11, 5:52 a.m.
Hello,

Im trying to getValue of Approvals's attribute but I obtained "" (empty string) when my workItem has text in this field. The WI is of type Component.

Im trying this in the server side, RTC v 3.0.1, here is my code:


...
service = getService(IWorkItemServer.class);
IWorkItem copy = (IWorkItem) wi.getWorkingCopy();

for(IAttributeHandle att : copy.getCustomAttributes()){
ATT = (IAttribute) RIS.fetchItem(att, IRepositoryItemService.COMPLETE);
IAttribute attribute = service.getAuditableCommon().resolveAuditable(att,IAttribute.FULL_PROFILE,null);

if (ATT.getIdentifier().equalsIgnoreCase(parsedConfig.idAtributo2)){
System.out.println("entro al if, encontr un att!!");
result = (String) wi.getValue(ATT);
result2 = (String) copy.getValue(attribute);

if (!result.equals("") || !result2.equals("")){
...


result and result2 are both empty strings.

Any idea?

mnka


Hi,

if anyone needs it this is how I do it and it works just fine:

List<IAttribute> attributes= auditableClient.resolveAuditables(workItemClient.findWorkItemById(id, IWorkItem.DEFAULT_PROFILE, null).getCustomAttributes(),IAttribute.FULL_PROFILE, null);

for(IAttribute attr : attributes) {
if(attr.getIdentifier().equals(attribute)) return attr.getValue(auditableClient, workItemClient.findWorkItemById(id, IWorkItem.DEFAULT_PROFILE, null), null);
}


Zbynek

Your answer


Register or to post your answer.