m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryUtils.java
blob: c46e32db017e6c023cba006071180ad2186b0645 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package pl.edu.mimuw.cloudatlas.querysigner;

import pl.edu.mimuw.cloudatlas.model.ValueQuery;

import java.rmi.RemoteException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class QueryUtils {

    public static void validateQueryName(String queryName) throws RemoteException {
        Pattern queryNamePattern = Pattern.compile("&[a-zA-Z][\\w_]*");
        Matcher matcher = queryNamePattern.matcher(queryName);
        if (!matcher.matches()) {
            throw new RemoteException("Invalid query identifier");
        }
    }

    public static QueryData constructQueryData(ValueQuery valueQuery) {
        return new QueryData(
                valueQuery.getCode(),
                valueQuery.getSignature(),
                valueQuery.getTimestamp(),
                valueQuery.isInstalled()
        );
    }
}