Skip to content

Commit

Permalink
Implement the search methods
Browse files Browse the repository at this point in the history
  • Loading branch information
abollini committed Jun 1, 2018
1 parent ef46959 commit 162cc7a
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,32 @@ public Page<EPersonRest> findAll(Context context, Pageable pageable) {
@SearchRestMethod(name = "byName")
public Page<EPersonRest> findByName(@Parameter(value = "q", required = true) String q,
Pageable pageable) {
return null;
List<EPerson> epersons = null;
int total = 0;
try {
Context context = obtainContext();
epersons = es.search(context, q, pageable.getOffset(), pageable.getOffset() + pageable.getPageSize());
total = es.searchResultCount(context, q);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<EPersonRest> page = new PageImpl<EPerson>(epersons, pageable, total).map(converter);
return page;
}

@SearchRestMethod(name = "byEmail")
public EPersonRest findByEmail(@Parameter(value = "email", required = true) String email) {
return null;
EPerson eperson = null;
try {
Context context = obtainContext();
eperson = es.findByEmail(context, email);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (eperson == null) {
return null;
}
return converter.fromModel(eperson);
}

@Override
Expand Down

0 comments on commit 162cc7a

Please sign in to comment.