Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.om2m.ipe.sdt/src/main')
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/ModuleSDTListener.java4
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTActionAdaptor.java2
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTDeviceAdaptor.java11
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTModuleAdaptor.java36
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTUtil.java93
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ActionFlexContainerService.java21
-rw-r--r--org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ModuleFlexContainerService.java33
7 files changed, 41 insertions, 159 deletions
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/ModuleSDTListener.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/ModuleSDTListener.java
index bdc8948f..782796ba 100644
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/ModuleSDTListener.java
+++ b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/ModuleSDTListener.java
@@ -78,9 +78,9 @@ public class ModuleSDTListener implements SDTEventListener {
AbstractFlexContainer toBeUpdated = new FlexContainer();
CustomAttribute ca = new CustomAttribute();
- ca.setCustomAttributeName(notif.getDataPoint().getName());
+ ca.setShortName(notif.getDataPoint().getName());
Object value = notif.getValue();
- ca.setCustomAttributeValue((value != null ? value.toString() : null));
+ ca.setValue((value != null ? value.toString() : null));
toBeUpdated.getCustomAttributes().add(ca);
ResponsePrimitive response = CseUtil.sendInternalNotifyFlexContainerRequest(toBeUpdated,
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTActionAdaptor.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTActionAdaptor.java
index 363da684..7008dcf1 100644
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTActionAdaptor.java
+++ b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTActionAdaptor.java
@@ -65,7 +65,7 @@ public class SDTActionAdaptor {
for (Arg arg : action.getArgs()) {
CustomAttribute customAttribute = new CustomAttribute();
- customAttribute.setCustomAttributeName(arg.getName());
+ customAttribute.setShortName(arg.getName());
actionFlexContainer.getCustomAttributes().add(customAttribute);
}
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTDeviceAdaptor.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTDeviceAdaptor.java
index fe2736c0..41b38621 100644
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTDeviceAdaptor.java
+++ b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTDeviceAdaptor.java
@@ -114,6 +114,9 @@ public class SDTDeviceAdaptor {
nwkDeviceInfo.setDevID(this.device.getName());
nwkDeviceInfo.setDevType("SDT");
+ // Set cnd in deviceInfo's deviceType
+ devInfo.setDeviceType(flexContainer.getContainerDefinition());
+
logger.info("Node mgmtObjs: " + node.getMgmtObjs());
if (hasToBeAnnounced) {
@@ -153,8 +156,8 @@ public class SDTDeviceAdaptor {
devInfo.setManufacturer(sdtProperty.getValue());
} else if (shortName.equals(PropertyType.deviceModelName.getShortName())) {
devInfo.setModel(sdtProperty.getValue());
- } else if (shortName.equals(PropertyType.deviceType.getShortName())) {
- devInfo.setDeviceType(sdtProperty.getValue());
+// } else if (shortName.equals(PropertyType.deviceType.getShortName())) {
+// devInfo.setDeviceType(sdtProperty.getValue());
} else if (shortName.equals(PropertyType.hardwareVersion.getShortName())) {
devInfo.setHwVersion(sdtProperty.getValue());
} else if (shortName.equals(PropertyType.manufacturerDetailsLink.getShortName())) {
@@ -179,8 +182,8 @@ public class SDTDeviceAdaptor {
devInfo.setProtocol(sdtProperty.getValue());
} else {
CustomAttribute customAttributeForSdtProperty = new CustomAttribute();
- customAttributeForSdtProperty.setCustomAttributeName(shortName);
- customAttributeForSdtProperty.setCustomAttributeValue(sdtProperty.getValue());
+ customAttributeForSdtProperty.setShortName(shortName);
+ customAttributeForSdtProperty.setValue(sdtProperty.getValue());
logger.info("new Property CustomAttribute (" + customAttributeForSdtProperty + ")");
flexContainer.getCustomAttributes().add(customAttributeForSdtProperty);
}
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTModuleAdaptor.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTModuleAdaptor.java
index a753fe03..4ccc9be0 100644
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTModuleAdaptor.java
+++ b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTModuleAdaptor.java
@@ -8,7 +8,6 @@
package org.eclipse.om2m.ipe.sdt;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -18,14 +17,11 @@ import org.eclipse.om2m.commons.resource.AbstractFlexContainer;
import org.eclipse.om2m.commons.resource.CustomAttribute;
import org.eclipse.om2m.commons.resource.ResponsePrimitive;
import org.eclipse.om2m.commons.resource.flexcontainerspec.FlexContainerFactory;
-import org.eclipse.om2m.core.service.CseService;
import org.eclipse.om2m.ipe.sdt.flexcontainerservice.ModuleFlexContainerService;
import org.eclipse.om2m.sdt.Action;
import org.eclipse.om2m.sdt.DataPoint;
import org.eclipse.om2m.sdt.Module;
import org.eclipse.om2m.sdt.Property;
-import org.eclipse.om2m.sdt.datapoints.AbstractDateDataPoint;
-import org.eclipse.om2m.sdt.datapoints.ArrayDataPoint;
import org.eclipse.om2m.sdt.datapoints.ValuedDataPoint;
import org.eclipse.om2m.sdt.exceptions.AccessException;
import org.eclipse.om2m.sdt.exceptions.DataPointException;
@@ -89,32 +85,15 @@ public class SDTModuleAdaptor {
/// each DataPoint is a custom attribute
for (DataPoint dp : module.getDataPoints()) {
CustomAttribute customAttribute = new CustomAttribute();
- String customAttributeName = dp.getShortDefinitionType();
+ String customAttributeName = dp.getShortName();
if (customAttributeName == null) {
customAttributeName = dp.getName();
}
- customAttribute.setCustomAttributeName(customAttributeName);
- String value = null;
+ customAttribute.setShortName(customAttributeName);
try {
- if (dp instanceof AbstractDateDataPoint) {
- value = ((AbstractDateDataPoint) dp).getStringValue();
- } else if (dp instanceof ArrayDataPoint<?>) {
- List<?> values = ((ArrayDataPoint<?>) dp).getValue();
- if (values != null) {
- StringBuffer sb = new StringBuffer();
- boolean first = true;
- for (Object i : values) {
- if (first) first = false;
- else sb.append(",");
- sb.append(i.toString());
- }
- value = sb.toString();
- }
- } else {
- Object val = ((ValuedDataPoint<Object>) dp).getValue();
- if (val != null)
- value = val.toString();
- }
+ customAttribute.setValue(((ValuedDataPoint<Object>) dp).toStringValue());
+ customAttribute.setLongName(dp.getLongName());
+ customAttribute.setType(dp.getDataType().getTypeChoice().getOneM2MType());
} catch (DataPointException e) {
// how to handle this exception?
// should we stop module publishing step in oneM2M tree ?
@@ -128,7 +107,6 @@ public class SDTModuleAdaptor {
} catch (Exception e) {
logger.error("Error in datapoint " + dp, e);
}
- customAttribute.setCustomAttributeValue(value);
logger.info("add DataPoint customAttribute(" + customAttribute + ")");
flexContainer.getCustomAttributes().add(customAttribute);
@@ -143,8 +121,8 @@ public class SDTModuleAdaptor {
}
CustomAttribute caForSdtProperty = new CustomAttribute();
- caForSdtProperty.setCustomAttributeName(sdtProperty.getShortName());
- caForSdtProperty.setCustomAttributeValue(sdtProperty.getValue());
+ caForSdtProperty.setShortName(sdtProperty.getShortName());
+ caForSdtProperty.setValue(sdtProperty.getValue());
logger.info("add Property customAttribute(" + caForSdtProperty + ")");
flexContainer.getCustomAttributes().add(caForSdtProperty);
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTUtil.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTUtil.java
deleted file mode 100644
index 364d9d07..00000000
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/SDTUtil.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 Orange.
- * 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
- *******************************************************************************/
-package org.eclipse.om2m.ipe.sdt;
-
-import java.net.URI;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.eclipse.om2m.commons.resource.CustomAttribute;
-
-public class SDTUtil {
-
- static final private DateFormat dateTimeFormat = DateFormat.getDateTimeInstance();
- static final private DateFormat dateFormat = DateFormat.getDateInstance();
- static final private DateFormat timeFormat = DateFormat.getTimeInstance();
-
- public static Object getValue(CustomAttribute attr, String type) throws Exception {
- return getValue(attr.getCustomAttributeValue(), type);
- }
-
- public static Object getValue(String value, String type) throws Exception {
- if (value == null)
- return null;
- switch (type) {
- case "xs:string": return value;
- case "xs:integer":
- return Integer.parseInt(value);
- case "xs:float": return Float.parseFloat(value);
- case "xs:boolean": return Boolean.parseBoolean(value);
- case "xs:datetime": return dateTimeFormat.parse(value);
- case "xs:time": return timeFormat.parse(value);
- case "xs:date": return dateFormat.parse(value);
- case "xs:byte": return Byte.parseByte(value);
- case "xs:enum":
- List<String> ret = new ArrayList<String>();
- value = value.trim();
- if (value.charAt(0) == '[')
- value = value.substring(1);
- int last = value.length() - 1;
- if (value.charAt(last) == ']')
- value = value.substring(0, last);
- for (String val : value.split(",")) {
- ret.add(val.trim());
- }
- return ret;
- case "xs:uri": return new URI(value);
- case "xs:blob": return value;
- default:
- return type.startsWith("hd:") ? Integer.parseInt(value) : value;
- }
- }
-
- public static String getStringValue(String type, Object val) throws Exception {
- if (val == null) {
- return null;
- }
- switch (type) {
- case "xs:string":
- return val.toString();//"\"" + val.toString() + "\"";
- case "xs:integer":
- case "xs:float":
- case "xs:boolean":
- case "xs:byte":
- case "xs:uri":
- return val.toString();
- case "xs:datetime": return dateTimeFormat.format((Date)val);
- case "xs:time": return timeFormat.format((Date)val);
- case "xs:date": return dateFormat.format((Date)val);
- case "xs:enum":
- String ret = "";
- boolean first = true;
- for (Object s : (List<?>)val) {
- if (first) ret += ",";
- else first = false;
- ret += s.toString();
- }
- return ret;
- case "xs:blob": return null;// TODO serialize byte array
- default:
- if (type.startsWith("hd:"))
- return val.toString();
- return null;
- }
- }
-
-}
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ActionFlexContainerService.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ActionFlexContainerService.java
index 6bc552bc..42d3d6be 100644
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ActionFlexContainerService.java
+++ b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ActionFlexContainerService.java
@@ -20,11 +20,11 @@ import org.eclipse.om2m.commons.resource.CustomAttribute;
import org.eclipse.om2m.commons.resource.RequestPrimitive;
import org.eclipse.om2m.flexcontainer.service.FlexContainerService;
import org.eclipse.om2m.ipe.sdt.Activator;
-import org.eclipse.om2m.ipe.sdt.SDTUtil;
import org.eclipse.om2m.sdt.Action;
import org.eclipse.om2m.sdt.args.Command;
import org.eclipse.om2m.sdt.exceptions.AccessException;
import org.eclipse.om2m.sdt.exceptions.ActionException;
+import org.eclipse.om2m.sdt.types.DataType;
import org.osgi.framework.ServiceRegistration;
public class ActionFlexContainerService implements FlexContainerService {
@@ -86,16 +86,15 @@ public class ActionFlexContainerService implements FlexContainerService {
for (String argName : action.getArgNames()) {
CustomAttribute ca = getCustomAttribute(customAttributes, argName);
if (ca != null) {
- args.put(argName, SDTUtil.getValue(ca, "string"));
+ DataType type = DataType.getDataType(ca.getType());
+ args.put(argName,
+ type.getTypeChoice().fromString(ca.getValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
-// actionToBeInvoked = true;
- } /* else nothing to do */
-// } else {
-// actionToBeInvoked = true;
+ }
}
// if (actionToBeInvoked) {
@@ -105,16 +104,16 @@ public class ActionFlexContainerService implements FlexContainerService {
Object response = ((Command) action).invoke(args);
if (response != null) {
CustomAttribute output = new CustomAttribute();
- output.setCustomAttributeName("output");
- output.setCustomAttributeValue(response.toString());
+ output.setShortName("output");
+ output.setValue(response.toString());
customAttributes.add(output);
}
} catch (ActionException e) {
- logger.debug("setCustomAttributeValues(" + customAttributes
+ logger.info("setCustomAttributeValues(" + customAttributes
+ ") - KO: " + e.getMessage());
throw new Om2mException("action execution failed:" + e.getMessage(), ResponseStatusCode.BAD_REQUEST);
} catch (AccessException e) {
- logger.debug("setCustomAttributeValues(" + customAttributes
+ logger.info("setCustomAttributeValues(" + customAttributes
+ ") - KO: " + e.getMessage());
throw new Om2mException("action execution failed:" + e.getMessage(), ResponseStatusCode.ACCESS_DENIED);
}
@@ -138,7 +137,7 @@ public class ActionFlexContainerService implements FlexContainerService {
private static CustomAttribute getCustomAttribute(List<CustomAttribute> customAttributes, String name) {
if (customAttributes != null) {
for (CustomAttribute ca : customAttributes) {
- if (name.equals(ca.getCustomAttributeName())) {
+ if (name.equals(ca.getShortName())) {
return ca;
}
}
diff --git a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ModuleFlexContainerService.java b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ModuleFlexContainerService.java
index 5fab0783..44d37dc2 100644
--- a/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ModuleFlexContainerService.java
+++ b/org.eclipse.om2m.ipe.sdt/src/main/java/org/eclipse/om2m/ipe/sdt/flexcontainerservice/ModuleFlexContainerService.java
@@ -20,13 +20,13 @@ import org.eclipse.om2m.commons.resource.CustomAttribute;
import org.eclipse.om2m.commons.resource.RequestPrimitive;
import org.eclipse.om2m.flexcontainer.service.FlexContainerService;
import org.eclipse.om2m.ipe.sdt.Activator;
-import org.eclipse.om2m.ipe.sdt.SDTUtil;
import org.eclipse.om2m.sdt.DataPoint;
import org.eclipse.om2m.sdt.Module;
import org.eclipse.om2m.sdt.Property;
import org.eclipse.om2m.sdt.datapoints.ValuedDataPoint;
import org.eclipse.om2m.sdt.exceptions.AccessException;
import org.eclipse.om2m.sdt.exceptions.DataPointException;
+import org.eclipse.om2m.sdt.types.DataType.TypeChoice;
import org.osgi.framework.ServiceRegistration;
public class ModuleFlexContainerService implements FlexContainerService {
@@ -60,7 +60,7 @@ public class ModuleFlexContainerService implements FlexContainerService {
@Override
public String getCustomAttributeValue(String customAttributeName) throws Om2mException {
- logger.debug("DataPointFlexContainerService - getCustomAttributeValue(customAttributeName="
+ logger.debug("DataPointFlexContainerService - getCustomAttributeValue(name="
+ customAttributeName + ")");
Property prop = module.getPropertyByShortName(customAttributeName);
if (prop != null) {
@@ -68,7 +68,7 @@ public class ModuleFlexContainerService implements FlexContainerService {
return prop.getValue();
}
- // retrieve the DataPoint object based on customAttributeName input parameter
+ // retrieve the DataPoint object based on name input parameter
DataPoint dataPoint = module.getDataPointByShortName(customAttributeName);
if (dataPoint == null) {
throw new Om2mException("unknown custom attribute " + customAttributeName + " in " + module,
@@ -76,24 +76,17 @@ public class ModuleFlexContainerService implements FlexContainerService {
}
// at this point, we are sure the DataPoint exist.
- String value = null;
try {
- Object o = ((ValuedDataPoint<?>) dataPoint).getValue();
- String type = dataPoint.getDataType().getTypeChoice().getOneM2MType();
- value = SDTUtil.getStringValue(type, o);
+ return ((ValuedDataPoint<?>) dataPoint).toStringValue();
} catch (AccessException e) {
- e.printStackTrace();
+ logger.info("", e);
throw new Om2mException("unable to retrieve value of DataPoint " + dataPoint.getName() + " : " + e.getMessage(),
ResponseStatusCode.ACCESS_DENIED);
} catch (Exception e) {
- e.printStackTrace();
+ logger.info("", e);
throw new Om2mException("unable to retrieve value of DataPoint " + dataPoint.getName() + " : " + e.getMessage(),
ResponseStatusCode.INTERNAL_SERVER_ERROR);
}
-
- logger.debug("DataPointFlexContainerService - getCustomAttributeValue(customAttributeName=" + customAttributeName
- + ") - value=" + value);
- return value;
}
@Override
@@ -112,13 +105,16 @@ public class ModuleFlexContainerService implements FlexContainerService {
dpNames.add(name);
} else {
logger.warn("CustomAttribute " + name + " unknown");
- throw new Om2mException(ResponseStatusCode.INVALID_ARGUMENTS);
+ // BONNARDEL Gregory - 2018 07 05
+ // voir pourquoi on rentre dans ce bout de code ???
+// throw new Om2mException(ResponseStatusCode.INVALID_ARGUMENTS);
}
}
for (Map.Entry<String, Object> entry : module.getDatapointHandler().getValues(dpNames).entrySet()) {
DataPoint dataPoint = module.getDataPointByShortName(entry.getKey());
String type = dataPoint.getDataType().getTypeChoice().getOneM2MType();
- ret.put(entry.getKey(), SDTUtil.getStringValue(type, entry.getValue()));
+// ret.put(entry.getKey(), SDTUtil.getStringValue(type, entry.getValue()));
+ ret.put(entry.getKey(), (entry.getValue() != null ? entry.getValue().toString() : null));
}
return ret;
} catch (AccessException e) {
@@ -140,16 +136,15 @@ public class ModuleFlexContainerService implements FlexContainerService {
Map<String, Object> values = new HashMap<String, Object>();
for (CustomAttribute ca : customAttributes) {
- DataPoint dataPoint = module.getDataPointByShortName(ca.getCustomAttributeName());
+ DataPoint dataPoint = module.getDataPointByShortName(ca.getShortName());
if (dataPoint == null)
// no datapoint for this attribute
// throw a Om2mException
throw new Om2mException(ResponseStatusCode.INVALID_ARGUMENTS);
try {
// retrieve type of the DataPoint
- String type = dataPoint.getDataType().getTypeChoice().getOneM2MType();
- values.put(ca.getCustomAttributeName(),
- SDTUtil.getValue(ca.getCustomAttributeValue(), type));
+ TypeChoice type = dataPoint.getDataType().getTypeChoice();
+ values.put(ca.getShortName(), type.fromString(ca.getValue()));
} catch (Exception e) {
logger.info("KO: " + e.getMessage());
throw new Om2mException(e.getMessage(), e,

Back to the top