Search in sources :

Example 1 with MetaItem

use of org.openremote.model.attribute.MetaItem in project openremote by openremote.

the class AbstractHttpServerProtocol method createDeployment.

protected ResteasyDeployment createDeployment(Application application, AssetAttribute protocolConfiguration) {
    ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
    resteasyDeployment.setApplication(application);
    List<String> allowedOrigins;
    if (devMode) {
        allowedOrigins = Collections.singletonList("*");
    } else {
        Optional<MetaItem> allowedOriginsMeta = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_ORIGINS);
        allowedOrigins = allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsString).map(Collections::singletonList).orElseGet(() -> allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsArray).flatMap(arrayValue -> Values.getArrayElements(arrayValue, StringValue.class, true, false, StringValue::getString)).orElse(null));
    }
    if (allowedOrigins != null) {
        String allowedMethods = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_METHODS).flatMap(AbstractValueHolder::getValueAsString).orElse(DEFAULT_ALLOWED_METHODS);
        if (TextUtil.isNullOrEmpty(allowedMethods)) {
            throw new IllegalArgumentException("Allowed methods meta item must be a non empty string: " + META_PROTOCOL_ALLOWED_METHODS);
        }
        CorsFilter corsFilter = new CorsFilter();
        corsFilter.getAllowedOrigins().addAll(allowedOrigins);
        corsFilter.setAllowedMethods(allowedMethods);
        resteasyDeployment.getProviders().add(corsFilter);
    }
    return resteasyDeployment;
}
Also used : java.util(java.util) ServletException(javax.servlet.ServletException) ProtocolConfiguration(org.openremote.model.asset.agent.ProtocolConfiguration) AttributeRef(org.openremote.model.attribute.AttributeRef) ArrayValue(org.openremote.model.value.ArrayValue) Application(javax.ws.rs.core.Application) ServletInfo(io.undertow.servlet.api.ServletInfo) HttpMethod(javax.ws.rs.HttpMethod) Level(java.util.logging.Level) Servlets(io.undertow.servlet.Servlets) Container(org.openremote.container.Container) Lists(com.google.common.collect.Lists) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) TextUtil(org.openremote.model.util.TextUtil) PROTOCOL_NAMESPACE(org.openremote.model.Constants.PROTOCOL_NAMESPACE) AbstractValueHolder(org.openremote.model.AbstractValueHolder) StringValue(org.openremote.model.value.StringValue) org.openremote.container.web(org.openremote.container.web) Pair(org.openremote.model.util.Pair) ModelValueMessageBodyConverter(org.openremote.container.json.ModelValueMessageBodyConverter) Logger(java.util.logging.Logger) DeploymentManager(io.undertow.servlet.api.DeploymentManager) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) AbstractProtocol(org.openremote.agent.protocol.AbstractProtocol) HttpHandler(io.undertow.server.HttpHandler) MetaItem(org.openremote.model.attribute.MetaItem) IdentityService(org.openremote.container.security.IdentityService) CorsFilter(org.jboss.resteasy.plugins.interceptors.CorsFilter) RoleBasedSecurityFeature(org.jboss.resteasy.plugins.interceptors.RoleBasedSecurityFeature) JacksonConfig(org.openremote.container.json.JacksonConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Values(org.openremote.model.value.Values) Pattern(java.util.regex.Pattern) ValueHolder(org.openremote.model.ValueHolder) AssetAttribute(org.openremote.model.asset.AssetAttribute) CorsFilter(org.jboss.resteasy.plugins.interceptors.CorsFilter) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) MetaItem(org.openremote.model.attribute.MetaItem) AbstractValueHolder(org.openremote.model.AbstractValueHolder) StringValue(org.openremote.model.value.StringValue)

Example 2 with MetaItem

use of org.openremote.model.attribute.MetaItem in project openremote by openremote.

the class ManagerDemoAgentSetup method onStart.

