protected String generateFrameId(final String label, final PlacementConfig placementConfig) throws CouldNotPerformException { try { String frameId = StringProcessor.transformToIdString(label); if (labelCollisionList.contains(frameId.toLowerCase())) { return locationRegistry.get(placementConfig.getLocationId()).getMessage().getPlacementConfig().getTransformationFrameId() + "_" + frameId; } labelCollisionList.add(frameId.toLowerCase()); return frameId; } catch (final CouldNotPerformException ex) { throw new CouldNotPerformException("Could not generate frame id!", ex); } }
private boolean containsAuthorizationGrouptByLabel(String label) throws CouldNotPerformException { for (UnitConfig authorizationGroupUnitConfig : authorisationGroupRegistry.getMessages()) { if (authorizationGroupUnitConfig.getLabel().equals(label)) { return true; } } return false; } }
public void setupRootLocationIfNeeded() throws RejectedException { try { // check if any location exist if (getRegistry().isEmpty()) { getRegistry().register(generateDefaultRootLocation()); } } catch (final CouldNotPerformException ex) { throw new RejectedException("Could not setup default root location!", ex); } }
@Override public void init(final ProtoBufRegistry<String, UnitConfig, Builder> registry) throws InitializationException, InterruptedException { try { super.init(registry); this.transformPublisher = transformerFactory.createTransformPublisher(registry.getName()); for (IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry : registry.getEntries()) { publishTransformation(entry); } } catch (CouldNotPerformException | TransformerFactory.TransformerFactoryException ex) { throw new InitializationException(this, ex); } }
@Override public void init(final ProtoBufRegistry<String, UserActivityClass, UserActivityClass.Builder> userActivityClassregistry) throws InitializationException, InterruptedException { try { UserActivityClass userActivityClass; // create missing unit template if (userActivityClassregistry.size() <= UserActivityType.values().length - 1) { for (UserActivityType userActivityType : UserActivityType.values()) { if (userActivityType == UserActivityType.UNKNOWN) { continue; } userActivityClass = UserActivityClass.newBuilder().setType(userActivityType).setLabel(StringProcessor.transformUpperCaseToCamelCase(userActivityType.name())).build(); if (!containsUnitTemplateByType(userActivityType, userActivityClassregistry)) { userActivityClassregistry.register(userActivityClass); } } } } catch (CouldNotPerformException ex) { throw new InitializationException("Could not init " + getClass().getSimpleName() + "!", ex); } }
try { rootLocationId = LocationUtils.getRootLocation(registry.getMessages()).getId(); } catch (CouldNotPerformException exx) { final UnitConfig rootUnitConfig = registry.get(rootLocationId).getMessage(); if (!rootUnitConfig.getPlacementConfig().hasTransformationFrameId() || rootUnitConfig.getPlacementConfig().getTransformationFrameId().isEmpty()) {
final String parentLocationTransformationFrameId = getRegistry().get(locationConfig.getPlacementConfig().getLocationId()).getMessage().getPlacementConfig().getTransformationFrameId(); transformation.setAuthority(getRegistry().getName()); transformPublisher.sendTransform(transformation, TransformType.STATIC);
@Override public void init(ProtoBufRegistry<String, UnitConfig, Builder> config) throws InitializationException, InterruptedException { try { if(!containsAuthorizationGrouptByLabel(ADMIN_GROUP_LABEL)) { UnitConfig unitConfig = UnitConfig.newBuilder().setType(UnitType.AUTHORIZATION_GROUP).setLabel(ADMIN_GROUP_LABEL).build(); authorisationGroupRegistry.register(unitConfig); } } catch (CouldNotPerformException ex) { throw new InitializationException(this, ex); } }
if (!registry.contains(childLocationId)) { List<String> childIds = new ArrayList<>(locationConfig.getChildIdList()); childIds.remove(childLocationId); childLocationConfig = registry.getMessage(childLocationId);
transformation.setAuthority(getRegistry().getName()); transformPublisher.sendTransform(transformation, TransformType.STATIC);
@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 locationUnitConfig = entry.getMessage(); for (String childLocationId : new ArrayList<>(locationUnitConfig.getLocationConfig().getChildIdList())) { UnitConfig childLocationUnitConfig = registry.getMessage(childLocationId); if (labelConsistencyMap.containsKey(childLocationUnitConfig.getLabel()) && !labelConsistencyMap.get(childLocationUnitConfig.getLabel()).equals(childLocationId)) { throw new InvalidStateException("Location [" + locationUnitConfig.getId() + "," + locationUnitConfig.getLabel() + "] has more than on child with the same label [" + childLocationUnitConfig.getLabel() + "]"); } else { labelConsistencyMap.put(childLocationUnitConfig.getLabel(), childLocationId); } } }
@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 afterConsistencyCheck() throws CouldNotPerformException { for (IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry : getRegistry().getEntries()) { updateUnitConfigs(entry); } }
@Override public void init(ProtoBufRegistry<String, UnitConfig, Builder> registry) throws InitializationException, InterruptedException { try { super.init(registry); this.transformPublisher = transformerFactory.createTransformPublisher(registry.getName()); for (IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry : registry.getEntries()) { publishTransformation(entry); } } catch (CouldNotPerformException | TransformerFactory.TransformerFactoryException ex) { throw new InitializationException(this, ex); } }
transformation = PoseTransformer.transform(deviceConfig.getPlacementConfig().getPosition(), locationRegistry.getMessage(deviceConfig.getPlacementConfig().getLocationId()).getPlacementConfig().getTransformationFrameId(), deviceConfig.getPlacementConfig().getTransformationFrameId()); transformation.setAuthority(getRegistry().getName()); transformPublisher.sendTransform(transformation, TransformType.STATIC);
case REGION: parent = registry.getMessage(locationUnit.getPlacementConfig().getLocationId()); if (parent.getLocationConfig().getType() == LocationType.ZONE) { throw new CouldNotPerformException("Parent[" + parent.getLabel() + "] of region[" + locationUnit.getLabel() + "]" child = registry.getMessage(childId); if (child.getLocationConfig().getType() != LocationType.REGION) { throw new CouldNotPerformException("Child[" + child.getLabel() + "] of region[" + locationUnit.getLabel() + "]" case TILE: parent = registry.getMessage(locationUnit.getPlacementConfig().getLocationId()); if (parent.getLocationConfig().getType() != LocationType.ZONE) { throw new CouldNotPerformException("Parent[" + parent.getLabel() + "] of tile[" + locationUnit.getLabel() + "]" child = registry.getMessage(childId); if (child.getLocationConfig().getType() != LocationType.REGION) { throw new CouldNotPerformException("Child[" + child.getLabel() + "] of tile[" + locationUnit.getLabel() + "]" parent = registry.getMessage(locationUnit.getPlacementConfig().getLocationId()); if (parent.getLocationConfig().getType() != LocationType.ZONE) { throw new CouldNotPerformException("Parent[" + parent.getLabel() + "] of zone[" + locationUnit.getLabel() + "]" child = registry.getMessage(childId); if (child.getLocationConfig().getType() == LocationType.REGION) { throw new CouldNotPerformException("Child[" + child.getLabel() + "] of zone[" + locationUnit.getLabel() + "]"
@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 deviceUnitConfig = entry.getMessage(); DeviceConfig deviceConfig = deviceUnitConfig.getDeviceConfig(); if (!oldInventoryStateMap.get(registry.isSandbox()).containsKey(deviceUnitConfig.getId())) { oldInventoryStateMap.get(registry.isSandbox()).put(deviceUnitConfig.getId(), deviceConfig.getInventoryState().getValue()); } if (!deviceConfig.hasInventoryState()) { throw new NotAvailableException("deviceConfig.inventoryState"); } if (!deviceConfig.getInventoryState().hasValue()) { throw new NotAvailableException("deviceConfig.inventoryState.value"); } if (deviceConfig.getInventoryState().getValue() != InventoryState.State.INSTALLED) { if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { EnablingState disabled = EnablingState.newBuilder().setValue(EnablingState.State.DISABLED).build(); throw new EntryModification(entry.setMessage(deviceUnitConfig.toBuilder().setEnablingState(disabled)), this); } } if (oldInventoryStateMap.get(registry.isSandbox()).get(deviceUnitConfig.getId()) != deviceConfig.getInventoryState().getValue()) { oldInventoryStateMap.get(registry.isSandbox()).put(deviceUnitConfig.getId(), deviceConfig.getInventoryState().getValue()); if (deviceConfig.getInventoryState().getValue() == InventoryState.State.INSTALLED) { EnablingState enabled = EnablingState.newBuilder().setValue(EnablingState.State.ENABLED).build(); throw new EntryModification(entry.setMessage(deviceUnitConfig.toBuilder().setEnablingState(enabled)), this); } } }
private void loopTestTopDown(final UnitConfig locationConfig, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry, List<String> processedLocations) throws InvalidStateException, CouldNotPerformException { markAsProcessed(locationConfig, processedLocations); for (String locationId : locationConfig.getLocationConfig().getChildIdList()) { loopTestTopDown(registry.get(locationId).getMessage(), registry, processedLocations); } }
private boolean containsUnitTemplateByType(final UserActivityType type, final ProtoBufRegistry<String, UserActivityClass, UserActivityClass.Builder> userActivityClassRegistry) throws CouldNotPerformException { for (UserActivityClass userActivityClass : userActivityClassRegistry.getMessages()) { if (userActivityClass.getType() == type) { return true; } } return false; }