1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.views.user.document.pagemode;
20
21 import java.util.List;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.springframework.security.access.annotation.Secured;
25 import org.springframework.stereotype.Component;
26
27 import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
28 import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentAttachment;
29 import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData;
30 import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData_;
31 import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
32 import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer_;
33 import com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData;
34 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
35 import com.hack23.cia.service.api.DataContainer;
36 import com.hack23.cia.web.impl.ui.application.action.ViewAction;
37 import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
38 import com.hack23.cia.web.impl.ui.application.views.common.pagelinks.impl.ExternalAttachmentDownloadLink;
39 import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
40 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.DocumentPageMode;
41 import com.vaadin.data.util.BeanItemContainer;
42 import com.vaadin.ui.Layout;
43 import com.vaadin.ui.MenuBar;
44 import com.vaadin.ui.Panel;
45 import com.vaadin.ui.VerticalLayout;
46
47
48
49
50 @Component
51 public final class DocumentAttachementsPageModContentFactoryImpl extends AbstractDocumentPageModContentFactoryImpl {
52
53
54 private static final String DOCUMENT_ATTACHMENTS = "Document Attachments";
55
56
57
58
59 public DocumentAttachementsPageModContentFactoryImpl() {
60 super();
61 }
62
63 @Override
64 public boolean matches(final String page, final String parameters) {
65 return NAME.equals(page) && (!StringUtils.isEmpty(parameters)
66 && parameters.contains(DocumentPageMode.DOCUMENTATTACHMENTS.toString()));
67 }
68
69 @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
70 @Override
71 public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
72 final VerticalLayout panelContent = createPanelContent();
73
74 final String pageId = getPageId(parameters);
75
76 final DataContainer<DocumentElement, String> documentElementDataContainer = getApplicationManager()
77 .getDataContainer(DocumentElement.class);
78
79 final DataContainer<DocumentStatusContainer, String> documentStatusContainerDataContainer = getApplicationManager()
80 .getDataContainer(DocumentStatusContainer.class);
81
82 getApplicationManager().getDataContainer(CommitteeProposalComponentData.class);
83
84 final DocumentElement documentElement = documentElementDataContainer.load(pageId);
85
86 if (documentElement != null) {
87
88 getDocumentMenuItemFactory().createDocumentMenuBar(menuBar, pageId);
89
90 final DocumentStatusContainer documentStatusContainer = documentStatusContainerDataContainer
91 .findByQueryProperty(DocumentStatusContainer.class, DocumentStatusContainer_.document,
92 DocumentData.class, DocumentData_.id, pageId);
93
94 LabelFactory.createHeader2Label(panelContent,DOCUMENT_ATTACHMENTS);
95
96
97 if (documentStatusContainer != null && documentStatusContainer.getDocumentAttachmentContainer() != null
98 && documentStatusContainer.getDocumentAttachmentContainer().getDocumentAttachmentList() != null) {
99 final BeanItemContainer<DocumentAttachment> documentAttachmentDataSource = new BeanItemContainer<>(
100 DocumentAttachment.class,
101 documentStatusContainer.getDocumentAttachmentContainer().getDocumentAttachmentList());
102
103 getGridFactory().createBasicBeanItemGrid(
104 panelContent, documentAttachmentDataSource,
105 "Document attachements", new String[] { "fileName", "fileSize", "fileType", "fileUrl" }, new String[] { "hjid" },
106 null, null, null);
107
108 final List<DocumentAttachment> documentAttachmentList = documentStatusContainer.getDocumentAttachmentContainer().getDocumentAttachmentList();
109
110 final VerticalLayout verticalLayout = new VerticalLayout();
111 panelContent.addComponent(verticalLayout);
112 panelContent.setExpandRatio(verticalLayout,ContentRatio.SMALL);
113
114 for (final DocumentAttachment documentAttachment : documentAttachmentList) {
115 final ExternalAttachmentDownloadLink link = new ExternalAttachmentDownloadLink(documentAttachment.getFileName(), documentAttachment.getFileType(), documentAttachment.getFileUrl());
116 verticalLayout.addComponent(link);
117 }
118 }
119
120 panel.setContent(panelContent);
121 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME,
122 parameters, pageId);
123 }
124
125 return panelContent;
126
127 }
128
129 }