Replace Activator by a Component

Update test to use the new version of the SensiNact component

update InfluxDBStorageConnection to store numerical values and others in two separated measurements
diff --git a/platform/northbound/influxdb-storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/influxdb/internal/InfluxDBStorageConnection.java b/platform/northbound/influxdb-storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/influxdb/internal/InfluxDBStorageConnection.java
index 5cb8077..352b219 100644
--- a/platform/northbound/influxdb-storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/influxdb/internal/InfluxDBStorageConnection.java
+++ b/platform/northbound/influxdb-storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/influxdb/internal/InfluxDBStorageConnection.java
@@ -130,11 +130,30 @@
 		}

 		this.extractLocation(fs, obj.opt("location"));

 		Object o = obj.opt(DataResource.VALUE);

-		if(o!=null && o.getClass()==String.class)

+		if(o == null)

+			return;

+		Object value = null;

+		

+		if(o.getClass().isPrimitive()) {

+			value = String.valueOf(o);

+			if(o.getClass() != char.class && o.getClass() != boolean.class ) 

+				value = Double.parseDouble((String) value);			

+		} else if(o instanceof Number) 

+			value = ((Number)o).doubleValue();

+		else 

+			value = String.valueOf(o);

+

+		if(value.getClass()==String.class)

 			measurement=this.measurement.concat("_str");

 		else

-			measurement=this.measurement.concat("_num");		

-		this.database.add(measurement, ts, fs, o);	

+			measurement=this.measurement.concat("_num");

+		long tm  = obj.optLong("timestamp");

+		long timestamp = 0;

+		if(tm>0)

+			timestamp = tm;

+		else

+			timestamp = System.currentTimeMillis();

+		this.database.add(measurement, ts, fs, value,timestamp);	

 	}

 

 	private void extractLocation(Dictionary<String,Object> fields, Object location)  {		

diff --git a/platform/northbound/rest-access/pom.xml b/platform/northbound/rest-access/pom.xml
index 6bbad49..3598024 100644
--- a/platform/northbound/rest-access/pom.xml
+++ b/platform/northbound/rest-access/pom.xml
@@ -97,8 +97,7 @@
 				<extensions>true</extensions>
 				<configuration>
 					<instructions>
-						<Bundle-Activator>org.eclipse.sensinact.gateway.nthbnd.rest.osgi.Activator</Bundle-Activator>
-						<Export-Package>org.eclipse.sensinact.gateway.nthbnd.rest.osgi</Export-Package>
+						<Export-Package>org.eclipse.sensinact.gateway.nthbnd.rest.component</Export-Package>
 						<Include-Resource>
 							about.html
 						</Include-Resource>
diff --git a/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java b/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/component/RestAccessConfigurator.java
similarity index 73%
rename from platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java
rename to platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/component/RestAccessConfigurator.java
index eba5814..b7e9677 100644
--- a/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java
+++ b/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/component/RestAccessConfigurator.java
@@ -8,10 +8,11 @@
  * Contributors:
 *    Kentyou - initial API and implementation
  */
-package org.eclipse.sensinact.gateway.nthbnd.rest.osgi;
+package org.eclipse.sensinact.gateway.nthbnd.rest.component;
 
 import java.io.IOException;
 import java.util.Hashtable;
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -23,7 +24,7 @@
 
 import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
 import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
-import org.eclipse.sensinact.gateway.common.bundle.AbstractActivator;
+import org.eclipse.sensinact.gateway.common.interpolator.Interpolator;
 import org.eclipse.sensinact.gateway.nthbnd.endpoint.NorthboundMediator;
 import org.eclipse.sensinact.gateway.nthbnd.rest.internal.RestAccessConstants;
 import org.eclipse.sensinact.gateway.nthbnd.rest.internal.http.CorsFilter;
@@ -35,15 +36,21 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
 import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 /**
- * @see AbstractActivator
+ * 
  */
-public class Activator extends AbstractActivator<NorthboundMediator> {
+@Component(immediate=true)
+public class RestAccessConfigurator {
     	
 	private CorsFilter corsFilter = null;
     private boolean corsHeader = false;
+	private NorthboundMediator mediator;
     
     private static ClassLoader loader = null;
     
@@ -62,21 +69,29 @@
     		}
     	}
     }
+
+    protected void injectPropertyFields() throws Exception {
+        this.mediator.debug("Starting introspection in bundle %s", mediator.getContext().getBundle().getSymbolicName());
+        Interpolator interpolator = new Interpolator(this.mediator);
+        interpolator.getInstance(this);
+        for(Map.Entry<String,String> entry:interpolator.getPropertiesInjected().entrySet()){
+            if(!this.mediator.getProperties().containsKey(entry.getKey()))
+                mediator.setProperty(entry.getKey(),entry.getValue());
+        }
+    }
     
