@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();
if (!unitLocationConfig.hasPlacementConfig()) {
throw new NotAvailableException("locationconfig.placementconfig");
}
if (!unitLocationConfig.getPlacementConfig().hasLocationId()) {
throw new NotAvailableException("locationconfig.placementconfig.locationid");
}
if (unitLocationConfig.getLocationConfig().getRoot()) {
return;
}
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);
}
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);
}
}