@Override public AppClass getAppClassById(String appClassId) throws CouldNotPerformException, InterruptedException { return appClassRegistry.getMessage(appClassId); }
@Override public UserActivityClass getUserActivityClassById(String userActivityClassId) throws CouldNotPerformException { return userActivityClassRegistry.getMessage(userActivityClassId); }
@Override public AgentClass getAgentClassById(String agentClassId) throws CouldNotPerformException { return agentClassRegistry.getMessage(agentClassId); } }
@Override public ServiceTemplate getServiceTemplateById(String serviceTemplateId) throws CouldNotPerformException { return serviceTemplateRegistry.getMessage(serviceTemplateId); }
@Override public UserActivityConfig getUserActivityConfigById(String userActivityConfigId) throws CouldNotPerformException { return userActivityConfigRegistry.getMessage(userActivityConfigId); }
private UnitConfig getUnitConfigById(String unitConfigId) throws CouldNotPerformException { if (dalUnitRegistry.contains(unitConfigId)) { return dalUnitRegistry.getMessage(unitConfigId); } else if (agentRegistry.contains(unitConfigId)) { return agentRegistry.getMessage(unitConfigId); } else if (appRegistry.contains(unitConfigId)) { return appRegistry.getMessage(unitConfigId); } else if (authorizationGroupRegistry.contains(unitConfigId)) { return authorizationGroupRegistry.getMessage(unitConfigId); } else if (connectionRegistry.contains(unitConfigId)) { return connectionRegistry.getMessage(unitConfigId); } else if (deviceRegistry.contains(unitConfigId)) { return deviceRegistry.getMessage(unitConfigId); } else if (locationRegistry.contains(unitConfigId)) { return locationRegistry.getMessage(unitConfigId); } else if (sceneRegistry.contains(unitConfigId)) { return sceneRegistry.getMessage(unitConfigId); } else if (unitGroupRegistry.contains(unitConfigId)) { return unitGroupRegistry.getMessage(unitConfigId); } else if (userRegistry.contains(unitConfigId)) { return userRegistry.getMessage(unitConfigId); } throw new NotAvailableException(unitConfigId); }
@Override public UnitConfig getUnitConfigById(final String unitConfigId) throws CouldNotPerformException { for (ProtoBufFileSynchronizedRegistry registry : getRegistries()) { try { return (UnitConfig) registry.getMessage(unitConfigId); } catch (CouldNotPerformException ex) { // ignore and throw a new exception if no registry contains the entry } } throw new CouldNotPerformException("None of the unit registries contains an entry with the id [" + unitConfigId + "]"); }
/** * Get a set of child locations of the given location. * They are resolved recursively. * * @param locationUnitConfig The location of whom the child set is generated. * @return A set of all children of the given location. * @throws CouldNotPerformException If a child id of the given location cannot be resolved. */ private Set<UnitConfig> getChildLocationSet(final UnitConfig locationUnitConfig) throws CouldNotPerformException { final Set<UnitConfig> childLocationSet = new HashSet<>(); for (String childId : locationUnitConfig.getLocationConfig().getChildIdList()) { UnitConfig child = locationUnitConfigRegistry.getMessage(childId); childLocationSet.add(child); childLocationSet.addAll(getChildLocationSet(child)); } return childLocationSet; }
/** * Get a set of all connections which have to be removed when the location * with the given TileConfig is removed. * * @param tileConfig The TileConfig of the location to be removed. * @return A set of all connections that have to be removed. These are connections connecting the given tile and and only one other tile. * @throws CouldNotPerformException If a connection id of the given tile cannot be resolved. */ private Set<UnitConfig> getConnectionsToRemove(final TileConfig tileConfig) throws CouldNotPerformException { final Set<UnitConfig> connectionsToRemove = new HashSet<>(); for (String connectionId : tileConfig.getConnectionIdList()) { UnitConfig connectionUnitConfig = connectionUnitConfigRegistry.getMessage(connectionId); if (connectionUnitConfig.getConnectionConfig().getTileIdCount() < 3) { connectionsToRemove.add(connectionUnitConfig); } } return connectionsToRemove; } }
/** * Method returns the unit shape of the given unit referred by the id. * * If this unit configuration does not provide any shape information the shape of the unit host will be returned. * In case the unit host even does not provide any shape information and the unit is a device than the shape of the device class will be used. * * @param unitId the id to resolve the unit shape. * @return the shape representing the unit. * @throws NotAvailableException is thrown if the unit shape is not available or the resolution has been failed. */ private Shape getUnitShape(final String unitId) throws NotAvailableException { try { for (ProtoBufFileSynchronizedRegistry<String, UnitConfig, UnitConfig.Builder, UnitRegistryData.Builder> registry : unitConfigRegistryList) { if (registry.contains(unitId)) { return getUnitShape(registry.getMessage(unitId)); } } throw new NotAvailableException("Unit with id["+unitId+"]"); } catch (final CouldNotPerformException ex) { throw new NotAvailableException("Shape", "of unit " + unitId, ex); } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig connectionUnitConfig = entry.getMessage(); Scope newScope = ScopeGenerator.generateConnectionScope(connectionUnitConfig, locationRegistry.getMessage(connectionUnitConfig.getPlacementConfig().getLocationId())); // verify and update scope if (!ScopeGenerator.generateStringRep(connectionUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { entry.setMessage(connectionUnitConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig dalUnitConfig = entry.getMessage(); // filter virtual units if(UnitConfigProcessor.isVirtualUnit(dalUnitConfig)) { return; } if (!dalUnitConfig.hasUnitHostId() || dalUnitConfig.getUnitHostId().isEmpty()) { throw new NotAvailableException("unitConfig.unitHostId"); } UnitConfig deviceUnitConfig = deviceRegistry.getMessage(dalUnitConfig.getUnitHostId()); if (!oldHostEnablingStateMap.get(registry.isSandbox()).containsKey(dalUnitConfig.getId())) { oldHostEnablingStateMap.get(registry.isSandbox()).put(dalUnitConfig.getId(), deviceUnitConfig.getEnablingState()); } if (oldHostEnablingStateMap.get(registry.isSandbox()).get(dalUnitConfig.getId()) != deviceUnitConfig.getEnablingState()) { oldHostEnablingStateMap.get(registry.isSandbox()).put(dalUnitConfig.getId(), deviceUnitConfig.getEnablingState()); if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { throw new EntryModification(entry.setMessage(dalUnitConfig.toBuilder().setEnablingState(deviceUnitConfig.getEnablingState())), this); } } if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.DISABLED) { if (dalUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { EnablingState disabled = EnablingState.newBuilder().setValue(EnablingState.State.DISABLED).build(); throw new EntryModification(entry.setMessage(dalUnitConfig.toBuilder().setEnablingState(disabled)), this); } } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig unitGroupUnitConfig = entry.getMessage(); if (!unitGroupUnitConfig.hasPlacementConfig()) { throw new NotAvailableException("unitGroupConfig.placementconfig"); } if (!unitGroupUnitConfig.getPlacementConfig().hasLocationId() || unitGroupUnitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("unitGroupConfig.placementconfig.locationid"); } UnitConfig locationConfig = locationRegistry.getMessage(unitGroupUnitConfig.getPlacementConfig().getLocationId()); ScopeType.Scope newScope = ScopeGenerator.generateUnitGroupScope(unitGroupUnitConfig, locationConfig); // verify and update scope if (!ScopeGenerator.generateStringRep(unitGroupUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { entry.setMessage(unitGroupUnitConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig agentUnitConfig = entry.getMessage(); if (!agentUnitConfig.hasPlacementConfig()) { throw new NotAvailableException("agent.placementConfig"); } if (!agentUnitConfig.getPlacementConfig().hasLocationId() || agentUnitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("agent.placementConfig.locationId"); } if (!agentUnitConfig.getAgentConfig().hasAgentClassId() || agentUnitConfig.getAgentConfig().getAgentClassId().isEmpty()) { throw new NotAvailableException("agent.agentClassId"); } Scope newScope = ScopeGenerator.generateAgentScope(agentUnitConfig, agentClassRegistry.get(agentUnitConfig.getAgentConfig().getAgentClassId()).getMessage(), locationRegistry.getMessage(agentUnitConfig.getPlacementConfig().getLocationId())); // verify and update scope if (!ScopeGenerator.generateStringRep(agentUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { if (agentMap.containsKey(ScopeGenerator.generateStringRep(newScope))) { throw new InvalidStateException("Two agents [" + agentUnitConfig + "][" + agentMap.get(ScopeGenerator.generateStringRep(newScope)) + "] are registered with the same label and location"); } else { agentMap.put(ScopeGenerator.generateStringRep(newScope), agentUnitConfig); entry.setMessage(agentUnitConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } } }
@Override public void processData(final String id, final IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, final ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig appUnitConfig = entry.getMessage(); if (!appUnitConfig.hasPlacementConfig()) { throw new NotAvailableException("agent.placementConfig"); } if (!appUnitConfig.getPlacementConfig().hasLocationId() || appUnitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("app.placementConfig.locationId"); } if (!appUnitConfig.getAppConfig().hasAppClassId() || appUnitConfig.getAppConfig().getAppClassId().isEmpty()) { throw new NotAvailableException("app.appClassId"); } Scope newScope = ScopeGenerator.generateAppScope(appUnitConfig, appClassRegistry.get(appUnitConfig.getAppConfig().getAppClassId()).getMessage(), locationRegistry.getMessage(appUnitConfig.getPlacementConfig().getLocationId())); // verify and update scope if (!ScopeGenerator.generateStringRep(appUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { if (appMap.containsKey(ScopeGenerator.generateStringRep(newScope))) { throw new InvalidStateException("Two apps [" + appUnitConfig + "][" + appMap.get(ScopeGenerator.generateStringRep(newScope)) + "] are registered with the same label and location"); } else { appMap.put(ScopeGenerator.generateStringRep(newScope), appUnitConfig); entry.setMessage(appUnitConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } } }
modification = true; } else { serviceTemplate = serviceTemplateRegistry.getMessage(serviceDescription.getServiceTemplateId());
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig sceneUnitConfig = entry.getMessage(); if (!sceneUnitConfig.hasPlacementConfig()) { throw new NotAvailableException("sceneConfig.placementConfig"); } if (!sceneUnitConfig.getPlacementConfig().hasLocationId()) { throw new NotAvailableException("sceneConfig.locationId"); } if (sceneUnitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("Field sceneConfig.locationId is empty"); } Scope newScope = ScopeGenerator.generateSceneScope(sceneUnitConfig, locationRegistry.getMessage(sceneUnitConfig.getPlacementConfig().getLocationId())); // verify and update scope if (!ScopeGenerator.generateStringRep(sceneUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { throw new EntryModification(entry.setMessage(sceneUnitConfig.toBuilder().setScope(newScope)), this); } } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig.Builder dalUnitConfig = entry.getMessage().toBuilder(); boolean modification = false; UnitConfig unitConfigClone = UnitConfig.newBuilder(dalUnitConfig.build()).build(); if (!dalUnitConfig.hasPlacementConfig()) { throw new NotAvailableException("placementconfig"); } if (!dalUnitConfig.getPlacementConfig().hasLocationId() || dalUnitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("placementconfig.locationid"); } ScopeType.Scope newScope = ScopeGenerator.generateUnitScope(unitConfigClone, locationRegistry.getMessage((dalUnitConfig.getPlacementConfig().getLocationId()))); // verify and update scope if (!ScopeGenerator.generateStringRep(dalUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { dalUnitConfig.setScope(newScope); modification = true; } if (unitScopeMap.containsKey(ScopeGenerator.generateStringRep(dalUnitConfig.getScope()))) { throw new InvalidStateException("Two units with same scope[" + ScopeGenerator.generateStringRep(dalUnitConfig.getScope()) + "]!"); } unitScopeMap.put(ScopeGenerator.generateStringRep(dalUnitConfig.getScope()), dalUnitConfig.build()); if (modification) { throw new EntryModification(entry.setMessage(dalUnitConfig), this); } }
logger.info("Publish " + locationRegistry.getMessage(deviceConfig.getPlacementConfig().getLocationId()).getPlacementConfig().getTransformationFrameId() + " to " + deviceConfig.getPlacementConfig().getTransformationFrameId()); transformation = PoseTransformer.transform(deviceConfig.getPlacementConfig().getPosition(), locationRegistry.getMessage(deviceConfig.getPlacementConfig().getLocationId()).getPlacementConfig().getTransformationFrameId(), deviceConfig.getPlacementConfig().getTransformationFrameId());
if (unitConfig.getBoundToUnitHost()) { try { UnitConfig deviceUnitConfig = deviceRegistry.getMessage(unitConfig.getUnitHostId()); PlacementConfig unitPlacement = unitConfig.getPlacementConfig(); PlacementConfig.Builder devicePlacement = deviceUnitConfig.toBuilder().getPlacementConfigBuilder();