<commit_before>package xdi2.connect.acmepizza;

import java.net.URI;
import java.util.ArrayDeque;
import java.util.Date;
import java.util.Deque;
import java.util.Iterator;

import xdi2.agent.impl.XDIBasicAgent;
import xdi2.agent.routing.impl.http.XDIHttpDiscoveryAgentRouter;
import xdi2.client.XDIClient;
import xdi2.client.XDIClientRoute;
import xdi2.client.exceptions.Xdi2ClientException;
import xdi2.connect.core.ConnectionResult;
import xdi2.core.Graph;
import xdi2.core.features.linkcontracts.instance.GenericLinkContract;
import xdi2.core.features.linkcontracts.instance.LinkContract;
import xdi2.core.syntax.XDIAddress;
import xdi2.core.util.XDIAddressUtil;
import xdi2.discovery.XDIDiscoveryClient;
import xdi2.messaging.Message;
import xdi2.messaging.MessageEnvelope;

public class AcmepizzaStatus {

	private static Deque<Status> statuses = new ArrayDeque<Status> ();

	public static String newStatus(ConnectionResult connectionResult, URI registryEndpointUri) {

		Status status = new Status();
		status.date = new Date();
		status.connectionResult = connectionResult;
		status.registryEndpointUri = registryEndpointUri;

		statuses.add(status);
		if (statuses.size() > 10) statuses.removeFirst();

		return status.getData();
	}

	public static String status() {

		StringBuffer buffer = new StringBuffer();

		for (Status status : statuses) {

			buffer.insert(0, status.toString() + "\n");
		}

		return buffer.toString();
	}

	private static class Status {

		private Date date;
		private ConnectionResult connectionResult;
		private URI registryEndpointUri;

		private String getData() {

			Iterator<LinkContract> linkContracts = this.connectionResult.getLinkContracts();
			if (linkContracts == null || ! linkContracts.hasNext()) return null;

			GenericLinkContract linkContract = (GenericLinkContract) linkContracts.next();
			XDIAddress requestingAuthority = linkContract.getRequestingAuthority();
			XDIAddress authorizingAuthority = linkContract.getAuthorizingAuthority();

			XDIBasicAgent XDIagent = new XDIBasicAgent(new XDIHttpDiscoveryAgentRouter(new XDIDiscoveryClient(this.registryEndpointUri)));

			StringBuffer buffer = new StringBuffer();

			try {

				XDIClientRoute<? extends XDIClient> route = XDIagent.route(authorizingAuthority);
				MessageEnvelope me = route.constructMessageEnvelope();
				Message m = route.constructMessage(me, requestingAuthority);
				m.setLinkContractXDIAddress(linkContract.getContextNode().getXDIAddress());
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#first><#name>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#last><#name>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#street>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#postal><#code>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#locality>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#country>")));

				Graph resultGraph = route.constructXDIClient().send(me).getResultGraph();

				buffer.append("\n\n");
				buffer.append(resultGraph.getDeepLiteralNode(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#first><#name>&"))).getLiteralDataString());
				buffer.append(" ");
				buffer.append(resultGraph.getDeepLiteralNode(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#last><#name>&"))).getLiteralDataString());<commit_msg>updated API<commit_after>package xdi2.connect.acmepizza;

import java.net.URI;
import java.util.ArrayDeque;
import java.util.Date;
import java.util.Deque;
import java.util.Iterator;

import xdi2.agent.impl.XDIBasicAgent;
import xdi2.agent.routing.impl.http.XDIHttpDiscoveryAgentRouter;
import xdi2.client.XDIClient;
import xdi2.client.XDIClientRoute;
import xdi2.client.exceptions.Xdi2ClientException;
import xdi2.connect.core.ConnectionResult;
import xdi2.core.Graph;
import xdi2.core.features.linkcontracts.instance.GenericLinkContract;
import xdi2.core.features.linkcontracts.instance.LinkContract;
import xdi2.core.syntax.XDIAddress;
import xdi2.core.util.XDIAddressUtil;
import xdi2.discovery.XDIDiscoveryClient;
import xdi2.messaging.Message;
import xdi2.messaging.MessageEnvelope;

public class AcmepizzaStatus {

	private static Deque<Status> statuses = new ArrayDeque<Status> ();

	public static String newStatus(ConnectionResult connectionResult, URI registryEndpointUri) {

		Status status = new Status();
		status.date = new Date();
		status.connectionResult = connectionResult;
		status.registryEndpointUri = registryEndpointUri;

		statuses.add(status);
		if (statuses.size() > 10) statuses.removeFirst();

		return status.getData();
	}

	public static String status() {

		StringBuffer buffer = new StringBuffer();

		for (Status status : statuses) {

			buffer.insert(0, status.toString() + "\n");
		}

		return buffer.toString();
	}

	private static class Status {

		private Date date;
		private ConnectionResult connectionResult;
		private URI registryEndpointUri;

		private String getData() {

			Iterator<LinkContract> linkContracts = this.connectionResult.getLinkContracts();
			if (linkContracts == null || ! linkContracts.hasNext()) return null;

			GenericLinkContract linkContract = (GenericLinkContract) linkContracts.next();
			XDIAddress requestingAuthority = linkContract.getRequestingAuthority();
			XDIAddress authorizingAuthority = linkContract.getAuthorizingAuthority();

			XDIBasicAgent XDIagent = new XDIBasicAgent(new XDIHttpDiscoveryAgentRouter(new XDIDiscoveryClient(this.registryEndpointUri)));

			StringBuffer buffer = new StringBuffer();

			try {

				XDIClientRoute<? extends XDIClient> route = XDIagent.route(authorizingAuthority);
				MessageEnvelope me = route.createMessageEnvelope();
				Message m = route.createMessage(me, requestingAuthority);
				m.setLinkContractXDIAddress(linkContract.getContextNode().getXDIAddress());
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#first><#name>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#last><#name>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#street>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#postal><#code>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#locality>")));
				m.createGetOperation(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("#address<#country>")));

				Graph resultGraph = route.constructXDIClient().send(me).getResultGraph();

				buffer.append("\n\n");
				buffer.append(resultGraph.getDeepLiteralNode(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#first><#name>&"))).getLiteralDataString());
				buffer.append(" ");
				buffer.append(resultGraph.getDeepLiteralNode(XDIAddressUtil.concatXDIAddresses(authorizingAuthority, XDIAddress.create("<#last><#name>&"))).getLiteralDataString());
{'fraction_non_alphanumeric': 0.11505143475906876, 'fraction_numerical': 0.005143475906876015, 'mean_word_length': 6.945161290322581, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1214927', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2203, 'n_words': 342}