예제 #1
0
  @RequestMapping(value = "/{needId}", method = RequestMethod.GET)
  public String viewNeed(@PathVariable String needId, Model model) {

    model.addAttribute("needId", needId);

    List<Need> needs = needRepository.findById(Long.valueOf(needId));
    if (needs.isEmpty()) return "noNeedFound";

    Need need = needs.get(0);
    model.addAttribute("active", need.getState() != NeedState.ACTIVE ? "activate" : "deactivate");
    model.addAttribute("needURI", need.getNeedURI());
    List<Facet> facets = facetRepository.findByNeedURI(need.getNeedURI());

    NeedPojo needCommandPojo = new NeedPojo(facets);
    model.addAttribute("command", needCommandPojo);

    NeedPojo pojo =
        new NeedPojo(
            need.getNeedURI(),
            linkedDataSource.getDataForResource(need.getNeedURI()).getDefaultModel());
    pojo.setState(need.getState());
    model.addAttribute("pojo", pojo);

    // set facets on 'command': (needed for the dropdown list in the 'connect' control TODO:
    // deuglify
    needCommandPojo.setNeedFacetURIs(pojo.getNeedFacetURIs());

    return "viewNeed";
  }
예제 #2
0
 @RequestMapping(value = "/{needId}/toggle", method = RequestMethod.POST)
 public String toggleNeed(@PathVariable String needId, Model model)
     throws NoSuchConnectionFault, IllegalMessageForConnectionStateFault {
   List<Need> needs = needRepository.findById(Long.valueOf(needId));
   if (needs.isEmpty()) return "noNeedFound";
   Need need = needs.get(0);
   try {
     if (need.getState() == NeedState.ACTIVE) {
       ownerService.deactivate(need.getNeedURI(), null);
     } else {
       ownerService.activate(need.getNeedURI(), null);
     }
   } catch (NoSuchNeedException e) {
     logger.warn("caught NoSuchNeedException:", e);
   } catch (Exception e) {
     logger.warn("caught Exception", e);
   }
   return "redirect:/need/" + need.getId().toString();
   // return viewNeed(need.getId().toString(), model);
 }