package ch.hsr.sa.eai.sandbox.server;

import java.util.Properties;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ch.hsr.sa.eai.sandbox.server.rest.api.JobResult;
import ch.hsr.sa.eai.sandbox.server.rest.api.JobStatus;
import ch.hsr.sa.eai.sandbox.server.rest.api.Jobs;

@Component("apiRouteBuilder")
public class APIRouteBuilder extends RouteBuilder {
	
	@Autowired
	private Properties properties;

	@Override
	public void configure() throws Exception {
		if("true".equals(properties.get("rest.api.enabled"))) {
			rest("/jobs").id("restRouteOverview").get().outType(Jobs.class).to("restRouteManagement");
			rest("/jobs/{jobName}").id("restRouteJobInfo").get().outType(JobStatus.class).to("restRouteStatus");
			rest("/jobs/{name}").id("restRouteStartJob").post().outType(JobResult.class).to("restRouteStarter");
			// the parameter name is different intentionally. camel does not allow
			// two rest routes with the exact same uri.
			from("jms:JobTrigger?exchangePattern=InOut").id("jmsRouteStarter").beanRef("jmsRouteStarter");
			from("quartz2://resetMetricsTimer?cron={{metrics.reset.cron}}").id("resetMetrics").to(
					"bean:metricHelper?method=resetMetrics");
		}

	}

}

@@ -38,40 +38,8 @@
 %0D%0A%0D%0A
-import java.util.Properties;%0D%0A%0D%0A
 impo
@@ -81,16 +81,75 @@
 ilder;%0D%0A
+import org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory;%0D%0A
 import o
@@ -192,25 +192,21 @@
 otation.
-Autowired
+Value
 ;%0D%0Aimpor
@@ -508,170 +508,241 @@
  %7B%0D%0A
-%09
 %0D%0A%09
-@Autowired%0D%0A%09private Properties properties;%0D%0A%0D%0A%09@Override%0D%0A%09public void configure() throws Exception %7B%0D%0A%09%09if(%22true%22.equals(properties.get(%22rest.api.enabled%22))
+private Logger logger = LoggerFactory.getLogger(APIRouteBuilder.class);%0D%0A%0D%0A%09private Boolean useRestApi;%0D%0A%0D%0A%09@Override%0D%0A%09public void configure() throws Exception %7B%0D%0A%09%09logger.info(%22setup api routes:%22 + useRestApi);%0D%0A%09%09if (useRestApi
 ) %7B%0D
@@ -1417,15 +1417,175 @@
 %09%7D%0D%0A
-%0D%0A
 %09%7D%0D%0A%0D%0A
+%09@Value(%22$%7Brest.api.enabled%7D%22)%0D%0A%09public void setRestApiEnabled(String enabled) %7B%0D%0A%09%09this.useRestApi = (enabled != null && enabled.equalsIgnoreCase(%22true%22));%0D%0A%09%7D%0D%0A
 %7D%0D%0A

fix properties injection