use of com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData in project cia by Hack23.
the class SearchDocumentService method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public SearchDocumentResponse processService(final SearchDocumentRequest serviceRequest) {
final SearchDocumentResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSearchExpression());
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
}
final SearchDocumentResponse response = new SearchDocumentResponse(ServiceResult.SUCCESS);
final List<DocumentElement> searchResultTitles = documentElementDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "title", "subTitle");
if (!searchResultTitles.isEmpty()) {
response.setResultElement(searchResultTitles);
} else {
final List<DocumentContentData> searchResultContent = documentContentDataDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "content");
if (!searchResultContent.isEmpty()) {
final List<DocumentElement> searchResultTitlesForContent = new ArrayList<>();
for (final DocumentContentData documentContent : searchResultContent) {
searchResultTitlesForContent.add(documentElementDAO.load(documentContent.getId()));
}
response.setResultElement(searchResultTitlesForContent);
}
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
return response;
}
Aggregations