Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties handling improvement #3

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,36 @@ public static Optional<Thing> convert(Schema schema) {
}

private static void setProperties(Thing.Builder builder, Schema schema, Class<?> builderClass)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
throws InvocationTargetException, IllegalAccessException {

// Set all the properties
for (String propertyName : schema.getProperties().keySet()) {
String methodName = String.format("add%s", capitalize(propertyName));
Method method = builderClass.getMethod(methodName, String.class);
method.invoke(builder, schema.getProperties().get(propertyName).get(0));
try {
String methodName = String.format("add%s", capitalize(propertyName));
Method method = builderClass.getMethod(methodName, String.class);
method.invoke(builder, schema.getProperties().get(propertyName).get(0));
}
catch (NoSuchMethodException e){
builder.addProperty(propertyName, schema.getProperties().get(propertyName).get(0));
}
}
}

private static void setChildren(Thing.Builder builder, Schema schema, Class<?> builderClass)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
throws InvocationTargetException, IllegalAccessException, ClassNotFoundException {

for (Schema child : schema.getChildren()) {
if (!StringUtils.isEmpty(child.getPropertyName())) {
Optional<Thing> optionalThing = convert(child);
if (optionalThing.isPresent()) {
String methodName = String.format("add%s", capitalize(child.getPropertyName()));
Method method = builderClass.getMethod(methodName, getInterfaceClass(getTypeName(child)));
method.invoke(builder, optionalThing.get());
try {
String methodName = String.format("add%s", capitalize(child.getPropertyName()));
Method method = builderClass.getMethod(methodName, getInterfaceClass(getTypeName(child)));
method.invoke(builder, optionalThing.get());
}
catch (NoSuchMethodException e){
builder.addProperty(child.getPropertyName(), optionalThing.get());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class MicrodataExtractor implements Extractor {

private static final String ITEM_PROP = "itemprop";

private static final String HYPERLINK_TAG = "a";

@Override
public List<Entity> getThings(Document document) {
Elements elements = getElements(document);
Expand Down Expand Up @@ -89,7 +87,7 @@ private Schema getTree(Element parent) {
}

private String getValue(Element element) {
if (HYPERLINK_TAG.equals(element.tagName()) && element.hasAttr("href")) {
if (element.hasAttr("href")) {
return element.attr("href");
}

Expand Down