public static boolean verifyServiceCompatibility(final UnitConfig unitConfig, final ServiceType serviceType) { return unitConfig.getServiceConfigList().stream().anyMatch((serviceConfig) -> (serviceConfig.getServiceDescription().getType() == serviceType)); }
private boolean unitConfigContainsServiceDescription(UnitConfig.Builder unitConfig, ServiceDescription serviceDescription) { return unitConfig.getServiceConfigList().stream().map((serviceConfig) -> serviceConfig.getServiceDescription()).anyMatch((description) -> (description.getType() == serviceDescription.getType() && description.getPattern() == serviceDescription.getPattern())); }
/** * {@inheritDoc} * * @param serviceType * @return * @throws CouldNotPerformException */ @Override public List<ServiceConfig> getServiceConfigs(final ServiceType serviceType) throws CouldNotPerformException { List<ServiceConfig> serviceConfigs = new ArrayList<>(); for (UnitConfig unitConfig : getUnitConfigs()) { for (ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { serviceConfigs.add(serviceConfig); } } } return serviceConfigs; }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} * @throws org.openbase.jul.exception.NotAvailableException {@inheritDoc} */ @Override public List<UnitConfig> getUnitConfigsByConnection(ServiceType type, String connectionConfigId) throws CouldNotPerformException, NotAvailableException { List<UnitConfig> unitConfigList = new ArrayList<>(); UnitConfig unitConfig; for (String unitConfigId : getConnectionConfigById(connectionConfigId).getConnectionConfig().getUnitIdList()) { try { unitConfig = unitRegistryRemote.getUnitConfigById(unitConfigId); for (ServiceConfigType.ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType().equals(type)) { unitConfigList.add(unitConfig); } } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not resolve UnitConfigId[" + unitConfigId + "] by device registry!", ex), logger); } } return unitConfigList; }
/** * {@inheritDoc} * * @param serviceType {@inheritDoc} * @return {@inheritDoc} * @throws CouldNotPerformException {@inheritDoc} * @throws NotAvailableException {@inheritDoc} */ @Override public List<ServiceConfig> getServiceConfigs(final ServiceType serviceType) throws CouldNotPerformException, NotAvailableException { List<ServiceConfig> serviceConfigs = new ArrayList<>(); for (UnitConfig unitConfig : getUnitConfigs()) { for (ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { serviceConfigs.add(serviceConfig); } } } return serviceConfigs; }
public static String generateItemName(final UnitConfig device, final String deviceClassLabel, final UnitConfig unit, final ServiceConfig service, final UnitConfig location) throws CouldNotPerformException { if (device == null) { throw new NotAvailableException("deviceconfig"); } if (unit == null) { throw new NotAvailableException("unitconfig"); } if (service == null) { throw new NotAvailableException("serviceconfig"); } return StringProcessor.transformToIdString(deviceClassLabel) + ITEM_SEGMENT_DELIMITER + ScopeGenerator.generateStringRepWithDelimiter(location.getScope(), ITEM_SUBSEGMENT_DELIMITER) + ITEM_SEGMENT_DELIMITER + StringProcessor.transformUpperCaseToCamelCase(unit.getType().toString()) + ITEM_SEGMENT_DELIMITER + StringProcessor.transformToIdString(unit.getLabel()) + ITEM_SEGMENT_DELIMITER + StringProcessor.transformUpperCaseToCamelCase(service.getServiceDescription().getType().toString()); } }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} * @throws org.openbase.jul.exception.NotAvailableException {@inheritDoc} */ @Override public List<UnitConfig> getUnitConfigsByLocation(final ServiceType type, final String locationConfigId) throws CouldNotPerformException, NotAvailableException { List<UnitConfig> unitConfigList = new ArrayList<>(); UnitConfig unitConfig; for (String unitConfigId : getLocationConfigById(locationConfigId).getLocationConfig().getUnitIdList()) { try { unitConfig = unitRegistry.getUnitConfigById(unitConfigId); for (ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType().equals(type)) { unitConfigList.add(unitConfig); } } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not resolve UnitConfigId[" + unitConfigId + "] by device registry!", ex), logger); } } return unitConfigList; }
/** * This method binds a service config to this unit service panel. * Make sure the remote unit was initialized before and the service config is compatible with this unit. * * @param serviceConfig the new service config to bind to this unit remote. * @throws CouldNotPerformException is thrown if any error occurs during the binding process. * @throws InterruptedException */ public void bindServiceConfig(final ServiceConfig serviceConfig) throws CouldNotPerformException, InterruptedException { try { if (unitRemote == null) { throw new InvalidStateException("The unit remote is unknown!!"); } setServiceConfig(serviceConfig); // updateDynamicComponents(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not bind ServiceConfig[" + serviceConfig.getServiceDescription().getType() + "] on UnitRemote[" + unitRemote.getScope() + "]!", ex); } }
public default List<UnitConfig> getUnitConfigsByService(final List<ServiceType> serviceTypes) throws CouldNotPerformException { validateData(); final List<UnitConfig> unitConfigs = getUnitConfigs(); boolean foundServiceType; for (final UnitConfig unitConfig : new ArrayList<>(unitConfigs)) { foundServiceType = false; for (final ServiceType serviceType : serviceTypes) { for (ServiceConfigType.ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { foundServiceType = true; } } if (!foundServiceType) { unitConfigs.remove(unitConfig); } } } return unitConfigs; }
/** * Initializes this consumer service and bounds those to the given provider service referred by the given provider service configuration. * * @param providerServiceConfig the config of the provider service to connect to. * @throws InitializationException is thrown if the initialization fails. * @throws InterruptedException is thrown if the current thread was externally interrupted. */ @Override public synchronized void init(final ServiceConfig providerServiceConfig) throws InitializationException, InterruptedException { try { if (boundedProviderService != null) { boundedProviderService.shutdown(); } boundedProviderService = ServiceRemoteFactoryImpl.getInstance().newInitializedInstanceById(providerServiceConfig.getServiceDescription().getType(), providerServiceConfig.getUnitId()); } catch (final CouldNotPerformException ex) { throw new InitializationException(this, ex); } }
@Override public List<UnitConfig> getUnitConfigsByUnitTypeAndServiceTypes(final UnitType type, final List<ServiceType> serviceTypes) throws CouldNotPerformException { validateData(); final List<UnitConfig> unitConfigs = getUnitConfigs(type); boolean foundServiceType; for (UnitConfig unitConfig : new ArrayList<>(unitConfigs)) { foundServiceType = false; for (ServiceTemplateType.ServiceTemplate.ServiceType serviceType : serviceTypes) { for (ServiceConfigType.ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { foundServiceType = true; } } if (!foundServiceType) { unitConfigs.remove(unitConfig); } } } return unitConfigs; }
/** * Returns the variable provider of this unit like {@code generateVariablePool()}. Additionally this provider also contains variables related to the given service of this unit. * For this it's needed that this unit supports the given service. Additional to the {@code generateVariablePool()} this method further provides: * * BindingServiceConfig (if available) * * ServiceMetaConfig (if available) * * ServiceConfig (protobuf fields) * * @return a key - value pair pool providing all related variable of this unit including the service variables. * * @throws NotAvailableException is thrown if the variable pool is not available e.g. because the unit is not compatible with the given service type.. */ default VariableProvider generateVariablePool(final ServiceType serviceType) throws NotAvailableException { for (ServiceConfig serviceConfig : getConfig().getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { return generateVariablePool(serviceConfig); } } throw new NotAvailableException("VariableProvider", new InvalidStateException("ServiceType[" + serviceType.name() + "] not supported by " + this)); }
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; }
private static boolean hasPowerStateService(UnitConfig config) throws InterruptedException { for (ServiceConfig sc : config.getServiceConfigList()) { ServiceTemplate.ServiceType type; try { type = getUnitRegistry().getServiceTemplateById(sc.getServiceDescription().getServiceTemplateId()).getType(); } catch (CouldNotPerformException ex) { type = sc.getServiceDescription().getType(); } if (ServiceTemplate.ServiceType.POWER_STATE_SERVICE == type && ServiceTemplate.ServicePattern.OPERATION == sc.getServiceDescription().getPattern()) { return true; } } return false; }
private boolean unitHasServiceAsOperationService(UnitConfig unitConfig, ServiceType serviceType) { return unitConfig.getServiceConfigList().stream().anyMatch((tmpServiceConfig) -> (tmpServiceConfig.getServiceDescription().getType() == serviceType && tmpServiceConfig.getServiceDescription().getPattern() == ServiceTemplate.ServicePattern.OPERATION)); } }
@Override default Set<ServiceType> getSupportedServiceTypes() throws NotAvailableException, InterruptedException { final Set<ServiceTemplate.ServiceType> serviceTypeSet = new HashSet<>(); try { for (final ServiceConfig serviceConfig : getConfig().getServiceConfigList()) { serviceTypeSet.add(serviceConfig.getServiceDescription().getType()); } } catch (CouldNotPerformException ex) { throw new NotAvailableException("SupportedServiceTypes", new CouldNotPerformException("Could not generate supported service type list!", ex)); } return serviceTypeSet; }
@Override public List<ServiceConfigType.ServiceConfig> getServiceConfigs(final ServiceTemplateType.ServiceTemplate.ServiceType serviceType) throws CouldNotPerformException { validateData(); List<ServiceConfigType.ServiceConfig> serviceConfigs = new ArrayList<>(); for (UnitConfig unitConfig : getUnitConfigs()) { for (ServiceConfigType.ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { serviceConfigs.add(serviceConfig); } } } return serviceConfigs; }
public String getServiceName() { for (ServiceConfig serviceConfig : serviceConfigs) { if (serviceConfig != null) { return serviceConfig.getServiceDescription().getType().name(); } } return "---"; }
private ServiceConfig loadServiceConfig() throws CouldNotPerformException { for (final ServiceConfig serviceConfig : ((Unit<?>) unit).getConfig().getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType().equals(serviceType)) { return serviceConfig; } } throw new CouldNotPerformException("Could not detect service config! Service[" + serviceType.name() + "] is not configured in Unit[" + ((Unit) unit).getId() + "]!"); }
private boolean checkAlreadyAvailableThrougOtherComponents(final UnitConfig unitConfig, final ServiceConfig serviceConfig) { // skip if function is already available through other components if (unitConfig.getType() == UnitType.COLORABLE_LIGHT && serviceConfig.getServiceDescription().getType() == ServiceType.BRIGHTNESS_STATE_SERVICE) { return true; } return false; }