Search in sources :

Example 1 with HardwareAddressImpl

use of cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl 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 HardwareAddressImpl

use of cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl 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 3 with HardwareAddressImpl

use of cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl in project c2mon by c2mon.

the class RestConfigStrategyTest method prepareTagConfigurationsShouldIncludeAllPropertiesInKeys.

@Test
void prepareTagConfigurationsShouldIncludeAllPropertiesInKeys() throws DynConfigException {
    DataTagAddress expected = new DataTagAddress(new HardwareAddressImpl());
    HashMap<String, String> parameters = new HashMap<>();
    parameters.put("url", "xxx");
    parameters.put("mode", "POST");
    parameters.put("getFrequency", "5");
    parameters.put("postFrequency", "3");
    parameters.put("jsonPathExpression", "aa");
    expected.setAddressParameters(parameters);
    URI uri = URI.create("http://host/path?url=xxx&mode=POST&getFrequency=5&postFrequency=3&jsonPathExpression=aa");
    strategy = ITagConfigStrategy.of(uri);
    DataTagAddress actual = this.strategy.prepareDataTagConfigurations().getAddress();
    assertEquals(expected, actual);
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) HashMap(java.util.HashMap) HardwareAddressImpl(cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 4 with HardwareAddressImpl

use of cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl 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)

Aggregations

DataTagAddress (cern.c2mon.shared.common.datatag.DataTagAddress)4 HardwareAddressImpl (cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl)4 URI (java.net.URI)4 QueryKey (cern.c2mon.client.core.configuration.dynamic.query.QueryKey)3 DataTag (cern.c2mon.shared.client.configuration.api.tag.DataTag)3 Test (org.junit.jupiter.api.Test)3 QueryObj (cern.c2mon.client.core.configuration.dynamic.query.QueryObj)2 HashMap (java.util.HashMap)2 DynConfigException (cern.c2mon.client.core.configuration.dynamic.DynConfigException)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 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1