Filtering dates with the SOAP API

Friday, October 30, 2015
Avatar
We are considering to use the SpiraTest SOAP API for a Java application.
I have set up a small Java project for testing the capabilities of the API. I am stuck by filtering Incidents by dates like CreationDate, LastUpdateDate, etc. According to this site it should work: https://www.inflectra.com/Support/KnowledgeBase/KB88.aspx

The central part of my code is:

ObjectFactory objectFactory = new ObjectFactory();
           
            RemoteFilter filter1 = objectFactory.createRemoteFilter();
            filter1.setPropertyName(objectFactory.createRemoteIncidentDescription("CreationDate"));

            // create calendas and set them as start and end date
            javax.xml.datatype.XMLGregorianCalendar calStart = new com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl();

            Calendar c = Calendar.getInstance();
            c.add(Calendar.DAY_OF_YEAR, -50);
            calStart.setYear(c.get(Calendar.YEAR));
            calStart.setMonth(c.get(Calendar.MONTH));
            calStart.setDay(c.get(Calendar.DAY_OF_MONTH));
           
            calStart.setTime(c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
            System.out.println(calStart.toGregorianCalendar().getTime());

            javax.xml.datatype.XMLGregorianCalendar calEnd = new com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl();
            Calendar c2 = Calendar.getInstance();
            calEnd.setYear(c2.get(Calendar.YEAR));
            calEnd.setMonth(c2.get(Calendar.MONTH));
            calEnd.setDay(c2.get(Calendar.DAY_OF_MONTH));
           
            calEnd.setTime(c2.get(Calendar.HOUR), c2.get(Calendar.MINUTE), c2.get(Calendar.SECOND));
            System.out.println(calEnd.toGregorianCalendar().getTime());
                                 
            DateRange dr = objectFactory.createDateRange();
            dr.setStartDate(objectFactory.createDateRangeStartDate(calStart));
            dr.setEndDate(objectFactory.createDateRangeEndDate(calEnd));
            dr.setConsiderTimes(true);

            JAXBElement<DateRange> drElement = objectFactory.createDateRange(dr);
            filter1.setDateRangeValue(drElement);
           
             // add filter to a filter array
            ArrayOfRemoteFilter filters = objectFactory.createArrayOfRemoteFilter();
            filters.getRemoteFilter().add(filter1);

            // Create RemoteSort
            RemoteSort sort = objectFactory.createRemoteSort();
            sort.setPropertyName(objectFactory.createRemoteFilterPropertyName("IncidentId"));
            sort.setSortAscending(true);
   
            ArrayOfRemoteIncident incidents = soap.incidentRetrieve(filters, sort, 1, 1000);
            List<RemoteIncident> inc = incidents.getRemoteIncident();
            // ... loop over the incidents, print them to console

It throws no exceptions, but doesn't filter anything, eighter... :(

Can someone with experience help me?

Thanks,
Zoltan

2 Replies
Wednesday, November 4, 2015
Avatar
re: itkdtk Friday, October 30, 2015
Hi Zoltan

The following doesn't look correct:

            filter1.setPropertyName(objectFactory.createRemoteIncidentDescription("CreationDate"));

the property name should be just "CreationDate"

If that doesn't work, I'd log a help desk ticket.

Regards

Adam
Thursday, November 5, 2015
Avatar
re: inflectra.david Wednesday, November 4, 2015
Hi Adam,

I suspected that line myself, too...

Your suggestion did not work, because the method setPropertyName() expects a JAXBElement<String> as parameter, it does not accept plain strings. I have already tried a couple of methods in the objectFactory that return a JAXBElement<String>, without luck.

After your answer I looked again, and I found the method createRemoteFilterPropertyName(), and that works! Its name is also pretty straight forward, but the objectFactory has hundreds of methods, I just missed it...

So the complete line is:
   filter1.setPropertyName(objectFactory.createRemoteFilterPropertyName("CreationDate"));

It seems the different filter parameter require different creator-methods. Too bad they are not documented, could have saved us some time...

But thank you, you led me to the solution at the end :)

Regards,
Zoltan

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Friday, October 30, 2015
  • Last Reply: Thursday, November 5, 2015
  • Replies: 2
  • Views: 11699