@Override
public void onStart() throws Exception {
    KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);
    Tenant masterTenant = keycloakDemoSetup.masterTenant;
    masterRealmId = masterTenant.getId();
    ServerAsset agent = new ServerAsset("Demo Agent", AGENT);
    agent.setRealmId(masterRealmId);
    agent = assetStorageService.merge(agent);
    if (knx) {
        LOG.info("Enable KNX demo protocol configuration, gateway/local IP: " + knxGatewayIp + "/" + knxLocalIp);
        agent.addAttributes(initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME).addMeta(new MetaItem(KNXProtocol.META_KNX_GATEWAY_IP, Values.create(knxGatewayIp)), new MetaItem(KNXProtocol.META_KNX_LOCAL_IP, Values.create(knxLocalIp))));
        ServerAsset knxDevices = new ServerAsset("KNX Devices", THING, agent, masterRealmId);
        knxDevices = assetStorageService.merge(knxDevices);
    }
    if (velbus) {
        LOG.info("Enable Velbus demo protocol configuration, COM port: " + velbusComPort);
        agent.addAttributes(initProtocolConfiguration(new AssetAttribute("velbusConfig"), VelbusSerialProtocol.PROTOCOL_NAME).addMeta(new MetaItem(VelbusSerialProtocol.META_VELBUS_SERIAL_PORT, Values.create(velbusComPort))));
        ServerAsset velbusDevices = new ServerAsset("VELBUS Devices", THING, agent, masterRealmId);
        velbusDevices = assetStorageService.merge(velbusDevices);
    }
    if (upnp) {
        LOG.info("Enable UPnP demo protocol configuration");
        ServerAsset upnpDevices = new ServerAsset("UPnP Devices", THING, agent, masterRealmId);
        upnpDevices = assetStorageService.merge(upnpDevices);
        agent.addAttributes(initProtocolConfiguration(new AssetAttribute("upnpConfig"), UpnpProtocol.PROTOCOL_NAME).addMeta(// TODO Protocols should create these grouping assets automatically and import assets underneath for each protocol configuration
        new MetaItem(UpnpProtocol.GROUP_ASSET_ID, Values.create(upnpDevices.getId()))));
    }
    agent = assetStorageService.merge(agent);
}
Also used : Tenant(org.openremote.model.security.Tenant) MetaItem(org.openremote.model.attribute.MetaItem) ServerAsset(org.openremote.manager.asset.ServerAsset) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Example 3 with MetaItem

use of org.openremote.model.attribute.MetaItem in project openremote by openremote.

the class ProtocolConfiguration method initProtocolConfiguration.

public static AssetAttribute initProtocolConfiguration(AssetAttribute attribute, String protocolName) throws IllegalArgumentException {
    if (attribute == null) {
        return null;
    }
    isValidProtocolNameOrThrow(protocolName);
    attribute.setReadOnly(true);
    attribute.setType(AttributeType.STRING);
    attribute.setValue(Values.create(protocolName));
    attribute.getMeta().add(new MetaItem(PROTOCOL_CONFIGURATION, Values.create(true)));
    return attribute;
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem)

Example 4 with MetaItem

use of org.openremote.model.attribute.MetaItem in project openremote by openremote.

the class UpnpProtocol method createAsset.

