/** * Retrieve all links of with the given type * * @param type attribute of link to search for * @return List of found Links */ public List<Link> findLinksByType(String type) { List<Link> foundLinks = new ArrayList<Link>(); for (Link link : this) { if (type.equals(link.getType())) foundLinks.add(link); } return foundLinks; }
public void addTrack(Link track) { if (track.getType() == Type.LOCAL) { // Don't add local tracks, can't do anything with them... return; } if (tracks == null) { tracks = new ArrayList<Link>(); } this.tracks.add(track); }
public void testCreate() throws Exception { Link link = Link.create("spotify:album:3PogVmhNucYNfyywZvTd7F"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.ALBUM, link.getType()); link = Link.create("spotify:track:3PogVmhNucYNfyywZvTd7F"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.TRACK, link.getType()); link = Link.create("jahspotify:queue:default"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.QUEUE, link.getType()); assertEquals("bad stuff", "default", link.getQueue()); link = link.create("jahspotify:podcast:http://www.localhost/"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.PODCAST, link.getType()); assertEquals("bad uri", "http://www.localhost/", link.getUri()); link = link.create("jahspotify:mp3:http://www.localhost/"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.MP3, link.getType()); assertEquals("bad uri", "http://www.localhost/", link.getUri()); link = Link.create("jahspotify:folder:0000000000000001"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.FOLDER, link.getType()); link = Link.create("jahspotify:folder:ROOT"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.FOLDER, link.getType()); link = Link.create("jahspotify:queue:default:d9418cb4-fff4-4542-9dee-cc136c5f1929"); assertNotNull("no link created", link); assertEquals("bad type", Link.Type.QUEUE_ENTRY, link.getType()); }
@RequestMapping("related") @Model @ResponseBody public Collection<ModelMap> getRelated(@RequestParam String uri) { Set<UID> related = new LinkedHashSet<UID>(); for (Link link : linkDao.getRelated(uri)) { if (!ABBREVIATION.equals(link.getType()) && link.getQuote() == null) { if (link.getUid1().getUri().equals(uri)) { related.add(link.getUid2()); } else { related.add(link.getUid1()); } } } return convertToPlainObjects( related, new ValueObjectUtils.Modifier<UID>() { @Override public void modify(UID entity, ModelMap map) { map.remove("content"); } }); }
@RequestMapping(value = "/", method = RequestMethod.GET) @Model public ModelMap get( @RequestParam("name") String termName, @RequestParam(required = false) boolean mark) { termName = termName.replace("_", " "); TermsMap.TermProvider provider = termsMap.getTermProvider(termName); if (provider == null) { throw new QuietException(format("Термин `%s` отсутствует", termName)); } if (provider.hasMainTerm()) { provider = provider.getMainTermProvider(); } ModelMap modelMap = new ModelMap(); // (ModelMap) getModelMap(term); Term term = provider.getTerm(); modelMap.put("uri", term.getUri()); modelMap.put("name", term.getName()); if (mark) { if (term.getTaggedShortDescription() == null && term.getShortDescription() != null) { term.setTaggedShortDescription(termsMarker.mark(term.getShortDescription())); termDao.save(term); } if (term.getTaggedDescription() == null && term.getDescription() != null) { term.setTaggedDescription(termsMarker.mark(term.getDescription())); termDao.save(term); } modelMap.put("shortDescription", term.getTaggedShortDescription()); modelMap.put("description", term.getTaggedDescription()); } else { modelMap.put("shortDescription", term.getShortDescription()); modelMap.put("description", term.getDescription()); } // LINKS List<ModelMap> quotes = new ArrayList<ModelMap>(); Set<UID> related = new LinkedHashSet<UID>(); Set<UID> aliases = new LinkedHashSet<UID>(); UID code = null; List<Link> links = linkDao.getAllLinks(term.getUri()); for (Link link : links) { UID source = link.getUid1().getUri().equals(term.getUri()) ? link.getUid2() : link.getUid1(); if (link.getQuote() != null || source instanceof Item) { quotes.add(getQuote(link, source, mark)); } else if (ABBREVIATION.equals(link.getType()) || ALIAS.equals(link.getType())) { aliases.add(source); } else if (CODE.equals(link.getType())) { code = source; } else { related.add(source); } } // Нужно также включить цитаты всех синонимов и сокращений и кода Set<UID> aliasesQuoteSources = new HashSet<UID>(aliases); if (code != null) { aliasesQuoteSources.add(code); } for (UID uid : aliasesQuoteSources) { List<Link> aliasLinksWithQuote = linkDao.getAllLinks(uid.getUri()); for (Link link : aliasLinksWithQuote) { UID source = link.getUid1().getUri().equals(uid.getUri()) ? link.getUid2() : link.getUid1(); if (link.getQuote() != null || source instanceof Item) { quotes.add(getQuote(link, source, mark)); } else if (ABBREVIATION.equals(link.getType()) || ALIAS.equals(link.getType()) || CODE.equals(link.getType())) { // Синонимы синонимов :) по идее их не должно быть, но если вдруг... // как минимум один есть и этот наш основной термин if (!source.getUri().equals(term.getUri())) { aliases.add(source); } } else { related.add(source); } } } sort( quotes, new Comparator<ModelMap>() { @Override public int compare(ModelMap o1, ModelMap o2) { return ((String) o1.get("uri")).compareTo((String) o2.get("uri")); } }); modelMap.put("code", code); modelMap.put("quotes", quotes); modelMap.put("related", toPlainObjectWithoutContent(related)); modelMap.put("aliases", toPlainObjectWithoutContent(aliases)); modelMap.put("categories", searchController.inCategories(termName)); return modelMap; }
/** * Retrieve the first found link of with the given type or null of it doesn't exist * * @param type attribute of link to search for * @return first found Link or null */ public Link findLinkByType(String type) { for (Link link : this) { if (type.equals(link.getType())) return link; } return null; }