Search in sources :

Example 1 with DocumentContentData

use of com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData 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 DocumentContentData

use of com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData in project cia by Hack23.

the class SearchIndexerImplITest method testSearchIndex.

@Test
@Transactional(timeout = 900)
public void testSearchIndex() throws Exception {
    final QueryBuilder qb = getFullTextEntityManager().getSearchFactory().buildQueryBuilder().forEntity(DocumentContentData.class).get();
    final org.apache.lucene.search.Query luceneQuery = qb.keyword().onFields("content").matching("programmering").createQuery();
    // wrap Lucene query in a javax.persistence.Query
    final javax.persistence.Query jpaQuery = getFullTextEntityManager().createFullTextQuery(luceneQuery, DocumentContentData.class);
    // execute search
    final List<DocumentContentData> result = jpaQuery.setMaxResults(500).getResultList();
    assertTrue("expect some result", result.size() > 0);
}
Also used : QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DocumentContentData

use of com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData in project cia by Hack23.

the class RiksdagenDocumentApiImplITest method getDocumentContent.

/**
 * Gets the document content.
 *
 * @return the document content
 * @throws Exception
 *             the exception
 */
@Test
public void getDocumentContent() throws Exception {
    final DocumentContentData documentContent = riksdagenApi.getDocumentContent("GX11916");
    assertNotNull(documentContent);
    assertTrue(documentContent.getContent().contains("till statsrådet Cristina Husmark Pehrsson (m)"));
}
Also used : DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Test(org.junit.Test)

Example 4 with DocumentContentData

use of com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData in project cia by Hack23.

the class DocumentContentDataDAOImpl method checkDocumentContentData.

@Override
public boolean checkDocumentContentData(final String documentId) {
    final CriteriaQuery<DocumentContentData> criteriaQuery = getCriteriaBuilder().createQuery(DocumentContentData.class);
    final Root<DocumentContentData> root = criteriaQuery.from(DocumentContentData.class);
    criteriaQuery.select(root);
    final Predicate condition = getCriteriaBuilder().equal(root.get(DocumentContentData_.id), documentId);
    criteriaQuery.where(condition);
    final TypedQuery<DocumentContentData> typedQuery = getEntityManager().createQuery(criteriaQuery);
    addCacheHints(typedQuery, "checkDocumentContentData");
    final List<DocumentContentData> resultList = typedQuery.getResultList();
    return !resultList.isEmpty();
}
Also used : DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Predicate(javax.persistence.criteria.Predicate)

Example 5 with DocumentContentData

use of com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData 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)

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