// Path: src/main/java/uk/bl/odin/orcid/domain/CacheManager.java
// public class CacheManager {
// 
// 	private final Cache<SearchKey, OrcidSearchResults> searchCache;
// 
// 	private final Cache<String, OrcidProfile> profileCache;
// 
// 	@Inject
// 	public CacheManager(@Named("OrcidCacheTimeout") Integer timeOutInMinutes,
// 			@Named("OrcidCacheMaxsize") Integer maximumSize) {
// 		searchCache = CacheBuilder.newBuilder().expireAfterWrite(timeOutInMinutes, TimeUnit.MINUTES)
// 				.maximumSize(maximumSize).build();
// 		profileCache = CacheBuilder.newBuilder().expireAfterWrite(timeOutInMinutes, TimeUnit.MINUTES)
// 				.maximumSize(maximumSize).build();
// 	}
// 
// 	public Cache<SearchKey, OrcidSearchResults> getSearchCache() {
// 		return searchCache;
// 	}
// 
// 	public Cache<String, OrcidProfile> getProfilecache() {
// 		return profileCache;
// 	}
// 
// }
// 
// Path: src/main/java/uk/bl/odin/orcid/guice/SelfInjectingServerResource.java
// public abstract class SelfInjectingServerResource extends ServerResource {
// 
// 	/**
// 	 * Implemented by DI framework-specific code. For example, with Guice, the
// 	 * statically-injected MembersInjector just calls
// 	 * {@code injector.injectMembers(object)}.
// 	 */
// 	public interface MembersInjector {
// 		void injectMembers(Object object);
// 	}
// 
// 	/**
// 	 * Subclasseses overriding this method must call {@code super.doInit()}
// 	 * first.
// 	 */
// 	protected void doInit() {
// 		ensureInjected(theMembersInjector);
// 	}
// 
// 	@Inject
// 	private void injected() { // NOPMD
// 		injected.set(true);
// 	}
// 
// 	void ensureInjected(MembersInjector membersInjector) {
// 		if (injected.compareAndSet(false, true)) {
// 			membersInjector.injectMembers(this);
// 		}
// 	}
// 
// 	/**
// 	 * Whether we've been injected yet. This protects against multiple injection
// 	 * of a subclass that gets injected before doInit is called.
// 	 */
// 	private final AtomicBoolean injected = new AtomicBoolean(false);
// 
// 	/**
// 	 * Must be statically injected by DI framework.
// 	 */
// 	@Inject
// 	private static volatile MembersInjector theMembersInjector;
// }


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.xml.bind.JAXBElement;
import org.restlet.data.Status;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import uk.bl.odin.orcid.client.OrcidPublicClient;
import uk.bl.odin.orcid.client.SearchKey;
import uk.bl.odin.orcid.client.SearchType;
import uk.bl.odin.orcid.client.constants.OrcidExternalIdentifierType;
import uk.bl.odin.orcid.client.constants.OrcidSearchField;
import uk.bl.odin.orcid.domain.CacheManager;
import uk.bl.odin.orcid.guice.SelfInjectingServerResource;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidId;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidSearchResult;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidSearchResults;
import com.google.common.base.Joiner;
package uk.bl.odin.orcid.rest.report;






/**
 * Resource that compiles reports for datacentres. The reports contain a list of
 * DOIs/Other identifiers the datacentre owns and the corresponding ORCiDs.
 * These reports have to be looked up one ORCiD at a time so can be SLOW to
 * compile.
 * 
 * Initial report contains number of ORCiDs+names.
 * 
 * A background task then fires in the browser to fetch all of those ORCiD
 * records in order to bring back the exact DOIs/Identifiers matched. This uses
 * OrcidProfileResource. We cannot compile this server side on GAE due to
 * timeout limitations.
 * 
 * TODO: urgh. WHY U SO ANNOYING ORCID. I'd love it if this query were built in.
 * TODO: this is a nightmare on GAE as we cannot run background tasks without
 * paying money.
 * 
 * Handles request/response in Datatable format. @see datatables.net
 * 
 * 
 * FETCH ALL WORKS ATTACHED TO ALL RESULTS.
 * 
 * 
 * @author tom
 * 
 */
public class OrcidDataCentreReportResource extends SelfInjectingServerResource {

	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(OrcidDataCentreReportResource.class.getName());

	@Inject
	OrcidPublicClient client;

