Search in sources :

Example 6 with DocumentContentData

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;
}
Also used : DocumentElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement) SearchDocumentResponse(com.hack23.cia.service.api.action.user.SearchDocumentResponse) ArrayList(java.util.ArrayList) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

DocumentContentData (com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData)6 Secured (org.springframework.security.access.annotation.Secured)3 DocumentElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement)2 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)2 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)2 DocumentWordCountResponse (com.hack23.cia.service.api.action.user.DocumentWordCountResponse)2 Test (org.junit.Test)2 DocumentWordCountRequest (com.hack23.cia.service.api.action.user.DocumentWordCountRequest)1 SearchDocumentResponse (com.hack23.cia.service.api.action.user.SearchDocumentResponse)1 FormLayout (com.vaadin.ui.FormLayout)1 Label (com.vaadin.ui.Label)1 Panel (com.vaadin.ui.Panel)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 ArrayList (java.util.ArrayList)1 Predicate (javax.persistence.criteria.Predicate)1 QueryBuilder (org.hibernate.search.query.dsl.QueryBuilder)1 OutputSettings (org.jsoup.nodes.Document.OutputSettings)1 Transactional (org.springframework.transaction.annotation.Transactional)1