Commit cfa15617 authored by Cristina Cocho's avatar Cristina Cocho

work related to references

parent c5aa7ada
......@@ -512,6 +512,8 @@ public class ServantManagerAccessor {
// Get response even if we do not treat it
servantManagerRequester.receive();
// TODO Update here the content of the descriptor
}
/*
......@@ -528,6 +530,8 @@ public class ServantManagerAccessor {
// Get response even if we do not treat it
servantManagerRequester.receive();
// TODO Update content of descriptor
}
public void setConfigurationMode(boolean mode) {
......@@ -635,7 +639,15 @@ public class ServantManagerAccessor {
// Obtain references
List<ServantDataConfiguration.ChildDescriptor> pbChildren = pbServant.getChildrenList();
addControllerReferences((ClientControllerServantDescriptor)descriptor, pbChildren);
if (pbChildren.size() == 0) {
// There are no children (= configured references). Get the not configured references through ReferenceDescriptor
List<ServantDataConfiguration.ReferenceDescriptor> pbReferences = pbServant.getReferencesList();
if (pbReferences.size() > 0) {
addNotConfiguredControllerReferences((ClientControllerServantDescriptor)descriptor, pbReferences);
}
} else {
addConfiguredControllerReferences((ClientControllerServantDescriptor)descriptor, pbChildren);
}
}
// add the list of child names
......@@ -727,9 +739,9 @@ public class ServantManagerAccessor {
}
/*
* Add References info in the descriptor of the controller
* Add Configured References info in the descriptor of the controller
*/
private void addControllerReferences(ClientControllerServantDescriptor controllerDescriptor, List<ServantDataConfiguration.ChildDescriptor> pbChildren) {
private void addConfiguredControllerReferences(ClientControllerServantDescriptor controllerDescriptor, List<ServantDataConfiguration.ChildDescriptor> pbChildren) {
Iterator<ServantDataConfiguration.ChildDescriptor> cd = pbChildren.iterator();
while (cd.hasNext()) {
// This is quite confusing BUT for the controller case, the first level will contain the references roles.
......@@ -737,14 +749,32 @@ public class ServantManagerAccessor {
ServantDataConfiguration.ChildDescriptor pbChild1 = cd.next();
String referenceRole = pbChild1.getName();
List<String> controllerReferencesNames = new ArrayList<String>(); // its final size should be one
// Important!!! I DO ASSUME HERE THAT THE NUMBER OF CHILDREN WITH THE SAME ROLE IS ONE. DISCUSS!
if (pbChild1.getChildArrayList().size() == 1) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = pbChild1.getChildArrayList().get(0);
String referenceName = pbChild2.getName();
controllerDescriptor.addReference(referenceRole, referenceName, "");
} else {
// Error
System.err.println("There is more than one child with the same role for the controller " +controllerDescriptor.getName());
}
/*
List<String> controllerReferencesNames = new ArrayList<String>(); // its final size should be one
Iterator<ServantDataConfiguration.ChildDescriptor.Child> ccd = pbChild1.getChildArrayList().iterator();
while (ccd.hasNext()) {
while (ccd.hasNext()) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = ccd.next();
String referenceName = pbChild2.getName();
controllerReferencesNames.add(referenceName);
}
controllerDescriptor.addReferenceInfo(referenceRole, controllerReferencesNames);
}*/
}
}
private void addNotConfiguredControllerReferences(ClientControllerServantDescriptor controllerDescriptor, List<ServantDataConfiguration.ReferenceDescriptor> pbReferences) {
Iterator<ServantDataConfiguration.ReferenceDescriptor> rd = pbReferences.iterator();
while (rd.hasNext()) {
ServantDataConfiguration.ReferenceDescriptor refDescript = rd.next();
controllerDescriptor.addReference(refDescript.getRole(), "Not Configured", refDescript.getType());
}
}
......
package fr.ill.ics.nscclient.servant;
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class ClientControllerServantDescriptor extends ClientServantDescriptor {
// NOTE: Discuss this point... we should only have a map <role, name>... is there the possibility to have the same role and different controller name?
private Map<String, List<String>> referencesInfo; //KEY = reference role, VALUE = reference name
private Map<String, String> referencesInfo; //KEY = reference role, VALUE = reference name
private Set<ReferencesDescriptor> referencesDescriptors;
public ClientControllerServantDescriptor(int ID, String name, String type, String family, String subfamily, boolean isCommand, boolean isVisible, boolean isEnabled, boolean isFavourite, boolean isRoot) {
super(ID, name, type, family, subfamily, isCommand, isVisible, isEnabled, isFavourite, isRoot);
referencesInfo = new HashMap<String, List<String>>();
referencesInfo = new HashMap<String, String>();
referencesDescriptors = new HashSet<ReferencesDescriptor>();
}
public void addReferenceInfo(String role, List<String> name) {
referencesInfo.put(role, name);
}
// public void addReferenceInfo(String role, String name) {
// referencesInfo.put(role, name);
// }
public Map<String, List<String>> getReferencesInfo() {
public Map<String, String> getReferencesInfo() {
return referencesInfo;
}
public void unconfiguredReferenceInfo(String role) {
// An unconfigured reference does not have any controller for a specific role
List<String> refNames = referencesInfo.get(role);
String name = "Not Configured";
for (int i = 0; i < refNames.size(); i++) {
// The list should contain only one element
refNames.set(i, name);
referencesInfo.put(role, name);
}
public void addReference(String role, String name, String type) {
referencesDescriptors.add(new ReferencesDescriptor(role, name, type));
}
public Set<ReferencesDescriptor> getReferencesDescriptor() {
return referencesDescriptors;
}
public class ReferencesDescriptor {
private String role;
private String name;
private String type;
public ReferencesDescriptor(String role, String name, String type) {
this.role = role;
this.name = name;
this.type = type;
}
public String getRole() {
return role;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public void setName(String name) {
this.name = name;
}
}
}
......@@ -18,8 +18,9 @@
package fr.ill.ics.nscclient.servant;
import java.util.List;
import java.util.Map;
import java.util.Set;
import fr.ill.ics.nscclient.servant.ClientControllerServantDescriptor.ReferencesDescriptor;
public class ControllerServant extends Servant {
......@@ -27,11 +28,15 @@ public class ControllerServant extends Servant {
super(databaseId, servantId, descriptor);
}
public Map<String, List<String>> getReferencesInfo() {
return ((ClientControllerServantDescriptor)servantDescriptor).getReferencesInfo();
}
// public Map<String, String> getReferencesInfo() {
// return ((ClientControllerServantDescriptor)servantDescriptor).getReferencesInfo();
// }
public boolean hasReferences() {
return (((ClientControllerServantDescriptor)servantDescriptor).getReferencesInfo().size() > 0);
return (((ClientControllerServantDescriptor)servantDescriptor).getReferencesDescriptor().size() > 0);
}
public Set<ReferencesDescriptor> getReferences() {
return ((ClientControllerServantDescriptor)servantDescriptor).getReferencesDescriptor();
}
}
\ No newline at end of file
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