@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; }
// 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"; }