Skip to content

Commit

Permalink
Thump
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Aug 1, 2023
1 parent 26a46a8 commit 93baede
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,16 @@ private AbstractIndexDocument createDocument(String subject) throws Instantiatio
AbstractIndexDocument document = construct();
Field field = FieldUtils.getField(type, ID, true);
field.set(document, parse(subject));
lookupProperties(document, subject);
lookupProperties(document, field, subject);
lookupSyncIds(document);
return document;
}

private void lookupProperties(AbstractIndexDocument document, String subject) {
private void lookupProperties(AbstractIndexDocument document, Field field, String subject) {
propertySourceTypeOps.parallelStream().forEach(typeOp -> {
try {
FieldSource source = typeOp.getPropertySource();
Model model = queryForModel(source, subject);



Model model = queryForModel(field, source, subject);

List<Object> values = lookupProperty(typeOp, source, model);

Expand All @@ -172,8 +169,11 @@ private void lookupProperties(AbstractIndexDocument document, String subject) {
});
}

private Model queryForModel(FieldSource source, String subject) {
String query = templateService.templateSparql(source.template(), subject);
// clean code author recommends avoiding triadic methods
private Model queryForModel(Field field, FieldSource source, String subject) {
String key = field.getName(); // property name or class member same as solr document field name
// what property from domain model
String query = templateService.templateSparql(source.template(), key, subject);
if (logger.isDebugEnabled()) {
logger.debug(String.format("%s:\n%s", source.template(), query));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,25 @@ public String template(String template, Object data) {
}
}

// clean code author recommends avoiding triadic methods
public String templateSparql(String name, String value) {
String path = String.format("templates/sparql/%s.sparql", name);
Map<String, String> data = new HashMap<String, String>();
// cost of increasing context variables?
data.put("uri", value);
data.put("subject", value);
Context context = Context.newBuilder(data).build();
try {
return handlebars.compileInline(resourceService.getTemplate(path)).apply(context);
} catch (IOException e) {
throw new RuntimeException(String.format("Unable to template %s sparql", name), e);
}
}

// clean code author recommends avoiding triadic methods
public String templateSparql(String name, String key, String value) {
String path = String.format("templates/sparql/%s.sparql", name);
Map<String, String> data = new HashMap<String, String>();
data.put("uri", value);
data.put("subject", key);
Context context = Context.newBuilder(data).build();
try {
return handlebars.compileInline(resourceService.getTemplate(path)).apply(context);
Expand Down

0 comments on commit 93baede

Please sign in to comment.