Search in sources :

Example 1 with SearchDocumentRequest

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

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

Example 3 with SearchDocumentRequest

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

the class SearchDocumentService method createApplicationEventForService.

@Override
protected CreateApplicationEventRequest createApplicationEventForService(final SearchDocumentRequest serviceRequest) {
    final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
    eventRequest.setEventGroup(ApplicationEventGroup.USER);
    eventRequest.setApplicationOperation(ApplicationOperationType.READ);
    eventRequest.setActionName(SearchDocumentRequest.class.getSimpleName());
    eventRequest.setSessionId(serviceRequest.getSessionId());
    return eventRequest;
}
Also used : SearchDocumentRequest(com.hack23.cia.service.api.action.user.SearchDocumentRequest) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)

Example 4 with SearchDocumentRequest

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

the class SearchDocumentPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout panelContent = createPanelContent();
    final String pageId = getPageId(parameters);
    documentMenuItemFactory.createDocumentsMenuBar(menuBar);
    final VerticalLayout searchLayout = new VerticalLayout();
    searchLayout.setSizeFull();
    panelContent.addComponent(searchLayout);
    final VerticalLayout searchresultLayout = new VerticalLayout();
    searchresultLayout.setSizeFull();
    final Panel formPanel = new Panel();
    formPanel.setSizeFull();
    searchresultLayout.addComponent(formPanel);
    final FormLayout formContent = new FormLayout();
    formPanel.setContent(formContent);
    panelContent.addComponent(searchresultLayout);
    panelContent.setExpandRatio(searchresultLayout, ContentRatio.LARGE);
    final SearchDocumentRequest searchRequest = new SearchDocumentRequest();
    searchRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
    searchRequest.setMaxResults(MAX_RESULT_SIZE);
    searchRequest.setSearchExpression("");
    getFormFactory().addRequestInputFormFields(formContent, searchRequest, SearchDocumentRequest.class, AS_LIST, SEARCH, new SearchDocumentClickListener(searchRequest, new SearchDocumentResponseHandlerImpl(getGridFactory(), formPanel, searchresultLayout)));
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    return panelContent;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Panel(com.vaadin.ui.Panel) SearchDocumentResponseHandlerImpl(com.hack23.cia.web.impl.ui.application.views.pageclicklisteners.handlers.impl.SearchDocumentResponseHandlerImpl) SearchDocumentClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SearchDocumentClickListener) SearchDocumentRequest(com.hack23.cia.service.api.action.user.SearchDocumentRequest) VerticalLayout(com.vaadin.ui.VerticalLayout) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

SearchDocumentRequest (com.hack23.cia.service.api.action.user.SearchDocumentRequest)3 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)2 SearchDocumentResponse (com.hack23.cia.service.api.action.user.SearchDocumentResponse)2 Secured (org.springframework.security.access.annotation.Secured)2 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 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)1 SearchDocumentClickListener (com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SearchDocumentClickListener)1 SearchDocumentResponseHandlerImpl (com.hack23.cia.web.impl.ui.application.views.pageclicklisteners.handlers.impl.SearchDocumentResponseHandlerImpl)1 FormLayout (com.vaadin.ui.FormLayout)1 Panel (com.vaadin.ui.Panel)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1