/******************************************************************************************************************* * * ******************************************************************************************************************/ @Override public void writeExternal (final @Nonnull ObjectOutput oo) throws IOException { oo.writeObject(taxon.getId()); }
@Nonnull public String getLocalizedName (final @Nonnull Taxon taxon) throws NotFoundException { // FIXME: string concatenation here kills the performance - make it "No name for %s", taxon); // return NotFoundException.throwWhenNull(map.get(taxon.getId()), "No name for " + taxon); return NotFoundException.throwWhenNull(map.get(taxon.getId()), "No name for taxon"); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ public void addToTaxonHistory (final @Nonnull Taxon taxon) { final Id id = taxon.getId(); taxonIdHistory.remove(id); taxonIdHistory.add(0, id); while (taxonIdHistory.size() > maxHistorySize) { taxonIdHistory.remove(maxHistorySize); } save(); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void addDisplayName (final @Nonnull JSONObject jsonObject, final @Nonnull Taxon taxon, final @Nonnull Locale locale) { final String languageCode = "lang_" + locale.getLanguage(); final String displayName = jsonObject.optString(languageCode); if ((displayName != null) && !displayName.equals("")) { final String language = locale.getLanguage(); Map<Id, String> nameBag = nameBagsByLanguage.get(language); if (nameBag == null) { nameBag = new HashMap<Id, String>(); nameBagsByLanguage.put(language, nameBag); } nameBag.put(taxon.getId(), displayName); } }
/******************************************************************************************************************* * * Creates an {@link Intent} for activating the given {@code Activity}, passing a {@link Taxon} as parameter. * * @param taxon the {@code Taxon} * @param activityClass the {@code Activity} * ******************************************************************************************************************/ @Nonnull public static Intent intentFor (final @Nonnull Taxon taxon, final @Nonnull Class<?> activityClass) throws NotFoundException { // FIXME: you should really use the Uri, but it fails to find the Intent // FIXME: probably it needs a further declaration in the Android manifest // return new Intent(ACTION_TAXON, Uri.parse(taxon.getId().stringValue())); final Intent intent = new Intent(Locator.find(Context.class), activityClass); intent.putExtra(TAXON_ID, taxon.getId().stringValue()); return intent; }
@Nonnull public synchronized FactSheet getFactSheet() throws NotFoundException { log.info("getFactSheet() - {}", taxon); log.debug(">>>> weak reference: {}", factSheetRef); FactSheet factSheet = null; if (factSheetRef != null) { factSheet = factSheetRef.get(); log.debug(">>>> factSheet from weak reference: {}", factSheet); } if (factSheet == null) { log.info(">>>> loading fact sheet for {}...", taxon); final long time = System.currentTimeMillis(); factSheet = new FactSheet(taxon.getId()); // FIXME: use Locator.findAll() or Locator.createAllProvidersFor() for (final FactSheetProvider provider : Lookup.getDefault().lookupAll(FactSheetProvider.class)) { log.debug(">>>> calling {} ...", provider); factSheet = factSheet.mergedWith(provider.createFactSheetFor(taxon)); } log.debug(">>>> fact sheet loaded in {} msec...", System.currentTimeMillis() - time); factSheetRef = new WeakReference<FactSheet>(factSheet); } return factSheet; } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public Graph getGraph() throws IOException { log.info("getGraph()"); final String resourceName = taxon.getId().stringValue().replaceAll(":", "_") + ".n3"; log.info(">>>> resourceName: {}", resourceName); final File file = createProviderFor.get().findAsset("factsheets.zip"); log.info(">>>> zip file: {}", file); final @Cleanup ZipFile zipFile = new ZipFile(file); final ZipEntry entry = zipFile.getEntry(resourceName); final @Cleanup InputStream is = zipFile.getInputStream(entry); return loadGraph(is, MimeTypes.MIME_N3); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public static Intent intentFor (final @Nonnull Taxon taxon) throws NotFoundException { // FIXME: you should really use the Uri, but it fails to find the Intent // FIXME: probably it needs a further declaration in the Android manifest // return new Intent(ACTION_TAXON, Uri.parse(taxon.getId().stringValue())); final Intent intent = new Intent(getActionPackage() + taxon.getRank().getNarrower().name()); intent.putExtra(TAXON_ID, taxon.getId().stringValue()); return intent; }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public ObservationSet loadObservationSet (final @Nonnull Taxon taxon) // FIXME: should be protected, throws IOException { // FIXME: now it loads xeno-canto, but should be a generic observation set with any kind of media log.info("loadObservationSet({})", taxon); final String resourceName = taxon.getId().stringValue().replaceAll(":", "_") + ".n3"; log.info(">>>> resourceName: {}", resourceName); final File file = smartAssetManager.get().findAsset("factsheets.zip"); log.info(">>>> zip file: {}", file); final @Cleanup ZipFile zipFile = new ZipFile(file); final ZipEntry entry = zipFile.getEntry(resourceName); if (entry == null) { log.warn("No entry for {}", resourceName); return new SimpleObservationSet(); } final @Cleanup InputStream is = zipFile.getInputStream(entry); return loadObservationSet(is, MimeTypes.MIME_N3); }