Search in sources :

Example 1 with QueryKey

use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.

the class QueryObjTest method mandatoryKeyForClassWithoutTargetShouldThrowError.

@Test
void mandatoryKeyForClassWithoutTargetShouldThrowError() throws DynConfigException {
    QueryKey<String> mode = new QueryKey<>("mode", "GET", true);
    mode.setVerifier(s -> s.equalsIgnoreCase("GET") || s.equalsIgnoreCase("POST"));
    URI uri = URI.create("opc.tcp://host:500/path?mode=GET");
    QueryObj queryObj = new QueryObj(uri, Collections.singletonList(mode));
    DataTag.CreateBuilder builder = DataTag.create("a", Object.class, new DataTagAddress(new HardwareAddressImpl()));
    assertThrows(DynConfigException.class, () -> queryObj.applyQueryPropertiesTo(builder));
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) QueryKey(cern.c2mon.client.core.configuration.dynamic.query.QueryKey) HardwareAddressImpl(cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl) URI(java.net.URI) DataTag(cern.c2mon.shared.client.configuration.api.tag.DataTag) QueryObj(cern.c2mon.client.core.configuration.dynamic.query.QueryObj) Test(org.junit.jupiter.api.Test)

Example 2 with QueryKey

use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.

the class QueryObjTest method createQueryObjWithMissingKeyShouldThrowException.

@Test
void createQueryObjWithMissingKeyShouldThrowException() {
    List<QueryKey<?>> key = Collections.singletonList(new QueryKey<Integer>("missing", null, true));
    assertThrows(DynConfigException.class, () -> new QueryObj(uri, key));
}
Also used : QueryKey(cern.c2mon.client.core.configuration.dynamic.query.QueryKey) QueryObj(cern.c2mon.client.core.configuration.dynamic.query.QueryObj) Test(org.junit.jupiter.api.Test)

Example 3 with QueryKey

use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.

the class QueryObjTest method mandatoryKeyForClassWithTargetShouldPassWork.

@Test
void mandatoryKeyForClassWithTargetShouldPassWork() throws DynConfigException {
    QueryKey<String> mode = new QueryKey<>("mode", "GET", true);
    mode.setVerifier(s -> s.equalsIgnoreCase("GET") || s.equalsIgnoreCase("POST"));
    mode.setTargetClass(DataTagAddress.class);
    URI uri = URI.create("opc.tcp://host:500/path?mode=GET");
    QueryObj queryObj = new QueryObj(uri, Collections.singletonList(mode));
    DataTag.CreateBuilder builder = DataTag.create("a", Object.class, new DataTagAddress(new HardwareAddressImpl()));
    queryObj.applyQueryPropertiesTo(builder);
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) QueryKey(cern.c2mon.client.core.configuration.dynamic.query.QueryKey) HardwareAddressImpl(cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl) URI(java.net.URI) DataTag(cern.c2mon.shared.client.configuration.api.tag.DataTag) QueryObj(cern.c2mon.client.core.configuration.dynamic.query.QueryObj) Test(org.junit.jupiter.api.Test)

Example 4 with QueryKey

use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.

the class RestConfigStrategy method prepareDataTagConfigurations.

/**
 * Create appropriate preliminary data tag configurations with a @{@link cern.c2mon.shared.common.datatag.address.DIPHardwareAddress}
 * which can then be passed to the C2MON server for creation.
 * @return the preliminary DataTags to pass on to the C2MON server for creation.
 * @throws DynConfigException if a value in the query cannot be converted to the necessary class, but is mandatory.
 */
public DataTag prepareDataTagConfigurations() throws DynConfigException {
    HardwareAddress restHardwareAddress = new HardwareAddressImpl();
    DataTag dataTag = super.toTagConfiguration(restHardwareAddress);
    HashMap<String, String> params = keys.stream().filter(k -> queryObj.contains(k)).collect(Collectors.toMap(QueryKey::getKeyName, o -> StringUtils.join(queryObj.get(o, String.class), ", "), (o, o2) -> o, HashMap::new));
    dataTag.getAddress().setAddressParameters(params);
    return dataTag;
}
Also used : CommandTag(cern.c2mon.shared.client.configuration.api.tag.CommandTag) StringUtils(org.apache.commons.lang.StringUtils) DataTag(cern.c2mon.shared.client.configuration.api.tag.DataTag) HardwareAddressImpl(cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DynConfigException(cern.c2mon.client.core.configuration.dynamic.DynConfigException) DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) List(java.util.List) QueryKey(cern.c2mon.client.core.configuration.dynamic.query.QueryKey) HardwareAddress(cern.c2mon.shared.common.datatag.address.HardwareAddress) URI(java.net.URI) HardwareAddressImpl(cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl) HardwareAddress(cern.c2mon.shared.common.datatag.address.HardwareAddress) DataTag(cern.c2mon.shared.client.configuration.api.tag.DataTag)

Example 5 with QueryKey

use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.

the class QueryObjTest method createQueryObjWithValidKeyShouldHaveNoInfluence.

@Test
void createQueryObjWithValidKeyShouldHaveNoInfluence() throws DynConfigException {
    QueryObj expected = new QueryObj(uri, Collections.emptyList());
    List<QueryKey<?>> key = Collections.singletonList(new QueryKey<Integer>("tagName", null, true));
    queryObj = new QueryObj(uri, key);
    assertEquals(expected, queryObj);
}
Also used : QueryKey(cern.c2mon.client.core.configuration.dynamic.query.QueryKey) QueryObj(cern.c2mon.client.core.configuration.dynamic.query.QueryObj) Test(org.junit.jupiter.api.Test)

Aggregations

QueryKey (cern.c2mon.client.core.configuration.dynamic.query.QueryKey)6 QueryObj (cern.c2mon.client.core.configuration.dynamic.query.QueryObj)5 Test (org.junit.jupiter.api.Test)4 DataTag (cern.c2mon.shared.client.configuration.api.tag.DataTag)3 DataTagAddress (cern.c2mon.shared.common.datatag.DataTagAddress)3 HardwareAddressImpl (cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl)3 URI (java.net.URI)3 DynConfigException (cern.c2mon.client.core.configuration.dynamic.DynConfigException)1 IQueryObj (cern.c2mon.client.core.configuration.dynamic.query.IQueryObj)1 CommandTag (cern.c2mon.shared.client.configuration.api.tag.CommandTag)1 HardwareAddress (cern.c2mon.shared.common.datatag.address.HardwareAddress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1