Problem setting list and multilist values using Agile PLM 9.3.6 core web services
Hi All,
I am facing problem while setting list and multi list values using Agile 9.3.6 core web services.
The below sample code snippet to update an agile object
public void testUpdateOOBWS() throws ParserConfigurationException, JAXBException{
UpdateObjectRequestType updateObjectRequestType = new UpdateObjectRequestType();
AgileUpdateObjectRequest agileUpdateObjectRequest = new AgileUpdateObjectRequest();
agileUpdateObjectRequest.setClassIdentifier(“Document”);
agileUpdateObjectRequest.setObjectNumber(“*******”);
List<Element> list=new ArrayList<Element>();
AgileRowType agileRow = new AgileRowType();
AgileListEntryType listEntry = new AgileListEntryType();
SelectionType multiSelect = new SelectionType();
// multiSelect[0].setId(150664);
multiSelect.setApiName(“valueAddedProductVAP”);
multiSelect.setValue(“Android”);
listEntry.getSelection().addAll(Arrays.asList(multiSelect));
Element el_projectState = createMessageElement(“valueAddedProductVAP”, listEntry);
// el_projectState.setAttribute(“attributeId”,”146245″);
agileRow.getAny().add(el_projectState);
agileUpdateObjectRequest.setData(agileRow);
updateObjectRequestType.getRequests().addAll(Arrays.asList(agileUpdateObjectRequest));
try {
// updateObjectRequestType.setDisableAllWarnings(true);
UpdateObjectResponseType updateResponse = businessObjServiceLocator()
.updateObject(updateObjectRequestType);
System.out.println(updateResponse.getResponses());
}
catch(Exception e){
e.printStackTrace();
}
}
private Element createMessageElement(String tagName, AgileListEntryType agileListEntryType) {
Element element = createMessageElement(tagName);
return marshal(element,agileListEntryType);
}
public static Element createMessageElement(String tagName) {
Document document = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
document = docBuilder.newDocument();
} catch (ParserConfigurationException e) {
return null;
}
return document.createElement(tagName);
}
public static Element marshal(Element domElement,AgileListEntryType agileListEntryType) {
JAXBContext jc;
try {
jc = JAXBContext.newInstance(AgileListEntryType.class);
Marshaller marshaller = jc.createMarshaller();
//marshaller.marshal(agileListEntryType, domElement);
JAXBElement<AgileListEntryType> jaxbEl = new JAXBElement<AgileListEntryType>(new QName(“”,domElement.getNodeName()),
AgileListEntryType.class, agileListEntryType);
marshaller.marshal(jaxbEl, domElement);
domElement = (Element) domElement.getFirstChild();
} catch (JAXBException e) {
e.printStackTrace();
}
//domElement.setAttributeNS(“http://xmlns.oracle.com/AgileObjects/Core/Common/V1”, “type”, “AgileListEntryType”);
domElement.setAttribute(“xmlns:xsi”,”http://xmlns.oracle.com/AgileObjects/Core/Common/V1″);
domElement.setAttribute(“xsi:type”, “AgileListEntryType”);
return domElement;
}
Few things which you can try
1) Don’t use Arrays.asList instead put a normal array. I had a similar problem and it worked after I removed Arrays.asList
2) I used the below snippet code for list updation
for(String indListVal:listVals) {
selectionType[count] = new SelectionType();
selectionType[count].setValue(indListVal.trim());
count++;
}
listType.setSelection(selectionType);
MessageElement messages_list = new MessageElement(namespaceUri, listAttribName);
messages_list.addAttribute(namespaceUri, SchemaConstants.attributeId.getValue(), baseid);
messages_list.addAttribute(XSIPREFIX, COMMONNAMESPACEURI, SchemaConstants.type.getValue(), “AgileListEntryType”);
messages_list.setObjectValue(listType);
But MessageElement is no longer used in Agile 9.3.6 and this is now replaced with Element of DOM API.
The below JAXB marshaller is used to marshal java object to xml to set list type values.
JAXBContext jc;
jc = JAXBContext.newInstance(AgileListEntryType.class);
Marshaller marshaller = jc.createMarshaller();
JAXBElement<AgileListEntryType> jaxbEl = new JAXBElement<AgileListEntryType>(new QName(“”,domElement.getNodeName()),
AgileListEntryType.class, agileListEntryType);
marshaller.marshal(jaxbEl, domElement);
domElement = (Element) domElement.getFirstChild();
Oh.. ok.. the previous code which I gave was for 933. The below snippet is the one which we use for 935 instance…
messages_list = createMessageElement(listAttribName);
JAXBContext jc = JAXBContext.newInstance(AgileListEntryType.class);
Marshaller marshaller = jc.createMarshaller();
JAXBElement<AgileListEntryType> jaxbEl = new JAXBElement<AgileListEntryType>(
new QName(“”, messages_list.getNodeName()), AgileListEntryType.class, listType);
marshaller.marshal(jaxbEl, messages_list);
messages_list = (Element) messages_list.getFirstChild();
messages_list.setAttribute(“attributeId”, baseid);
messages_list.setAttribute(“xmlns:xsi”, COMMONNAMESPACEURI);
messages_list.setAttribute(“xsi:type”, “AgileListEntryType”);