final List<UnitConfig> pathFromRootList = new ArrayList<>(); pathFromRootList.add(locationUnitConfig); while (!locationUnitConfig.getLocationConfig().getRoot()) { locationUnitConfig = locationUnitConfigRegistry.getMessage(locationUnitConfig.getPlacementConfig().getLocationId());
if (!locationType.equals(LocationConfig.LocationType.UNKNOWN) && !locationType.equals(unitConfig.getLocationConfig().getType())) { continue;
for (String childId : locationUnitConfig.getLocationConfig().getChildIdList()) { unitIdList.addAll(locationRegistry.get(childId).getMessage().getLocationConfig().getUnitIdList());
for (UnitConfig locationUnitConfig : Registries.getUnitRegistry().getUnitConfigs(UnitType.LOCATION)) { Map<ServiceType, ServiceDescription> serviceDescriptionsOnLocation = new HashMap<>(); for (final String childUnitId : locationUnitConfig.getLocationConfig().getChildIdList()) { final UnitConfig unitConfig = Registries.getUnitRegistry().getUnitConfigById(childUnitId); for (ServiceDescription serviceDescription : Registries.getUnitRegistry().getUnitTemplateByType(unitConfig.getType()).getServiceDescriptionList()) {
LocationConfig tileLocationConfig = LocationConfig.newBuilder().setType(LocationType.TILE).build(); LocationConfig regionLocationConfig = LocationConfig.newBuilder().setType(LocationType.REGION).build();
if (!locationUnit.getLocationConfig().hasType()) { throw new NotAvailableException("locationConfig.type"); switch (locationUnit.getLocationConfig().getType()) { case REGION: if (parent.getLocationConfig().getType() == LocationType.ZONE) { throw new CouldNotPerformException("Parent[" + parent.getLabel() + "] of region[" + locationUnit.getLabel() + "]" + " is a zone which is against the location hierarchy!"); for (String childId : locationUnit.getLocationConfig().getChildIdList()) { child = registry.getMessage(childId); if (child.getLocationConfig().getType() != LocationType.REGION) { throw new CouldNotPerformException("Child[" + child.getLabel() + "] of region[" + locationUnit.getLabel() + "]" + " is not a region but[" + child.getLocationConfig().getType() + "] which is against the location hierarchy!"); if (parent.getLocationConfig().getType() != LocationType.ZONE) { throw new CouldNotPerformException("Parent[" + parent.getLabel() + "] of tile[" + locationUnit.getLabel() + "]" + " is not a zone but[" + parent.getLocationConfig().getType() + "] which is against the location hierarchy!"); for (String childId : locationUnit.getLocationConfig().getChildIdList()) { child = registry.getMessage(childId); if (child.getLocationConfig().getType() != LocationType.REGION) { throw new CouldNotPerformException("Child[" + child.getLabel() + "] of tile[" + locationUnit.getLabel() + "]" + " is not a region but[" + parent.getLocationConfig().getType() + "] which is against the location hierarchy!"); if (parent.getLocationConfig().getType() != LocationType.ZONE) { throw new CouldNotPerformException("Parent[" + parent.getLabel() + "] of zone[" + locationUnit.getLabel() + "]" + " is not a zone but[" + parent.getLocationConfig().getType() + "] which is against the location hierarchy!");
if ((!unitConfig.hasLocationConfig() || !unitConfig.getLocationConfig().getRoot()) && unitConfig.hasPlacementConfig() && unitConfig.getPlacementConfig().hasLocationId()) { return;
@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 { if (entry.getMessage().getLocationConfig().getType() != LocationType.TILE) { return;
switch (unitConfig.getType()) { case LOCATION: unitTypeName = StringModifier.getCamelCaseName(unitConfig.getLocationConfig().getType().name()); break; case CONNECTION:
if (locationConfig.getLocationConfig().getRoot()) { return;
public void beforeRemove(IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry) throws RejectedException { if (entry.getMessage().getLocationConfig().getRoot()) { throw new RejectedException("The root location cannot be removed. If you want to remove this location introduce another root first."); if (entry.getMessage().getLocationConfig().getType() == LocationType.TILE) { for (UnitConfig unitConfig : getConnectionsToRemove(entry.getMessage().getLocationConfig().getTileConfig())) { connectionUnitConfigRegistry.remove(unitConfig);
if (locationUnit.getLocationConfig().getRoot()) { return LocationType.ZONE; LocationType parentLocationType = locationRegistry.get(locationUnit.getPlacementConfig().getLocationId()).getMessage().getLocationConfig().getType(); Set<LocationType> childLocationTypes = new HashSet<>(); for (String childId : locationUnit.getLocationConfig().getChildIdList()) { childLocationTypes.add(locationRegistry.get(childId).getMessage().getLocationConfig().getType());
@Override public Future<AuthenticatedValue> registerUnitConfigAuthenticated(final AuthenticatedValue authenticatedValue) throws CouldNotPerformException { return GlobalCachedExecutorService.submit(() -> { return AuthenticatedServiceProcessor.authenticatedAction(authenticatedValue, getAuthorizationGroupUnitConfigRegistry().getEntryMap(), getLocationUnitConfigRegistry().getEntryMap(), UnitConfig.class, (UnitConfig unitConfig) -> getUnitConfigRegistry(unitConfig.getType()).register(unitConfig), (UnitConfig unitConfig) -> { // If the unit has a location, use the location's UnitConfig for the permissions. if (unitConfig.hasPlacementConfig() && unitConfig.getPlacementConfig().hasLocationId()) { return getLocationUnitConfigRegistry().getMessage(unitConfig.getPlacementConfig().getLocationId()); } // Else, user the permission for the root location UnitConfig rootLocation = null; for (UnitConfig locationUnitConfig : getLocationUnitConfigRegistry().getMessages()) { if (locationUnitConfig.getLocationConfig().getRoot()) { rootLocation = locationUnitConfig; break; } } if (rootLocation == null) { // no root location yet available so use all rights PermissionConfig.Builder permissionConfig = PermissionConfig.newBuilder(); permissionConfig.setOtherPermission(Permission.newBuilder().setAccess(true).setRead(true).setWrite(true)); rootLocation = UnitConfig.newBuilder().setPermissionConfig(permissionConfig).build(); } return rootLocation; } ); }); }
@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 unitLocationConfig = entry.getMessage().toBuilder(); // check if placement exists. if (!unitLocationConfig.hasPlacementConfig()) { throw new NotAvailableException("locationconfig.placementconfig"); } // check children consistency if (!unitLocationConfig.getPlacementConfig().hasLocationId()) { throw new NotAvailableException("locationconfig.placementconfig.locationid"); } // skip root locations if (unitLocationConfig.getLocationConfig().getRoot()) { return; } // check if parent is registered. if (!entryMap.containsKey(unitLocationConfig.getPlacementConfig().getLocationId())) { entry.setMessage(unitLocationConfig.setPlacementConfig(unitLocationConfig.getPlacementConfig().toBuilder().clearLocationId())); throw new EntryModification("Parent[" + unitLocationConfig.getPlacementConfig().getLocationId() + "] of child[" + unitLocationConfig.getId() + "] is unknown! Entry will moved to root location!", entry, this); } // check if parents knows given child. IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> parent = registry.get(unitLocationConfig.getPlacementConfig().getLocationId()); if (parent != null && !parentHasChild(parent.getMessage(), unitLocationConfig.build()) && !parent.getMessage().getPlacementConfig().getLocationId().equals(unitLocationConfig.getId())) { LocationConfig.Builder parentLocationConfig = parent.getMessage().getLocationConfig().toBuilder().addChildId(unitLocationConfig.getId()); parent.setMessage(parent.getMessage().toBuilder().setLocationConfig(parentLocationConfig)); throw new EntryModification("Parent[" + parent.getId() + "] does not know Child[" + unitLocationConfig.getId() + "]", parent, this); } }
public static ScopeType.Scope generateLocationScope(final UnitConfig unitConfig, final ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException { if (unitConfig == null) { throw new NotAvailableException("unitConfig"); } if (!unitConfig.hasLocationConfig() || unitConfig.getLocationConfig() == null) { throw new NotAvailableException("locationConfig"); } if (registry == null) { throw new NotAvailableException("registry"); } if (!unitConfig.hasLabel()) { throw new NotAvailableException("location.label"); } if (!unitConfig.hasPlacementConfig()) { throw new NotAvailableException("location.placementconfig"); } if (!unitConfig.getPlacementConfig().hasLocationId() || unitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("location.placementconfig.locationid"); } ScopeType.Scope.Builder scope = ScopeType.Scope.newBuilder(); if (!unitConfig.getLocationConfig().getRoot()) { scope.addAllComponent(registry.get(unitConfig.getPlacementConfig().getLocationId()).getMessage().getScope().getComponentList()); } scope.addComponent(convertIntoValidScopeComponent(unitConfig.getLabel())); return scope.build(); }
public static void validateRootLocation(final UnitConfig newRootLocation, final ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, final ConsistencyHandler consistencyHandler) throws CouldNotPerformException, EntryModification { try { boolean modified = false; // detect root location IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> detectedRootLocationConfigEntry = entryMap.get(newRootLocation.getId()); UnitConfig.Builder detectedRootLocationConfigBuilder = detectedRootLocationConfigEntry.getMessage().toBuilder(); // verify if root flag is set. if (!detectedRootLocationConfigBuilder.getLocationConfig().hasRoot() || !detectedRootLocationConfigBuilder.getLocationConfig().getRoot()) { detectedRootLocationConfigBuilder.getLocationConfigBuilder().setRoot(true); modified = true; } // verify if placement field is set. if (!detectedRootLocationConfigBuilder.hasPlacementConfig()) { detectedRootLocationConfigBuilder.setPlacementConfig(PlacementConfigType.PlacementConfig.newBuilder()); modified = true; } // verify if placement location id is set. if (!detectedRootLocationConfigBuilder.getPlacementConfig().hasLocationId() || !detectedRootLocationConfigBuilder.getPlacementConfig().getLocationId().equals(detectedRootLocationConfigBuilder.getId())) { detectedRootLocationConfigBuilder.getPlacementConfigBuilder().setLocationId(detectedRootLocationConfigBuilder.getId()); modified = true; } if (modified) { throw new EntryModification(detectedRootLocationConfigEntry.setMessage(detectedRootLocationConfigBuilder), consistencyHandler); } } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not validate root location!", ex); } }
@Override public List<UnitConfig> getLocationConfigsByCoordinate(Vec3DDoubleType.Vec3DDouble coordinate, LocationConfig.LocationType locationType) throws CouldNotPerformException, InterruptedException, ExecutionException { List<UnitConfig> result = new ArrayList<>(); for (UnitConfig unitConfig : locationUnitConfigRemoteRegistry.getMessages()) { // Check if the unit meets the requirements of the filter if (!locationType.equals(LocationConfig.LocationType.UNKNOWN) && !locationType.equals(unitConfig.getLocationConfig().getType())) { continue; } // Get the shape of the floor List<Vec3DDoubleType.Vec3DDouble> floorList = unitConfig.getPlacementConfig().getShape().getFloorList(); // Convert the shape into a PolygonsSet List<Vector2D> vertices = floorList.stream() .map(vec3DDouble -> new Vector2D(vec3DDouble.getX(), vec3DDouble.getY())) .collect(Collectors.toList()); PolygonsSet polygonsSet = new PolygonsSet(0.1, vertices.toArray(new Vector2D[]{})); // Transform the given coordinate Transform3D unitTransform = getRootToUnitTransformationFuture(unitConfig).get().getTransform(); Point3d transformedCoordinate = new Point3d(coordinate.getX(), coordinate.getY(), coordinate.getZ()); unitTransform.transform(transformedCoordinate); // NOTE: Hence apache-math builds its polygons counter clockwise unlike bco, the resulting polygon is inverted. // Therefore we check whether the point lies on the outside of the polygon. if (polygonsSet.checkPoint(new Vector2D(transformedCoordinate.x, transformedCoordinate.y)) == Location.OUTSIDE) { result.add(unitConfig); } } return result; }
MultiException.ExceptionStack exceptionStack = null; for (final String unitId : getConfig().getLocationConfig().getUnitIdList()) { try { UnitRemote<? extends GeneratedMessage> unitRemote = Units.getUnit(unitId, false);
/** * Method collects all connections between this and the given location and returns those instances. * * @param locationID the location id of the location to check. * @param waitForData flag defines if the method should block until all needed instances are available. * @return a collection of unit connection remotes. * @throws CouldNotPerformException is thrown if the check could not be performed e.g. if some data is not available yet. */ public List<ConnectionRemote> getDirectConnectionList(final String locationID, final boolean waitForData) throws CouldNotPerformException { if (!getConfig().getLocationConfig().getType().equals(LocationType.TILE)) { throw new CouldNotPerformException("Location is not a Tile!"); } List<ConnectionRemote> connectionList = new ArrayList<>(); try { for (UnitConfig connectionUnitConfig : Registries.getLocationRegistry().getConnectionConfigs()) { ConnectionRemote connection = Units.getUnit(connectionUnitConfig, waitForData, CONNECTION); if (connectionUnitConfig.getConnectionConfig().getTileIdList().contains(getId()) && connectionUnitConfig.getConnectionConfig().getTileIdList().contains(locationID)) { connectionList.add(connection); } } } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all connections!", ex); } return connectionList; }