@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 FactSheet mergedWith (final @Nonnull FactSheet factSheet) // FIXME: could be pushed up? { FactSheet result = this; for (final Key<?> key : factSheet.getKeys()) { final Collection values = factSheet.getMultiple(key); result = result.with(key, values); } return result; } }
@Override @Nonnull public As unmarshal (final @Nonnull List<Statement> statements, final @Nonnull Context context) { final Id id = new Id(statements.get(0).getSubject().stringValue()); FactSheet factSheet = new FactSheet(id); for (final Statement statement : context.findStatements(ID_FOAF_DEPICTS, id)) { factSheet = factSheet.with(FOAF_IMAGE, (Media)context.find(statement.getSubject())); } try { final String string = findStatementWithPredicate(statements, FactSheet.ID_DESCRIPTION).getObject().stringValue(); factSheet = factSheet.with(FactSheet.DESCRIPTION, string); } catch (NotFoundException e) { throw new RuntimeException(e); // ok. no description } return factSheet; } }
@Override @Nonnull protected FactSheet clone (final @Nonnull Id id, final @Nonnull Map<Key<?>, Object> propertyMap, final @Nonnull Object[] capabilities) { return new FactSheet(id, propertyMap, capabilities); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @ThreadConfined(type=NOT_UI) protected void createPresentationModels (final @Nonnull Taxon taxon) throws NotFoundException { log.info("createPresentationModels({})", taxon); // stillImages.addAll(taxon.as(Documentable).getFactSheet().getMultiple(FOAF_IMAGE)); for (final Media stillImage : taxon.as(Documentable).getFactSheet().getMultiple(FOAF_IMAGE)) { addPresentationModel(stillImage.with(ID, replacedId(stillImage.get(ID))).as(Presentable).createPresentationModel()); } }
@ThreadConfined(type=NOT_UI) protected void createPresentationModels (final @Nonnull Taxon taxon) { addPresentationModel(new TextPresentationModel(taxon.as(HtmlRenderable).render(HIERARCHY))); try { // FIXME: instead of tweaking h2, use a CSS addPresentationModel(new DocumentPresentationModel(taxon.as(Documentable).getFactSheet().get(DESCRIPTION).replaceAll(("h2>"), "h3>"))); } catch (AsException e) { addPresentationModel(new TextPresentationModel("No info")); // FIXME } catch (NotFoundException e) { addPresentationModel(new TextPresentationModel("No info")); // FIXME } } }
FactSheet factSheet = new FactSheet(id).with(DC_PUBLISHER, BbcFactSheetProvider.BBC) .with(DC_RIGHTS, BBC_SYNDICATION_GUIDELINES); factSheet = factSheet.with(key, context.find(object)); factSheet = factSheet.with(key, context.find(object)); factSheet = factSheet.with(key, deserialize(object)); factSheet = factSheet.with(IMAGE, new Media().with(Media.ID, new Id(context.find(statement.getSubject())))); factSheet = factSheet.with(BIBLIO, new Biblio(new Id(context.find(statement.getSubject())))); factSheet = factSheet.with(MOVIE, movie);