package com.mediasmiths.std.guice.web.rest.setup;

import com.google.inject.Injector;
import com.google.inject.Module;
import com.mediasmiths.std.indexservice.rest.client.guice.IndexServiceModule;
import com.mediasmiths.std.guice.apploader.GuiceSetup;
import com.mediasmiths.std.guice.web.rest.CoreRestServicesModule;
import com.mediasmiths.std.guice.web.rest.scoping.ServletScopingModule;
import com.mediasmiths.std.io.PropertyFile;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * Abstract GuiceSetup implementation that registers standard functionality we offer to REST service modules
 */
public abstract class AbstractRESTGuiceSetup implements GuiceSetup
{
	private static final Logger log = Logger.getLogger(AbstractRESTGuiceSetup.class);

	public static final String INDEX_SERVICE_ENDPOINT = "service.IndexRestService.endpoint";

	/**
	 * The override for the index service enable property - allows services to opt out of a globally configured index service
	 */
	public static final String DISABLE_INDEX_SERVICE = "framework.indexservice.disabled";

	@Override
	public void registerModules(List<Module> modules, PropertyFile config)
	{
		modules.add(new ServletScopingModule());
		modules.add(new CoreRestServicesModule());

		// Enable the index service if the webapp wants to use it
		final boolean indexServiceDisabled = config.getBoolean(DISABLE_INDEX_SERVICE, false);

		final boolean hasIndexEndpoint = (config.get(INDEX_SERVICE_ENDPOINT, null) != null);

		if (hasIndexEndpoint && !indexServiceDisabled)
		{
			log.info("Enabling index service capabilities...");
			modules.add(new IndexServiceModule());
		}
		else
		{
			log.info("Index service capabilities were not enabled");
		}

		addModules(modules, config);
	}

	public abstract void addModules(List<Module> modules, PropertyFile config);

	@Override
	public final void injectorCreated(Injector injector)
	{
		injectorWasCreated(injector);
	}

	public abstract void injectorWasCreated(Injector injector);
}

@@ -116,86 +116,8 @@
 le;%0A
-import com.mediasmiths.std.indexservice.rest.client.guice.IndexServiceModule;%0A
 impo
@@ -297,32 +297,110 @@
 tScopingModule;%0A
+import com.mediasmiths.std.indexservice.rest.client.guice.IndexServiceModule;%0A
 import com.media
@@ -1071,180 +1071,470 @@
 ;%0A%0A%09
-@Override%0A%09public void registerModules(List%3CModule%3E modules, PropertyFile config)%0A%09%7B%0A%09%09modules.add(new ServletScopingModule());%0A%09%09modules.add(new CoreRestServicesModule());
+/**%0A%09 * The override for the core REST services%0A%09 */%0A%09public static final String DISABLE_CORE_SERVICES = %22framework.restcoreservices.disabled%22;%0A%0A%0A%09@Override%0A%09public void registerModules(List%3CModule%3E modules, PropertyFile config)%0A%09%7B%0A%09%09modules.add(new ServletScopingModule());%0A%0A%09%09if (!config.getBoolean(DISABLE_CORE_SERVICES, false))%0A%09%09%7B%0A%09%09%09modules.add(new CoreRestServicesModule());%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09log.info(%22REST Core Services disabled by config parameter%22);%0A%09%09%7D
 %0A%0A%09%09
@@ -2029,24 +2029,25 @@
 onfig);%0A%09%7D%0A%0A
+%0A
 %09public abst
@@ -2112,16 +2112,17 @@
 nfig);%0A%0A
+%0A
 %09@Overri
@@ -2217,16 +2217,17 @@
 r);%0A%09%7D%0A%0A
+%0A
 %09public 

Allow the core REST services to be disabled if required