-    /**
-     * @inheritDoc
-     * @see org.eclipse.sensinact.gateway.common.bundle.AbstractActivator#
-     * doStart()
-     */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-	public void doStart() throws Exception {
+    @Activate
+	public void activate(ComponentContext componentContext) throws Exception {
     	
-    	findJettyClassLoader(super.mediator.getContext());
+    	this.mediator = new NorthboundMediator(componentContext.getBundleContext());
+
+        injectPropertyFields();
+    	findJettyClassLoader(this.mediator.getContext());
     	        
-    	this.corsHeader = Boolean.valueOf((String) super.mediator.getProperty(RestAccessConstants.CORS_HEADER));
+    	this.corsHeader = Boolean.valueOf((String) this.mediator.getProperty(RestAccessConstants.CORS_HEADER));
         if (this.corsHeader) {
             this.corsFilter = new CorsFilter(mediator);                    
-            mediator.register(Activator.this.corsFilter, Filter.class, new Hashtable() {{
+            mediator.register(RestAccessConfigurator.this.corsFilter, Filter.class, new Hashtable() {{
             	this.put(Constants.SERVICE_RANKING, 1);
                 this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/*");
                 this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=default)");
@@ -84,13 +99,13 @@
             });
         }
         
-        super.mediator.register(
+        this.mediator.register(
         	new Hashtable() {{
         		this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.WS_ROOT);
         		this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=default)");}}, 
         	new WebSocketServlet() { 			
 				private static final long serialVersionUID = 1L;			
-				private WebSocketConnectionFactory sessionPool = new WebSocketConnectionFactory(Activator.super.mediator);
+				private WebSocketConnectionFactory sessionPool = new WebSocketConnectionFactory(RestAccessConfigurator.this.mediator);
 				
 		        private final AtomicBoolean firstCall = new AtomicBoolean(true); 
 		    
@@ -138,37 +153,32 @@
                 };
             }, 
         	new Class[]{ Servlet.class, WebSocketServlet.class });
-        super.mediator.info(String.format("%s servlet registered", RestAccessConstants.WS_ROOT));
+        this.mediator.info(String.format("%s servlet registered", RestAccessConstants.WS_ROOT));
         
-        super.mediator.register(new HttpLoginEndpoint(mediator), Servlet.class, new Hashtable() {{
+        this.mediator.register(new HttpLoginEndpoint(mediator), Servlet.class, new Hashtable() {{
         	this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.LOGIN_ENDPOINT);
         	this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=default)");
         	}
         });
-        super.mediator.info(String.format("%s servlet registered", RestAccessConstants.LOGIN_ENDPOINT));
+        this.mediator.info(String.format("%s servlet registered", RestAccessConstants.LOGIN_ENDPOINT));
         
         mediator.register(new HttpRegisteringEndpoint(mediator), Servlet.class, new Hashtable() {{
         	this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.REGISTERING_ENDPOINT);
         	this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=default)");
         	}
         });
-        super.mediator.info(String.format("%s servlet registered", RestAccessConstants.REGISTERING_ENDPOINT));
+        this.mediator.info(String.format("%s servlet registered", RestAccessConstants.REGISTERING_ENDPOINT));
         
         mediator.register(new HttpEndpoint(mediator), Servlet.class, new Hashtable() {{
         	this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.HTTP_ROOT);
         	this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=default)");
         	}
         });      
-        super.mediator.info(String.format("%s servlet registered", RestAccessConstants.HTTP_ROOT));
+        this.mediator.info(String.format("%s servlet registered", RestAccessConstants.HTTP_ROOT));
     }
 
-    @Override
-    public void doStop() throws Exception {
+    @Deactivate
+    public void deactivate() throws Exception {
     }
 
-    @Override
-    public NorthboundMediator doInstantiate(BundleContext context) {
-        NorthboundMediator mediator = new NorthboundMediator(context);
-        return mediator;
-    }
 }
diff --git a/platform/northbound/sensinact-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/endpoint/test/TestContext.java b/platform/northbound/sensinact-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/endpoint/test/TestContext.java
index 0068bdb..4dd419c 100644
--- a/platform/northbound/sensinact-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/endpoint/test/TestContext.java
+++ b/platform/northbound/sensinact-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/endpoint/test/TestContext.java
@@ -109,7 +109,8 @@
 
     private final ServiceRegistration registrationFiltering = Mockito.mock(ServiceRegistration.class);
 
-	private final ComponentContext cpctx = Mockito.mock(ComponentContext.class);
+	private final ComponentContext componentContext= Mockito.mock(ComponentContext.class);
+
 	
     private MyModelInstance instance;
     private SnaAgent agent;
@@ -382,20 +383,23 @@
         Mockito.when(bundle.getBundleId()).thenReturn(MOCK_BUNDLE_ID);
         Mockito.when(bundle.getState()).thenReturn(Bundle.ACTIVE);
 
-		mediator = new NorthboundMediator(context);        
-		sensinact = new SensiNact(mediator);		
-		
-        instance = (MyModelInstance) new ModelInstanceBuilder(mediator).build(
-        	"serviceProvider", null, new ModelConfigurationBuilder(mediator,
-        	  ModelConfiguration.class,MyModelInstance.class
-        	   ).withStartAtInitializationTime(true).build());
-        
-        initialized = true;
+		Mockito.when(componentContext.getBundleContext()).thenReturn(context);
 
-        callbackCount = 0;
-        linkCallbackCount = 0;
-        extraCallbackCount = 0;
-        agentCallbackCount = 0;
+		mediator = new NorthboundMediator(context);
+		sensinact = new SensiNact();
+		sensinact.activate(componentContext);;
+		
+		instance = (MyModelInstance) new ModelInstanceBuilder(mediator
+			).build("serviceProvider", null, new ModelConfigurationBuilder(
+				mediator,ModelConfiguration.class, MyModelInstance.class
+				).withStartAtInitializationTime(true).build());
+		
+		initialized = true;
+
+		callbackCount = 0;
+		linkCallbackCount = 0;
+		extraCallbackCount = 0;
+		agentCallbackCount = 0;
     }
 
     public final SnaAgent getAgent() {