SiteServiceParticipation getOneSiteServiceParticipationForHousehold(Household household) {
// used to ultimately get a program id for the first column of CSV2, not sure if it has any other use
// makes the assumption that a household ID is bound to a single program. Big assumption.
// I think in Rosie, a household is attributed to only one agency. Not in HUD HMIS XML where IDs link households to agency in a more dynamic way.
SiteServiceParticipation siteServiceParticipationElement = null;
JAXBContext jc = null;
InputStream zis = openXMLStream(hudXMLURL);
XMLStreamReader xmlr8 = null;
String searchHHID = household.getHouseholdID().getIDStr();
log.info("searching for siteserviceparticipations with household ID: " + searchHHID);
try {
// set up a StAX reader
xmlr8 = xmlif.createXMLStreamReader(zis);
} catch (Exception e) {
log.info("exception caught creating StAX stream " + e.toString());
}
//Use StAX to retrieve serviceID (proxy for agencyID) from the SiteService
try {
jc = JAXBContext.newInstance(SiteServiceParticipation.class);
} catch (JAXBException e) {
log.info("JAXB SiteServiceParticipation.class context problem: " + e.toString());
}
try {
unmarshaller = jc.createUnmarshaller();
} catch (JAXBException e) {
log.info("Problem unmarshalling SiteServiceParticipation context: " + e.toString());
}
try {
while(xmlr8.hasNext()) {
xmlr8.next();
if (xmlr8.isStartElement()) {
//System.out.println("local name is: " + xmlr.getLocalName());
if (xmlr8.getLocalName().equals("SiteServiceParticipation")) {
xmlr8.require(XMLStreamConstants.START_ELEMENT, null, "SiteServiceParticipation");
JAXBElement<SiteServiceParticipation> siteServiceParticipationJAXB = unmarshaller.unmarshal(xmlr8, SiteServiceParticipation.class);
siteServiceParticipationElement = (SiteServiceParticipation)siteServiceParticipationJAXB.getValue();
//Get only this household's SiteServiceParticipations
try {
String hhid = siteServiceParticipationElement.getHouseholdID().getIDStr();
if (hhid != null && !hhid.isEmpty()) {
if (hhid.equals(searchHHID)) {
log.info("siteServiceParticipationElement.getHouseholdID().getIDStr is a match for household: " + searchHHID);
log.info("Found an ssp with id: " + siteServiceParticipationElement.getSiteServiceParticipationID().getIDNum().toString() + " for household:" + searchHHID);
break;
} else {
log.info("siteServiceParticipationElement's hhid " + hhid + " is not a match for household: " + searchHHID);
}
} else {