/******************************************************************************************************************* * * ******************************************************************************************************************/ public FactSheetStatementUnmarshallerFactory() { // FIXME: discover with Lookup unmarshallerMapByType.put(ID_TAXON, new FactSheetUnmarshaller()); unmarshallerMapByType.put(ID_FOAF_IMAGE, new FoafImageUnmarshaller()); // unmarshallerMapByType.put(new Id("http://xmlns.com/foaf/0.1/Agent"), new GenericEntityUnmarshaller()); }
@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); } } }
@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; } }
final String label = findStatementWithPredicate(statements, ID_RDFS_LABEL).getObject().stringValue(); capabilities.add(new DefaultDisplayable(label, "")); final String givenName = findStatementWithPredicate(statements, ID_FOAF_GIVEN_NAME).getObject().stringValue(); capabilities.add(new DefaultDisplayable(givenName, ""));