Skip to content

Commit

Permalink
Ajout en dur de nodes histoire de tester l'interface REST
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaclin committed Apr 26, 2011
1 parent 7ecfbcf commit c28546a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/fr/astek/gex/server/rest/NodeResource.java
Expand Up @@ -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);
}
Expand All @@ -35,4 +35,4 @@ public List<Node> getNodeList(@PathParam("nodeId") String nodeId) {
public Node getNode(@PathParam("nodeId") String nodeId) {
return AgexService.getNode(nodeId);
}
}
}
57 changes: 51 additions & 6 deletions src/main/java/fr/astek/gex/server/service/AgexService.java
Expand Up @@ -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.