1. John Paulett
  2. UploadAssistant

Commits

Kevin A. Archie  committed 520ec69

global default script is absolute URL, not relative URI. treat separately from other script paths

  • Participants
  • Parent commits 3927337
  • Branches default

Comments (0)

Files changed (3)

File src/main/java/org/nrg/net/xnat/BaseScriptApplicatorRetreiver.java

View file
 class BaseScriptApplicatorRetreiver<T> implements Callable<T> {
 	private final Logger logger = Logger.getLogger(BaseScriptApplicatorRetreiver.class);
 	private final RestServer xnat;
-	private final Collection<String> urls;
+	private final Collection<String> uris;
 	private final ScriptApplicatorFactory<T> factory;
+	private final T defaultApplicator;
 
 	protected static interface ScriptApplicatorFactory<T> {
 		T createScriptApplicator(final InputStream in) throws Exception;
 
 	BaseScriptApplicatorRetreiver(final RestServer xnat,
 			final ScriptApplicatorFactory<T> factory,
-			final String...urls) {
+			final String globalDefault,
+			final String...uris) {
 		this.xnat = xnat;
-		this.urls = Arrays.asList(urls);
 		this.factory = factory;
+		this.uris = Arrays.asList(uris);
+		
+		T da = null;
+		if (null != globalDefault) {
+			try {
+				da = getApplicator(factory, new URL(globalDefault));
+			} catch (Exception e) {
+				logger.error("Unable to load global default script " + globalDefault, e);
+			}
+		}
+		if (null == da) {
+			try {
+				da = factory.createScriptApplicator(null);
+			} catch (RuntimeException e) {
+				throw e;
+			} catch (Exception e) {
+				throw new RuntimeException(e);
+			}
+		}
+		this.defaultApplicator = da;
 	}
 
 	/*
 	public final T call() throws Exception {
 		final ConnectionProcessor processor = new ConnectionProcessor(factory);
 		T applicator = null;
-		for (final String url : urls) {
+		for (final String uri : uris) {
 			try {
-				xnat.doGet(url, processor);
+				xnat.doGet(uri, processor);
 				applicator = processor.getApplicator();
 				if (null != applicator) {
 					return applicator;
 				}
 				return processor.getApplicator();
 			} catch (Throwable e) {
-				logger.debug("unable to load script applicator from " + url, e);
+				logger.debug("unable to load script applicator from " + uri, e);
 			}
 		}
-		return factory.createScriptApplicator(null);
+		assert null == applicator;
+		return defaultApplicator;
 	}
 
 	

File src/main/java/org/nrg/net/xnat/DicomScriptApplicatorRetriever.java

View file
 	public DicomScriptApplicatorRetriever(final RestServer xnat, final String project,
 			final Map<String,? extends ScriptFunction> scriptFunctions) {
 		super(xnat, buildFactory(scriptFunctions),
+				"http://nrg.wustl.edu/projects/DICOM/id.das",	// global default: id variables only
 				"/REST/projects/" + project + "/resources/UPLOAD_CONFIG/files/dicom.das",
-				"/REST/projects/" + project + "/resources/DICOM_ANON/files/anon.das",
-				"http://nrg.wustl.edu/projects/DICOM/id.das"	// global default: id variables only
+				"/REST/projects/" + project + "/resources/DICOM_ANON/files/anon.das"
 		);
 	}
 

File src/main/java/org/nrg/net/xnat/ECATScriptApplicatorRetriever.java

View file
 	public ECATScriptApplicatorRetriever(final RestServer xnat, final String project,
 			final Map<String,? extends ScriptFunction> scriptFunctions) {
 		super(xnat, buildFactory(scriptFunctions),
+				null,	// no global default script
 				"/REST/projects/" + project + "/resources/UPLOAD_CONFIG/files/ecat.eas");
 	}