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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations