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