From 05f8b895f82b67637e5758810139c30c29be9f1a Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Fri, 21 Mar 2014 08:34:53 +0100 Subject: refactored eHVD plugin to use jaxb --- .../stork2/EHvdAttributeProviderPlugin.java | 67 +++++++--------------- 1 file changed, 22 insertions(+), 45 deletions(-) (limited to 'id/server/idserverlib') diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java index a257474e3..5e9d9404c 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java @@ -8,8 +8,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPConnection; @@ -18,16 +18,6 @@ import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPPart; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - import at.gv.egovernment.moa.id.auth.builder.BPKBuilder; import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; import at.gv.egovernment.moa.id.auth.exception.MOAIDException; @@ -36,6 +26,8 @@ import at.gv.egovernment.moa.logging.Logger; import eu.stork.peps.auth.commons.IPersonalAttributeList; import eu.stork.peps.auth.commons.PersonalAttribute; import eu.stork.peps.auth.commons.PersonalAttributeList; +import eu.stork.peps.complex.attributes.IsHealthCareProfessionalType; +import eu.stork.peps.complex.attributes.ObjectFactory; /** * Fetches the attribute IsHealthcareProfessional from the BAGDAD SOAP service @@ -141,7 +133,7 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider { SOAPElement resultElement = (SOAPElement) responseElement.getChildElements().next(); // collect all info in a map - Iterator it = resultElement.getChildElements(); + Iterator it = resultElement.getChildElements(); Map collection = new HashMap(); while (it.hasNext()) { SOAPElement current = (SOAPElement) it.next(); @@ -168,43 +160,29 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider { acquiredAttribute = new PersonalAttribute("isHealthCareProfessional", false, new ArrayList(), "NotAvailable"); } else { // go on and parse the data + IsHealthCareProfessionalType result = new IsHealthCareProfessionalType(); + result.setNameOfOrganisation(collection.get("NameOfOrganisation")); - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - - // create the root element - Element root = doc.createElement("isHealthCareProfessional"); - doc.appendChild(root); - - Element orgname = doc.createElement("nameOfOrganisation"); - orgname.appendChild(doc.createTextNode(collection.get("NameOfOrganisation"))); - root.appendChild(orgname); - - Element type = doc.createElement("HCP"); - // TODO fix value mapping if (collection.get("Type").equals("Medical doctor")) - type.appendChild(doc.createTextNode("D")); - root.appendChild(type); + result.setHCPType("D"); + else + result.setHCPType("?"); - Element specialization = doc.createElement("specialisation"); if (collection.get("Specialization").contains("Arzt für Allgemeinmedizin")) - specialization.appendChild(doc.createTextNode("GP")); - root.appendChild(specialization); - - Element aqaa = doc.createElement("AQAA"); - aqaa.appendChild(doc.createTextNode("4")); - root.appendChild(aqaa); + result.setSpecialisation("GP"); + else + result.setSpecialisation("??"); - // get string from dom tree - Source source = new DOMSource(doc); - StringWriter out = new StringWriter(); - Result result = new StreamResult(out); - - TransformerFactory tFactory = TransformerFactory.newInstance(); - Transformer transformer = tFactory.newTransformer(); - transformer.transform(source, result); + result.setAQAA(4); + final Marshaller m = JAXBContext.newInstance(IsHealthCareProfessionalType.class).createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + StringWriter stringWriter = new StringWriter(); + m.marshal(new ObjectFactory().createIsHealthCareProfessional(result), stringWriter); + ArrayList value = new ArrayList(); - value.add(out.toString()); + value.add(stringWriter.toString()); acquiredAttribute = new PersonalAttribute("isHealthCareProfessional", false, value, "Available"); } @@ -212,12 +190,11 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider { // pack and return the result PersonalAttributeList result = new PersonalAttributeList(); result.add(acquiredAttribute); - + // add stork id for verification ArrayList value = new ArrayList(); value.add(new BPKBuilder().buildStorkbPK(moasession.getIdentityLink().getIdentificationValue(), spCountryCode)); result.add(new PersonalAttribute("eIdentifier", false, value, "Available")); - return result; } catch (Exception e) { -- cgit v1.2.3