Commit c68a83fe authored by Cristina Cocho's avatar Cristina Cocho

Work done related to the setting/change of a servant name via Configura

parent 73740fde
......@@ -22,10 +22,14 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientConfigurationState;
import fr.ill.ics.nscclient.servant.ClientControllerServantDescriptor;
import fr.ill.ics.nscclient.servant.ClientControllerServantDescriptor.ReferencesDescriptor;
import fr.ill.ics.nscclient.servant.ClientServantDescriptor;
public class ServantDatabase {
......@@ -247,4 +251,22 @@ public class ServantDatabase {
controllers.clear();
}
/*
* Method from Configura project. Update all references to an specific servant.
* The update is related to a change of name. Is it possible to be due to another parameter change (like the type or the role?)
*/
public void updateReferencesToServant(ClientServantDescriptor servantDescriptor, String servantDescriptorName) {
// The descriptor is the real servant descriptor of the reference and it can be a driver or controller. However, we will search only in the controllers because they are the only ones that have references.
Iterator<Entry<Integer, ClientServantDescriptor>> it = controllers.entrySet().iterator();
while (it.hasNext()) {
ClientControllerServantDescriptor controllerDescriptor = (ClientControllerServantDescriptor)it.next().getValue();
Optional<ReferencesDescriptor> refDescriptor = controllerDescriptor.getReferencesDescriptor().stream().filter(referenceDescriptor-> (referenceDescriptor.getName().equals(servantDescriptor.getName()) && referenceDescriptor.getType().equals(servantDescriptor.getType()))).findAny();
if (refDescriptor.isPresent()) {
ReferencesDescriptor descript = refDescriptor.get();
// Update the name
descript.setName(servantDescriptorName);
}
}
}
}
\ No newline at end of file
......@@ -571,6 +571,17 @@ public class ServantManagerAccessor {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!answer.equals("NOT OK")) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getServantDescriptorWithId(servantID);
// First update all references to the servant whose name has been changed
ServantDatabase.getInstance().updateReferencesToServant(descriptor, servantName);
// Second update the descriptor of servant
descriptor.setName(servantName); // The answer is not the name!
}
return answer;
}
......
......@@ -79,7 +79,7 @@ public class ClientControllerServantDescriptor extends ClientServantDescriptor {
}
public boolean isConfigured() {
return (name != NOT_CONFIGURED_NAME);
return !name.equals(NOT_CONFIGURED_NAME);
}
}
......
......@@ -85,6 +85,10 @@ public class ClientServantDescriptor {
public boolean isRoot() {
return isRoot;
}
public void setName(String name) {
this.name = name;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment