Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrançois Aïssaoui2016-01-20 10:21:17 +0000
committerFrançois Aïssaoui2016-01-20 10:21:17 +0000
commitcb204bbd937017f52d6d1567a04b83c06b902cc8 (patch)
treef5a9005e34ad3403aaa8be0c0a5cd432c9dfc702
parentd2f608d5df8b34a00d8f8ecf1359c65351a01022 (diff)
downloadorg.eclipse.om2m-cb204bbd937017f52d6d1567a04b83c06b902cc8.tar.gz
org.eclipse.om2m-cb204bbd937017f52d6d1567a04b83c06b902cc8.tar.xz
org.eclipse.om2m-cb204bbd937017f52d6d1567a04b83c06b902cc8.zip
Fix resource representation in IPE Sample
Change-Id: I95d30aaf9e02dcce281a83d4048e1fcddeb52026 Signed-off-by: François Aïssaoui <aissaoui@laas.fr>
-rw-r--r--org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/RequestSender.java2
-rw-r--r--org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/constants/SampleConstants.java1
-rw-r--r--org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/LifeCycleManager.java129
-rw-r--r--org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/SampleController.java3
-rw-r--r--org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/util/ObixUtil.java20
-rw-r--r--org.eclipse.om2m.ipe.sample/src/org/om2m/ipu/sample/Activator.java70
6 files changed, 53 insertions, 172 deletions
diff --git a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/RequestSender.java b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/RequestSender.java
index d7797e09..6db962c7 100644
--- a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/RequestSender.java
+++ b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/RequestSender.java
@@ -17,7 +17,7 @@ import org.eclipse.om2m.ipe.sample.controller.SampleController;
public class RequestSender {
/**
- * Private constructor to avoir creation of this object
+ * Private constructor to avoid creation of this object
*/
private RequestSender(){}
diff --git a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/constants/SampleConstants.java b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/constants/SampleConstants.java
index fc9601ad..a195601a 100644
--- a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/constants/SampleConstants.java
+++ b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/constants/SampleConstants.java
@@ -17,4 +17,5 @@ public class SampleConstants {
public static final boolean GUI = Boolean.valueOf(System.getProperty("org.eclipse.om2m.ipe.sample.gui", "true"));
public static String CSE_ID = "/" + Constants.CSE_ID;
+ public static String CSE_PREFIX = CSE_ID + "/" + Constants.CSE_NAME;
}
diff --git a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/LifeCycleManager.java b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/LifeCycleManager.java
index 7699eaca..b2764080 100644
--- a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/LifeCycleManager.java
+++ b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/LifeCycleManager.java
@@ -6,12 +6,8 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.eclipse.om2m.commons.constants.Constants;
import org.eclipse.om2m.commons.constants.MimeMediaType;
import org.eclipse.om2m.commons.constants.ResponseStatusCode;
-import org.eclipse.om2m.commons.obix.Bool;
-import org.eclipse.om2m.commons.obix.Obj;
-import org.eclipse.om2m.commons.obix.io.ObixDecoder;
import org.eclipse.om2m.commons.resource.AE;
import org.eclipse.om2m.commons.resource.Container;
import org.eclipse.om2m.commons.resource.ContentInstance;
@@ -38,48 +34,18 @@ public class LifeCycleManager {
}
SampleModel.setModel(lamps);
- // register the IPE
- if(registerAE()){
- // Case when the AE has just been created
- // Create initial resources for the 2 lamps
- for(int i=0; i<2; i++) {
- String lampId = Lamp.TYPE+"_"+i;
- createLampResources(lampId, false, SampleConstants.POA);
- }
- createLampAll(SampleConstants.POA);
- } else {
- // AE and other resources already created
- ResponsePrimitive response = RequestSender.getRequest("/" + Constants.CSE_ID + "/" +Constants.CSE_NAME + "/" + SampleConstants.AE_NAME + "/"+ SampleConstants.LAMP_0 +"/DATA/la");
- if(response.getResponseStatusCode().equals(ResponseStatusCode.OK) && response.getContent() instanceof ContentInstance){
- ContentInstance lamp0Value = (ContentInstance) response.getContent();
- Obj lamp0 = ObixDecoder.fromString(lamp0Value.getContent());
- for(Object obj : lamp0.getObjGroup()){
- if(obj instanceof Bool
- && ((Bool) obj).getName().equals("state")){
- SampleModel.setLampState(SampleConstants.LAMP_0, ((Bool) obj).getVal());
- break;
- }
- }
- }
- response = RequestSender.getRequest("/" + Constants.CSE_ID + "/" +Constants.CSE_NAME + "/" + SampleConstants.AE_NAME + "/"+ SampleConstants.LAMP_1 +"/DATA/la");
- if(response.getResponseStatusCode().equals(ResponseStatusCode.OK) && response.getContent() instanceof ContentInstance){
- ContentInstance lamp1Value = (ContentInstance) response.getContent();
- Obj lamp1 = ObixDecoder.fromString(lamp1Value.getContent());
- for(Object obj : lamp1.getObjGroup()){
- if(obj instanceof Bool
- && ((Bool) obj).getName().equals("state")){
- SampleModel.setLampState(SampleConstants.LAMP_1, ((Bool) obj).getVal());
- break;
- }
- }
- }
+ // Create initial resources for the 2 lamps
+ for(int i=0; i<2; i++) {
+ String lampId = Lamp.TYPE+"_"+i;
+ createLampResources(lampId, false, SampleConstants.POA);
}
-
+ createLampAll(SampleConstants.POA);
+
// Start the GUI
if(SampleConstants.GUI){
GUI.init();
}
-
+
}
/**
@@ -92,43 +58,23 @@ public class LifeCycleManager {
}
/**
- * Register the IPE as an AE in the platform
- * @return
- * if the registration has been performed, otherwise, there is an error or it's already created
- */
- private static boolean registerAE(){
- AE ae = new AE();
- ae.setRequestReachability(true);
- ae.getPointOfAccess().add(SampleConstants.POA);
- ae.setAppID("IPE_" + SampleConstants.POA.toUpperCase());
- // ResponsePrimitive response = SampleController.CSE.doRequest(request);
- ResponsePrimitive response = RequestSender.createAE(ae, SampleConstants.AE_NAME);
- LOGGER.info("Response for IPE registration : " + response);
- if(response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)
- && response.getContent() instanceof AE){
- AE createdAe = (AE) response.getContent();
- SampleController.AE_ID = createdAe.getAEID();
- LOGGER.info("AEID of the createed AE: " + SampleController.AE_ID);
- return true;
- }
- return false;
- }
-
- /**
* Creates all required resources.
- * @param cntId - Application ID
+ * @param appId - Application ID
* @param initValue - initial lamp value
- * @param aPoCPath - lamp aPocPath
+ * @param poa - lamp Point of Access
*/
- private static void createLampResources(String cntId, boolean initValue, String aPoCPath) {
+ private static void createLampResources(String appId, boolean initValue, String poa) {
// Create the Application resource
Container container = new Container();
container.getLabels().add("lamp");
container.setMaxNrOfInstances(BigInteger.valueOf(0));
- ResponsePrimitive response = RequestSender.
- createContainer("/" + Constants.CSE_ID + "/" +Constants.CSE_NAME + "/" + SampleConstants.AE_NAME, cntId, container);
+ AE ae = new AE();
+ ae.setRequestReachability(true);
+ ae.getPointOfAccess().add(poa);
+ ae.setAppID(appId);
+ ResponsePrimitive response = RequestSender.createAE(ae, appId);
// Create Application sub-resources only if application not yet created
if(response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
container = new Container();
@@ -140,41 +86,46 @@ public class LifeCycleManager {
String content;
// Create DESCRIPTION contentInstance on the DESCRIPTOR container resource
- content = ObixUtil.getDescriptorRep(SampleConstants.CSE_ID, cntId, SampleConstants.DATA);
+ content = ObixUtil.getDescriptorRep(SampleConstants.CSE_ID, appId, SampleConstants.DATA);
ContentInstance contentInstance = new ContentInstance();
contentInstance.setContent(content);
contentInstance.setContentInfo(MimeMediaType.OBIX);
RequestSender.createContentInstance(
- SampleConstants.CSE_ID + "/" +Constants.CSE_NAME + "/" + SampleConstants.AE_NAME + "/" + cntId + "/" + SampleConstants.DESC, null, contentInstance);
+ SampleConstants.CSE_PREFIX + "/" + appId + "/" + SampleConstants.DESC, null, contentInstance);
// Create initial contentInstance on the STATE container resource
- content = ObixUtil.getStateRep(cntId, initValue);
+ content = ObixUtil.getStateRep(appId, initValue);
contentInstance.setContent(content);
RequestSender.createContentInstance(
- SampleConstants.CSE_ID + "/" +Constants.CSE_NAME + "/" + SampleConstants.AE_NAME + "/" + cntId + "/" + SampleConstants.DATA, null, contentInstance);
+ SampleConstants.CSE_PREFIX + "/" + appId + "/" + SampleConstants.DATA, null, contentInstance);
}
}
/**
* Create the LAMP_ALL container
- * @param apocpath2
+ * @param poa
*/
- private static void createLampAll(String apocpath2) {
+ private static void createLampAll(String poa) {
// Creation of the LAMP_ALL container
- Container cnt = new Container();
- cnt.getLabels().add("lamp");
- String targetId = SampleConstants.CSE_ID + "/" +Constants.CSE_NAME + "/" + SampleConstants.AE_NAME;
- RequestSender.createContainer(targetId, "LAMP_ALL", cnt);
-
- // Creation of the DESCRIPTOR container
- cnt.setMaxNrOfInstances(BigInteger.valueOf(10));
- RequestSender.createContainer(targetId + "/" + "LAMP_ALL", SampleConstants.DESC, cnt);
-
- // Create the description
- ContentInstance cin = new ContentInstance();
- cin.setContent(ObixUtil.createLampAllDescriptor());
- cin.setContentInfo(MimeMediaType.OBIX);
- RequestSender.createContentInstance(targetId + "/" + "LAMP_ALL" + "/" + SampleConstants.DESC, null, cin);
+ AE ae = new AE();
+ ae.setRequestReachability(true);
+ ae.getPointOfAccess().add(poa);
+ ae.setAppID("LAMP_ALL");
+ ResponsePrimitive response = RequestSender.createAE(ae, "LAMP_ALL");
+
+ // Create descriptor container if not yet created
+ if(response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)){
+ // Creation of the DESCRIPTOR container
+ Container cnt = new Container();
+ cnt.setMaxNrOfInstances(BigInteger.valueOf(10));
+ RequestSender.createContainer(SampleConstants.CSE_PREFIX + "/" + "LAMP_ALL", SampleConstants.DESC, cnt);
+
+ // Create the description
+ ContentInstance cin = new ContentInstance();
+ cin.setContent(ObixUtil.createLampAllDescriptor());
+ cin.setContentInfo(MimeMediaType.OBIX);
+ RequestSender.createContentInstance(SampleConstants.CSE_PREFIX + "/" + "LAMP_ALL" + "/" + SampleConstants.DESC, null, cin);
+ }
}
}
diff --git a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/SampleController.java b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/SampleController.java
index 53faf99b..3b632fa8 100644
--- a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/SampleController.java
+++ b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/controller/SampleController.java
@@ -1,6 +1,5 @@
package org.eclipse.om2m.ipe.sample.controller;
-import org.eclipse.om2m.commons.constants.Constants;
import org.eclipse.om2m.commons.constants.MimeMediaType;
import org.eclipse.om2m.commons.resource.ContentInstance;
import org.eclipse.om2m.core.service.CseService;
@@ -18,7 +17,7 @@ public class SampleController {
// Set the value in the "real world" model
SampleModel.setLampState(lampId, value);
// Send the information to the CSE
- String targetID = SampleConstants.CSE_ID+"/"+Constants.CSE_NAME + "/" +SampleConstants.AE_NAME+"/"+lampId +"/" + SampleConstants.DATA;
+ String targetID = SampleConstants.CSE_PREFIX + "/" + lampId + "/" + SampleConstants.DATA;
ContentInstance cin = new ContentInstance();
cin.setContent(ObixUtil.getStateRep(lampId, value));
cin.setContentInfo(MimeMediaType.OBIX + ":" + MimeMediaType.ENCOD_PLAIN);
diff --git a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/util/ObixUtil.java b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/util/ObixUtil.java
index 14edf1c2..46c74be6 100644
--- a/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/util/ObixUtil.java
+++ b/org.eclipse.om2m.ipe.sample/src/main/java/org/eclipse/om2m/ipe/sample/util/ObixUtil.java
@@ -18,21 +18,21 @@ public class ObixUtil {
/**
* Returns an obix XML representation describing the lamp.
* @param cseId - SclBase id
- * @param cntId - Application Id
+ * @param appId - Application Id
* @param stateCont - the STATE container id
* @return Obix XML representation
*/
- public static String getDescriptorRep(String cseId, String cntId, String stateCont) {
- String prefix = cseId+"/"+ Constants.CSE_NAME +"/"+SampleConstants.AE_NAME;
+ public static String getDescriptorRep(String cseId, String appId, String stateCont) {
+ String prefix = cseId+"/"+ Constants.CSE_NAME + "/" + appId;
// oBIX
Obj obj = new Obj();
obj.add(new Str("type",Lamp.TYPE));
obj.add(new Str("location",Lamp.LOCATION));
- obj.add(new Str("appId",cntId));
+ obj.add(new Str("appId",appId));
// OP GetState from SCL DataBase
Op opState = new Op();
opState.setName("getState");
- opState.setHref(new Uri(prefix +"/"+cntId+"/"+stateCont+"/"+ ShortName.LATEST));
+ opState.setHref(new Uri(prefix +"/"+stateCont+"/"+ ShortName.LATEST));
opState.setIs(new Contract("retrieve"));
opState.setIn(new Contract("obix:Nil"));
opState.setOut(new Contract("obix:Nil"));
@@ -40,7 +40,7 @@ public class ObixUtil {
// OP GetState from SCL IPU
Op opStateDirect = new Op();
opStateDirect.setName("getState(Direct)");
- opStateDirect.setHref(new Uri(prefix + "?op="+ Operations.GET_STATE_DIRECT+"&lampid=" + cntId));
+ opStateDirect.setHref(new Uri(prefix + "?op="+ Operations.GET_STATE_DIRECT+"&lampid=" + appId));
opStateDirect.setIs(new Contract("execute"));
opStateDirect.setIn(new Contract("obix:Nil"));
opStateDirect.setOut(new Contract("obix:Nil"));
@@ -48,7 +48,7 @@ public class ObixUtil {
// OP SwitchON
Op opON = new Op();
opON.setName("switchON");
- opON.setHref(new Uri(prefix + "?op="+ Operations.SET_ON +"&lampid=" + cntId));
+ opON.setHref(new Uri(prefix + "?op="+ Operations.SET_ON +"&lampid=" + appId));
opON.setIs(new Contract("execute"));
opON.setIn(new Contract("obix:Nil"));
opON.setOut(new Contract("obix:Nil"));
@@ -56,7 +56,7 @@ public class ObixUtil {
// OP SwitchOFF
Op opOFF = new Op();
opOFF.setName("switchOFF");
- opOFF.setHref(new Uri(prefix + "?op=" + Operations.SET_OFF + "&lampid=" + cntId));
+ opOFF.setHref(new Uri(prefix + "?op=" + Operations.SET_OFF + "&lampid=" + appId));
opOFF.setIs(new Contract("execute"));
opOFF.setIn(new Contract("obix:Nil"));
opOFF.setOut(new Contract("obix:Nil"));
@@ -64,7 +64,7 @@ public class ObixUtil {
// OP Toggle
Op opToggle = new Op();
opToggle.setName("toggle");
- opToggle.setHref(new Uri(prefix + "?op="+ Operations.TOGGLE +"&lampid=" + cntId));
+ opToggle.setHref(new Uri(prefix + "?op="+ Operations.TOGGLE +"&lampid=" + appId));
opToggle.setIs(new Contract("execute"));
opToggle.setIn(new Contract("obix:Nil"));
opToggle.setOut(new Contract("obix:Nil"));
@@ -90,7 +90,7 @@ public class ObixUtil {
}
public static String createLampAllDescriptor(){
- String prefix = SampleConstants.CSE_ID +"/"+ Constants.CSE_NAME + "/" + SampleConstants.AE_NAME;
+ String prefix = SampleConstants.CSE_ID +"/"+ Constants.CSE_NAME + "/" + "LAMP_ALL";
Obj descriptor = new Obj();
Op opSwitchOn = new Op();
opSwitchOn.setName(Operations.SET_ON.toString());
diff --git a/org.eclipse.om2m.ipe.sample/src/org/om2m/ipu/sample/Activator.java b/org.eclipse.om2m.ipe.sample/src/org/om2m/ipu/sample/Activator.java
deleted file mode 100644
index 8cf62ea9..00000000
--- a/org.eclipse.om2m.ipe.sample/src/org/om2m/ipu/sample/Activator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013-2015 LAAS-CNRS (www.laas.fr)
- * 7 Colonel Roche 31077 Toulouse - France
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Thierry Monteil (Project co-founder) - Management and initial specification,
- * conception and documentation.
- * Mahdi Ben Alaya (Project co-founder) - Management and initial specification,
- * conception, implementation, test and documentation.
- * Khalil Drira - Management and initial specification.
- * Guillaume Garzone - Initial specification, conception, implementation, test
- * and documentation.
- * François Aïssaoui - Initial specification, conception, implementation, test
- * and documentation.
- *******************************************************************************/
-package org.eclipse.om2m.ipu.sample;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.om2m.ipu.sample"; //$NON-NLS-1$
-
- // The shared instance
- private static Activator plugin;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
-}

Back to the top