Permalink
Browse files

Ajout en dur de nodes histoire de tester l'interface REST

  • Loading branch information...
1 parent 7ecfbcf commit c28546ae3cd8e8608b00001c67d5c62b8cb183ee sdaclin committed Apr 26, 2011
@@ -15,11 +15,11 @@
* @author sdaclin
*/
@Path("/node")
-@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public class NodeResource {
@POST
+ @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public void addNode(Node node){
AgexService.addNode(node);
}
@@ -35,4 +35,4 @@ public void addNode(Node node){
public Node getNode(@PathParam("nodeId") String nodeId) {
return AgexService.getNode(nodeId);
}
-}
+}
@@ -2,27 +2,72 @@
import fr.astek.gex.model.Node;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author sdaclin
*/
public class AgexService {
-
+ private static Map<String,Node> nodes = new HashMap<String, Node>();
+ static {
+ Node vivop = new Node();
+ vivop.setId("vivop");
+ vivop.setLabel("Vivop");
+ vivop.setParentId(null);
+ vivop.setProject(false);
+ nodes.put("vivop", vivop);
+ Node vio = new Node();
+ vivop.setId("vio");
+ vio.setLabel("Vio");
+ vio.setParentId("vivop");
+ vio.setProject(true);
+ nodes.put("vio", vio);
+ Node siclop = new Node();
+ siclop.setId("siclop");
+ siclop.setLabel("Siclop");
+ siclop.setParentId("vivop");
+ siclop.setProject(true);
+ nodes.put("siclop", siclop);
+ }
+
+ /**
+ * Retourne tous les fils d'un node
+ * @param nodeId
+ * @return
+ */
public static List<Node> listNode(String nodeId) {
List<Node> list = new ArrayList<Node>();
- list.add(new Node("Modification de l'en-tête du formulaire."));
- list.add(new Node("Suppression du champ libellé."));
+ for(Map.Entry<String,Node> entry : nodes.entrySet()){
+ String key = entry.getKey();
+ Node node = entry.getValue();
+ if (node.getParentId()!=null && node.getParentId().equalsIgnoreCase(nodeId)){
+ list.add(node);
+ }
+ }
return list;
}
public static Node getNode(String nodeId) {
- return new Node("Modification du libelle");
+ for(Map.Entry<String,Node> entry : nodes.entrySet()){
+ String key = entry.getKey();
+ Node node = entry.getValue();
+ if (node.getId()!=null && node.getId().equalsIgnoreCase(nodeId)){
+ return node;
+ }
+ }
+ return null;
}
public static void addNode(Node node) {
- System.out.println("Node" + node);
- return;
+ if(node.getId() == null || node.getId().trim().equals("")){
+ throw new IllegalArgumentException("la valeur id du node doit être remplie");
+ }
+ if (nodes.containsKey(node.getId())){
+ throw new RuntimeException("Ce nodeId existe déjà");
+ }
+ nodes.put(node.getId().toLowerCase(), node);
}
}

0 comments on commit c28546a

Please sign in to comment.