Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Context registration classes cleanup Context subscription implementation (tests and auto refresh pending)

Rich Turner0509f174e2f4
diff --git a/agent/src/main/java/org/openremote/agent/Connector.java b/agent/src/main/java/org/openremote/agent/Connector.java
index b80f3a56a..965889592 100644
--- a/agent/src/main/java/org/openremote/agent/Connector.java
+++ b/agent/src/main/java/org/openremote/agent/Connector.java
@@ -59,7 +59,7 @@ public interface Connector {
long addConnectionListener(Consumer<ConnectionState> callback);
/**
- * Remove an existing connection listerner
+ * Remove an existing connection listener
*/
void removeConnectionListener(long listenerId);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/AbstractContextBrokerResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/assets/AbstractContextBrokerResourceImpl.java
index 8b0711707..9717b55a5 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/AbstractContextBrokerResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/AbstractContextBrokerResourceImpl.java
@@ -19,7 +19,7 @@
*/
package org.openremote.manager.server.assets;
-import org.jboss.marshalling.Pair;
+import org.jgroups.util.Tuple;
import org.openremote.manager.shared.ngsi.*;
import java.util.ArrayList;
@@ -30,22 +30,22 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-public abstract class AbstractContextBrokerResourceImpl implements ContextProvider {
+public abstract class AbstractContextBrokerResourceImpl implements RegistrationProvider {
protected static final Logger LOG = Logger.getLogger(AbstractContextBrokerResourceImpl.class.getName());
public static final int REFRESH_INTERVAL = 180;
// Key = ENTITY_ID
// Value = MAP<ATTRIBUTE, PROVIDER>
- protected Map<Pair<String,String>, Map<Attribute, AssetProvider>> providers = new HashMap<>();
+ protected Map<Tuple<String,String>, Map<Attribute, AssetProvider>> providers = new HashMap<>();
protected int refreshInterval = REFRESH_INTERVAL;
@Override
public synchronized boolean registerAssetProvider(String assetType, String assetId, List<Attribute> attributes, AssetProvider provider) {
LOG.fine("Registering Asset Provider for '" + assetId + "'");
List<Attribute> regAttributes = new ArrayList<>(attributes);
- Map.Entry<Pair<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
+ Map.Entry<Tuple<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
.entrySet()
.stream()
- .filter(es -> es.getKey().getA().equalsIgnoreCase(assetId))
+ .filter(es -> es.getKey().getVal1().equalsIgnoreCase(assetId))
.findFirst()
.orElse(null);
Map<Attribute, AssetProvider> providerInfo = providerEntry != null ? providerEntry.getValue() : null;
@@ -71,16 +71,25 @@ public abstract class AbstractContextBrokerResourceImpl implements ContextProvid
providerInfo.put(attr, provider);
}
- providers.putIfAbsent(new Pair<>(assetId, assetType), providerInfo);
+ providers.putIfAbsent(new Tuple<>(assetId, assetType), providerInfo);
return true;
}
+ @Override
+ public synchronized void unregisterAssetProvider(AssetProvider provider) {
+ providers
+ .entrySet()
+ .stream()
+ .filter(es -> es.getValue().containsValue(provider))
+ .forEach(es -> unregisterAssetProvider(es.getKey().getVal1(), es.getKey().getVal2(), provider));
+ }
+
@Override
public synchronized void unregisterAssetProvider(String assetType, String assetId, AssetProvider provider) {
- Map.Entry<Pair<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
+ Map.Entry<Tuple<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
.entrySet()
.stream()
- .filter(es -> es.getKey().getA().equalsIgnoreCase(assetId))
+ .filter(es -> es.getKey().getVal1().equalsIgnoreCase(assetId))
.findFirst()
.orElse(null);
Map<Attribute, AssetProvider> providerInfo = providerEntry != null ? providerEntry.getValue() : null;
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/AssetProvider.java b/manager/server/src/main/java/org/openremote/manager/server/assets/AssetProvider.java
index 2c55e5e2e..8b18a773d 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/AssetProvider.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/AssetProvider.java
@@ -24,10 +24,7 @@ import org.openremote.manager.shared.ngsi.Attribute;
import java.util.List;
public interface AssetProvider {
-
- Attribute getAssetAttributeValue(String assetId, String attribute);
-
- List<Attribute> getAssetAttributeValues(String assetId);
-
List<Attribute> getAssetAttributeValues(String assetId, List<String> attributes);
+
+ boolean setAssetAttributeValues(String assetId, List<Attribute> attributes);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsResourceImpl.java
index 5dc44a453..c31a1dc9f 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsResourceImpl.java
@@ -19,23 +19,36 @@
*/
package org.openremote.manager.server.assets;
+import com.fasterxml.jackson.databind.ObjectMapper;
import elemental.json.Json;
-import elemental.json.JsonArray;
import elemental.json.JsonObject;
+import org.openremote.container.Container;
import org.openremote.container.web.WebResource;
+import org.openremote.container.web.WebService;
import org.openremote.manager.shared.assets.AssetsResource;
import org.openremote.manager.shared.http.RequestParams;
import org.openremote.manager.shared.ngsi.Entity;
-import org.openremote.manager.shared.ngsi.params.EntityListParams;
-import org.openremote.manager.shared.ngsi.params.EntityParams;
+import org.openremote.manager.shared.ngsi.params.*;
+import org.openremote.manager.shared.ngsi.SubscribeRequestV2;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import java.net.URI;
+import java.util.*;
+import java.util.concurrent.Callable;
import java.util.logging.Logger;
-public class AssetsResourceImpl extends WebResource implements AssetsResource {
+import static org.openremote.manager.shared.Constants.MASTER_REALM;
+public class AssetsResourceImpl extends WebResource implements AssetsResource, SubscriptionProvider {
+ public static final String SUBSCRIBER_ENDPOINT_PATH = "assets/subscriber";
private static final Logger LOG = Logger.getLogger(AssetsResourceImpl.class.getName());
+ public static final int SUBSCRIPTION_REFRESH_INTERVAL = 180;
+ protected URI hostUri;
+ protected ObjectMapper mapper;
+ protected Map<Callable<Entity[]>, SubscribeRequestV2> subscribers = new HashMap<>();
+ protected Calendar calendar;
protected final AssetsService assetsService;
@@ -43,6 +56,11 @@ public class AssetsResourceImpl extends WebResource implements AssetsResource {
this.assetsService = assetsService;
}
+ public void configure(Container container) {
+ hostUri = container.getService(WebService.class).getHostUri();
+ mapper = container.JSON;
+ }
+
@Override
public Entity[] getEntities(RequestParams requestParams, EntityListParams entityListParams) {
return assetsService.getContextBroker().getEntities(entityListParams);
@@ -75,6 +93,13 @@ public class AssetsResourceImpl extends WebResource implements AssetsResource {
checkSuccessResponse(assetsService.getContextBroker().patchEntityAttributes(entityId, entity));
}
+ @Override
+ public void subscriberCallback(Entity[] entities) {
+ // We get here when Orion detects a change to a currently subscribed entity
+ // TODO: Notify the listeners interested in this asset
+
+ }
+
protected Response checkSuccessResponse(Response response) {
if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL)
return response;
@@ -95,4 +120,78 @@ public class AssetsResourceImpl extends WebResource implements AssetsResource {
copy.remove("type");
return copy;
}
+
+ @Override
+ public boolean register(Callable<Entity[]> listener, SubscriptionParams subscription) {
+ // Find existing subscription for this listener (if it exists)
+ SubscribeRequestV2 storedSubscription = subscribers.get(listener);
+
+ if (storedSubscription != null) {
+ String id = storedSubscription.getId();
+ storedSubscription.setSubject(subscription);
+ storedSubscription.setExpires(createNewExpiryDate());
+ Response response = assetsService.getContextBroker().updateSubscription(id, storedSubscription);
+ // TODO: Handle failed subscription update
+ return response.getStatus() == 204;
+ }
+
+ // Create a new subscription
+ storedSubscription = new SubscribeRequestV2();
+ storedSubscription.setNotification(createNotificationParams());
+ storedSubscription.setSubject(subscription);
+ storedSubscription.setExpires(createNewExpiryDate());
+
+ Response response = assetsService.getContextBroker().createSubscription(storedSubscription);
+
+ if (response.getStatus() == 204) {
+ String locationHeader = response.getHeaderString("Location");
+ String id = locationHeader.split("/")[3];
+ storedSubscription.setId(id);
+ subscribers.put(listener, storedSubscription);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public SubscriptionParams getSubscription(Callable<Entity[]> listener) {
+ SubscribeRequestV2 subscriber = subscribers.get(listener);
+ return subscriber != null ? subscriber.getSubject() : null;
+ }
+
+ @Override
+ public synchronized void unregister(Callable<Entity[]> listener) {
+ SubscribeRequestV2 subscriber = subscribers.get(listener);
+
+ if (subscriber != null) {
+ assetsService.getContextBroker().deleteSubscription(subscriber.getId());
+ subscribers.remove(subscriber);
+ }
+ }
+
+ @Override
+ public String getSubscriptionCallbackUri() {
+ return UriBuilder.fromUri(hostUri)
+ .path(MASTER_REALM)
+ .path(SUBSCRIBER_ENDPOINT_PATH)
+ .build()
+ .toString();
+ }
+
+ protected synchronized void notifySubscribers(Entity[] modifiedEntities) {
+
+ }
+
+ protected Date createNewExpiryDate() {
+ calendar.setTime(new Date());
+ calendar.add(Calendar.MINUTE, 3);
+ return calendar.getTime();
+ }
+
+ protected NotificationParams createNotificationParams() {
+ NotificationParams params = new NotificationParams();
+ params.setHttp(new HttpParams(getSubscriptionCallbackUri()));
+ return params;
+ }
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsService.java b/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsService.java
index a289c5563..c95f4ff71 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/AssetsService.java
@@ -26,7 +26,9 @@ import org.openremote.container.ContainerService;
import org.openremote.container.observable.RetryWithDelay;
import org.openremote.container.web.WebClient;
import org.openremote.container.web.WebService;
+import org.openremote.manager.shared.assets.AssetsResource;
import org.openremote.manager.shared.ngsi.*;
+import org.openremote.manager.shared.ngsi.params.SubscriptionParams;
import rx.Observable;
import javax.ws.rs.WebApplicationException;
@@ -34,6 +36,7 @@ import javax.ws.rs.client.Client;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.*;
+import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@@ -57,7 +60,8 @@ public class AssetsService implements ContainerService {
protected UriBuilder contextBrokerHostUri;
protected Client httpClient;
protected URI hostUri;
- protected ContextProvider contextProvider;
+ protected RegistrationProvider registrationProvider;
+ protected SubscriptionProvider subscriptionProvider;
@Override
public void init(Container container) throws Exception {
@@ -91,19 +95,22 @@ public class AssetsService implements ContainerService {
.build();
hostUri = container.getService(WebService.class).getHostUri();
-
- contextProvider = new ContextBrokerV1ResourceImpl(httpClient, contextBrokerHostUri);
}
@Override
public void configure(Container container) throws Exception {
+ AssetsResourceImpl assetsResource = new AssetsResourceImpl(this);
+
container.getService(WebService.class).getApiSingletons().add(new EntryPointMessageBodyConverter());
container.getService(WebService.class).getApiSingletons().add(new EntityMessageBodyConverter());
container.getService(WebService.class).getApiSingletons().add(new EntityArrayMessageBodyConverter());
- container.getService(WebService.class).getApiSingletons().add(new AssetsResourceImpl(this));
+ container.getService(WebService.class).getApiSingletons().add(assetsResource);
+
+ subscriptionProvider = assetsResource;
+ registrationProvider = new ContextBrokerV1ResourceImpl(httpClient, contextBrokerHostUri);
- // Configure the context provider
- contextProvider.configure(container);
+ // Configure the registration provider
+ registrationProvider.configure(container);
}
@Override
@@ -118,15 +125,15 @@ public class AssetsService implements ContainerService {
if (httpClient != null)
httpClient.close();
- if (contextProvider != null)
- contextProvider.stop();
+ if (registrationProvider != null)
+ registrationProvider.stop();
}
public Client getHttpClient() {
return httpClient;
}
- public ContextProvider getContextProvider() { return contextProvider; }
+ public RegistrationProvider getRegistrationProvider() { return registrationProvider; }
public ContextBrokerV2Resource getContextBroker() {
return getContextBroker(getTarget(httpClient, contextBrokerHostUri.build()));
@@ -156,10 +163,26 @@ public class AssetsService implements ContainerService {
}
public boolean registerAssetProvider(String assetType, String assetId, List<Attribute> attributes, AssetProvider provider) {
- return contextProvider.registerAssetProvider(assetType, assetId, attributes, provider);
+ return registrationProvider.registerAssetProvider(assetType, assetId, attributes, provider);
}
public void unregisterAssetProvider(String assetType, String assetId, AssetProvider provider) {
- contextProvider.unregisterAssetProvider(assetType, assetId, provider);
+ registrationProvider.unregisterAssetProvider(assetType, assetId, provider);
+ }
+
+ public void unregisterAssetProvider(AssetProvider provider) {
+ registrationProvider.unregisterAssetProvider(provider);
+ }
+
+ public boolean registerAssetListener(Callable<Entity[]> listener, SubscriptionParams subscription) {
+ return subscriptionProvider.register(listener, subscription);
+ }
+
+ public SubscriptionParams getAssetListenerSubscription(Callable<Entity[]> listener) {
+ return subscriptionProvider.getSubscription(listener);
+ }
+
+ public void unregisterAssetListener(Callable<Entity[]> listener) {
+ subscriptionProvider.unregister(listener);
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1Resource.java b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1Resource.java
index 3f067be06..82f6b4d98 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1Resource.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1Resource.java
@@ -40,7 +40,13 @@ public interface ContextBrokerV1Resource {
@Path("queryContext")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
- ContextResponseWrapper queryContext(EntityAttributeQuery query);
+ QueryResponseWrapper queryContext(EntityAttributeQuery query);
+
+ @POST
+ @Path("updateContext")
+ @Consumes(APPLICATION_JSON)
+ @Produces(APPLICATION_JSON)
+ QueryResponseWrapper updateContext(UpdateRequestV1 updateRequest);
/*
* ***************************************
@@ -52,5 +58,5 @@ public interface ContextBrokerV1Resource {
@Path("registry/registerContext")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
- ContextRegistrationV1Response registerContext(ContextRegistrationV1 registration);
+ RegistrationResponseV1 registerContext(RegistrationRequestV1 registration);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1ResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1ResourceImpl.java
index 03c438870..7cca3c97e 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1ResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV1ResourceImpl.java
@@ -21,8 +21,9 @@ package org.openremote.manager.server.assets;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.jboss.marshalling.Pair;
+import elemental.json.Json;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.jgroups.util.Tuple;
import org.openremote.container.Container;
import org.openremote.container.web.WebService;
import org.openremote.manager.shared.ngsi.*;
@@ -51,7 +52,7 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
protected URI hostUri;
protected ObjectMapper mapper;
protected Client httpClient;
- protected ContextRegistrationV1 providerRegistration = new ContextRegistrationV1(new ArrayList<>(), null);
+ protected RegistrationRequestV1 providerRegistration = new RegistrationRequestV1(new ArrayList<>(), null);
protected Timer updateTimer;
ContextBrokerV1ResourceImpl(Client httpClient, UriBuilder contextBrokerHostUri) {
@@ -74,27 +75,32 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
}
@Override
- public ContextResponseWrapper queryContext(EntityAttributeQuery query) {
- List<ContextResponse> responses = query.getEntities()
+ public QueryResponseWrapper queryContext(EntityAttributeQuery query) {
+ List<QueryResponse> responses = query.getEntities()
.stream()
- .map(e -> getContextResponse(e, query.getAttributes()))
+ .map(e -> getContextResponse(e, query.getAttributes().stream().map(attr -> new Tuple<String, String>(attr, null)).collect(Collectors.toList()), false))
.filter(cr -> cr != null)
.collect(Collectors.toList());
if (responses.size() == 0) {
- return new ContextResponseWrapper(null, new StatusCode("404", "No context element found"));
+ return new QueryResponseWrapper(null, new StatusCode("404", "No context element found"));
} else {
- return new ContextResponseWrapper(responses);
+ return new QueryResponseWrapper(responses);
}
}
@Override
- public ContextRegistrationV1Response registerContext(ContextRegistrationV1 registration) {
+ public QueryResponseWrapper updateContext(UpdateRequestV1 updateRequest) {
return null;
}
@Override
- public String getContextProviderUri() {
+ public RegistrationResponseV1 registerContext(RegistrationRequestV1 registration) {
+ return null;
+ }
+
+ @Override
+ public String getRegistrationCallbackUri() {
return UriBuilder.fromUri(hostUri)
.path(MASTER_REALM)
.path(CONTEXT_PROVIDER_V1_ENDPOINT_PATH)
@@ -110,37 +116,37 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
return target.proxy(ContextBrokerV1Resource.class);
}
- protected synchronized ContextResponse getContextResponse(ContextEntity entityQuery, List<String> attributeNames) {
- Map.Entry<Pair<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
+ protected synchronized QueryResponse getContextResponse(ContextEntity entityQuery, List<Tuple<String,String>> attributesAndValues, boolean isUpdate) {
+ Map.Entry<Tuple<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
.entrySet()
.stream()
- .filter(es -> es.getKey().getA().equalsIgnoreCase(entityQuery.getId()))
+ .filter(es -> es.getKey().getVal1().equalsIgnoreCase(entityQuery.getId()))
.findFirst()
.orElse(null);
Map<Attribute, AssetProvider> providerInfo = providerEntry != null ? providerEntry.getValue() : null;
- Map<AssetProvider, List<String>> attributeProviders = null;
+ Map<AssetProvider, List<Attribute>> attributeProviders = null;
if (providerInfo != null) {
- if (attributeNames == null || attributeNames.isEmpty()) {
- // Get all attribute providers
+ if (attributesAndValues == null || attributesAndValues.isEmpty()) {
+ // Get all attribute providers for these attributes
attributeProviders = providerInfo
.entrySet()
.stream()
- .collect(Collectors.groupingBy(es -> es.getValue(), Collectors.mapping(es -> es.getKey().getName(), Collectors.toList())));
+ .collect(Collectors.groupingBy(es -> es.getValue(), Collectors.mapping(es -> es.getKey(), Collectors.toList())));
} else {
- attributeProviders = attributeNames
+ attributeProviders = attributesAndValues
.stream()
.map(attr -> {
Map.Entry<Attribute, AssetProvider> entry = providerInfo
.entrySet()
.stream()
- .filter(es -> es.getKey().getName().equals(attr))
+ .filter(es -> es.getKey().getName().equals(attr.getVal1()))
.findFirst()
.orElse(null);
- return new Pair<>(entry.getValue(), attr);
+ return new Tuple<>(entry.getValue(), entry.getKey());
})
- .filter(p -> p.getA() != null)
- .collect(Collectors.groupingBy(Pair::getA, Collectors.mapping(Pair::getB, Collectors.toList())));
+ .filter(p -> p.getVal1() != null)
+ .collect(Collectors.groupingBy(Tuple::getVal1, Collectors.mapping(Tuple::getVal2, Collectors.toList())));
}
}
@@ -149,18 +155,41 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
return null;
}
- List<Attribute> attributes = attributeProviders.entrySet()
- .stream()
- .filter(es -> !es.getValue().isEmpty())
- .flatMap(es -> es.getKey().getAssetAttributeValues(entityQuery.getId(), es.getValue()).stream())
- .collect(Collectors.toList());
+ List<Attribute> attributes;
+
+ if (isUpdate) {
+ attributes = attributeProviders.entrySet()
+ .stream()
+ .filter(es -> !es.getValue().isEmpty())
+ .flatMap(es -> {
+ List<Attribute> attrs = attributesAndValues
+ .stream()
+ .filter(attrVal ->
+ es.getValue()
+ .stream()
+ .anyMatch(attr -> attr.getName().equalsIgnoreCase(attrVal.getVal1())))
+ .map(attrValue -> new Attribute(attrValue.getVal1(), null, Json.create(attrValue.getVal2())))
+ .collect(Collectors.toList());
+ // Call set attributes on provider
+
+ es.getKey().setAssetAttributeValues(entityQuery.getId(), attrs);
+ return attrs.stream();
+ })
+ .collect(Collectors.toList());
+ } else {
+ attributes = attributeProviders.entrySet()
+ .stream()
+ .filter(es -> !es.getValue().isEmpty())
+ .flatMap(es -> es.getKey().getAssetAttributeValues(entityQuery.getId(), es.getValue().stream().map(Attribute::getName).collect(Collectors.toList())).stream())
+ .collect(Collectors.toList());
+ }
if (attributes.isEmpty()) {
LOG.info("Asset provider returned no attributes when asked for the value of one or more attributes");
return null;
}
- return new ContextResponse(
+ return new QueryResponse(
new ContextElement(entityQuery.getType(),entityQuery.getId(), false, attributes),
new StatusCode("200", "OK"));
}
@@ -168,7 +197,7 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
@Override
protected synchronized void updateRegistration(String assetType, String assetId, List<Attribute> attributes) {
// Check if this asset ID is already registered
- EntityAttributeRegistrationV1 existingReg = providerRegistration.getRegistrations()
+ EntityAttributeListV1 existingReg = providerRegistration.getRegistrations()
.stream()
.filter(reg ->
reg.getEntities()
@@ -214,7 +243,7 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
}
if (!attributes.isEmpty()) {
- EntityAttributeRegistrationV1 newReg = providerRegistration.getRegistrations()
+ EntityAttributeListV1 newReg = providerRegistration.getRegistrations()
.stream()
.filter(reg ->
attributes
@@ -236,7 +265,7 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
List<ContextAttribute> attrs = new ArrayList<>();
entities.add(entity);
attributes.forEach(attr -> attrs.add(new ContextAttribute(attr.getName(), attr.getType().getName(), false)));
- newReg = new EntityAttributeRegistrationV1(entities, attrs, getContextProviderUri());
+ newReg = new EntityAttributeListV1(entities, attrs, getRegistrationCallbackUri());
providerRegistration.getRegistrations().add(newReg);
}
}
@@ -258,16 +287,16 @@ public class ContextBrokerV1ResourceImpl extends AbstractContextBrokerResourceIm
private synchronized void refreshRegistration() {
// If registration is set to 0s then we need to provide a dummy entity - WTF?
- ContextRegistrationV1 reg = providerRegistration;
+ RegistrationRequestV1 reg = providerRegistration;
if (reg.getDuration().equalsIgnoreCase("PT0S")) {
- reg = new ContextRegistrationV1(new ArrayList<>(), reg.getDuration(), reg.getRegistrationId());
+ reg = new RegistrationRequestV1(new ArrayList<>(), reg.getDuration(), reg.getRegistrationId());
List<ContextEntity> dummyEntities = new ArrayList<>();
dummyEntities.add(new ContextEntity("##############","##############", false));
- reg.getRegistrations().add(new EntityAttributeRegistrationV1(dummyEntities, null, getContextProviderUri()));
+ reg.getRegistrations().add(new EntityAttributeListV1(dummyEntities, null, getRegistrationCallbackUri()));
}
- ContextRegistrationV1Response response = getContextBrokerV1().registerContext(reg);
+ RegistrationResponseV1 response = getContextBrokerV1().registerContext(reg);
boolean success = false;
if (response == null) {
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2Resource.java b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2Resource.java
index 8fd4355f1..e6cfe67a4 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2Resource.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2Resource.java
@@ -20,9 +20,11 @@
package org.openremote.manager.server.assets;
import org.openremote.manager.shared.http.PATCH;
+import org.openremote.manager.shared.http.SuccessStatusCode;
import org.openremote.manager.shared.ngsi.*;
import org.openremote.manager.shared.ngsi.params.EntityListParams;
import org.openremote.manager.shared.ngsi.params.EntityParams;
+import org.openremote.manager.shared.ngsi.params.SubscriptionParams;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
@@ -73,6 +75,33 @@ public interface ContextBrokerV2Resource {
@Consumes(APPLICATION_JSON)
Response patchEntityAttributes(@PathParam("entityId") String entityId, Entity entity);
+ @GET
+ @Path("subscriptions")
+ @Produces(APPLICATION_JSON)
+ SubscribeRequestV2[] getSubscriptions();
+
+ @GET
+ @Path("subscriptions/{subscriptionId}")
+ @Produces(APPLICATION_JSON)
+ SubscribeRequestV2 getSubscription(@PathParam("subscriptionId")String subscriptionId);
+
+ @POST
+ @Path("subscriptions")
+ @Consumes(APPLICATION_JSON)
+ Response createSubscription(SubscribeRequestV2 subscription);
+
+ @PATCH
+ @Path("subscriptions/{subscriptionId}")
+ @Consumes(APPLICATION_JSON)
+ @SuccessStatusCode(204)
+ Response updateSubscription(@PathParam("subscriptionId")String subscriptionId, SubscribeRequestV2 subscription);
+
+ @DELETE
+ @Path("subscriptions/{subscriptionId}")
+ @Consumes(APPLICATION_JSON)
+ @SuccessStatusCode(204)
+ Response deleteSubscription(@PathParam("subscriptionId")String subscriptionId);
+
/*
* ***************************************
* NGSI9
@@ -82,7 +111,7 @@ public interface ContextBrokerV2Resource {
@POST
@Path("registrations")
@Consumes(APPLICATION_JSON)
- Response createRegistration(ContextRegistrationV2 registration);
+ Response createRegistration(RegistrationRequestV2 registration);
@PATCH
@Path("registrations/{registrationId}")
@@ -96,5 +125,5 @@ public interface ContextBrokerV2Resource {
@POST
@Path("op/register")
@Consumes(APPLICATION_JSON)
- Response batchRegistration(BatchContextRegistrationV2 registrations);
+ Response batchRegistration(BatchRegistrationRequestV2 registrations);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2ResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2ResourceImpl.java
index 42eb766a5..10c024f3b 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2ResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/ContextBrokerV2ResourceImpl.java
@@ -21,13 +21,14 @@ package org.openremote.manager.server.assets;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.jboss.marshalling.Pair;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.jgroups.util.Tuple;
import org.openremote.container.Container;
import org.openremote.container.web.WebService;
import org.openremote.manager.shared.ngsi.*;
import org.openremote.manager.shared.ngsi.params.EntityListParams;
import org.openremote.manager.shared.ngsi.params.EntityParams;
+import org.openremote.manager.shared.ngsi.params.SubscriptionParams;
import javax.ws.rs.BeanParam;
import javax.ws.rs.NotSupportedException;
@@ -37,6 +38,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.*;
+import java.util.concurrent.Callable;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -59,7 +61,7 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
protected ObjectMapper mapper;
protected Client httpClient;
protected Timer updateTimer;
- protected BatchContextRegistrationV2 providerRegistration;
+ protected BatchRegistrationRequestV2 providerRegistration;
ContextBrokerV2ResourceImpl(Client httpClient, UriBuilder contextBrokerHostUri) {
this.httpClient = httpClient;
@@ -129,7 +131,32 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
}
@Override
- public Response createRegistration(ContextRegistrationV2 registration) {
+ public SubscribeRequestV2[] getSubscriptions() {
+ throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
+ }
+
+ @Override
+ public Response createSubscription(SubscribeRequestV2 subscription) {
+ throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
+ }
+
+ @Override
+ public Response updateSubscription(String subscriptionId, SubscribeRequestV2 subscription) {
+ throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
+ }
+
+ @Override
+ public Response deleteSubscription(String subscriptionId) {
+ throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
+ }
+
+ @Override
+ public Response createRegistration(RegistrationRequestV2 registration) {
+ throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
+ }
+
+ @Override
+ public SubscribeRequestV2 getSubscription(String subscriptionId) {
throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
}
@@ -144,12 +171,12 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
}
@Override
- public Response batchRegistration(BatchContextRegistrationV2 registrations) {
+ public Response batchRegistration(BatchRegistrationRequestV2 registrations) {
throw new NotSupportedException("NGSI v2 Provider doesn't support this method");
}
@Override
- public String getContextProviderUri() {
+ public String getRegistrationCallbackUri() {
return UriBuilder.fromUri(hostUri)
.path(MASTER_REALM)
.path(CONTEXT_PROVIDER_V2_ENDPOINT_PATH)
@@ -167,7 +194,7 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
protected synchronized String[] resolveIds(EntityListParams entityListParams) {
// TODO: Add support for non entity ID/type based queries
- Stream<Map.Entry<Pair<String, String>, Map<Attribute, AssetProvider>>> filteredProviders = providers
+ Stream<Map.Entry<Tuple<String, String>, Map<Attribute, AssetProvider>>> filteredProviders = providers
.entrySet()
.stream();
@@ -177,13 +204,13 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
.filter(
es -> Arrays
.stream(entityListParams.id)
- .anyMatch(id -> id.equalsIgnoreCase(es.getKey().getA())));
+ .anyMatch(id -> id.equalsIgnoreCase(es.getKey().getVal1())));
} else if (entityListParams.idPattern != null) {
// Filter by ID (regex)
Pattern idRegex = Pattern.compile(entityListParams.idPattern);
filteredProviders = filteredProviders
.filter(
- es -> idRegex.matcher(es.getKey().getA()).matches()
+ es -> idRegex.matcher(es.getKey().getVal1()).matches()
);
}
@@ -193,25 +220,25 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
.filter(
es -> Arrays
.stream(entityListParams.type)
- .anyMatch(type -> type.equalsIgnoreCase(es.getKey().getB())));
+ .anyMatch(type -> type.equalsIgnoreCase(es.getKey().getVal2())));
} else if (entityListParams.typePattern != null) {
// Further filter by type (regex)
Pattern typeRegex = Pattern.compile(entityListParams.typePattern);
filteredProviders = filteredProviders.filter(
- es -> typeRegex.matcher(es.getKey().getB()).matches()
+ es -> typeRegex.matcher(es.getKey().getVal2()).matches()
);
}
- return filteredProviders.map(es -> es.getKey().getA()).toArray(size -> new String[size]);
+ return filteredProviders.map(es -> es.getKey().getVal1()).toArray(size -> new String[size]);
}
protected synchronized Entity getEntityResponse(String entityId, List<String> attributeNames) {
Map<AssetProvider, List<String>> attributeProviders = null;
- Map.Entry<Pair<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
+ Map.Entry<Tuple<String, String>, Map<Attribute, AssetProvider>> providerEntry = providers
.entrySet()
.stream()
- .filter(es -> es.getKey().getA().equalsIgnoreCase(entityId))
+ .filter(es -> es.getKey().getVal1().equalsIgnoreCase(entityId))
.findFirst()
.orElse(null);
@@ -234,10 +261,10 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
.filter(es -> es.getKey().getName().equals(attr))
.findFirst()
.orElse(null);
- return new Pair<>(entry.getValue(), attr);
+ return new Tuple<>(entry.getValue(), attr);
})
- .filter(p -> p.getA() != null)
- .collect(Collectors.groupingBy(Pair::getA, Collectors.mapping(Pair::getB, Collectors.toList())));
+ .filter(p -> p.getVal1() != null)
+ .collect(Collectors.groupingBy(Tuple::getVal1, Collectors.mapping(Tuple::getVal2, Collectors.toList())));
}
}
@@ -259,18 +286,18 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
// Construct the entity object
Entity entity = new Entity();
- entity.setType(providerEntry.getKey().getB());
- entity.setId(providerEntry.getKey().getA());
+ entity.setType(providerEntry.getKey().getVal2());
+ entity.setId(providerEntry.getKey().getVal1());
attributes.forEach(entity::addAttribute);
return entity;
}
@Override
- // TODO: Update registration code cnce NGSI9 v2 is finalised
+ // TODO: Update registration code once NGSI9 v2 is finalised
protected synchronized void updateRegistration(String assetType, String assetId, List<Attribute> attributes) {
// Check if this asset ID is already registered
- ContextRegistrationV2 existingReg = providerRegistration.getRegistrations()
+ RegistrationRequestV2 existingReg = providerRegistration.getRegistrations()
.stream()
.filter(reg ->
reg.getSubject().getEntities()
@@ -314,7 +341,7 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
}
}
- ContextRegistrationV2 newReg = providerRegistration.getRegistrations()
+ RegistrationRequestV2 newReg = providerRegistration.getRegistrations()
.stream()
.filter(reg ->
attributes
@@ -335,8 +362,8 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
List<ContextAttribute> attrs = new ArrayList<>();
entities.add(entity);
attributes.forEach(attr -> attrs.add(new ContextAttribute(attr.getName())));
- EntityAttributeRegistrationV2 subject = new EntityAttributeRegistrationV2(entities,attrs);
- newReg = new ContextRegistrationV2(subject, getContextProviderUri(), null, null);
+ EntityAttributeListV2 subject = new EntityAttributeListV2(entities,attrs);
+ newReg = new RegistrationRequestV2(subject, getRegistrationCallbackUri(), null, null);
newReg.setDuration("PT" + getRefreshInterval() + "S");
providerRegistration.getRegistrations().add(newReg);
}
@@ -359,7 +386,7 @@ public class ContextBrokerV2ResourceImpl extends AbstractContextBrokerResourceIm
refreshRegistration();
}
- // TODO: Update registration code cnce NGSI9 v2 is finalised
+ // TODO: Update registration code once NGSI9 v2 is finalised
private synchronized void refreshRegistration() {
Response response = getContextBroker().batchRegistration(providerRegistration);
boolean success = false;
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextProvider.java b/manager/server/src/main/java/org/openremote/manager/server/assets/RegistrationProvider.java
similarity index 91%
rename from manager/server/src/main/java/org/openremote/manager/server/assets/ContextProvider.java
rename to manager/server/src/main/java/org/openremote/manager/server/assets/RegistrationProvider.java
index 5a00cfe89..93bf2ffcc 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/assets/ContextProvider.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/RegistrationProvider.java
@@ -24,18 +24,20 @@ import org.openremote.manager.shared.ngsi.Attribute;
import java.util.List;
-public interface ContextProvider {
+public interface RegistrationProvider {
void configure(Container container) throws Exception;
void stop();
- String getContextProviderUri();
+ String getRegistrationCallbackUri();
boolean registerAssetProvider(String assetType, String assetId, List<Attribute> attributes, AssetProvider provider);
void unregisterAssetProvider(String assetType, String assetId, AssetProvider provider);
+ void unregisterAssetProvider(AssetProvider provider);
+
/**
* Get the refresh interval duration of this context providers registrations
* @return Registration refresh interval in seconds
diff --git a/manager/server/src/main/java/org/openremote/manager/server/assets/SubscriptionProvider.java b/manager/server/src/main/java/org/openremote/manager/server/assets/SubscriptionProvider.java
new file mode 100644
index 000000000..a1361167c
--- /dev/null
+++ b/manager/server/src/main/java/org/openremote/manager/server/assets/SubscriptionProvider.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.server.assets;
+
+import org.openremote.manager.shared.ngsi.Entity;
+import org.openremote.manager.shared.ngsi.params.SubscriptionParams;
+
+import java.util.concurrent.Callable;
+
+public interface SubscriptionProvider {
+ boolean register(Callable<Entity[]> listener, SubscriptionParams subscription);
+
+ SubscriptionParams getSubscription(Callable<Entity[]> listener);
+
+ void unregister(Callable<Entity[]> listener);
+
+ String getSubscriptionCallbackUri();
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/assets/AssetsResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/assets/AssetsResource.java
index 434f6c388..1ca338de3 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/assets/AssetsResource.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/assets/AssetsResource.java
@@ -40,7 +40,6 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@Path("assets")
@JsType(isNative = true)
public interface AssetsResource {
-
@GET
@Path("entities")
@Produces(APPLICATION_JSON)
@@ -82,4 +81,8 @@ public interface AssetsResource {
@RolesAllowed({"write:assets"})
void patchEntityAttributes(@BeanParam RequestParams requestParams, @PathParam("entityId") String entityId, Entity entity);
+ @POST
+ @Path("subscriber")
+ @Consumes(APPLICATION_JSON)
+ void subscriberCallback(Entity[] entities);
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/BatchContextRegistrationV2.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/BatchRegistrationRequestV2.java
similarity index 85%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/BatchContextRegistrationV2.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/BatchRegistrationRequestV2.java
index ecd9affdb..fc73d8ebc 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/BatchContextRegistrationV2.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/BatchRegistrationRequestV2.java
@@ -21,16 +21,16 @@ package org.openremote.manager.shared.ngsi;
import java.util.List;
-public class BatchContextRegistrationV2 {
- protected List<ContextRegistrationV2> registrations;
+public class BatchRegistrationRequestV2 {
+ protected List<RegistrationRequestV2> registrations;
protected ActionType actionType;
- public BatchContextRegistrationV2(List<ContextRegistrationV2> registrations, ActionType actionType) {
+ public BatchRegistrationRequestV2(List<RegistrationRequestV2> registrations, ActionType actionType) {
this.registrations = registrations;
this.actionType = actionType;
}
- public List<ContextRegistrationV2> getRegistrations() {
+ public List<RegistrationRequestV2> getRegistrations() {
return registrations;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeRegistrationV1.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeListV1.java
similarity index 85%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeRegistrationV1.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeListV1.java
index 5aa74f8a6..5cd9a2a46 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeRegistrationV1.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeListV1.java
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
-public class EntityAttributeRegistrationV1 {
+public class EntityAttributeListV1 {
@JsonInclude
protected List<ContextEntity> entities;
@JsonInclude
@@ -32,7 +32,7 @@ public class EntityAttributeRegistrationV1 {
@JsonProperty(value = "providingApplication")
protected String providerUri;
- public EntityAttributeRegistrationV1(@JsonProperty("entities") List<ContextEntity> entities, @JsonProperty("attributes") List<ContextAttribute> attributes, @JsonProperty("providingApplication") String providerUri) {
+ public EntityAttributeListV1(@JsonProperty("entities") List<ContextEntity> entities, @JsonProperty("attributes") List<ContextAttribute> attributes, @JsonProperty("providingApplication") String providerUri) {
this.entities = entities;
this.attributes = attributes;
this.providerUri = providerUri;
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeRegistrationV2.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeListV2.java
similarity index 87%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeRegistrationV2.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeListV2.java
index 5b999c847..3aa8e3f0c 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeRegistrationV2.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/EntityAttributeListV2.java
@@ -25,14 +25,14 @@ import elemental.json.JsonObject;
import java.util.List;
-public class EntityAttributeRegistrationV2 {
+public class EntityAttributeListV2 {
@JsonInclude
protected List<ContextEntity> entities;
@JsonInclude
protected List<ContextAttribute> attributes;
- public EntityAttributeRegistrationV2(@JsonProperty("entities") List<ContextEntity> entities, @JsonProperty("attributes") List<ContextAttribute> attributes) {
+ public EntityAttributeListV2(@JsonProperty("entities") List<ContextEntity> entities, @JsonProperty("attributes") List<ContextAttribute> attributes) {
this.entities = entities;
this.attributes = attributes;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextResponse.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/QueryResponse.java
similarity index 88%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextResponse.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/QueryResponse.java
index 9cb14cca7..70cab88ba 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextResponse.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/QueryResponse.java
@@ -22,13 +22,13 @@ package org.openremote.manager.shared.ngsi;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class ContextResponse {
+public class QueryResponse {
@JsonInclude
protected ContextElement contextElement;
@JsonInclude
protected StatusCode statusCode;
- public ContextResponse(@JsonProperty("contextElement") ContextElement contextElement, @JsonProperty("statusCode") StatusCode statusCode) {
+ public QueryResponse(@JsonProperty("contextElement") ContextElement contextElement, @JsonProperty("statusCode") StatusCode statusCode) {
this.contextElement = contextElement;
this.statusCode = statusCode;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextResponseWrapper.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/QueryResponseWrapper.java
similarity index 76%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextResponseWrapper.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/QueryResponseWrapper.java
index 2171bb221..14e4322f9 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextResponseWrapper.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/QueryResponseWrapper.java
@@ -24,26 +24,26 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
-public class ContextResponseWrapper {
+public class QueryResponseWrapper {
@JsonInclude(JsonInclude.Include.NON_NULL)
- protected List<ContextResponse> contextResponses;
+ protected List<QueryResponse> contextResponses;
@JsonInclude(JsonInclude.Include.NON_NULL)
protected StatusCode errorCode;
- public ContextResponseWrapper(@JsonProperty("contextResponses") List<ContextResponse> contextResponses, @JsonProperty("errorCode") StatusCode errorCode) {
+ public QueryResponseWrapper(@JsonProperty("contextResponses") List<QueryResponse> contextResponses, @JsonProperty("errorCode") StatusCode errorCode) {
this.contextResponses = contextResponses;
this.errorCode = errorCode;
}
- public ContextResponseWrapper(List<ContextResponse> contextResponses) {
+ public QueryResponseWrapper(List<QueryResponse> contextResponses) {
this.contextResponses = contextResponses;
}
- public ContextResponseWrapper(StatusCode errorCode) {
+ public QueryResponseWrapper(StatusCode errorCode) {
this.errorCode = errorCode;
}
- public List<ContextResponse> getContextResponses() {
+ public List<QueryResponse> getContextResponses() {
return contextResponses;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV1.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationRequestV1.java
similarity index 76%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV1.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationRequestV1.java
index e9ecf167b..7de8df1c6 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV1.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationRequestV1.java
@@ -24,26 +24,26 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
-public class ContextRegistrationV1 {
+public class RegistrationRequestV1 {
@JsonProperty(value = "contextRegistrations")
- protected List<EntityAttributeRegistrationV1> registrations;
+ protected List<EntityAttributeListV1> registrations;
@JsonInclude
protected String duration;
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String registrationId;
- public ContextRegistrationV1(List<EntityAttributeRegistrationV1> registrations, String duration) {
+ public RegistrationRequestV1(List<EntityAttributeListV1> registrations, String duration) {
this.registrations = registrations;
this.duration = duration;
}
- public ContextRegistrationV1(@JsonProperty("registrations") List<EntityAttributeRegistrationV1> registrations, @JsonProperty("duration") String duration, @JsonProperty("registrationId") String registrationId) {
+ public RegistrationRequestV1(@JsonProperty("registrations") List<EntityAttributeListV1> registrations, @JsonProperty("duration") String duration, @JsonProperty("registrationId") String registrationId) {
this.registrations = registrations;
this.duration = duration;
this.registrationId = registrationId;
}
- public List<EntityAttributeRegistrationV1> getRegistrations() {
+ public List<EntityAttributeListV1> getRegistrations() {
return registrations;
}
@@ -63,7 +63,7 @@ public class ContextRegistrationV1 {
this.registrationId = registrationId;
}
- public void setRegistrations(List<EntityAttributeRegistrationV1> registrations) {
+ public void setRegistrations(List<EntityAttributeListV1> registrations) {
this.registrations = registrations;
}
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV2.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationRequestV2.java
similarity index 86%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV2.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationRequestV2.java
index 402ac13d9..7d98828db 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV2.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationRequestV2.java
@@ -24,9 +24,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import elemental.json.JsonObject;
-public class ContextRegistrationV2 {
+public class RegistrationRequestV2 {
@JsonInclude(JsonInclude.Include.NON_NULL)
- protected EntityAttributeRegistrationV2 subject;
+ protected EntityAttributeListV2 subject;
@JsonProperty(value = "callback")
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String providerUri;
@@ -37,18 +37,18 @@ public class ContextRegistrationV2 {
@JsonIgnore
protected String registrationId;
- public ContextRegistrationV2(EntityAttributeRegistrationV2 subject, String providerUri, JsonObject metadata, String duration) {
+ public RegistrationRequestV2(EntityAttributeListV2 subject, String providerUri, JsonObject metadata, String duration) {
this.subject = subject;
this.providerUri = providerUri;
this.metadata = metadata;
this.duration = duration;
}
- public ContextRegistrationV2(String duration) {
+ public RegistrationRequestV2(String duration) {
this.duration = duration;
}
- public EntityAttributeRegistrationV2 getSubject() {
+ public EntityAttributeListV2 getSubject() {
return subject;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV1Response.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationResponseV1.java
similarity index 86%
rename from manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV1Response.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationResponseV1.java
index b2c5dc770..b08648151 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/ContextRegistrationV1Response.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/RegistrationResponseV1.java
@@ -22,7 +22,7 @@ package org.openremote.manager.shared.ngsi;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class ContextRegistrationV1Response {
+public class RegistrationResponseV1 {
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String duration;
@JsonInclude
@@ -30,7 +30,7 @@ public class ContextRegistrationV1Response {
@JsonInclude(JsonInclude.Include.NON_NULL)
protected StatusCode errorCode;
- public ContextRegistrationV1Response(@JsonProperty("duration")String duration, @JsonProperty("registrationId")String registrationId, @JsonProperty("errorCode")StatusCode errorCode) {
+ public RegistrationResponseV1(@JsonProperty("duration")String duration, @JsonProperty("registrationId")String registrationId, @JsonProperty("errorCode")StatusCode errorCode) {
this.duration = duration;
this.errorCode = errorCode;
this.registrationId = registrationId;
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/SubscribeRequestV2.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/SubscribeRequestV2.java
new file mode 100644
index 000000000..6de29763b
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/SubscribeRequestV2.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.manager.shared.ngsi.params.NotificationParams;
+import org.openremote.manager.shared.ngsi.params.SubscriptionParams;
+
+import java.util.Date;
+
+public class SubscribeRequestV2 {
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected String id;
+ @JsonInclude
+ protected SubscriptionParams subject;
+ @JsonInclude
+ protected NotificationParams notification;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected Date expires;
+
+ public SubscribeRequestV2() {
+ }
+
+ public SubscribeRequestV2(@JsonProperty String id, @JsonProperty SubscriptionParams subject, @JsonProperty NotificationParams notification, @JsonProperty Date expires) {
+ this.id = id;
+ this.subject = subject;
+ this.notification = notification;
+ this.expires = expires;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public SubscriptionParams getSubject() {
+ return subject;
+ }
+
+ public void setSubject(SubscriptionParams subject) {
+ this.subject = subject;
+ }
+
+ public NotificationParams getNotification() {
+ return notification;
+ }
+
+ public void setNotification(NotificationParams notification) {
+ this.notification = notification;
+ }
+
+ public Date getExpires() {
+ return expires;
+ }
+
+ public void setExpires(Date expires) {
+ this.expires = expires;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/UpdateRequestV1.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/UpdateRequestV1.java
new file mode 100644
index 000000000..341f919a7
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/UpdateRequestV1.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+import java.util.List;
+
+public class UpdateRequestV1 {
+ @JsonInclude
+ protected List<ContextElement> contextElements;
+
+ @JsonInclude
+ protected ActionType updateAction;
+
+ public UpdateRequestV1(List<ContextElement> contextElements, ActionType updateAction) {
+ this.contextElements = contextElements;
+ this.updateAction = updateAction;
+ }
+
+ public List<ContextElement> getContextElements() {
+ return contextElements;
+ }
+
+ public ActionType getUpdateAction() {
+ return updateAction;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/BasicEntityParams.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/BasicEntityParams.java
new file mode 100644
index 000000000..7c618ea25
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/BasicEntityParams.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi.params;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+public class BasicEntityParams {
+ @JsonInclude
+ protected String id;
+ @JsonInclude
+ protected String idPattern;
+ @JsonInclude
+ protected String type;
+
+ public BasicEntityParams(String idParam, boolean isPattern) {
+ if (isPattern) {
+ this.idPattern = idParam;
+ } else {
+ this.id = idParam;
+ }
+ }
+
+ public BasicEntityParams(String idParam, boolean isPattern, String type) {
+ this(idParam, isPattern);
+ this.type = type;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getIdPattern() {
+ return idPattern;
+ }
+
+ public String getType() {
+ return type;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/Condition.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/Condition.java
new file mode 100644
index 000000000..a87383ef2
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/Condition.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi.params;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.manager.shared.ngsi.simplequery.Query;
+
+import java.util.List;
+
+public class Condition {
+ @JsonProperty("attrs")
+ protected List<String> attributes;
+ @JsonProperty("expression")
+ protected Query query;
+
+ public Condition(List<String> attributes) {
+ this.attributes = attributes;
+ }
+
+ public Condition(Query query) {
+ this.query = query;
+ }
+
+ public Condition(List<String> attributes, Query query) {
+ this.attributes = attributes;
+ this.query = query;
+ }
+
+ public List<String> getAttributes() {
+ return attributes;
+ }
+
+ public Query getQuery() {
+ return query;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/HttpCustomParams.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/HttpCustomParams.java
new file mode 100644
index 000000000..579557c64
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/HttpCustomParams.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi.params;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.ws.rs.HttpMethod;
+import java.util.Map;
+
+public class HttpCustomParams extends HttpParams {
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected Map<String, String> headers;
+ @JsonProperty("qs")
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected Map<String, String> parameters;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected HttpMethod method;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected String payload;
+
+ public HttpCustomParams(@JsonProperty String url, @JsonProperty Map<String, String> headers, @JsonProperty("qs") Map<String, String> parameters, @JsonProperty HttpMethod method, @JsonProperty String payload) {
+ super(url);
+ this.headers = headers;
+ this.parameters = parameters;
+ this.method = method;
+ this.payload = payload;
+ }
+
+ public HttpCustomParams(String url) {
+ super(url);
+ }
+
+ public Map<String, String> getHeaders() {
+ return headers;
+ }
+
+ public void setHeaders(Map<String, String> headers) {
+ this.headers = headers;
+ }
+
+ public Map<String, String> getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map<String, String> parameters) {
+ this.parameters = parameters;
+ }
+
+ public HttpMethod getMethod() {
+ return method;
+ }
+
+ public void setMethod(HttpMethod method) {
+ this.method = method;
+ }
+
+ public String getPayload() {
+ return payload;
+ }
+
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/HttpParams.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/HttpParams.java
new file mode 100644
index 000000000..8ecf206a0
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/HttpParams.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi.params;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+public class HttpParams {
+ @JsonInclude
+ protected String url;
+
+ public HttpParams(String url) {
+ this.url = url;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/NotificationParams.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/NotificationParams.java
new file mode 100644
index 000000000..fa7ec4f79
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/NotificationParams.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi.params;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Date;
+import java.util.List;
+
+public class NotificationParams {
+ @JsonProperty("attrs")
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected List<String> includeAttributes;
+ @JsonProperty("exceptAttrs")
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected List<String> excludeAttributes;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected HttpParams http;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected HttpCustomParams httpCustom;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected Date lastNotification;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected int timesSent;
+
+ public NotificationParams() {
+ }
+
+ public void setIncludeAttributes(List<String> includeAttributes) {
+ this.includeAttributes = includeAttributes;
+ }
+
+ public void setExcludeAttributes(List<String> excludeAttributes) {
+ this.excludeAttributes = excludeAttributes;
+ }
+
+ public void setHttp(HttpParams http) {
+ this.http = http;
+ }
+
+ public void setHttpCustom(HttpCustomParams httpCustom) {
+ this.httpCustom = httpCustom;
+ }
+
+ public List<String> getIncludeAttributes() {
+ return includeAttributes;
+ }
+
+ public List<String> getExcludeAttributes() {
+ return excludeAttributes;
+ }
+
+ public HttpParams getHttp() {
+ return http;
+ }
+
+ public HttpCustomParams getHttpCustom() {
+ return httpCustom;
+ }
+
+ public Date getLastNotification() {
+ return lastNotification;
+ }
+
+ public int getTimesSent() {
+ return timesSent;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/SubscriptionParams.java b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/SubscriptionParams.java
new file mode 100644
index 000000000..719997b72
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/ngsi/params/SubscriptionParams.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.shared.ngsi.params;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+public class SubscriptionParams {
+ @JsonInclude
+ protected BasicEntityParams entities;
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ protected Condition condition;
+}
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetsServiceTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetsServiceTest.groovy
index f6f2c2a87..72bf040d4 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetsServiceTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetsServiceTest.groovy
@@ -30,6 +30,8 @@ import org.openremote.test.ContainerTrait
import spock.lang.Specification
import spock.util.concurrent.PollingConditions
+import javax.ws.rs.NotFoundException
+
class AssetsServiceTest extends Specification implements ContainerTrait {
def "Register Asset Provider"() {
@@ -49,19 +51,6 @@ class AssetsServiceTest extends Specification implements ContainerTrait {
];
def assetProvider = new AssetProvider() {
- @Override
- Attribute getAssetAttributeValue(String assetId, String attribute) {
- requestedAttributes.add(attribute);
- return attribute.equals("temperature") ?
- fakeAttributes[0]
- : fakeAttributes[1];
- }
-
- @Override
- List<Attribute> getAssetAttributeValues(String assetId) {
- return fakeAttributes;
- }
-
@Override
List<Attribute> getAssetAttributeValues(String assetId, List<String> attributes) {
if (attributes.size() != 2 || !attributes.contains("temperature") || !attributes.contains("speed")) {
@@ -72,6 +61,11 @@ class AssetsServiceTest extends Specification implements ContainerTrait {
return fakeAttributes;
}
+
+ @Override
+ boolean setAssetAttributeValues(String assetId, List<Attribute> attributes) {
+ return false
+ }
}
and: "the mock provider registers as a provider of a fake entity with the assets service"
@@ -81,29 +75,24 @@ class AssetsServiceTest extends Specification implements ContainerTrait {
result == true;
when: "an asset registered with the mock provider is requested"
- def response = assetsService.getContextBrokerV1().queryContext(
- new EntityAttributeQuery([new ContextEntity("Car", "Car1", false)], null)
- );
+ def entity = assetsService.getContextBroker().getEntity("Car1", null);
then: "the mock asset provider should have resolved the request"
def conditions = new PollingConditions(timeout: 10)
conditions.eventually {
- assert response.contextResponses != null;
+ assert entity != null;
}
requestedAttributes.size() == 2;
- response.contextResponses.size() == 1;
- response.contextResponses.get(0).getContextElement().getId() == "Car1";
- response.contextResponses.get(0).getContextElement().getType() == "Car";
- response.contextResponses.get(0).getContextElement().getAttributes().size() == 2;
- Attribute tempAttr = response.contextResponses.get(0).getContextElement().getAttributes()
- .stream()
+ entity.getId() == "Car1";
+ entity.getType() == "Car";
+ entity.getAttributes().length == 2;
+ Attribute tempAttr = Arrays.stream(entity.getAttributes())
.filter({ a -> a.getName().equals("temperature") })
.findFirst()
.get();
- Attribute speedAttr = response.contextResponses.get(0).getContextElement().getAttributes()
- .stream()
+ Attribute speedAttr = Arrays.stream(entity.getAttributes())
.filter({ a -> a.getName().equals("speed") })
.findFirst()
.get();
@@ -116,15 +105,10 @@ class AssetsServiceTest extends Specification implements ContainerTrait {
when: "provider is unregistered and previously registered asset is requested"
assetsService.unregisterAssetProvider("Car", "Car1", assetProvider);
- response = assetsService.getContextBrokerV1().queryContext(
- new EntityAttributeQuery([new ContextEntity("Car", "Car1", false)], null)
- );
+ entity = assetsService.getContextBroker().getEntity("Car1", null);
then: "a 404 response should be received"
- conditions.eventually {
- assert response.getErrorCode() != null;
- assert response.getErrorCode().code == "404"
- }
+ thrown(NotFoundException)
cleanup: "ensure mock provider is unregistered"
assetsService.unregisterAssetProvider("Car", "Car1", assetProvider);
@@ -150,19 +134,6 @@ class AssetsServiceTest extends Specification implements ContainerTrait {
];
def assetProvider = new AssetProvider() {
- @Override
- Attribute getAssetAttributeValue(String assetId, String attribute) {
- requestedAttributes.add(attribute);
- return attribute.equals("temperature") ?
- fakeAttributes[0]
- : fakeAttributes[1];
- }
-
- @Override
- List<Attribute> getAssetAttributeValues(String assetId) {
- return fakeAttributes;
- }
-
@Override
List<Attribute> getAssetAttributeValues(String assetId, List<String> attributes) {
if (attributes.size() != 2 || !attributes.contains("temperature") || !attributes.contains("speed")) {
@@ -173,10 +144,15 @@ class AssetsServiceTest extends Specification implements ContainerTrait {
return fakeAttributes;
}
+
+ @Override
+ boolean setAssetAttributeValues(String assetId, List<Attribute> attributes) {
+ return false
+ }
}
and: "the context provider refresh interval is set to 30s (minimum)"
- assetsService.getContextProvider().setRefreshInterval(30);
+ assetsService.getRegistrationProvider().setRefreshInterval(30);
and: "the mock provider registers as a provider of a fake entity with the assets service"
def result = assetsService.registerAssetProvider("Car", "Car1", fakeAttributes, assetProvider);