package nl.nijmegen.mule.agelimits;_x000D_
_x000D_
import java.time.LocalDate;_x000D_
import org.mule.api.MuleMessage;_x000D_
import org.mule.api.transformer.TransformerException;_x000D_
import org.mule.api.transport.PropertyScope;_x000D_
import org.mule.transformer.AbstractMessageTransformer;_x000D_
import org.apache.commons.logging.Log;_x000D_
import org.apache.commons.logging.LogFactory;_x000D_
_x000D_
public class calculateAgeLimits  extends AbstractMessageTransformer{_x000D_
	private static Log logger = LogFactory.getLog("nl.Nijmegen.brp.irma-api.calculateagelimits");_x000D_
		      _x000D_
		      _x000D_
		      @Override_x000D_
			public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {_x000D_
		    	 _x000D_
		    	//Zet geboortedatum_x000D_
			  		//String bDay = "20000000";_x000D_
			    	//String bDay =  message.getInvocationProperty("sv_geboortedatum");_x000D_
			    	String bDay = message.getProperty("sv_geboortedatum", PropertyScope.INVOCATION);_x000D_
			  		//Code uit elkaar halen op jaar, maand en dag		  		_x000D_
			    	int lengteBDay = bDay.length();_x000D_
					if (lengteBDay !=8) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");_x000D_
						_x000D_
					}		_x000D_
					//Code uit elkaar halen op jaar, maand en dag_x000D_
					String bYear = (bDay.substring(0,4));_x000D_
					String bMonth1=	bDay.substring(bDay.length() - 4);_x000D_
					String bMonth2 = (bMonth1.substring(0,2));_x000D_
					String bDag = bDay.substring(bDay.length() - 2);_x000D_
					_x000D_
					_x000D_
					//omzetten naar een int._x000D_
					int bYearInt = Integer.parseInt(bYear);_x000D_
					int bMonthInt = Integer.parseInt(bMonth2);_x000D_
					int bDagInt = Integer.parseInt(bDag);_x000D_
					logger.debug("jaar: " + bYearInt);_x000D_
					logger.debug("maand: " + bMonthInt);_x000D_
					logger.debug("dag: " + bDagInt);_x000D_
					_x000D_
					if (bYearInt ==0 || bYearInt <1850) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");_x000D_
					}_x000D_
					if (bMonthInt >12) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");		_x000D_
					}_x000D_
					if (bDagInt >31) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");		_x000D_
					}_x000D_
					_x000D_
					//als maand null is dan 1 juli invullen_x000D_
					if (bMonthInt == 0) {_x000D_
						bMonthInt = 1;_x000D_
						bMonthInt = 7;}_x000D_
					//als dag null is, dan waarde op 1 zetten en vervolgens naar laatste dag van de maand_x000D_
					if (bDagInt == 00) {_x000D_
_x000D_
						LocalDate noDay = LocalDate.of(bYearInt,bMonthInt,1);_x000D_
					    LocalDate end = noDay.withDayOfMonth(noDay.lengthOfMonth());_x000D_
					    int dayOfMonth = end.getDayOfMonth();_x000D_
					    bDagInt = dayOfMonth;_x000D_
					      }_x000D_
					if (bMonthInt == 2 & bDagInt == 29) {_x000D_
						bDagInt=28;_x000D_
					}_x000D_
_x000D_
					String resultString = "";_x000D_
					_x000D_
					//geboortedag bepalen_x000D_
					      LocalDate currentTime = LocalDate.now();_x000D_
					      LocalDate birthday = LocalDate.of(bYearInt,bMonthInt,bDagInt);_x000D_
					      logger.debug("Huidige datum: " + currentTime);_x000D_
					      logger.debug("Geboortedatum: " + birthday);_x000D_
					      _x000D_
					      _x000D_
					 //array maken met alle jaren erin      _x000D_
					      int[] jaar = new int[] {12,16,18,21,65};_x000D_
					      for (int i=0; i<jaar.length; i++)_x000D_
					      {_x000D_
					    	//door array lopen_x000D_
					    	//in de array current date bepalen_x000D_
					    	//jaren van currentdate afhalen_x000D_
					    	LocalDate date1 = LocalDate.now().minusYears(jaar[i]);_x000D_
					    	       _x000D_
					    	String resultValue;_x000D_
					    	String resultLabel;_x000D_
					    	//vergelijken geboortedatum en currentdate_x000D_
					        if(date1.isBefore(birthday)) {_x000D_
					        	resultValue = "No";_x000D_
					        }_x000D_
					        else {_x000D_
					    		resultValue = "Yes";_x000D_
					    		_x000D_
					        }_x000D_
					        //string met "isOver+jaar":'ja/nee'" vullen en concateren over loop heen_x000D_
					        resultLabel = "\"" +"over" + jaar[i];		                        _x000D_
					        resultString = resultString + resultLabel + "\"" +":"+ "\"" + resultValue + "\"" + ",";_x000D_
					      }_x000D_
					      	//resultString teruggeven_x000D_
					      resultString = "{" + resultString.substring(0, resultString.length()-1) +"}";_x000D_
					      resultString = "{"+ "\""+"ageLimits"+"\""+": " + resultString +"}";_x000D_
					      logger.debug("resultString: " + resultString);_x000D_
					return resultString;_x000D_
				_x000D_
			}_x000D_
_x000D_
	};_x000D_
	_x000D_
_x000D_
_x000D_

