Add the new 'rws' field to the DataResource JSON description : it defines the Read/Write status, meaning whether the default attribute of this DataResource is modifiable or not
diff --git a/platform/northbound/geo-filtering/geojson-filter/src/main/java/org/eclipse/sensinact/gateway/nthbnd/filter/geojson/internal/GeoJSONFiltering.java b/platform/northbound/geo-filtering/geojson-filter/src/main/java/org/eclipse/sensinact/gateway/nthbnd/filter/geojson/internal/GeoJSONFiltering.java
index 4f646ed..4888cdc 100644
--- a/platform/northbound/geo-filtering/geojson-filter/src/main/java/org/eclipse/sensinact/gateway/nthbnd/filter/geojson/internal/GeoJSONFiltering.java
+++ b/platform/northbound/geo-filtering/geojson-filter/src/main/java/org/eclipse/sensinact/gateway/nthbnd/filter/geojson/internal/GeoJSONFiltering.java
@@ -73,20 +73,11 @@
this.mediator = mediator;
}
- /**
- * @inheritDoc
- * @see org.eclipse.sensinact.gateway.core.Filtering#handle(java.lang.String)
- */
@Override
public boolean handle(String type) {
return "geojson".equals(type);
}
-
- /**
- * @inheritDoc
- * @see org.eclipse.sensinact.gateway.core.Filtering#apply(java.lang.String, java.lang.Object)
- */
@Override
public String apply(String definition, Object result) {
JSONObject obj = new JSONObject(definition);
@@ -149,16 +140,26 @@
boolean writeLocation(String name, String location, int index, StringBuilder builder) {
try {
- String[] locationElements = location.split(":");
-
+ char[] seps = new char[] {':',',',' '};
+ int pos = 0;
+ for(;pos < seps.length; pos++) {
+ int sep = location.indexOf(':');
+ if(sep >= 0)
+ break;
+ }
+ if(pos == seps.length)
+ return false;
+
+ char sep = seps[pos];
+ String[] locationElements = location.split(new String(new char[] {sep}));
double latitude = Double.parseDouble(locationElements[0]);
double longitude = Double.parseDouble(locationElements[1]);
STATEMENT.apply("latitude", latitude);
STATEMENT.apply("longitude", longitude);
STATEMENT.apply("name", name);
- if (index > 0) {
+ if (index > 0)
builder.append(",");
- }
+
builder.append(STATEMENT.toString());
return true;
@@ -171,10 +172,6 @@
return false;
}
- /**
- * @inheritDoc
- * @see org.eclipse.sensinact.gateway.core.Filtering#getLDAPComponent()
- */
@Override
public String getLDAPComponent(String definition) {
String ldapFilter = null;
@@ -186,20 +183,23 @@
Segment rad0 = null;
Segment rad90 = null;
-
+ int bearing0 = Double.valueOf(LocationUtils.fromReverseClockedDegreesAngleToNorthOrientedBearing(0)).intValue();
+ int bearing90 = Double.valueOf(LocationUtils.fromReverseClockedDegreesAngleToNorthOrientedBearing(90)).intValue();
if (distance < 200) {
- rad0 = LocationUtils.getSphericalEarthModelCoordinates(lat, lng, 0, distance);
- rad90 = LocationUtils.getSphericalEarthModelCoordinates(lat, lng, 90, distance);
-
+ rad0 = LocationUtils.getSphericalEarthModelCoordinates(lat, lng, bearing0 , distance);
+ rad90 = LocationUtils.getSphericalEarthModelCoordinates(lat, lng, bearing90, distance);
} else {
- rad0 = LocationUtils.getElipsoidEarthModelCoordinates(lat, lng, 0, distance);
- rad90 = LocationUtils.getElipsoidEarthModelCoordinates(lat, lng, 90, distance);
+ rad0 = LocationUtils.getElipsoidEarthModelCoordinates(lat, lng, bearing0,distance);
+ rad90 = LocationUtils.getElipsoidEarthModelCoordinates(lat, lng, bearing90, distance);
}
double diffLat = Math.abs((rad0.getLat1() - rad0.getLat2()));
double diffLng = Math.abs((rad90.getLng1() - rad90.getLng2()));
- ldapFilter = String.format("(&(latitude <= %s)(latitude >= %s)(longitude <= %s)(longitude >= %s))", (lat + diffLat), (lat - diffLat), (lng + diffLng), (lng - diffLng));
- } catch (JSONException e) {
+ ldapFilter = String.format("(&(latitude <= %s)(latitude >= %s)(longitude <= %s)(longitude >= %s))",
+ (lat + diffLat), (lat - diffLat), (lng + diffLng), (lng - diffLng));
+
+ } catch (Exception e) {
+ e.printStackTrace();
return null;
}
return ldapFilter;
diff --git a/platform/sensinact-common/src/main/java/org/eclipse/sensinact/gateway/common/primitive/Primitive.java b/platform/sensinact-common/src/main/java/org/eclipse/sensinact/gateway/common/primitive/Primitive.java
index df8a5ac..ca3c907 100644
--- a/platform/sensinact-common/src/main/java/org/eclipse/sensinact/gateway/common/primitive/Primitive.java
+++ b/platform/sensinact-common/src/main/java/org/eclipse/sensinact/gateway/common/primitive/Primitive.java
@@ -124,23 +124,18 @@
/**
* Constructor
*
- * @param jsonObject the JSONObject describing the Primitive
- * to instantiate
+ * @param jsonObject the JSONObject describing the Primitive to instantiate
*/
protected Primitive(Mediator mediator, JSONObject jsonObject) throws InvalidValueException {
- this(mediator, jsonObject == null ? null : jsonObject.optString(PrimitiveDescription.NAME_KEY), jsonObject == null ? null : jsonObject.optString(PrimitiveDescription.TYPE_KEY));
-
+ this(mediator, jsonObject == null ? null : jsonObject.optString(PrimitiveDescription.NAME_KEY),
+ jsonObject == null ? null : jsonObject.optString(PrimitiveDescription.TYPE_KEY));
// set the value if defined in the JSONObject
Object ovalue = jsonObject.opt(PrimitiveDescription.VALUE_KEY);
- if (ovalue != null) {
+ if (ovalue != null)
this.setValue(CastUtils.getObjectFromJSON(this.mediator.getClassLoader(), this.getType(), ovalue));
- }
}
-
- /**
- * @inheritDoc
- * @see Nameable#getName()
- */
+
+ @Override
public String getName() {
return this.name;
}
@@ -175,23 +170,23 @@
* Sets this Primitive's value
*
* @param value the value to set
+ *
* @throws InvalidValueException if the value cannot be set
*/
public Object setValue(Object value) throws InvalidValueException {
- if (Modifiable.FIXED.equals(this.getModifiable())) {
+ if (Modifiable.FIXED.equals(this.getModifiable()))
throw new InvalidValueException("the value cannot be modified");
- }
+
Object valueObject = cast(value);
Object copy = CastUtils.copy(this.type, valueObject);
synchronized (lock) {
- boolean hasChanged = ((valueObject == null && this.value != null) || (valueObject != null && !valueObject.equals(this.value)));
-
+ boolean hasChanged = ((valueObject == null && this.value != null)
+ || (valueObject != null && !valueObject.equals(this.value)));
this.beforeChange(copy);
this.value = valueObject;
- if (hasChanged) {
+ if (hasChanged)
this.afterChange(copy);
- }
}
return copy;
}
@@ -202,7 +197,11 @@
* @param type the type to validate
*/
protected void checkType(Class<?> type) throws InvalidValueTypeException {
- if (!CastUtils.isPrimitive(type) && !JSONObject.class.isAssignableFrom(type) && !JSONArray.class.isAssignableFrom(type) && !type.isEnum() && (!type.isArray() || !CastUtils.isPrimitive(type.getComponentType()))) {
+ if (!CastUtils.isPrimitive(type)
+ && !JSONObject.class.isAssignableFrom(type)
+ && !JSONArray.class.isAssignableFrom(type)
+ && !type.isEnum()
+ && (!type.isArray() || !CastUtils.isPrimitive(type.getComponentType()))) {
throw new InvalidValueTypeException("Invalid type : " + type.getCanonicalName());
}
}
@@ -213,10 +212,13 @@
*
* @param value the value object to cast
* @return the casted object value
- * @throws InvalidValueException if the value object cannot be cast into the type
- * of this Primitive
+ *
+ * @throws InvalidValueException if the value object cannot be cast
+ * into the type of this Primitive
*/
protected Object cast(Object value) throws InvalidValueException {
+ if(value == null)
+ return value;
Object valueObject = null;
try {
valueObject = CastUtils.cast(this.mediator.getClassLoader(), this.getType(), value);
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Attribute.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Attribute.java
index 3a5c74f..1a6bb0a 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Attribute.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Attribute.java
@@ -112,11 +112,9 @@
* Constructs an attribute from the given {@link JSONObject} for the
* ResourceImpl passed as parameter
*
- * @param mediator
- * the {@link Mediator} allowing the Attribute to be instantiated to
- * interact with the OSGi host environment
- * @param attribute
- * the {@link JSONObject} describing the attribute to instantiate
+ * @param mediator the {@link Mediator} allowing the Attribute to be instantiated to
+ * interact with the OSGi host environment
+ * @param attribute the {@link JSONObject} describing the attribute to instantiate
*/
protected Attribute(Mediator mediator, ResourceImpl resource, JSONObject attribute) throws InvalidValueException {
super(mediator, attribute == null ? null : attribute.optString(PrimitiveDescription.NAME_KEY),
@@ -170,12 +168,10 @@
* Defines the value of the {@link Metadata} whose whose name is passed as
* parameter
*
- * @param name
- * the name of the {@link Metadata} to set the value of
- * @param value
- * the value to set
+ * @param name the name of the {@link Metadata} to set the value of
+ * @param value the value to set
* @return the extended {@link Description} describing the modified Metadata
- * {@link Metadata}
+ * {@link Metadata}
*
* @throws InvalidValueException
*/
@@ -193,17 +189,16 @@
* this Attribute if it does not already exist or replaces the existing one with
* the same name if it is defined as modifiable
*
- * @param metadata
- * the {@link Metadata} to add or update
+ * @param metadata the {@link Metadata} to add or update
*/
public void addMetadata(Metadata metadata) {
Metadata meta = this.get(metadata.getName());
synchronized (this.metadata) {
- if (meta == null) {
+ if (meta == null) {
this.metadata.add(metadata);
- super.weakDescription = null;
+ super.weakDescription = null;
if(!metadata.getName().equals(Metadata.HIDDEN) && metadata.getModifiable().equals(Modifiable.FIXED))
- this.resource.updated(this, metadata.getDescription());
+ this.resource.updated(this, metadata.getDescription());
} else {
try {
this.setMetadataValue(metadata.getName(), metadata.getValue());
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/LinkedResourceImpl.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/LinkedResourceImpl.java
index 46d7523..a193393 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/LinkedResourceImpl.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/LinkedResourceImpl.java
@@ -46,7 +46,7 @@
String defaultAttributeName = resourceConfig.getTypeConfig()
.<String>getConstantValue(Resource.ATTRIBUTE_DEFAULT_PROPERTY, false);
- this.setDefault(defaultAttributeName);
+ super.setDefault(defaultAttributeName);
try {
super.elements.add(new Attribute(super.modelInstance.mediator(), this, Resource.NAME, String.class,
UriUtils.getLeaf(super.uri), Modifiable.FIXED, true));
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Metadata.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Metadata.java
index 4e6c3e1..7291bd3 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Metadata.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/Metadata.java
@@ -65,8 +65,7 @@
/**
* Constructs a Metadata using the given {@link JSONObject}
*
- * @param metadata
- * the {@link JSONObject} describing the Metadata to instantiate
+ * @param metadata the {@link JSONObject} describing the Metadata to instantiate
*
* @throws InvalidConstraintDefinitionException
*/
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ModelInstanceRegistration.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ModelInstanceRegistration.java
index 45727f3..e3e5d60 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ModelInstanceRegistration.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ModelInstanceRegistration.java
@@ -194,9 +194,8 @@
}
private final void updateObserved(String observed, Object value) {
- if (!registered || observed == null) {
+ if (!registered || observed == null)
return;
- }
Dictionary<String, Object> properties = properties();
properties.remove(observed);
@@ -222,9 +221,8 @@
}
}
}
- if (value == null) {
- return;
- }
+ if (value == null)
+ return;
properties.put(observed, value);
this.update(properties);
}
@@ -411,7 +409,7 @@
}
break;
case METADATA_VALUE_UPDATED:
- Object value = notification.opt(DataResource.VALUE);
+ Object value = notification.opt(DataResource.VALUE);
this.updateObserved(new StringBuilder().append(key).append("."
).append(uriElements[3]).append(".").append(uriElements[4]).toString(), value);
break;
@@ -425,7 +423,9 @@
JSONObject initial = null;
switch (l.getType()) {
case RESOURCE_APPEARING:
+ key = new StringBuilder().append(uriElements[1]).append(".").append(uriElements[2]).toString();
initial = (JSONObject) ((SnaLifecycleMessageImpl) l).get("initial");
+
type = ((SnaLifecycleMessageImpl) l).getNotification().optString("type");
ResourceConfig config = configuration.getResourceConfig(new ResourceDescriptor(
).withResourceName(uriElements[2]
@@ -462,7 +462,12 @@
if (!list.contains(attr))
list.add(attr);
}
- }
+ }
+ String modifiable = initial==null?null:String.valueOf(initial.opt(Metadata.MODIFIABLE));
+ if(modifiable!=null)
+ this.updateObserved(new StringBuilder().append(key).append("."
+ ).append(DataResource.VALUE).append(".").append(Metadata.MODIFIABLE).toString(),
+ modifiable);
case SERVICE_APPEARING:
case PROVIDER_DISAPPEARING:
case RESOURCE_DISAPPEARING:
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/RegistryEndpoint.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/RegistryEndpoint.java
index 141618a..0068dad 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/RegistryEndpoint.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/RegistryEndpoint.java
@@ -98,15 +98,14 @@
SensiNactResourceModel model = mediator.getContext().getService(ref);
ServiceProvider provider = null;
try {
- provider = (ServiceProvider) model.getRootElement()
- .getProxy(sessionKey.getAccessTree());
+ provider = (ServiceProvider) model.getRootElement().getProxy(
+ sessionKey.getAccessTree());
} catch (ModelElementProxyBuildException e) {
mediator.error(e);
}
- if (provider != null && provider.isAccessible()) {
+ if (provider != null && provider.isAccessible())
providers.add(provider);
- }
}
return providers;
}
@@ -140,9 +139,8 @@
String resourceName) {
Service service = this.service(sessionKey, serviceProviderName, serviceName);
Resource resource = null;
- if (service != null) {
+ if (service != null)
resource = service.getResource(resourceName);
- }
return resource;
}
@@ -305,22 +303,52 @@
int rlength = resourceList == null ? 0 : resourceList.size();
for (; rindex < rlength; rindex++) {
String resource = resourceList.get(rindex);
- String resolvedResource = new StringBuilder().append(service).append(".").append(resource)
- .toString();
+ String resolvedResource = new StringBuilder().append(service).append(".").append(resource).toString();
String resourceUri = UriUtils.getUri(new String[] { name, service, resource });
Integer resourceLevel = (Integer) reference.getProperty(resolvedResource.concat(".DESCRIBE"));
- if (resourceLevel == null) {
+
+ if (resourceLevel == null)
resourceLevel = Integer.valueOf(AccessLevelOption.OWNER.getAccessLevel().getLevel());
- }
+
node = sessionKey.getAccessTree().getRoot().get(resourceUri);
- if (node == null) {
+ if (node == null)
node = tree.getRoot();
- }
- if (node.getAccessLevelOption(describe).getAccessLevel().getLevel() < resourceLevel
- .intValue()) {
+
+ if (node.getAccessLevelOption(describe).getAccessLevel().getLevel() < resourceLevel.intValue())
continue;
- }
+
String type = (String) reference.getProperty(resolvedResource.concat(".type"));
+ String rws = null;
+
+ switch(type) {
+ case "PROPERTY":
+ case "STATE_VARIABLE":
+ case "SENSOR":
+ StringBuilder sbuilder = new StringBuilder();
+ sbuilder.append(resolvedResource);
+ sbuilder.append(".");
+ sbuilder.append(DataResource.VALUE);
+ sbuilder.append(".");
+ sbuilder.append(Metadata.MODIFIABLE);
+ String st = (String) reference.getProperty(sbuilder.toString());
+ if(st!=null) {
+ switch(st) {
+ case "MODIFIABLE":
+ rws = "RW";
+ break;
+ case "FIXED":
+ case "UPDATABLE":
+ rws = "RO";
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case "ACTION":
+ default:
+ break;
+ }
builder.append(rindex > 0 ? ',' : "");
builder.append('{');
builder.append("\"name\":");
@@ -331,6 +359,12 @@
builder.append('"');
builder.append(type);
builder.append('"');
+ if(rws != null) {
+ builder.append(",\"rws\":");
+ builder.append('"');
+ builder.append(rws);
+ builder.append('"');
+ }
builder.append('}');
}
builder.append(']');
@@ -373,11 +407,6 @@
}
}
- /**
- * @inheritDoc
- *
- * @see org.eclipse.sensinact.gateway.core.Core#namespace()
- */
protected String namespace() {
String namespace = this.mediator.callService(SensinactCoreBaseIFaceManager.class,
new Executable<SensinactCoreBaseIFaceManager,String>() {
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ResourceImpl.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ResourceImpl.java
index 7190cf1..49e0a76 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ResourceImpl.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/ResourceImpl.java
@@ -99,6 +99,35 @@
buffer.append(JSONUtils.QUOTE);
buffer.append(ResourceProxyWrapper.this.getType().name());
buffer.append(JSONUtils.QUOTE);
+
+ switch(ResourceProxyWrapper.this.getType()) {
+ case ACTION:
+ break;
+ case PROPERTY:
+ case SENSOR:
+ case STATE_VARIABLE:
+ buffer.append(JSONUtils.COMMA);
+ buffer.append(JSONUtils.QUOTE);
+ buffer.append("rws");
+ buffer.append(JSONUtils.QUOTE);
+ buffer.append(JSONUtils.COLON);
+ buffer.append(JSONUtils.QUOTE);
+ switch(ResourceProxyWrapper.this.element(DataResource.VALUE).getModifiable()) {
+ case MODIFIABLE:
+ buffer.append("RW");
+ break;
+ case FIXED:
+ case UPDATABLE:
+ buffer.append("RO");
+ break;
+ default:
+ break;
+ }
+ buffer.append(JSONUtils.QUOTE);
+ break;
+ default:
+ break;
+ }
buffer.append(JSONUtils.CLOSE_BRACE);
return buffer.toString();
}
@@ -496,10 +525,9 @@
/**
* Defines the name of the default {@link Attribute} of this ResourceImpl
*
- * @param defaultAttribute
- * the name of the default {@link Attribute}
+ * @param defaultAttribute the name of the default {@link Attribute}
*/
- public void setDefault(String defaultAttribute) {
+ void setDefault(String defaultAttribute) {
this.defaultAttribute = defaultAttribute;
}
@@ -770,20 +798,29 @@
int length = metadataDescriptions.length;
for (; index < length; index++) {
MetadataDescription metadataDescription = metadataDescriptions[index];
- String metadataName = metadataDescription.getName().intern();
+ String metadataName = metadataDescription.getName().intern();
+
+// if (Modifiable.FIXED.equals(metadataDescription.getModifiable())
+// && Metadata.LOCKED.intern() != metadataName && Metadata.MODIFIABLE.intern() != metadataName
+// && Metadata.HIDDEN.intern() != metadataName && Attribute.NICKNAME.intern() != metadataName)
+// jsonAttribute.put(metadataDescription.getName(), PrimitiveDescription.toJson(metadataDescription.getType(),
+// metadataDescription.getValue()));
+
if (Modifiable.FIXED.equals(metadataDescription.getModifiable())
- && Metadata.LOCKED.intern() != metadataName && Metadata.MODIFIABLE.intern() != metadataName
- && Metadata.HIDDEN.intern() != metadataName && Attribute.NICKNAME.intern() != metadataName) {
- jsonAttribute.put(metadataDescription.getName(),
- PrimitiveDescription.toJson(metadataDescription.getType(), metadataDescription.getValue()));
- }
+ && Metadata.LOCKED.intern() != metadataName && Metadata.HIDDEN.intern() != metadataName
+ && Attribute.NICKNAME.intern() != metadataName)
+ jsonAttribute.put(metadataDescription.getName(), PrimitiveDescription.toJson(metadataDescription.getType(),
+ metadataDescription.getValue()));
+
}
((SnaLifecycleMessageImpl) notification).put("initial", jsonAttribute);
}
if(attribute.isHidden())
continue;
for(Metadata m : attribute.metadata) {
- if(!m.getName().equals(Metadata.HIDDEN) && m.getModifiable().equals(Modifiable.FIXED) && m.getValue()!=null )
+ if(!m.getName().equals(Metadata.HIDDEN)
+ && m.getModifiable().equals(Modifiable.FIXED)
+ && m.getValue()!=null )
this.updated(attribute, m.getDescription());
}
}
diff --git a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/SensiNact.java b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/SensiNact.java
index f3534b3..64c3a10 100644
--- a/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/SensiNact.java
+++ b/platform/sensinact-core/src/main/java/org/eclipse/sensinact/gateway/core/SensiNact.java
@@ -565,10 +565,9 @@
builder.setAccessMethodObjectResult(result);
response = builder.createAccessMethodResponse(Status.SUCCESS);
- if (filterCollection != null) {
+ if (filterCollection != null)
response.put("filters", new JSONArray(filterCollection.filterJsonDefinition()),
filterCollection.hideFilter());
- }
return tatooRequestId(requestId, response);
}
@@ -596,7 +595,7 @@
});
if (providers == null) {
response = SensiNact.<String, DescribeResponse<String>>createErrorResponse(mediator,
- DescribeType.PROVIDERS_LIST, UriUtils.PATH_SEPARATOR, SnaErrorfulMessage.NOT_FOUND_ERROR_CODE,
+ DescribeType.PROVIDERS_LIST, UriUtils.PATH_SEPARATOR, SnaErrorfulMessage.NOT_FOUND_ERROR_CODE,
"Internal server error", null);
return tatooRequestId(requestId, response);
@@ -1669,7 +1668,7 @@
* @return the {@link Service}
*/
protected Service service(String identifier, String serviceProviderId, String serviceId) {
- final SessionKey sessionKey = this.getSessionKeyFromToken(identifier);
+ SessionKey sessionKey = this.getSessionKeyFromToken(identifier);
return this.registry.service(sessionKey, serviceProviderId, serviceId);
}
@@ -1691,10 +1690,7 @@
* @return the {@link Resource}
*/
protected Resource resource(String identifier, String serviceProviderId, String serviceId, String resourceId) {
- SessionKey sessionKey;
- synchronized(this.sessions) {
- sessionKey = this.sessions.get(new KeyExtractor<KeyExtractorType>(KeyExtractorType.TOKEN,identifier));
- }
+ SessionKey sessionKey = this.getSessionKeyFromToken(identifier);
return this.registry.resource(sessionKey, serviceProviderId, serviceId, resourceId);
}
@@ -1868,46 +1864,6 @@
return object;
}
- private boolean match(String expected, String found) {
- if(expected == null)
- return true;
- if(found == null)
- return false;
- if(found.equals(expected))
- return true;
- if(!expected.startsWith("(") || !expected.endsWith(")"))
- return false;
- String pattern = expected.substring(1,expected.length()-1);
- boolean match = true;
- if(pattern.startsWith("*")) {
- int pos = found.length()-1;
- for(int i=pattern.length()-1;i>0;i--) {
- if(pattern.charAt(i)!=found.charAt(pos)) {
- match=false;
- break;
- }
- pos--;
- }
- } else if(pattern.endsWith("*")){
- int pos = 0;
- for(int i=0;i<pattern.length()-1;i++) {
- if(pattern.charAt(i)!=found.charAt(pos)) {
- match=false;
- break;
- }
- pos++;
- }
- } else {
- try {
- Pattern _pattern = Pattern.compile(pattern);
- match = _pattern.matcher(found).matches();
- } catch(Exception e) {
- match = false;
- }
- }
- return match;
- }
-
/**
* Invokes the GET access method on the resource whose String identifier is
* passed as parameter, held by the specified service provider and service
@@ -2354,7 +2310,7 @@
});
}
- final SessionKey getSessionKeyFromToken(String sessionId) {
+ private final SessionKey getSessionKeyFromToken(String sessionId) {
SessionKey sessionKey;
synchronized(this.sessions) {
sessionKey = this.sessions.get(new KeyExtractor<KeyExtractorType>(KeyExtractorType.TOKEN, sessionId));
@@ -2364,7 +2320,47 @@
return sessionKey;
}
- String nextToken() {
+ private boolean match(String expected, String found) {
+ if(expected == null)
+ return true;
+ if(found == null)
+ return false;
+ if(found.equals(expected))
+ return true;
+ if(!expected.startsWith("(") || !expected.endsWith(")"))
+ return false;
+ String pattern = expected.substring(1,expected.length()-1);
+ boolean match = true;
+ if(pattern.startsWith("*")) {
+ int pos = found.length()-1;
+ for(int i=pattern.length()-1;i>0;i--) {
+ if(pattern.charAt(i)!=found.charAt(pos)) {
+ match=false;
+ break;
+ }
+ pos--;
+ }
+ } else if(pattern.endsWith("*")){
+ int pos = 0;
+ for(int i=0;i<pattern.length()-1;i++) {
+ if(pattern.charAt(i)!=found.charAt(pos)) {
+ match=false;
+ break;
+ }
+ pos++;
+ }
+ } else {
+ try {
+ Pattern _pattern = Pattern.compile(pattern);
+ match = _pattern.matcher(found).matches();
+ } catch(Exception e) {
+ match = false;
+ }
+ }
+ return match;
+ }
+
+ private String nextToken() {
boolean exists = false;
String token = null;
do {
@@ -2378,4 +2374,5 @@
} while (exists);
return token;
}
+
}
diff --git a/platform/sensinact-core/src/test/java/org/eclipse/sensinact/gateway/core/test/TestResourceBuilder.java b/platform/sensinact-core/src/test/java/org/eclipse/sensinact/gateway/core/test/TestResourceBuilder.java
index 13ae27a..158f7eb 100644
--- a/platform/sensinact-core/src/test/java/org/eclipse/sensinact/gateway/core/test/TestResourceBuilder.java
+++ b/platform/sensinact-core/src/test/java/org/eclipse/sensinact/gateway/core/test/TestResourceBuilder.java
@@ -731,7 +731,7 @@
"untriggered");
Session s = testContext.getSensiNact().getAnonymousSession();
- Thread.sleep(1000);
+ Thread.sleep(1000);
String obj = s.getAll(
new FilteringCollection(this.testContext.getMediator(), false, new FilteringDefinition("xfilter", "a")))
.getJSON();
diff --git a/platform/sensinact-utils/src/main/java/org/eclipse/sensinact/gateway/util/LocationUtils.java b/platform/sensinact-utils/src/main/java/org/eclipse/sensinact/gateway/util/LocationUtils.java
index 4b1ad56..d0ce5a4 100644
--- a/platform/sensinact-utils/src/main/java/org/eclipse/sensinact/gateway/util/LocationUtils.java
+++ b/platform/sensinact-utils/src/main/java/org/eclipse/sensinact/gateway/util/LocationUtils.java
@@ -39,7 +39,7 @@
}
return m;
}
-
+
public static double getDistance(double lat1, double lng1, double lat2, double lng2) {
double a = Constants.EARTH_SPHERICAL_MODEL_RADIUS * 1000D;
double dlong = ((lng2 - lng1) * Constants.DEGREES_TO_RADIUS_COEF) / 2;
@@ -75,7 +75,44 @@
backBrg = backBrg * Constants.RADIUS_TO_DEGREES_COEF;
return new Segment(lat, lng, lat2, lng2, finalBrg, backBrg , distance);
}
+
+ public static double fromReverseClockedRadiusAngleToNorthOrientedBearing(double angle) {
+ return fromReverseClockedDegreesAngleToNorthOrientedBearing(Constants.RADIUS_TO_DEGREES_COEF * angle);
+ }
+
+ public static double fromReverseClockedDegreesAngleToNorthOrientedBearing(double angle) {
+ double bearing=angle;
+ if(angle < 90)
+ bearing = 90-angle;
+ else if(angle <180)
+ bearing = 270+(180-angle);
+ else if(angle < 270)
+ bearing = 180+(270-angle);
+ else
+ bearing = 90+(360-angle);
+ return Constants.DEGREES_TO_RADIUS_COEF * bearing;
+ }
+
+ public static Point getDiffLatLng(Point origin, double dx, double dy) {
+ if(dx==0.0d && dy==0.0d)
+ return origin;
+ double agl = 0.0d;
+
+ if(dy == 0)
+ agl = dx >= 0?0:180;
+ else if(dx == 0)
+ agl = dy >= 0?90:270;
+ else {
+ agl = Constants.RADIUS_TO_DEGREES_COEF * Math.atan((dy/dx));
+ agl = agl + (dy<0 && dx<0?180:0);
+ }
+ double distance = Math.sqrt((Math.pow(Math.abs(dx),2)+ Math.pow(Math.abs(dy),2)));
+ Segment segment = getElipsoidEarthModelCoordinates(origin.latitude, origin.longitude,
+ fromReverseClockedDegreesAngleToNorthOrientedBearing(agl) ,distance);
+ return new Point(segment.getLat2(),segment.getLng2());
+ }
+
public static Segment getElipsoidEarthModelDistance(double latdep, double lngdep, double latarr, double lngarr) {
// The WGS 84 datum surface is an oblate spheroid (ellipsoid)
// with major (equatorial) radius a = 6378137 m at the equator
diff --git a/platform/southbound/mqtt/smart-topic-device/src/main/java/org/eclipse/sensinact/gateway/sthbnd/mqtt/smarttopic/processor/ProcessorExecutor.java b/platform/southbound/mqtt/smart-topic-device/src/main/java/org/eclipse/sensinact/gateway/sthbnd/mqtt/smarttopic/processor/ProcessorExecutor.java
index 671fc07..c7c24a9 100644
--- a/platform/southbound/mqtt/smart-topic-device/src/main/java/org/eclipse/sensinact/gateway/sthbnd/mqtt/smarttopic/processor/ProcessorExecutor.java
+++ b/platform/southbound/mqtt/smart-topic-device/src/main/java/org/eclipse/sensinact/gateway/sthbnd/mqtt/smarttopic/processor/ProcessorExecutor.java
@@ -43,9 +43,9 @@
String incompleteProcessedInData = inData;
for (SelectorIface selector : selectors) {
try {
- LOG.info("Selector {} IN Data {} Expression {}", selector.getName(), incompleteProcessedInData, selector.getExpression());
+ //LOG.info("Selector {} IN Data {} Expression {}", selector.getName(), incompleteProcessedInData, selector.getExpression());
incompleteProcessedInData = processors.get(selector.getName()).process(incompleteProcessedInData, selector);
- LOG.info("Selector {} OUT {}", selector.getName(), incompleteProcessedInData);
+ //LOG.info("Selector {} OUT {}", selector.getName(), incompleteProcessedInData);
} catch (Exception e) {
throw new ProcessorException("Failed to execute processor " + selector.getName(), e);
}