static void verifyValueRange(final String name, final double value, final double min, final double max) throws VerificationFailedException { if (value < min) { throw new VerificationFailedException("The value of " + name + " is " + value + " which is lower than the defined minimum of " + min); } else if (value > max) { throw new VerificationFailedException("The value of " + name + " is " + value + " which is higher than the defined maximum of " + max); } } }
private void verify() throws VerificationFailedException { if (itemId.contains("-")) { throw new VerificationFailedException("Found \"-\" in item id which is not allowed for openhab configurations!"); } }
/** * {@inheritDoc} * * @throws VerificationFailedException {@inheritDoc} */ @Override public void verifyMaintainability() throws VerificationFailedException { if (isLocked()) { throw new VerificationFailedException("Manipulation of " + this + "is currently not valid because the maintains is protected by another instance! " + "Did you try to modify an instance which is locked by a managed instance pool?"); } }
static void verifyTemperatureState(final TemperatureState temperatureState) throws VerificationFailedException { if (!temperatureState.hasTemperature()) { throw new VerificationFailedException("Temperature value unknown!"); } switch (temperatureState.getTemperatureDataUnit()) { case UNKNOWN: throw new VerificationFailedException("TemperatureState data unit unknown!"); default: return; } }
/** * {@inheritDoc} * * @throws VerificationFailedException {@inheritDoc} */ @Override public void verifyMaintainability() throws VerificationFailedException { if (isLocked()) { throw new VerificationFailedException("Manipulation of " + this + "is currently not valid because the maintains is protected by another instance! " + "Did you try to modify an instance which is locked by a managed instance pool?"); } }
public static void verifyOperationServiceStateValue(final Enum value) throws VerificationFailedException { if (value == null) { throw new VerificationFailedException(new NotAvailableException("ServiceStateValue")); } if (value.name().equals("UNKNOWN")) { throw new VerificationFailedException("UNKNOWN." + value.getClass().getSimpleName() + " is an invalid operation service state!"); } }
/** * @param value * * @throws VerificationFailedException * @deprecated please use Services.verifyOperationServiceStateValue(...) instead */ @Deprecated default void verifyOperationServiceStateValue(final Enum value) throws VerificationFailedException { if (value == null) { throw new VerificationFailedException(new NotAvailableException("ServiceStateValue")); } if (value.name().equals("UNKNOWN")) { throw new VerificationFailedException("UNKNOWN." + value.getClass().getSimpleName() + " is an invalid operation service state of " + this + "!"); } }
/** * Method reinitialize this remote. If the remote was previously active the activation state will be recovered. * This method can be used in case of a broken connection or if the participant config has been changed. * <p> * Note: After reinit the data remains the same but a new sync task is created. So to make sure to have new data * it is necessary to call {@code requestData.get()}. * * @param scope the new scope to configure. * @param maintainer the current maintainer of this remote * @throws InterruptedException is thrown if the current thread was externally interrupted. * @throws CouldNotPerformException is throws if the reinit has been failed. * @throws VerificationFailedException is thrown if the given maintainerLock does not match the current maintainer */ public void reinit(final Scope scope, final Object maintainer) throws InterruptedException, CouldNotPerformException, VerificationFailedException { if (this.maintainer.equals(maintainer)) { reinit(scope); } else { throw new VerificationFailedException("Manipulation of " + this + "is not valid using lock[" + maintainerLock + "]"); } }
public static void verifyUnitType(final UnitConfigOrBuilder unitConfig, final UnitType unitType) throws VerificationFailedException { // verify if unit type is defined if (!unitConfig.hasType()) { throw new VerificationFailedException("UnitType not available!"); } // verify unit type if (unitConfig.getType() != unitType) { throw new VerificationFailedException("UnitType verification failed. Expected[" + unitType + "] but was[" + unitConfig.getType() + "]!"); } }
public static void verifyUnitConfig(final UnitConfigOrBuilder unitConfig, final UnitType unitType) throws VerificationFailedException { verifyUnitType(unitConfig, unitType); // verify unit type config if (isBaseUnit(unitType)) { try { if (!(boolean) unitConfig.getClass().getMethod("has" + StringProcessor.transformUpperCaseToCamelCase(unitType.name()) + "Config").invoke(unitConfig)) { throw new VerificationFailedException("UnitType config missing of given UnitConfig!"); } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NullPointerException ex) { throw new VerificationFailedException("Given unit config is not compatible with current programm version!", ex); } } }
@Override public void verify() throws VerificationFailedException { if (!getLaunchable().isConsistent()) { throw new VerificationFailedException(getLaunchable().getClass().getSimpleName() + " is inconsistent"); } } }
protected <U extends AbstractUnitController<?, ?>> void registerUnit(final U unit) throws CouldNotPerformException { synchronized (unitMapLock) { try { if (unitMap.containsKey(unit.getId())) { throw new VerificationFailedException("Could not register " + unit + "! Unit with same name already registered!"); } unitMap.put(unit.getId(), unit); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not registerUnit!", ex); } } }
public static void verifyOperationServiceState(final Message serviceState) throws VerificationFailedException { if (serviceState == null) { throw new VerificationFailedException(new NotAvailableException("ServiceState")); } final Method valueMethod; try { valueMethod = serviceState.getClass().getMethod("getValue"); try { verifyOperationServiceStateValue((Enum) valueMethod.invoke(serviceState)); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassCastException ex) { ExceptionPrinter.printHistory("Operation service verification phase failed of ServiceState[ " + serviceState.getClass().getSimpleName() + "]!", ex, LOGGER); } } catch (NoSuchMethodException ex) { // service state does contain any value so verification is not needed. } verifyServiceState(serviceState); }
/** * @param serviceState * * @throws VerificationFailedException * @deprecated please use Services.verifyOperationServiceState(...) instead */ @Deprecated default void verifyOperationServiceState(final Object serviceState) throws VerificationFailedException { if (serviceState == null) { throw new VerificationFailedException(new NotAvailableException("ServiceState")); } final Method valueMethod; try { valueMethod = serviceState.getClass().getMethod("getValue"); } catch (NoSuchMethodException ex) { // service state does contain any value so verification is not possible. return; } try { verifyOperationServiceStateValue((Enum) valueMethod.invoke(serviceState)); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassCastException ex) { ExceptionPrinter.printHistory("Operation service verification phase failed!", ex, LoggerFactory.getLogger(getClass())); } }
@Override public void processData(final String id, final IdentifiableMessage<String, UnitTemplate, Builder> entry, final ProtoBufMessageMap<String, UnitTemplate, Builder> entryMap, ProtoBufRegistry<String, UnitTemplate, Builder> registry) throws CouldNotPerformException, EntryModification { final UnitTemplate unitTemplate = entry.getMessage(); if (unitTypeUnitTemplateMap.containsKey(unitTemplate.getType()) && !unitTemplate.getId().equals(unitTypeUnitTemplateMap.get(unitTemplate.getType()).getId())) { throw new VerificationFailedException("UnitTemplate[" + unitTypeUnitTemplateMap.get(unitTemplate.getType()) + "] and unitTemplate[" + unitTemplate + "] both contain the same type"); } unitTypeUnitTemplateMap.put(unitTemplate.getType(), unitTemplate); }
/** * Atomic deactivate which makes sure that the maintainer stays the same. * * @param maintainer the current maintainer of this remote * @throws InterruptedException if deactivation is interrupted * @throws CouldNotPerformException if deactivation fails * @throws VerificationFailedException is thrown if the given maintainer does not match the current one */ public void deactivate(final Object maintainer) throws InterruptedException, CouldNotPerformException, VerificationFailedException { if (this.maintainer.equals(maintainer)) { synchronized (maintainerLock) { unlock(maintainer); deactivate(); lock(maintainer); } } else { throw new VerificationFailedException("[" + maintainer + "] is not the current maintainer of this remote"); } }
protected Element getElementFromXPath(final String xPath, final Document document) throws VerificationFailedException { Nodes regNodes = document.query(xPath); if (regNodes.size() != 1) { throw new VerificationFailedException("Invalide data from XPath[" + xPath + "]!"); } return (Element) regNodes.get(0); }
public static void verifyUnitType(final Unit<?> unit) throws VerificationFailedException { try { UnitConfigProcessor.verifyUnitType(unit.getConfig(), unit.getUnitType()); } catch (NotAvailableException ex) { throw new VerificationFailedException("Could not verify unit type!", ex); } }
public static void verifyUnitConfig(final Unit<?> unit) throws VerificationFailedException { try { UnitConfigProcessor.verifyUnitConfig(unit.getConfig(), unit.getUnitType()); } catch (NotAvailableException ex) { throw new VerificationFailedException("Could not verify unit type!", ex); } }
static void verifyColorState(final ColorState colorState) throws VerificationFailedException { if(!colorState.hasColor()) { throw new VerificationFailedException("Color state unknown!"); } verifyColor(colorState.getColor()); }