	@Inject
// Path: src/main/java/uk/bl/odin/orcid/domain/CacheManager.java
// public class CacheManager {
// 
// 	private final Cache<SearchKey, OrcidSearchResults> searchCache;
// 
// 	private final Cache<String, OrcidProfile> profileCache;
// 
// 	@Inject
// 	public CacheManager(@Named("OrcidCacheTimeout") Integer timeOutInMinutes,
// 			@Named("OrcidCacheMaxsize") Integer maximumSize) {
// 		searchCache = CacheBuilder.newBuilder().expireAfterWrite(timeOutInMinutes, TimeUnit.MINUTES)
// 				.maximumSize(maximumSize).build();
// 		profileCache = CacheBuilder.newBuilder().expireAfterWrite(timeOutInMinutes, TimeUnit.MINUTES)
// 				.maximumSize(maximumSize).build();
// 	}
// 
// 	public Cache<SearchKey, OrcidSearchResults> getSearchCache() {
// 		return searchCache;
// 	}
// 
// 	public Cache<String, OrcidProfile> getProfilecache() {
// 		return profileCache;
// 	}
// 
// }
// 
// Path: src/main/java/uk/bl/odin/orcid/guice/SelfInjectingServerResource.java
// public abstract class SelfInjectingServerResource extends ServerResource {
// 
// 	/**
// 	 * Implemented by DI framework-specific code. For example, with Guice, the
// 	 * statically-injected MembersInjector just calls
// 	 * {@code injector.injectMembers(object)}.
// 	 */
// 	public interface MembersInjector {
// 		void injectMembers(Object object);
// 	}
// 
// 	/**
// 	 * Subclasseses overriding this method must call {@code super.doInit()}
// 	 * first.
// 	 */
// 	protected void doInit() {
// 		ensureInjected(theMembersInjector);
// 	}
// 
// 	@Inject
// 	private void injected() { // NOPMD
// 		injected.set(true);
// 	}
// 
// 	void ensureInjected(MembersInjector membersInjector) {
// 		if (injected.compareAndSet(false, true)) {
// 			membersInjector.injectMembers(this);
// 		}
// 	}
// 
// 	/**
// 	 * Whether we've been injected yet. This protects against multiple injection
// 	 * of a subclass that gets injected before doInit is called.
// 	 */
// 	private final AtomicBoolean injected = new AtomicBoolean(false);
// 
// 	/**
// 	 * Must be statically injected by DI framework.
// 	 */
// 	@Inject
// 	private static volatile MembersInjector theMembersInjector;
// }


// Path: src/main/java/uk/bl/odin/orcid/rest/report/OrcidDataCentreReportResource.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.xml.bind.JAXBElement;
import org.restlet.data.Status;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import uk.bl.odin.orcid.client.OrcidPublicClient;
import uk.bl.odin.orcid.client.SearchKey;
import uk.bl.odin.orcid.client.SearchType;
import uk.bl.odin.orcid.client.constants.OrcidExternalIdentifierType;
import uk.bl.odin.orcid.client.constants.OrcidSearchField;
import uk.bl.odin.orcid.domain.CacheManager;
import uk.bl.odin.orcid.guice.SelfInjectingServerResource;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidId;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidSearchResult;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidSearchResults;
import com.google.common.base.Joiner;

package uk.bl.odin.orcid.rest.report;






/**
 * Resource that compiles reports for datacentres. The reports contain a list of
 * DOIs/Other identifiers the datacentre owns and the corresponding ORCiDs.
 * These reports have to be looked up one ORCiD at a time so can be SLOW to
 * compile.
 * 
 * Initial report contains number of ORCiDs+names.
 * 
 * A background task then fires in the browser to fetch all of those ORCiD
 * records in order to bring back the exact DOIs/Identifiers matched. This uses
 * OrcidProfileResource. We cannot compile this server side on GAE due to
 * timeout limitations.
 * 
 * TODO: urgh. WHY U SO ANNOYING ORCID. I'd love it if this query were built in.
 * TODO: this is a nightmare on GAE as we cannot run background tasks without
 * paying money.
 * 
 * Handles request/response in Datatable format. @see datatables.net
 * 
 * 
 * FETCH ALL WORKS ATTACHED TO ALL RESULTS.
 * 
 * 
 * @author tom
 * 
 */
public class OrcidDataCentreReportResource extends SelfInjectingServerResource {

	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(OrcidDataCentreReportResource.class.getName());

	@Inject
	OrcidPublicClient client;

	@Inject
	CacheManager cache;