<%
	boolean isAuthenticated = false;
	String token = request.getParameter("token");
	String sourceRepositoryId = request.getParameter("source");
	
	// TODO: really needs to be some form of decrypt or unpack
	// for now make a trivial test
	String userId = token; 			
	isAuthenticated = ((token != null) && (token.length() > 0));
	
	StringBuffer xml = new StringBuffer("\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
	if (isAuthenticated) {	
		xml.append("\n<audit>");
		try {
			edu.calstate.osidutil.ProviderUtilities providerUtilities = new edu.calstate.osidutil.ProviderUtilities("../conf/providerConfig.xml",true);
			
			xml.append("\n\t<auditId>");
			try {
				xml.append(providerUtilities.getIdManagerInstance().createId().getIdString());
			} catch (Throwable t) {}
			xml.append("</auditId>");
			
			xml.append("\n\t<userId>");
			xml.append(token); // this may change
			xml.append("</userId>");

			// generate list of crosswalks, asset transforms, and object transoforms that will serve all targets
			xml.append("\n\t<crosswalks>");
			int num = 0;
			boolean hasMore = true;
			while (hasMore) {
				String parameter = "crosswalk" + num;
				String crosswalk = request.getParameter(parameter);
				if (crosswalk == null) {
					hasMore = false;
					break;
				}
				num++;
				xml.append("\n\t\t<crosswalk>");
				xml.append(crosswalk);
				xml.append("</crosswalk>");
			}
			xml.append("\n\t</crosswalks>");
			
			xml.append("\n\t<assetxforms>");
		 	num = 0;
			hasMore = true;
			while (hasMore) {
				String parameter = "assetxform" + num;
				String assetxform = request.getParameter(parameter);
				if (assetxform == null) {
					hasMore = false;
					break;
				}
				num++;
				xml.append("\n\t\t<assetxform>");
				xml.append(assetxform);
				xml.append("</assetxform>");
			}
			xml.append("\n\t</assetxforms>");
			
			xml.append("\n\t<objectxforms>");
		 	num = 0;
			hasMore = true;
			while (hasMore) {
				String parameter = "objectxform" + num;
				String objectxform = request.getParameter(parameter);
				if (objectxform == null) {
					hasMore = false;
					break;
				}
				num++;
				xml.append("\n\t\t<objectxform>");
				xml.append(objectxform);
				xml.append("</objectxform>");
			}
			xml.append("\n\t</objectxforms>");
			
			xml.append("\n\t<migrations>");
			
			// once per target
			int targetNum = 0;
			boolean hasMoreTargets = true;
			while (hasMoreTargets) {
				String parameter = "target" + targetNum;
				String targetRepositoryId = request.getParameter(parameter);
				if (targetRepositoryId == null) {
					hasMore = false;
					break;
				}
				targetNum++;
				
			    xml.append("\n\t\t<migration>");
				String time = java.util.Calendar.getInstance().getTime().toString();
				xml.append("\n\t\t\t<starttime>");
				xml.append(time);
				xml.append("</starttime>");
			
				xml.append("\n\t\t\t<source>");
				xml.append(sourceRepositoryId); // this may change to include name as well as this id
				xml.append("</source>");
			
				xml.append("\n\t\t\t<target>");
				xml.append(targetRepositoryId); // this may change to include name as well as this id
				xml.append("</target>");
			
				// TODO: do migration here
				Thread.sleep(3000);
			
				time = java.util.Calendar.getInstance().getTime().toString();
				xml.append("\n\t\t\t<endtime>");
				xml.append(time);
				xml.append("</endtime>");
							
				xml.append("\n\t\t\t<status>");
				xml.append("SAMPLE passed");
				xml.append("</status>");
			
				xml.append("\n\t\t\t<message>");
				xml.append("SAMPLE 5 assets migrated");
				xml.append("</message>");
			
				xml.append("\n\t\t</migration>");
			}
			xml.append("\n\t</migrations>");
		} catch (Throwable t) {}
		xml.append("\n</audit>");
		%>
			<%=xml%>
		<%
	} else {
%>
Authentication Error
<%
	}
%>

