Search in sources :

Example 1 with DocumentWordCountRequest

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

the class DocumentDataPageModContentFactoryImpl 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);
    final DataContainer<DocumentElement, String> documentElementDataContainer = getApplicationManager().getDataContainer(DocumentElement.class);
    final DataContainer<DocumentContentData, String> documentContentDataDataContainer = getApplicationManager().getDataContainer(DocumentContentData.class);
    getApplicationManager().getDataContainer(CommitteeProposalComponentData.class);
    final DocumentElement documentElement = documentElementDataContainer.load(pageId);
    if (documentElement != null) {
        getDocumentMenuItemFactory().createDocumentMenuBar(menuBar, pageId);
        LabelFactory.createHeader2Label(panelContent, DOCUMENT_DATA);
        final List<DocumentContentData> documentContentlist = documentContentDataDataContainer.getAllBy(DocumentContentData_.id, pageId);
        if (!documentContentlist.isEmpty()) {
            final Panel formPanel = new Panel();
            formPanel.setSizeFull();
            panelContent.addComponent(formPanel);
            final FormLayout formContent = new FormLayout();
            formPanel.setContent(formContent);
            final String cleanContent = Jsoup.clean(documentContentlist.get(0).getContent(), "", Whitelist.simpleText(), new OutputSettings().indentAmount(4));
            final Label htmlContent = new Label(cleanContent, ContentMode.HTML);
            formContent.addComponent(htmlContent);
            final DocumentWordCountRequest documentWordCountRequest = new DocumentWordCountRequest();
            documentWordCountRequest.setDocumentId(pageId);
            documentWordCountRequest.setMaxResults(MAX_RESULTS);
            documentWordCountRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
            final DocumentWordCountResponse resp = (DocumentWordCountResponse) getApplicationManager().service(documentWordCountRequest);
            if (resp.getWordCountMap() != null) {
                final Label wordCloud = new Label(createWordCloud(resp.getWordCountMap()), ContentMode.HTML);
                formContent.addComponent(wordCloud);
            }
            panelContent.setExpandRatio(formPanel, ContentRatio.GRID);
        }
        panel.setContent(panelContent);
        getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    }
    return panelContent;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Label(com.vaadin.ui.Label) DocumentWordCountResponse(com.hack23.cia.service.api.action.user.DocumentWordCountResponse) DocumentWordCountRequest(com.hack23.cia.service.api.action.user.DocumentWordCountRequest) DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Panel(com.vaadin.ui.Panel) OutputSettings(org.jsoup.nodes.Document.OutputSettings) DocumentElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement) VerticalLayout(com.vaadin.ui.VerticalLayout) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with DocumentWordCountRequest

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

the class DocumentWordCountServiceITest method Test.

/**
 * Test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void Test() throws Exception {
    setAuthenticatedAnonymousUser();
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final DocumentWordCountRequest serviceRequest = new DocumentWordCountRequest();
    serviceRequest.setSessionId(createSessionRequest.getSessionId());
    serviceRequest.setMaxResults(100);
    serviceRequest.setDocumentId("GNB47");
    final DocumentWordCountResponse response = (DocumentWordCountResponse) applicationManager.service(serviceRequest);
    assertNotNull("Expect a result", response);
    System.out.println(response.getWordCountMap());
    assertTrue("Expect a result", response.getWordCountMap().size() > 0);
}
Also used : CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) DocumentWordCountResponse(com.hack23.cia.service.api.action.user.DocumentWordCountResponse) DocumentWordCountRequest(com.hack23.cia.service.api.action.user.DocumentWordCountRequest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Example 3 with DocumentWordCountRequest

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

the class DocumentWordCountService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public DocumentWordCountResponse processService(final DocumentWordCountRequest serviceRequest) {
    final DocumentWordCountResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getDocumentId());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    final DocumentWordCountResponse response = new DocumentWordCountResponse(ServiceResult.SUCCESS);
    final DocumentContentData documentContentData = documentContentDataDAO.findFirstByProperty(DocumentContentData_.id, serviceRequest.getDocumentId());
    if (documentContentData == null) {
        response.setWordCountMap(new HashMap<>());
    } else {
        response.setWordCountMap(wordCounter.calculateWordCount(documentContentData, serviceRequest.getMaxResults()));
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : DocumentWordCountResponse(com.hack23.cia.service.api.action.user.DocumentWordCountResponse) 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 4 with DocumentWordCountRequest

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

the class DocumentWordCountService method createApplicationEventForService.

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

Aggregations

DocumentWordCountRequest (com.hack23.cia.service.api.action.user.DocumentWordCountRequest)3 DocumentWordCountResponse (com.hack23.cia.service.api.action.user.DocumentWordCountResponse)3 DocumentContentData (com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData)2 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)2 Secured (org.springframework.security.access.annotation.Secured)2 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 FormLayout (com.vaadin.ui.FormLayout)1 Label (com.vaadin.ui.Label)1 Panel (com.vaadin.ui.Panel)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 OutputSettings (org.jsoup.nodes.Document.OutputSettings)1 Test (org.junit.Test)1