Skip to content

Commit

Permalink
Fixing parsing of unknown schemas (#41)
Browse files Browse the repository at this point in the history
* Fixing parsing of unknown schemas

* Removing unecessary info logs
  • Loading branch information
leboiko authored Jan 9, 2025
1 parent d49b87a commit 3514625
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions consumer/src/mode/resolver/atom_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,42 +161,49 @@ async fn try_to_resolve_schema_org_properties(
obj: &Value,
) -> Result<AtomMetadata, ConsumerError> {
if let Some(obj_type) = obj.get("@type").and_then(|t| t.as_str()) {
match AtomType::from_str(obj_type)? {
AtomType::Thing => {
let thing = create_thing_from_obj(atom, obj).upsert(pg_pool).await?;
create_thing_atom_value(atom, &thing, pg_pool).await?;
Ok(AtomMetadata::thing(
thing.name.unwrap_or_default(),
thing.image.clone(),
))
}
AtomType::Person => {
let person = create_person_from_obj(atom, obj).upsert(pg_pool).await?;
create_person_atom_value(atom, &person, pg_pool).await?;
Ok(AtomMetadata::person(
person.name.unwrap_or_default(),
person.image.clone(),
))
}
AtomType::Organization => {
let organization = create_organization_from_obj(atom, obj)
.upsert(pg_pool)
.await?;
create_organization_atom_value(atom, &organization, pg_pool).await?;
Ok(AtomMetadata::organization(
organization.name.unwrap_or_default(),
organization.image.clone(),
))
}
AtomType::Book => {
let book = create_book_from_obj(atom, obj).upsert(pg_pool).await?;
create_book_atom_value(atom, &book, pg_pool).await?;
Ok(AtomMetadata::book(book.name.unwrap_or_default()))
}
_ => {
warn!("Unsupported schema.org type: {}", obj_type);
Ok(AtomMetadata::unknown())
// This will fail if the atom type is not supported, i.e. it's not part of
// the [`AtomType`] enum.
if let Ok(atom_type) = AtomType::from_str(obj_type) {
match atom_type {
AtomType::Thing => {
let thing = create_thing_from_obj(atom, obj).upsert(pg_pool).await?;
create_thing_atom_value(atom, &thing, pg_pool).await?;
Ok(AtomMetadata::thing(
thing.name.unwrap_or_default(),
thing.image.clone(),
))
}
AtomType::Person => {
let person = create_person_from_obj(atom, obj).upsert(pg_pool).await?;
create_person_atom_value(atom, &person, pg_pool).await?;
Ok(AtomMetadata::person(
person.name.unwrap_or_default(),
person.image.clone(),
))
}
AtomType::Organization => {
let organization = create_organization_from_obj(atom, obj)
.upsert(pg_pool)
.await?;
create_organization_atom_value(atom, &organization, pg_pool).await?;
Ok(AtomMetadata::organization(
organization.name.unwrap_or_default(),
organization.image.clone(),
))
}
AtomType::Book => {
let book = create_book_from_obj(atom, obj).upsert(pg_pool).await?;
create_book_atom_value(atom, &book, pg_pool).await?;
Ok(AtomMetadata::book(book.name.unwrap_or_default()))
}
_ => {
warn!("Unsupported schema.org type: {}", obj_type);
Ok(AtomMetadata::unknown())
}
}
} else {
warn!("Unsupported schema.org type: {}", obj_type);
Ok(AtomMetadata::unknown())
}
} else {
Ok(AtomMetadata::unknown())
Expand Down

0 comments on commit 3514625

Please sign in to comment.