Search in sources :

Example 1 with SearchDocumentResponse

use of com.hack23.cia.service.api.action.user.SearchDocumentResponse in project cia by Hack23.

the class SearchDocumentClickListener method buttonClick.

@Override
public void buttonClick(final ClickEvent event) {
    final SearchDocumentResponse response = (SearchDocumentResponse) ApplicationMangerAccess.getApplicationManager().service(reqisterRequest);
    if (ServiceResult.SUCCESS == response.getResult()) {
        LOGGER.info(LOG_MSG_SEARCH_DOCUMENT, reqisterRequest.getSearchExpression());
        Notification.show(SEARCH_SUCCESS, "Found :" + response.getResultElement().size(), Notification.Type.HUMANIZED_MESSAGE);
        responseHandler.handle(response);
    } else {
        Notification.show(SEARCH_FAILED, ERROR_MESSAGE, Notification.Type.WARNING_MESSAGE);
        LOGGER.info(LOG_MSG_SEARCH_DOCUMENT_FAILURE, reqisterRequest.getSearchExpression());
    }
}
Also used : SearchDocumentResponse(com.hack23.cia.service.api.action.user.SearchDocumentResponse)

Example 2 with SearchDocumentResponse

use of com.hack23.cia.service.api.action.user.SearchDocumentResponse in project cia by Hack23.

the class SearchDocumentServiceITest method Test.

/**
 * Test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void Test() throws Exception {
    setAuthenticatedAnonymousUser();
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final SearchDocumentRequest serviceRequest = new SearchDocumentRequest();
    serviceRequest.setSessionId(createSessionRequest.getSessionId());
    serviceRequest.setMaxResults(10);
    serviceRequest.setSearchExpression("kan");
    final SearchDocumentResponse response = (SearchDocumentResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertTrue(EXPECT_A_RESULT, response.getResultElement().size() > 0);
}
Also used : CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) SearchDocumentRequest(com.hack23.cia.service.api.action.user.SearchDocumentRequest) SearchDocumentResponse(com.hack23.cia.service.api.action.user.SearchDocumentResponse) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Example 3 with SearchDocumentResponse

use of com.hack23.cia.service.api.action.user.SearchDocumentResponse 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

SearchDocumentResponse (com.hack23.cia.service.api.action.user.SearchDocumentResponse)3 DocumentContentData (com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData)1 DocumentElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement)1 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)1 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)1 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 SearchDocumentRequest (com.hack23.cia.service.api.action.user.SearchDocumentRequest)1 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Secured (org.springframework.security.access.annotation.Secured)1