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;
}
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);
}
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)"));
}
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();
}
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;
}
Aggregations