private void detectNegation(final String askQuery) throws MultiException { // official w3c sparql negation forms final String[] negationForms = new String[] {"not exists", "!exists", "minus", "not in", "not bound"}; MultiException.ExceptionStack exceptionStack = null; for (final String negationForm : negationForms) { try { if (askQuery.toLowerCase().contains(negationForm)) { throw new NotAvailableException("Found negation keyword: " + negationForm); } } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not parse ontologyChange from query string, because of negation phrase in query string! Certain determination of " + "trigger changes criteria can't be guarantee. Select manual criteria for this trigger!", exceptionStack); }
public static String resolveVariable(final String variable, final VariableProvider... providers) throws MultiException { MultiException.ExceptionStack exceptionStack = null; for (VariableProvider provider : providers) { try { return provider.getValue(variable); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(VariableProcessor.class, ex, exceptionStack); continue; } } MultiException.checkAndThrow("Could not resolve Variable[" + variable + "]!", exceptionStack); throw new AssertionError("Fatal error during variable resolving."); } }
public final void registerUnits(final Collection<UnitConfig> unitConfigs) throws CouldNotPerformException, InterruptedException { MultiException.ExceptionStack exceptionStack = null; for (UnitConfig unitConfig : unitConfigs) { try { registerUnit(unitConfig); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not register all hosted units of " + this, exceptionStack); }
private void initMethods(final LocalServer localServer) throws NotAvailableException, CouldNotPerformException { MultiException.ExceptionStack exceptionStack = null; synchronized (participantLock) { for (Entry<String, Callback> entry : localMethodStack.entrySet()) { try { localServer.addMethod(entry.getKey(), entry.getValue()); } catch (RSBException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("Could not register all methods!", exceptionStack); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } } }
@Override public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.deactivate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not deactivate all hosted units of " + this, exceptionStack); }
public Collection<GenericUnitPanel<RS>> add(final Collection<String> unitLabelList) throws InitializationException, InterruptedException { final List<GenericUnitPanel<RS>> unitPanelList = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; try { // create and add unit panels. for (String unitLabel : unitLabelList) { try { unitPanelList.addAll(add(unitLabel)); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not add all units!", exceptionStack); } catch (MultiException ex) { throw new InitializationException(this, ex); } return unitPanelList; }
@Override public void activate() throws InterruptedException, CouldNotPerformException { super.activate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.activate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not activate all hosted units of " + this, exceptionStack); }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteStateRelation(final List<ServiceType> serviceTypes) { final List<RdfTriple> triples = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; for (final ServiceType serviceType : serviceTypes) { try { triples.add(getDeleteStateRelation(serviceType)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely services!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteUnitInstances(final List<UnitConfig> unitConfigs) { final List<RdfTriple> triples = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; for (final UnitConfig unitConfig : unitConfigs) { try { triples.add(getDeleteUnitInstance(unitConfig)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely units!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * Constructor creates an continuous state change instance, which based on not manipulated state values * (literals like e.g. 17.35^^xsd:int) to store them. The information parts (input argument) will be convert * to specific data types (see getter of this class). * * @param timestamp is the timestamp at which the state change occurred. Must be parsable to OffsetDateTime. * @param stateValues is the value (literal type) of the state change. The rdf nodes must be based on literals. * @throws MultiException is thrown in case at least one input parameter is null/invalid or one state value * isn't a literal (/continuous value). */ public Continuous(final String timestamp, final List<RDFNode> stateValues) throws MultiException { final MultiException.ExceptionStack exceptionStack = Preconditions.multipleCheckNotNull(this, null, timestamp, stateValues); this.timestamp = Preconditions.Function.apply(OffsetDateTime::parse, timestamp, this, exceptionStack); this.stateValues = new ArrayList<>(); for (final RDFNode stateValue : stateValues) { // convert rdf node to literal and add to list. Invalid nodes will be stacked final Literal literal = Preconditions.Supplier.get(stateValue::asLiteral, this, exceptionStack); if (literal != null) { this.stateValues.add(literal); } } MultiException.checkAndThrow("Input argument(s) invalid. Null or no literal type!", exceptionStack); }
/** * Constructor creates an discrete state change instance, which based on not manipulated state values (e.g. * ON, OFF, ...) to store them. The information parts (input argument) will be convert to specific data types * (see getter of this class). * * @param timestamp is the timestamp at which the state change occurred. Must be parsable to OffsetDateTime. * @param stateValue is the value (resource type) of the state change. Must be based on rdf resource. * @throws MultiException is thrown in case at least one input parameter is null/invalid or the state value * isn't a resource (/discrete value). */ public Discrete(final String timestamp, final RDFNode stateValue) throws MultiException { final MultiException.ExceptionStack exceptionStack = Preconditions.multipleCheckNotNull(this, null, timestamp, stateValue); this.timestamp = Preconditions.Function.apply(OffsetDateTime::parse, timestamp, this, exceptionStack); this.stateValue = Preconditions.Supplier.get(stateValue::asResource, this, exceptionStack); MultiException.checkAndThrow("Input argument invalid. Null or no resource type!", exceptionStack); }
/** * Method ensures that one or multiple object reference(s) passed as a parameter to the calling method is/are not * null. Throws Exception otherwise. * * @param source is the source of the reference(s). Can be ignored by NULL. * @param objects are the reference parameter, which should be checked. * @throws MultiException is thrown in case at least one reference parameter is NULL. */ static void multipleCheckNotNullAndThrow(final Object source, final Object... objects) throws MultiException { final ExceptionStack exceptionStack = new ExceptionStack(); for (int i = 0; i < objects.length; i++) { try { checkNotNull(objects[i], "Parameter " + i + " in argument array is null!"); } catch (NotAvailableException e) { MultiException.push(source, e, exceptionStack); } } MultiException.checkAndThrow("Input is invalid.", exceptionStack); }
private void addAggDiscrete(final OntUnits ontUnits, final String unitId, final String providerService, final RDFNode stateValue, final String timeWeighting, final String quantity, final QuerySolution querySolution, final ExceptionStack exceptionStack) throws MultiException { final String activityTime = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, ACTIVITY_TIME.getName(), this, exceptionStack); // depend on the classification the aggregated values shouldn't be null MultiException.checkAndThrow("Invalid parameters or variables in sparql query.", exceptionStack); final OntStateChange ontStateChange = OntStateChange.asAggregatedDiscrete(timeWeighting, activityTime, quantity, stateValue); // insert collected information ontUnits.addOntProviderService(unitId, providerService, ontStateChange); }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteProviderServiceInstances(final List<ServiceType> serviceTypes) { MultiException.ExceptionStack exceptionStack = null; final List<RdfTriple> triples = new ArrayList<>(); for (final ServiceType serviceType : serviceTypes) { try { final String serviceName = StringModifier.firstCharToLowerCase(StringModifier.getServiceTypeName(serviceType)); triples.add(new RdfTriple(serviceName, OntExpr.IS_A.getName(), null)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely services!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteStateInstances(final List<ServiceType> serviceTypes) { MultiException.ExceptionStack exceptionStack = null; final List<RdfTriple> triples = new ArrayList<>(); for (final ServiceType serviceType : serviceTypes) { try { final String stateName = StringModifier.firstCharToLowerCase(Services.getServiceStateName(serviceType)); triples.add(new RdfTriple(stateName, OntExpr.IS_A.getName(), null)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely states!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
public final void registerUnitsById(final Collection<String> unitIds) throws CouldNotPerformException, InterruptedException { CachedUnitRegistryRemote.waitForData(); MultiException.ExceptionStack exceptionStack = null; for (String unitId : unitIds) { try { registerUnit(Registries.getUnitRegistry(true).getUnitConfigById(unitId)); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not register all hosted units of " + this, exceptionStack); }
private List<RdfTriple> getInsertProviderServiceRelation(final UnitConfig unitConfig) { final List<RdfTriple> triples = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; for (final ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { try { final String serviceTypeName = StringModifier.firstCharToLowerCase(StringModifier.getServiceTypeName(serviceConfig.getServiceDescription().getType())); triples.add(new RdfTriple(unitConfig.getId(), OntProp.PROVIDER_SERVICE.getName(), serviceTypeName)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely services!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getInsertStateInstances() { MultiException.ExceptionStack exceptionStack = null; final List<RdfTriple> triples = new ArrayList<>(); for (final ServiceType serviceType : ServiceType.values()) { if (serviceType.equals(ServiceType.UNKNOWN)) { continue; } try { final String stateName = StringModifier.firstCharToLowerCase(Services.getServiceStateName(serviceType)); triples.add(new RdfTriple(stateName, OntExpr.IS_A.getName(), OntCl.STATE.getName())); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely stateTypes!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
private void initServiceSimulators(final UnitController unitController) throws InitializationException, InterruptedException { try { final MultiException.ExceptionStack exceptionStack = new MultiException.ExceptionStack(); for (final ServiceDescription serviceDescription : unitController.getUnitTemplate().getServiceDescriptionList()) { try { serviceSimulatorList.add(serviceSimulatorFactory.newInstance(unitController, serviceDescription.getType())); } catch (final CouldNotPerformException ex) { MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("Could not init all service simulators!", exceptionStack); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, LOGGER); } } catch (CouldNotPerformException ex) { throw new InitializationException(this, ex); } }
private void addAggContinuous(final OntUnits ontUnits, final String unitId, final String providerService, final RDFNode stateValue, final String timeWeighting, final String quantity, final QuerySolution querySolution, final ExceptionStack exceptionStack) throws MultiException { final String variance = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, VARIANCE.getName(), this, exceptionStack); final String standardDeviation = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, STANDARD_DEVIATION.getName(), this, exceptionStack); final String mean = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, MEAN.getName(), this, exceptionStack); // depend on the classification the aggregated values shouldn't be null MultiException.checkAndThrow("Invalid parameters or variables in sparql query.", exceptionStack); final OntStateChange ontStateChange = OntStateChange.asAggregatedContinuous(mean, variance, standardDeviation, timeWeighting, quantity, stateValue); // insert collected information ontUnits.addOntProviderService(unitId, providerService, ontStateChange); }