예제 #1
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);
 }
예제 #2
0
  // TODO use NeedModelBuilder here instead
  @RequestMapping(value = "/create", method = RequestMethod.POST)
  public String createNeedPost(@ModelAttribute("SpringWeb") NeedPojo needPojo, Model model)
      throws Exception {
    URI needURI;

    try {
      URI ownerURI = this.uriService.getOwnerProtocolOwnerServiceEndpointURI();

      NeedPojoNeedModelBuilder needPojoNeedModelBuilder = new NeedPojoNeedModelBuilder(needPojo);
      needPojoNeedModelBuilder.setUri("no:uri");
      com.hp.hpl.jena.rdf.model.Model needModel = needPojoNeedModelBuilder.build();
      needModel.setNsPrefix("", "no:uri");

      if (needPojo.getWonNode().equals("")) {
        ListenableFuture<URI> futureResult =
            ownerService.createNeed(needModel, needPojo.getState() == NeedState.ACTIVE, null);
        needURI = futureResult.get();
      } else {
        ListenableFuture<URI> futureResult =
            ownerService.createNeed(
                needModel,
                needPojo.getState() == NeedState.ACTIVE,
                URI.create(needPojo.getWonNode()),
                null);
        needURI = futureResult.get();
      }

      List<Need> needs = needRepository.findByNeedURI(needURI);
      // TODO: race condition between need saving logic and redirect. adapt interface.
      if (needs.size() == 1) return "redirect:/need/" + needs.get(0).getId().toString();
      // return viewNeed(need.getId().toString(), model);
    } catch (IllegalNeedContentException e) {
      logger.warn("caught IllegalNeedContentException:", e);
    }

    model.addAttribute("command", new NeedPojo());

    return "createNeed";
  }
  @RequestMapping(value = "/{conId}/accept", method = RequestMethod.POST)
  public String accept(@PathVariable String conId, Model model) {
    List<Connection> cons = connectionRepository.findById(Long.valueOf(conId));
    if (cons.isEmpty()) return "noNeedFound";
    Connection con = cons.get(0);
    try {
      // TODO: add rdf content here as soon as we support its creation in the owner app
      ownerService.open(con.getConnectionURI(), null);
    } catch (Exception e) {
      logger.warn("error during accept", e);
      return "error during accept: " + e.getMessage();
    }

    return "redirect:/connection/" + con.getId().toString() + "/body";
  }
  @RequestMapping(value = "/{conId}/send", method = RequestMethod.POST)
  public String sendText(
      @PathVariable String conId, @ModelAttribute("SpringWeb") TextMessagePojo text, Model model) {
    List<Connection> cons = connectionRepository.findById(Long.valueOf(conId));
    if (cons.isEmpty()) return "noNeedFound";
    Connection con = cons.get(0);

    try {

      ownerService.textMessage(
          con.getConnectionURI(), WonRdfUtils.MessageUtils.textMessage(text.getText()));
    } catch (Exception e) {
      logger.warn("error sending text message");
      return "error sending text message: " + e.getMessage();
    }

    return "redirect:/connection/" + con.getId().toString(); // "viewConnection";
  }
예제 #5
0
  @RequestMapping(value = "/match/{matchId}/connect", method = RequestMethod.POST)
  public String connect(@PathVariable String matchId, Model model) {
    String ret = "noNeedFound";

    try {
      List<Match> matches = matchRepository.findById(Long.valueOf(matchId));
      if (!matches.isEmpty()) {
        Match match = matches.get(0);
        List<Need> needs = needRepository.findByNeedURI(match.getFromNeed());
        if (!needs.isEmpty()) {
          ret =
              "redirect:/need/"
                  + needs
                      .get(0)
                      .getId()
                      .toString(); // viewNeed(needs.get(0).getId().toString(), model);
        }
        // TODO: match object does not contain facet info, assume OwnerFacet.
        com.hp.hpl.jena.rdf.model.Model facetModel =
            WonRdfUtils.FacetUtils.createFacetModelForHintOrConnect(
                FacetType.OwnerFacet.getURI(), FacetType.OwnerFacet.getURI());
        ownerService.connect(match.getFromNeed(), match.getToNeed(), facetModel, null);
      }
    } catch (ConnectionAlreadyExistsException e) {
      logger.warn("caught ConnectionAlreadyExistsException:", e);
    } catch (IllegalMessageForNeedStateException e) {
      logger.warn("caught IllegalMessageForNeedStateException:", e);
    } catch (NoSuchNeedException e) {
      logger.warn("caught NoSuchNeedException:", e);
    } catch (InterruptedException e) {
      logger.warn("caught InterruptedEception", e);
    } catch (ExecutionException e) {
      logger.warn("caught ExecutionException", e);
    } catch (CamelConfigurationFailedException e) {
      logger.warn(
          "caught CamelConfigurationException",
          e); // To change body of catch statement use File | Settings | File Templates.
      logger.warn("caught CamelConfigurationFailedException");
    } catch (Exception e) {
      logger.warn("caught Exception", e);
    }

    return ret;
  }
예제 #6
0
  @RequestMapping(value = "/{needId}/connect", method = RequestMethod.POST)
  public String connect2Need(
      @PathVariable String needId, @ModelAttribute("SpringWeb") NeedPojo needPojo, Model model) {
    try {
      List<Need> needs = needRepository.findById(Long.valueOf(needId));
      if (needs.isEmpty()) return "noNeedFound";

      Need need1 = needs.get(0);

      com.hp.hpl.jena.rdf.model.Model facetModel =
          WonRdfUtils.FacetUtils.createFacetModelForHintOrConnect(
              URI.create(needPojo.getOwnFacetURI()), URI.create(needPojo.getRemoteFacetURI()));
      ownerService.connect(need1.getNeedURI(), new URI(needPojo.getNeedURI()), facetModel, null);
      return "redirect:/need/"
          + need1.getId().toString(); // viewNeed(need1.getId().toString(), model);
    } catch (URISyntaxException e) {
      logger.warn("caught URISyntaxException:", e);
    } catch (ConnectionAlreadyExistsException e) {
      logger.warn("caught ConnectionAlreadyExistsException:", e);
    } catch (IllegalMessageForNeedStateException e) {
      logger.warn("caught IllegalMessageForNeedStateException:", e);
    } catch (NoSuchNeedException e) {
      logger.warn("caught NoSuchNeedException:", e);
    } catch (InterruptedException e) {
      logger.warn("caught InterruptedException", e);
    } catch (ExecutionException e) {
      logger.warn("caught ExcutionException", e);
    } catch (CamelConfigurationFailedException e) {
      logger.warn("caught CameConfigurationException", e);
      logger.warn("caught CamelConfigurationFailedException", e);
    } catch (Exception e) {
      logger.warn("caught Exception", e);
    }

    return "noNeedFound";
  }