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); }
/** * 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)); } }
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); }
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()); }
private void createEmailUser(String name, String email, String password, String host, int port, boolean createActive) { EmailConfiguration newEmailUser = emailConfigs.add(); newEmailUser.userName().<StringResource>create().setValue(name); newEmailUser.email().<StringResource>create().setValue(email); newEmailUser.password().<StringResource>create().setValue(password); newEmailUser.serverURL().<StringResource>create().setValue(host); newEmailUser.port().<IntegerResource>create().setValue(port); newEmailUser.active().<BooleanResource>create().setValue(createActive); newEmailUser.activate(true); }
private void createSmsUser(String name, String sms, String password, String host, int port, boolean createActive) { SmsConfiguration newSmsUser = smsConfigs.add(); newSmsUser.userName().<StringResource>create().setValue(name); newSmsUser.smsEmail().<StringResource>create().setValue(sms); newSmsUser.smsEmailPassword().<StringResource>create().setValue(password); newSmsUser.smsEmailServer().<StringResource>create().setValue(host); newSmsUser.smsEmailPort().<IntegerResource>create().setValue(port); newSmsUser.active().<BooleanResource>create().setValue(createActive); newSmsUser.activate(true); }
/** * Set the resource value; the passed integer value is converted by the respective * canonical conversion method to the primitive (or String) value type of <code>resource</code>. * @param resource * @param value */ public static void setValue(SingleValueResource resource, int value) { if (resource instanceof StringResource) { ((StringResource) resource).setValue(String.valueOf(value)); } else if (resource instanceof FloatResource) { ((FloatResource) resource).setValue(value); } else if (resource instanceof IntegerResource) { ((IntegerResource) resource).setValue(value); } else if (resource instanceof BooleanResource) { ((BooleanResource) resource).setValue(value == 1 ? true : false); } else if (resource instanceof TimeResource) { ((TimeResource) resource).setValue(value); } }
/** * Set the resource value; the passed float value is converted by the respective * canonical conversion method to the primitive (or String) value type of <code>resource</code>. * @param resource * @param value */ public static void setValue(SingleValueResource resource, float value) { if (resource instanceof StringResource) { ((StringResource) resource).setValue(String.valueOf(value)); } else if (resource instanceof FloatResource) { ((FloatResource) resource).setValue(value); } else if (resource instanceof IntegerResource) { ((IntegerResource) resource).setValue((int) value); } else if (resource instanceof BooleanResource) { ((BooleanResource) resource).setValue(value == 1 ? true : false); } else if (resource instanceof TimeResource) { ((TimeResource) resource).setValue((long) value); } }
@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); }
private void createXmppUser(String name, String xmpp, String password, int port, boolean createActive) { XmppConfiguration newXmppUser = xmppConfigs.add(); newXmppUser.userName().<StringResource>create().setValue(name); newXmppUser.xmpp().<StringResource>create().setValue(xmpp); newXmppUser.password().<StringResource>create().setValue(password); newXmppUser.port().<IntegerResource>create().setValue(port); newXmppUser.active().<BooleanResource>create().setValue(createActive); newXmppUser.activate(true); }
@Override public void onPOSTComplete(String data, OgemaHttpRequest req) { String xmppRegex = "[A-Za-z0-9.-]+[@][A-Za-z0-9.-]+[.][a-zA-Z_0-9]+$"; String portRegex = "[0-9]{1,5}$"; int port = 70000; if (editXmppPortTextField.getValue(req).matches(portRegex)) { port = Integer.parseInt(editXmppPortTextField.getValue(req)); } if (editXmppTextField.getValue(req).matches(xmppRegex) && !editXmppPasswordTextField.getValue(req).isEmpty() && (port <= 65535)) { config.xmpp().setValue(editXmppTextField.getValue(req)); config.password().setValue(editXmppPasswordTextField.getValue(req)); config.port().setValue(port); alert.showAlert("Changes on User '" + id + "' confirmed", true, req); } else { if (!editXmppTextField.getValue(req).matches(xmppRegex)) alert.showAlert("Invalid Xmpp-Address", false, req); if (editXmppPasswordTextField.getValue(req).isEmpty()) alert.showAlert("No Password entered", false, req); if (port > 65535) alert.showAlert("Invalid Port", false, req); } }
@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; } }
@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
public void storeEvent(HmEvent e, SingleValueResource res) { logger.debug("storing event data for {}@{} to {}", e.getValueKey(), e.getAddress(), res.getPath()); if (res instanceof FloatResource) { ((FloatResource) res).setValue(e.getValueFloat()); } else if (res instanceof IntegerResource) { ((IntegerResource) res).setValue(e.getValueInt()); } else if (res instanceof StringResource) { ((StringResource) res).setValue(e.getValueString()); } else if (res instanceof BooleanResource) { ((BooleanResource) res).setValue(e.getValueBoolean()); } else { logger.warn("HomeMatic parameter resource is of unsupported type: {}", res.getResourceType()); } }
private void storeCommonData(HmDevice dev, DeviceDescription desc) { dev.type().<StringResource>create().setValue(desc.getType()); dev.address().<StringResource>create().setValue(desc.getAddress()); dev.version().<IntegerResource>create().setValue(desc.getVersion()); dev.paramsets().<StringArrayResource>create().setValues(desc.getParamsets()); }
/** * Set the resource value; the passed value is converted by the respective * method of {@link Value}. * @param resource * @param value */ public static void setValue(SingleValueResource resource, Value value) { if (resource instanceof StringResource) { ((StringResource) resource).setValue(value.getStringValue()); } else if (resource instanceof FloatResource) { ((FloatResource) resource).setValue(value.getFloatValue()); } else if (resource instanceof IntegerResource) { ((IntegerResource) resource).setValue(value.getIntegerValue()); } else if (resource instanceof BooleanResource) { if (value instanceof BooleanValue) ((BooleanResource) resource).setValue(value.getBooleanValue()); else // workaround... we cannot directly retrieve a boolean value from a FloatValue ((BooleanResource) resource).setValue(Math.abs(value.getFloatValue()) > 0.0001); } else if (resource instanceof TimeResource) { ((TimeResource) resource).setValue(value.getLongValue()); } }
@Override public boolean commit() { if (m_targetResource == null) { return false; } // delete the old configuration if it exsited. if (m_config != null) { m_config.delete(); } m_config = m_base.createResource(ProgramEnforcerModel.class); m_config.targetResource().setAsReference(m_targetResource); m_config.updateInterval().create(); m_config.updateInterval().setValue(m_updateInterval); m_config.exclusiveAccessRequired().create(); m_config.exclusiveAccessRequired().setValue(m_exclusiveAccessRequired); m_config.priority().create(); m_config.priority().setValue(m_priority.toString()); m_config.deactivateIfValueMissing().create(); m_config.deactivateIfValueMissing().setValue(m_deactivate); if (m_scheduleName != null) { m_config.scheduleResourceName().<StringResource> create().setValue(m_scheduleName); } m_config.activate(true); return true; }
result.application().setValue(appId); return (T) result;