@XmlElement public String getValue() { return ((StringResource) res).getValue(); }
private void createTestReceiverResource(ResourceList<ReceiverConfiguration> receiverConfigs, ApplicationManager appMan) { ReceiverConfiguration testConfig = receiverConfigs.add(); StringResource name = testConfig.userName().create(); name.setValue("XAll"); StringResource email = testConfig.email().create(); email.setValue("testtransmitter@web.de"); StringResource sms = testConfig.sms().create(); sms.setValue("49157123456789.testtransmitter@tmsg.de"); StringResource xmpp = testConfig.xmpp().create(); xmpp.setValue("testtransmitter2@jabber.de"); StringResource rest = testConfig.remoteMessageRestUrl().create(); rest.setValue("https://localhost:8444/rest/resources"); StringResource restUser = testConfig.remoteMessageRestUrl().create(); restUser.setValue("rest"); StringResource restPw = testConfig.remoteMessagePassword().create(); restPw.setValue("rest"); testConfig.activate(true); }
@Override public void onPOSTComplete(String data, OgemaHttpRequest req) { StringResource source = getResource(sva, req, StringResource.class); String val = myField.getValue(req); /*String value; try { value = Float.parseFloat(val); } catch (NumberFormatException | NullPointerException e) { if(alert != null) alert.showAlert(notAllowedMessageUsed, false, req); return; } if (value < minimumAllowed) { if(alert != null) alert.showAlert(notAllowedMessageUsed, false, req); return; } if (value > maximumAllowed) { if(alert != null) alert.showAlert(notAllowedMessageUsed, false, req); return; }*/ if(!source.exists()) { source.create(); source.setValue(val); source.activate(true); } else { source.setValue(val); } if(alert != null) alert.showAlert("New value: " + val, true, req); }
@Override public void onPOSTComplete(String data, OgemaHttpRequest req) { if(object.isActive()) { T newCat = OGEMAResourceCopyHelper.copySubResourceIntoResourceList(objectList, object, appMan, false); newCat.getSubResource("name", StringResource.class).setValue( "CopyOf_"+object.getSubResource("name", StringResource.class).getValue()); } else { object.activate(true); } } @Override
/** * Set the resource value. The <code>value</code> parameter must be parsable to the primitive (or String) * value type of <code>resource</code>. For instance, if <code>resource</code> is a {@link FloatResource}, * then <code>value</code> must be parsable as float. * @param resource * @param value * @throws NumberFormatException */ public static void setValue(SingleValueResource resource, String value) throws NumberFormatException { if (resource instanceof StringResource) { ((StringResource) resource).setValue(value); } else if (resource instanceof FloatResource) { ((FloatResource) resource).setValue(Float.parseFloat(value)); } else if (resource instanceof IntegerResource) { ((IntegerResource) resource).setValue(Integer.parseInt(value)); } else if (resource instanceof BooleanResource) { ((BooleanResource) resource).setValue(Boolean.parseBoolean(value)); } else if (resource instanceof TimeResource) { ((TimeResource) resource).setValue(Long.parseLong(value)); } }
config.email().create(); config.email().setValue(email); config.email().activate(true); } else { config.email().delete(); config.sms().create(); config.sms().setValue(sms); config.sms().activate(true); } else { config.sms().delete(); config.xmpp().create(); config.xmpp().setValue(xmpp); config.xmpp().activate(true); } else { config.xmpp().delete(); config.remoteMessageRestUrl().create(); config.remoteMessageRestUrl().setValue(rest.endsWith("/") ? rest : rest + "/"); config.remoteMessageRestUrl().activate(true); } else { config.remoteMessageRestUrl().delete(); config.remoteMessageUser().create(); config.remoteMessageUser().setValue(restUser); config.remoteMessageUser().activate(true); } else { config.remoteMessageUser().delete();
throw new UnsupportedOperationException("Cannot create a resource instance for unknown or un-implemented configuration type " + type.getName()); result.application().create(); result.application().requestAccessMode(AccessMode.EXCLUSIVE, AccessPriority.PRIO_HIGHEST); result.application().setValue(appId); return (T) result;
@Override protected void parseValue(Value value, String channelAddress) { switch (channelAddress) { case "ATTRIBUTE:0001": highWater.setValue(value.getStringValue()); highWater.activate(true); break; case "ATTRIBUTE:0002": batteryStatus.setValue(value.getFloatValue()); batteryStatus.activate(true); break; } }
private void addMandatoryChannels() { HM_hlConfig attributeConfig = new HM_hlConfig(); attributeConfig.driverId = hm_hlConfig.driverId; attributeConfig.interfaceId = hm_hlConfig.interfaceId; attributeConfig.deviceAddress = hm_hlConfig.deviceAddress; attributeConfig.channelAddress = "ATTRIBUTE:0001"; attributeConfig.timeout = -1; attributeConfig.resourceName = hm_hlConfig.resourceName + "_HighWater"; attributeConfig.chLocator = addChannel(attributeConfig); attributeConfig = new HM_hlConfig(); attributeConfig.driverId = hm_hlConfig.driverId; attributeConfig.interfaceId = hm_hlConfig.interfaceId; attributeConfig.deviceAddress = hm_hlConfig.deviceAddress; attributeConfig.channelAddress = "ATTRIBUTE:0002"; attributeConfig.timeout = -1; attributeConfig.resourceName = hm_hlConfig.resourceName + "_BatteryStatus"; attributeConfig.chLocator = addChannel(attributeConfig); WaterDetector threeStateDevice = resourceManager.createResource(hm_hlConfig.resourceName, WaterDetector.class); highWater = threeStateDevice.reading().create(); // highWater.activate(true); // highWater.setValue("dry"); highWater.requestAccessMode(AccessMode.EXCLUSIVE, AccessPriority.PRIO_HIGHEST); StateOfChargeSensor eSens = threeStateDevice.battery().chargeSensor().create(); batteryStatus = eSens.reading().create(); // batteryStatus.activate(true); // batteryStatus.setValue(95); batteryStatus.requestAccessMode(AccessMode.EXCLUSIVE, AccessPriority.PRIO_HIGHEST); // do not activate value resources, since they do not contain sensible values yet ResourceUtils.activateComplexResources(threeStateDevice, true, appManager.getResourceAccess()); }
public int doPush() throws IOException { Resource target = getTargetResource(); CloseableHttpClient client = getClient(); int i = 0; if (!con.pushConfig().isActive() && con.individualPushConfigs().isActive()) { for (RestPushConfig config: con.individualPushConfigs().getAllElements()) { if (!config.remoteRelativePath().isActive()) { logger.error("Individual push configuration lacks relative path. Ignoring this. "+con.pushConfig()); i = 1000; continue; } i = Math.max(pushIndividual(target, config, con, client),i); } } else if (con.pushConfig().isActive()) { if (con.pushConfig().remoteRelativePath().isActive()) { logger.error("Global push configuration has a relative path. Ignoring this. "+con.pushConfig()); return 1000; } i = pushIndividual(target, con.pushConfig(), con, client); } return i; }
private static void setValue(ValueResource svr, String text) { if (svr instanceof StringResource) { ((StringResource) svr).setValue(text); } else if (svr instanceof FloatResource) { ((FloatResource) svr).setValue(Float.parseFloat(text)); } else if (svr instanceof IntegerResource) { ((IntegerResource) svr).setValue(Integer.parseInt(text)); } else if (svr instanceof TimeResource) { ((TimeResource) svr).setValue(Long.parseLong(text)); } else if (svr instanceof BooleanResource) { ((BooleanResource) svr).setValue(Boolean.parseBoolean(text)); } else if (svr instanceof ByteArrayResource) { ((ByteArrayResource) svr).setValues(DatatypeConverter.parseHexBinary(text)); } else throw new RuntimeException("Invalid resource type " + svr.getResourceType().getSimpleName()); }
return appManFuture.thenApplyAsync(appMan -> { final Optional<ProfileConfiguration> opt = appMan.getResourceAccess().getResources(ProfileConfiguration.class).stream() .filter(cfg -> id.equals(cfg.id().getValue())) .filter(cfg -> template.id().equals(cfg.profileTemplateId().getValue())) .findAny(); if (!opt.isPresent()) final List<String> dpIds = dps.map(DataPoint::id).collect(Collectors.toList()); final Map<DataPoint, Resource> map = cfg.dataPoints().getAllElements().stream() .filter(dpc -> dpIds.contains(dpc.dataPointId().getValue())) .filter(dpc -> dpc.target().isReference(false)) .collect(Collectors.toMap(dpc -> getDataPoint(template, dpc), DataPointConfig::target)); final OnOffSwitch oo = cfg.onOffSwitch().isActive() ? cfg.onOffSwitch() : null; final String endStateId = cfg.endState().isActive() ? cfg.endState().getValue() : null; final State endState = endStateId == null ? null : template.states().stream() .filter(st -> endStateId.equals(st.id()))
public static void addNewReceiver(ResourceList<ReceiverConfiguration> receiverConfigs, String name, String email, String sms, String xmpp, String rest, String restUser, String restPw) { ReceiverConfiguration newReceiver = receiverConfigs.add(); newReceiver.userName().<StringResource>create().setValue(name); if(!email.isEmpty()) newReceiver.email().<StringResource>create().setValue(email); if(!sms.isEmpty()) newReceiver.sms().<StringResource>create().setValue(sms); if(!xmpp.isEmpty()) newReceiver.xmpp().<StringResource>create().setValue(xmpp); if(!rest.isEmpty()) newReceiver.remoteMessageRestUrl().<StringResource>create().setValue( rest.endsWith("/") ? rest : rest+"/"); if(!restUser.isEmpty()) newReceiver.remoteMessageUser().<StringResource>create().setValue(restUser); if(!restPw.isEmpty()) newReceiver.remoteMessagePassword().<StringResource>create().setValue(restPw); newReceiver.activate(true); }