private void doMatches(Map<String, Object> ret, BagQueryResult bqr) { for (Entry<Integer, List> pair : bqr.getMatches().entrySet()) { Map<String, Object> resultItem; InterMineObject imo; try { imo = im.getObjectStore().getObjectById(pair.getKey()); } catch (ObjectStoreException e) { throw new IllegalStateException("Could not retrieve object reported as match", e); } String idKey = String.valueOf(imo.getId()); if (ret.containsKey(idKey)) { resultItem = (Map<String, Object>) ret.get(idKey); } else { resultItem = new HashMap<String, Object>(); resultItem.put("identifiers", new HashMap<String, Object>()); } if (!resultItem.containsKey("summary")) { resultItem.put("summary", getObjectDetails(imo)); } Map<String, Object> identifiers = (Map<String, Object>) resultItem.get("identifiers"); for (Object o : pair.getValue()) { String ident = (String) o; if (!identifiers.containsKey(ident)) { identifiers.put(ident, new HashSet<String>()); } Set<String> categories = (Set<String>) identifiers.get(ident); categories.add("MATCH"); } String className = DynamicUtil.getSimpleClassName(imo.getClass()); resultItem.put("type", className.replaceAll("^.*\\.", "")); ret.put(idKey, resultItem); } }
/** * Adds objects to the a bag for the matches against a set of identifiers. * * @param ids A collection of identifiers * @param bag The bag to add the objects to * @param type The type of this bag * @param extraFieldValue An extra value for disambiguation. * @param unmatchedIds An accumulator to store the failed matches. * @param acceptableIssues the list of issues that are OK to ignore. * @throws ClassNotFoundException if the type is not a valid class. * @throws InterMineException If something goes wrong building the bag. * @throws ObjectStoreException If there is a problem on the database level. */ protected void addIdsToList( final Collection<? extends String> ids, final InterMineBag bag, final String type, final String extraFieldValue, final Set<String> unmatchedIds, final Collection<String> acceptableIssues) throws ClassNotFoundException, InterMineException, ObjectStoreException { final BagQueryResult result = runner.searchForBag( type, new ArrayList<String>(ids), extraFieldValue, acceptableIssues.contains(BagQueryResult.WILDCARD)); bag.addIdsToBag(result.getMatches().keySet(), type); for (final String issueType : result.getIssues().keySet()) { if (acceptableIssues.contains(issueType)) { bag.addIdsToBag(result.getIssueIds(issueType), type); } else { unmatchedIds.addAll(result.getInputIdentifiersForIssue(issueType)); } } unmatchedIds.addAll(result.getUnresolvedIdentifiers()); }
private void doDuplicates(final Map<String, Object> ret, BagQueryResult bqr, String key) { Map<String, Map<String, List>> issues = bqr.getIssues().get(key); if (issues == null) { return; } for (Map<String, List> issueSet : issues.values()) { for (Entry<String, List> identToObjects : issueSet.entrySet()) { String ident = identToObjects.getKey(); for (Object o : identToObjects.getValue()) { InterMineObject imo; Map<String, Object> resultItem; if (o instanceof Integer) { try { imo = im.getObjectStore().getObjectById((Integer) o); } catch (ObjectStoreException e) { throw new IllegalStateException("Could not retrieve object reported as match", e); } } else if (o instanceof ConvertedObjectPair) { imo = ((ConvertedObjectPair) o).getNewObject(); } else { imo = (InterMineObject) o; } String idKey = String.valueOf(imo.getId()); if (ret.containsKey(idKey)) { resultItem = (Map<String, Object>) ret.get(idKey); } else { resultItem = new HashMap<String, Object>(); resultItem.put("identifiers", new HashMap<String, Object>()); } if (!resultItem.containsKey("summary")) { resultItem.put("summary", getObjectDetails(imo)); } Map<String, Object> identifiers = (Map<String, Object>) resultItem.get("identifiers"); if (!identifiers.containsKey(ident)) { identifiers.put(ident, new HashSet<String>()); } Set<String> categories = (Set<String>) identifiers.get(ident); categories.add(key); String className = DynamicUtil.getSimpleClassName(imo.getClass()); resultItem.put("type", className.replaceAll("^.*\\.", "")); ret.put(idKey, resultItem); } } } }