/** * */ 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 = "
\"Rufezeichen\"  " + error + "
"; } form = loadForm(physical, familyName, givenName, dateOfBirth, streetName, buildingNumber, unit, postalCode, municipality, cbFullName, cbIdentificationType, cbIdentificationValue, error); if (form == null) { return null; } } else { return ""; // everything is ok } } catch (Exception e) { //e.printStackTrace(); Logger.info(e); return null; } return form; } /** * Loads the empty user input form and replaces tag occurences with given variables * * @param physical * @param familyName * @param givenName * @param dateOfBirth * @param streetName * @param buildingNumber * @param unit * @param postalCode * @param municipality * @param cbFullName * @param cbIdentificationType * @param cbIdentificationValue * @param errorText * @return */ private String loadForm( boolean physical, String familyName, String givenName, String dateOfBirth, String streetName, String buildingNumber, String unit, String postalCode, String municipality, String cbFullName, String cbIdentificationType, String cbIdentificationValue, String errorText) { String form = ""; try { String fileName = parepConfiguration.getInputProcessorTemplate(representationID); InputStream instream = null; File file = new File(fileName); if (file.exists()) { //if this resolves to a file, load it instream = new FileInputStream(fileName); } else { fileName = parepConfiguration.getFullDirectoryName(fileName); if (fileName.startsWith("file:\\")) fileName = fileName.substring(6); file = new File(fileName); if (file.exists()) { //if this resolves to a file, load it instream = new FileInputStream(fileName); } else { //else load a named resource in our classloader. instream = this.getClass().getResourceAsStream(parepConfiguration.getInputProcessorTemplate(representationID)); if (instream == null) { Logger.error("Form Prozessor Input Template \"" + fileName + "\" fehlt"); return null; } } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); ParepUtils.dumpInputOutputStream(instream, bos); form = bos.toString("UTF-8"); } catch(Exception e) { Logger.error("Fehler beim Einlesen des Input-Templates.", e); } if (!ParepUtils.isEmpty(form)) { boolean cbEnabled = parepConfiguration.isRepresentingCorporateParty(representationID); boolean physEnabled = parepConfiguration.isRepresentingPhysicalParty(representationID); boolean reducedSelection = (!physEnabled || !cbEnabled); if (reducedSelection) { physical = !cbEnabled;//wird somit umgesetzt falls jur. Person nicht vetretbar } if (ParepUtils.isEmpty(dateOfBirth)) dateOfBirth = "JJJJ-MM-TT"; form = ParepUtils.replaceAll(form, "", rpGivenName); form = ParepUtils.replaceAll(form, "", rpFamilyName); form = ParepUtils.replaceAll(form, "", rpDateOfBirth.substring(0,4)); form = ParepUtils.replaceAll(form, "", rpDateOfBirth.substring(5,7)); form = ParepUtils.replaceAll(form, "", rpDateOfBirth.substring(8,10)); //darf zw. phys. und jur. Person gewählt werden: //form = replaceAll(form, "seldisabled=\"\"", reducedSelection ? "disabled=\"true\"" : ""); form = ParepUtils.replaceAll(form, "physdisabled=\"\"", physEnabled ? "" : "disabled=\"true\""); form = ParepUtils.replaceAll(form, "physselected=\"\"", physical ? "checked=\"checked\"" : ""); form = ParepUtils.replaceAll(form, "", givenName); form = ParepUtils.replaceAll(form, "", familyName); form = ParepUtils.replaceAll(form, "", dateOfBirth.substring(0,4).trim()); form = ParepUtils.replaceAll(form, "", dateOfBirth.substring(5,7).trim()); form = ParepUtils.replaceAll(form, "", dateOfBirth.substring(8,10).trim()); form = ParepUtils.replaceAll(form, "", streetName); form = ParepUtils.replaceAll(form, "", buildingNumber); form = ParepUtils.replaceAll(form, "", unit); form = ParepUtils.replaceAll(form, "", postalCode); form = ParepUtils.replaceAll(form, "", municipality); form = ParepUtils.replaceAll(form, "cbdisabled=\"\"", cbEnabled ? "" : "disabled=\"true\""); form = ParepUtils.replaceAll(form, "", cbFullName); form = ParepUtils.replaceAll(form, "cbseldisabled=\"\"", cbEnabled ? "" : "disabled=\"disabled\""); form = ParepUtils.replaceAll(form, "cbselected=\"\"", physical ? "" : "checked=\"checked\""); form = ParepUtils.replaceAll(form, "fnselected=\"\"", cbIdentificationType.equals("urn:publicid:gv.at:baseid+XFN") ? "selected=\"selected\"" : ""); form = ParepUtils.replaceAll(form, "vrselected=\"\"", cbIdentificationType.equals("urn:publicid:gv.at:baseid+XVR") ? "selected=\"selected\"" : ""); form = ParepUtils.replaceAll(form, "ersbselected=\"\"", cbIdentificationType.equals("urn:publicid:gv.at:baseid+XERSB") ? "selected=\"selected\"" : ""); form = ParepUtils.replaceAll(form, "", cbIdentificationValue); form = ParepUtils.replaceAll(form, "", errorText); } return form; } }