m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-13 22:21:55 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-13 22:21:55 +0100
commit6a2a65319fd804b5d3ca3aa6636fb3dc25db930b (patch)
tree021901ce94f86bd3a1e2f8bc3fea5f490c3cd5be /src/main/java/pl/edu/mimuw/cloudatlas/agent
parent50924560e8829914a4b8d315752c693890210c88 (diff)
parent12175874524e19d999880302c66b7242de47e482 (diff)
Merge branch 'query_signer' of github.com:m-chrzan/CloudAtlas into query_signer
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java16
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java16
2 files changed, 14 insertions, 18 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java
index d2e808a..90e7789 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java
@@ -28,6 +28,8 @@ import pl.edu.mimuw.cloudatlas.model.Type;
import pl.edu.mimuw.cloudatlas.model.TypePrimitive;
import pl.edu.mimuw.cloudatlas.model.ZMI;
import pl.edu.mimuw.cloudatlas.api.Api;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryUtils;
public class ApiImplementation implements Api {
ZMI root;
@@ -60,16 +62,11 @@ public class ApiImplementation implements Api {
}
}
- public void installQuery(String name, String queryCode) throws RemoteException {
- Pattern queryNamePattern = Pattern.compile("&[a-zA-Z][\\w_]*");
- Matcher matcher = queryNamePattern.matcher(name);
- if (!matcher.matches()) {
- throw new RemoteException("Invalid query identifier");
- }
+ public void installQuery(String name, QueryData query) throws RemoteException {
+ QueryUtils.validateQueryName(name);
try {
- ValueQuery query = new ValueQuery(queryCode);
Attribute attributeName = new Attribute(name);
- installQueryInHierarchy(root, attributeName, query);
+ installQueryInHierarchy(root, attributeName, new ValueQuery(query));
executeAllQueries(root);
} catch (Exception e) {
throw new RemoteException("Failed to install query", e);
@@ -85,7 +82,8 @@ public class ApiImplementation implements Api {
}
}
- public void uninstallQuery(String queryName) throws RemoteException {
+ public void uninstallQuery(String queryName, QueryData query) throws RemoteException {
+ QueryUtils.validateQueryName(queryName);
uninstallQueryInHierarchy(root, new Attribute(queryName));
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
index b293446..0bf4338 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
@@ -22,6 +22,8 @@ import pl.edu.mimuw.cloudatlas.interpreter.Main;
import pl.edu.mimuw.cloudatlas.interpreter.QueryResult;
import pl.edu.mimuw.cloudatlas.model.*;
import pl.edu.mimuw.cloudatlas.api.Api;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryUtils;
public class NewApiImplementation implements Api {
private EventBus eventBus;
@@ -79,18 +81,13 @@ public class NewApiImplementation implements Api {
}
}
- public void installQuery(String name, String queryCode) throws RemoteException {
- Pattern queryNamePattern = Pattern.compile("&[a-zA-Z][\\w_]*");
- Matcher matcher = queryNamePattern.matcher(name);
- if (!matcher.matches()) {
- throw new RemoteException("Invalid query identifier");
- }
+ public void installQuery(String name, QueryData query) throws RemoteException {
+ QueryUtils.validateQueryName(name);
try {
- ValueQuery query = new ValueQuery(queryCode);
Attribute attributeName = new Attribute(name);
ValueTime timestamp = new ValueTime(System.currentTimeMillis());
Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
- queries.put(attributeName, new SimpleImmutableEntry(query, timestamp));
+ queries.put(attributeName, new SimpleImmutableEntry(new ValueQuery(query), timestamp));
UpdateQueriesMessage message = new UpdateQueriesMessage("", 0, queries);
eventBus.addMessage(message);
} catch (Exception e) {
@@ -98,7 +95,8 @@ public class NewApiImplementation implements Api {
}
}
- public void uninstallQuery(String queryName) throws RemoteException {
+ public void uninstallQuery(String queryName, QueryData query) throws RemoteException {
+ QueryUtils.validateQueryName(queryName);
try {
Attribute attributeName = new Attribute(queryName);
ValueTime timestamp = new ValueTime(System.currentTimeMillis());