@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 protected Habitat clone (final @Nonnull Id id, final @Nonnull Map<Key<?>, Object> propertyMap, final @Nonnull Object[] capabilities) { return new Habitat(id, propertyMap, capabilities); } }
@Nonnull public As unmarshal (final @Nonnull List<Statement> statements, final @Nonnull Context context) final Id id = findId(statements, context); 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);
@Nonnull public As unmarshal (final @Nonnull List<Statement> statements, final @Nonnull Context context) { final Id id = findId(statements, context); Biblio biblio = new Biblio(id); for (final Statement statement : statements) { final String predicate = statement.getPredicate().stringValue(); if (predicate.startsWith(NS_DC_TERMS)) { final Key<Object> key = new Key<Object>(predicate); biblio = biblio.with(key, deserialize(statement.getObject())); } else if (!predicate.equals(TYPE_RDF_TYPE.stringValue()) && !predicate.equals(ID_FOAF_PRIMARY_TOPIC.stringValue())) { System.err.println("BIBLIO Unused statement: " + statement); } } return biblio; } }
@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; } }
@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 As unmarshal (final @Nonnull List<Statement> statements, final @Nonnull Context context) { return new Adaptation(findId(statements, context)); } }
@Nonnull public FactSheet createFactSheetFor (final @Nonnull Taxon taxon) throws NotFoundException { try { final GraphProvider graphProvider = new DefaultGraphProvider(taxon); final Graph graph = graphProvider.getGraph(); final GraphUnmarshaller unmarshaller = new GraphUnmarshallerImpl(); unmarshaller.registerStatementUnmarshallerFactory(new FactSheetStatementUnmarshallerFactory()); return unmarshaller.unmarshal(graph, TYPE_TAXON); } catch (IOException e) { throw new NotFoundException(e); } } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @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()); } }
@Override @Nonnull protected Biblio clone (final @Nonnull Id id, final @Nonnull Map<Key<?>, Object> propertyMap, final @Nonnull Object[] capabilities) { return new Biblio(id, propertyMap, capabilities); } }
@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); }
@Override @Nonnull protected Adaptation clone (final @Nonnull Id id, final @Nonnull Map<Key<?>, Object> propertyMap, final @Nonnull Object[] capabilities) { return new Adaptation(id, propertyMap, capabilities); } }
@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 } } }