//string met "isOver+jaar":'ja/nee'" vullen en concateren over loop heen_x000D_
package nl.nijmegen.mule.agelimits;_x000D_
_x000D_
import java.time.LocalDate;_x000D_
import org.mule.api.MuleMessage;_x000D_
import org.mule.api.transformer.TransformerException;_x000D_
import org.mule.api.transport.PropertyScope;_x000D_
import org.mule.transformer.AbstractMessageTransformer;_x000D_
import org.apache.commons.logging.Log;_x000D_
import org.apache.commons.logging.LogFactory;_x000D_
_x000D_
public class calculateAgeLimits  extends AbstractMessageTransformer{_x000D_
	private static Log logger = LogFactory.getLog("nl.Nijmegen.brp.irma-api.calculateagelimits");_x000D_
		      _x000D_
		      _x000D_
		      @Override_x000D_
			public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {_x000D_
		    	 _x000D_
		    	//Zet geboortedatum_x000D_
			  		//String bDay = "20000000";_x000D_
			    	//String bDay =  message.getInvocationProperty("sv_geboortedatum");_x000D_
			    	String bDay = message.getProperty("sv_geboortedatum", PropertyScope.INVOCATION);_x000D_
			  		//Code uit elkaar halen op jaar, maand en dag		  		_x000D_
			    	int lengteBDay = bDay.length();_x000D_
					if (lengteBDay !=8) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");_x000D_
						_x000D_
					}		_x000D_
					//Code uit elkaar halen op jaar, maand en dag_x000D_
					String bYear = (bDay.substring(0,4));_x000D_
					String bMonth1=	bDay.substring(bDay.length() - 4);_x000D_
					String bMonth2 = (bMonth1.substring(0,2));_x000D_
					String bDag = bDay.substring(bDay.length() - 2);_x000D_
					_x000D_
					_x000D_
					//omzetten naar een int._x000D_
					int bYearInt = Integer.parseInt(bYear);_x000D_
					int bMonthInt = Integer.parseInt(bMonth2);_x000D_
					int bDagInt = Integer.parseInt(bDag);_x000D_
					logger.debug("jaar: " + bYearInt);_x000D_
					logger.debug("maand: " + bMonthInt);_x000D_
					logger.debug("dag: " + bDagInt);_x000D_
					_x000D_
					if (bYearInt ==0 || bYearInt <1850) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");_x000D_
					}_x000D_
					if (bMonthInt >12) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");		_x000D_
					}_x000D_
					if (bDagInt >31) {_x000D_
						throw new ArithmeticException("Geen valide geboortedatum ingevoerd.");		_x000D_
					}_x000D_
					_x000D_
					//als maand null is dan 1 juli invullen_x000D_
					if (bMonthInt == 0) {_x000D_
						bMonthInt = 1;_x000D_
						bMonthInt = 7;}_x000D_
					//als dag null is, dan waarde op 1 zetten en vervolgens naar laatste dag van de maand_x000D_
					if (bDagInt == 00) {_x000D_
_x000D_
						LocalDate noDay = LocalDate.of(bYearInt,bMonthInt,1);_x000D_
					    LocalDate end = noDay.withDayOfMonth(noDay.lengthOfMonth());_x000D_
					    int dayOfMonth = end.getDayOfMonth();_x000D_
					    bDagInt = dayOfMonth;_x000D_
					      }_x000D_
					if (bMonthInt == 2 & bDagInt == 29) {_x000D_
						bDagInt=28;_x000D_
					}_x000D_
_x000D_
					String resultString = "";_x000D_
					_x000D_
					//geboortedag bepalen_x000D_
					      LocalDate currentTime = LocalDate.now();_x000D_
					      LocalDate birthday = LocalDate.of(bYearInt,bMonthInt,bDagInt);_x000D_
					      logger.debug("Huidige datum: " + currentTime);_x000D_
					      logger.debug("Geboortedatum: " + birthday);_x000D_
					      _x000D_
					      _x000D_
					 //array maken met alle jaren erin      _x000D_
					      int[] jaar = new int[] {12,16,18,21,65};_x000D_
					      for (int i=0; i<jaar.length; i++)_x000D_
					      {_x000D_
					    	//door array lopen_x000D_
					    	//in de array current date bepalen_x000D_
					    	//jaren van currentdate afhalen_x000D_
					    	LocalDate date1 = LocalDate.now().minusYears(jaar[i]);_x000D_
					    	       _x000D_
					    	String resultValue;_x000D_
					    	String resultLabel;_x000D_
					    	//vergelijken geboortedatum en currentdate_x000D_
					        if(date1.isBefore(birthday)) {_x000D_
					        	resultValue = "No";_x000D_
					        }_x000D_
					        else {_x000D_
					    		resultValue = "Yes";_x000D_
					    		_x000D_
					        }_x000D_
					        //string met<SUF>
					        resultLabel = "\"" +"over" + jaar[i];		                        _x000D_
					        resultString = resultString + resultLabel + "\"" +":"+ "\"" + resultValue + "\"" + ",";_x000D_
					      }_x000D_
					      	//resultString teruggeven_x000D_
					      resultString = "{" + resultString.substring(0, resultString.length()-1) +"}";_x000D_
					      resultString = "{"+ "\""+"ageLimits"+"\""+": " + resultString +"}";_x000D_
					      logger.debug("resultString: " + resultString);_x000D_
					return resultString;_x000D_
				_x000D_
			}_x000D_
_x000D_
	};_x000D_
	_x000D_
_x000D_
_x000D_
