/** * */ package at.gv.egovernment.moa.id.auth.validator.parep; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Map; import at.gv.egovernment.moa.id.auth.validator.parep.client.szrgw.CreateMandateRequest; import at.gv.egovernment.moa.id.auth.validator.parep.client.szrgw.SZRGWClientException; import at.gv.egovernment.moa.id.auth.validator.parep.config.ParepConfiguration; import at.gv.egovernment.moa.logging.Logger; /** * Implements the standard party representation infobox validator input processor * * @author Peter Danner * */ public class ParepInputProcessorImpl implements ParepInputProcessor{ /** the requested representation ID (currently * or OID) */ private String representationID; /** contains the configuration of the owning validator */ private ParepConfiguration parepConfiguration; /** Family name of the representative */ private String rpFamilyName; /** Given name of the representative */ private String rpGivenName; /** The representatives date of birth */ private String rpDateOfBirth; /** The current CreateMandateRequest to the SZR-gateway */ private CreateMandateRequest request; /* * (non-Javadoc) * * @see at.gv.egovernment.moa.id.auth.validator.parep.ParepInputProcessor#initialize(String, ParepConfiguration, String, String, String, CreateMandateRequest) */ public void initialize( String representationID, ParepConfiguration parepConfiguration, String rpFamilyName, String rpGivenName, String rpDateOfBirth, CreateMandateRequest request) { // Initialization this.representationID = representationID; this.parepConfiguration = parepConfiguration; this.rpFamilyName = rpFamilyName; this.rpGivenName = rpGivenName; this.rpDateOfBirth = rpDateOfBirth; this.request = request; } /* * (non-Javadoc) * * @see at.gv.egovernment.moa.id.auth.validator.parep.ParepInputProcessor#start(boolean, String, String, String, String, String, String, String, String, String, String, String) */ public String start( boolean physical, String familyName, String givenName, String dateOfBirth, String streetName, String buildingNumber, String unit, String postalCode, String municipality, String cbFullName, String cbIdentificationType, String cbIdentificationValue) { // Load the form String form = loadForm( physical, familyName, givenName, dateOfBirth, streetName, buildingNumber, unit, postalCode, municipality, cbFullName, cbIdentificationType, cbIdentificationValue, ""); try { request.setMandator(familyName, givenName, dateOfBirth, postalCode, municipality, streetName, buildingNumber, unit, physical, cbFullName, cbIdentificationType, cbIdentificationValue); } catch (SZRGWClientException e) { //e.printStackTrace(); Logger.info(e); return null; } return form; } /* * (non-Javadoc) * * @see at.gv.egovernment.moa.id.auth.validator.parep.ParepInputProcessor#validate(Map, String) */ public String validate(Map parameters, String extErrortext) { // Process the gotten parameters String form = null; boolean formNecessary = false; if (!ParepUtils.isEmpty(extErrortext)) formNecessary = true; String locErrortext = "Folgende Parameter fehlen: "; String familyName = (String) parameters.get("familyname_"); if (null == familyName) familyName =""; String givenName = (String) parameters.get("givenname_"); if (null == givenName) givenName =""; boolean physical = "true".equals(parameters.get("physical_")); String dobday = (String) parameters.get("dobday_"); if (null!=dobday && dobday.equalsIgnoreCase("TT")) dobday=""; String dobmonth = (String) parameters.get("dobmonth_"); if (null!=dobmonth && dobmonth.equalsIgnoreCase("MM")) dobmonth=""; String dobyear = (String) parameters.get("dobyear_"); if (null!=dobyear && dobyear.equalsIgnoreCase("JJJJ")) dobyear=""; String dateOfBirth = ""; dobyear = (" ".substring(0, 4-dobyear.length()) + dobyear); dobmonth = (" ".substring(0, 2-dobmonth.length()) + dobmonth); dobday = (" ".substring(0, 2-dobday.length()) + dobday); dateOfBirth = dobyear + "-" + dobmonth + "-" + dobday; String cbFullName = (String) parameters.get("fullname_"); if (null == cbFullName) cbFullName =""; String cbIdentificationType = (String) parameters.get("cbidentificationtype_"); if (null == cbIdentificationType) cbIdentificationType =""; String cbIdentificationValue = (String) parameters.get("cbidentificationvalue_"); if (null == cbIdentificationValue) cbIdentificationValue =""; String postalCode = (String) parameters.get("postalcode_"); if (null == postalCode) postalCode =""; String municipality = (String) parameters.get("municipality_"); if (null == municipality) municipality =""; String streetName = (String) parameters.get("streetname_"); if (null == streetName) streetName =""; String buildingNumber = (String) parameters.get("buildingnumber_"); if (null == buildingNumber) buildingNumber =""; String unit = (String) parameters.get("unit_"); if (null == unit) unit =""; if (physical) { if (ParepUtils.isEmpty(familyName)) { formNecessary = true; locErrortext = locErrortext + "Familienname"; } if (ParepUtils.isEmpty(givenName)) { formNecessary = true; if (!locErrortext.endsWith(": ")) locErrortext = locErrortext + ", "; locErrortext = locErrortext + "Vorname"; } // Auf existierendes Datum prüfen SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); format.setLenient(false); // Wir wollen keine künstliche Pareserintelligenz, nur Datum prüfen try { format.parse(dateOfBirth); } catch(ParseException pe) { formNecessary = true; if (!locErrortext.endsWith("fehlen: ")) locErrortext = locErrortext + ", "; locErrortext = locErrortext + "korrektes Geburtsdatum"; } } else { if (ParepUtils.isEmpty(cbFullName) || ParepUtils.isEmpty(cbIdentificationType) || ParepUtils.isEmpty(cbIdentificationValue)) { formNecessary = true; if (ParepUtils.isEmpty(cbFullName)) { locErrortext = locErrortext + "Name der Organisation"; } if (ParepUtils.isEmpty(cbIdentificationType)) { if (!locErrortext.endsWith("fehlen: ")) locErrortext = locErrortext + ", "; locErrortext = locErrortext + "Auswahl des Registers"; } if (ParepUtils.isEmpty(cbIdentificationValue)) { if (!locErrortext.endsWith("fehlen: ")) locErrortext = locErrortext + ", "; locErrortext = locErrortext + "Ordnungsnummer im ausgewählten Register"; } } } try { request.setMandator(familyName, givenName, dateOfBirth, postalCode, municipality, streetName, buildingNumber, unit, physical, cbFullName, cbIdentificationType, cbIdentificationValue); if (formNecessary) { // Daten noch nicht vollständig oder anderer Fehler if (locErrortext.endsWith("fehlen: ")) locErrortext =""; String error = ""; if (!ParepUtils.isEmpty(extErrortext)) { error = extErrortext; if (!ParepUtils.isEmpty(locErrortext)) error = error + "; "; } if (!ParepUtils.isEmpty(locErrortext)) error = error + locErrortext; if (!ParepUtils.isEmpty(error)) { error = "