protected Asset createAsset(String parentId, Device device) {
    Asset asset = new Asset(device.getDisplayString(), AssetType.THING);
    asset.setParentId(parentId);
    asset.setId(getAssetId(device));
    long currentTime = timerService.getCurrentTimeMillis();
    Optional.ofNullable(device.getType().getDisplayString()).ifPresent(v -> asset.addAttributes(new AssetAttribute("type", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Device Type")))));
    Optional.ofNullable(device.getDetails().getManufacturerDetails().getManufacturer()).ifPresent(v -> asset.addAttributes(new AssetAttribute("manufacturer", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Manufacturer")))));
    Optional.ofNullable(device.getDetails().getFriendlyName()).ifPresent(v -> asset.addAttributes(new AssetAttribute("friendlyName", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Friendly Name")))));
    Optional.ofNullable(device.getDetails().getModelDetails().getModelNumber()).ifPresent(v -> asset.addAttributes(new AssetAttribute("modelNumber", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Model Number")))));
    Optional.ofNullable(device.getDetails().getModelDetails().getModelName()).ifPresent(v -> asset.addAttributes(new AssetAttribute("modelName", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Model Name")))));
    Optional.ofNullable(device.getDetails().getModelDetails().getModelDescription()).ifPresent(v -> asset.addAttributes(new AssetAttribute("modelDescription", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Model Description")))));
    Optional.ofNullable(device.getDetails().getSerialNumber()).ifPresent(v -> asset.addAttributes(new AssetAttribute("serialNumber", STRING, Values.create(v), currentTime).addMeta(new MetaItem(LABEL, Values.create("Serial Number")))));
    return asset;
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem) AssetAttribute(org.openremote.model.asset.AssetAttribute) Asset(org.openremote.model.asset.Asset)

Example 5 with MetaItem

use of org.openremote.model.attribute.MetaItem in project openremote by openremote.

the class MetaEditor method addItem.

protected boolean addItem(MetaItem item, boolean viewOnly) {
    if (!viewOnly) {
        MetaItemDescriptor[] descriptor = new MetaItemDescriptor[1];
        // Check item can be added
        boolean canAdd = Arrays.stream(metaItemDescriptors).filter(metaItemDescriptor -> metaItemDescriptor.getUrn().equals(item.getName().orElse(null))).findFirst().map(metaItemDescriptor -> {
            descriptor[0] = metaItemDescriptor;
            return metaItemDescriptor.getMaxPerAttribute();
        }).map(maxCount -> attribute.getMeta().stream().filter(metaItem -> metaItem.getName().map(name -> name.equals(item.getName().orElse(null))).orElse(false)).count() < maxCount).orElse(true);
        if (!canAdd) {
            showValidationError(attribute.getName().orElse(""), null, new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_DUPLICATION, getMetaItemDisplayName(environment, descriptor[0].name())));
            return false;
        }
        attribute.getMeta().add(item);
        // Notify the presenter that the attribute has changed
        notifyAttributeModified();
    }
    int index = itemListPanel.getWidgetCount();
    MetaItemEditor metaItemEditor = createMetaItemEditor(item, false);
    itemListPanel.add(metaItemEditor);
    setLabelVisible(itemListPanel.getWidgetCount() > 0);
    // Check if we have a validation failure for this editor
    if (lastValidationResult != null && lastValidationResult.getMetaFailures() != null) {
        List<ValidationFailure> failures = lastValidationResult.getMetaFailures().get(index);
        if (failures != null && !failures.isEmpty()) {
            metaItemEditor.setError(true);
        }
    }
    return true;
}
Also used : IntStream(java.util.stream.IntStream) Supplier(org.openremote.model.interop.Supplier) java.util(java.util) ValueType(org.openremote.model.value.ValueType) Environment(org.openremote.app.client.Environment) MetaItemDescriptor(org.openremote.model.attribute.MetaItemDescriptor) Pair(org.openremote.model.util.Pair) EnumUtil(org.openremote.model.util.EnumUtil) ValidationFailure(org.openremote.model.ValidationFailure) org.openremote.app.client.widget(org.openremote.app.client.widget) Collectors(java.util.stream.Collectors) AssetMeta(org.openremote.model.asset.AssetMeta) AttributeValidationResult(org.openremote.model.attribute.AttributeValidationResult) MetaItem(org.openremote.model.attribute.MetaItem) AgentLink(org.openremote.model.asset.agent.AgentLink) Value(org.openremote.model.value.Value) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) ProtocolDescriptor(org.openremote.model.asset.agent.ProtocolDescriptor) IsWidget(com.google.gwt.user.client.ui.IsWidget) Values(org.openremote.model.value.Values) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) AssetAttribute(org.openremote.model.asset.AssetAttribute) MetaItemDescriptor(org.openremote.model.attribute.MetaItemDescriptor) ValidationFailure(org.openremote.model.ValidationFailure)

Aggregations

MetaItem (org.openremote.model.attribute.MetaItem)14 ValidationFailure (org.openremote.model.ValidationFailure)4 AssetAttribute (org.openremote.model.asset.AssetAttribute)4 java.util (java.util)3 Level (java.util.logging.Level)2 SimulatorAgent (org.openremote.agent.protocol.simulator.SimulatorAgent)2 SimulatorAgentLink (org.openremote.agent.protocol.simulator.SimulatorAgentLink)2 Asset (org.openremote.model.asset.Asset)2 Attribute (org.openremote.model.attribute.Attribute)2 GeoJSONPoint (org.openremote.model.geo.GeoJSONPoint)2 Tenant (org.openremote.model.security.Tenant)2 Pair (org.openremote.model.util.Pair)2 Values (org.openremote.model.value.Values)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Lists (com.google.common.collect.Lists)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 HttpHandler (io.undertow.server.HttpHandler)1 Servlets (io.undertow.servlet.Servlets)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1