diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java index a28e042af..78762828f 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java @@ -36,7 +36,7 @@ import org.librecms.contentsection.ContentSection; import com.arsdigita.cms.dispatcher.CMSPage; //ToDo NG import com.arsdigita.cms.ui.category.CategoryAdminPane; -//ToDo NG import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; +import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; import com.arsdigita.cms.ui.folder.FolderAdminPane; import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane; //import com.arsdigita.cms.ui.role.RoleAdminPane; @@ -335,7 +335,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { if (m_csePane == null) { m_csePane = new LayoutPanel(); m_csePane.setLeft(new SimpleComponent()); -//ToDo NG m_csePane.setBody(new ContentSoonExpiredPane()); + m_csePane.setBody(new ContentSoonExpiredPane()); } return m_csePane; } @@ -454,7 +454,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { // } else if (pane == m_userAdminPane) { //m_userAdminPane.reset(state); } else if (pane == m_csePane) { - //m_csePane.reset(state); + m_csePane.reset(state); } } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java new file mode 100755 index 000000000..125a29417 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2002-2005 Runtime Collective Ltd. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.arsdigita.cms.ui.cse; + +import com.arsdigita.bebop.SimpleContainer; + +/** + * A pane that contains details to soon to be expired content. + * + * @author Unknown + * @author Jens Pelzetter + */ +public class ContentSoonExpiredPane extends SimpleContainer { + + public ContentSoonExpiredPane() { + super(); + add(new ContentSoonExpiredTable()); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java.off deleted file mode 100755 index 34f1bb2dc..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java.off +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2002-2005 Runtime Collective Ltd. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package com.arsdigita.cms.ui.cse; - -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Link; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.cms.CMS; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentSection; -import com.arsdigita.cms.ui.ContentItemPage; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.cms.util.SecurityConstants; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.User; -import com.arsdigita.kernel.permissions.PermissionDescriptor; -import com.arsdigita.kernel.permissions.PermissionService; -import com.arsdigita.kernel.permissions.PrivilegeDescriptor; -import com.arsdigita.persistence.DataQuery; -import com.arsdigita.persistence.Filter; -import com.arsdigita.persistence.FilterFactory; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.Session; -import com.arsdigita.persistence.SessionManager; -import com.arsdigita.toolbox.ui.DataQueryBuilder; -import com.arsdigita.toolbox.ui.DataTable; -import com.arsdigita.ui.admin.Admin; -import com.arsdigita.web.Application; -import com.arsdigita.web.Web; -import com.arsdigita.xml.Element; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Component; - -import java.math.BigDecimal; -import java.util.Calendar; -import java.util.Iterator; - -import org.apache.log4j.Logger; - -/** - * A pane that contains details to soon to be expired content. - * - * @version $Id: ContentSoonExpiredPane.java 775 2005-09-12 14:54:17Z fabrice $ - */ -public class ContentSoonExpiredPane extends SimpleContainer { - - private static final Logger log = Logger.getLogger(ContentSoonExpiredPane.class); - - private DataTable dataTable; - - public ContentSoonExpiredPane() { - add(getDataTable()); - } - - public final void generateXML(final PageState state, final Element parent) { - if (!isVisible(state)) { - return; - } - - SecurityManager sm = CMS.getContext().getSecurityManager(); - User user = Web.getWebContext().getUser(); - - DataTable dt = getDataTable(); - DataQuery dq = dt.getDataQuery(state); - dq.addFilter(getViewFilter(dq, user)); - - dt.generateXML(state, parent); - - } - - private static Filter getViewFilter(DataQuery query, User user) { - PrivilegeDescriptor privilege = new PrivilegeDescriptor(SecurityConstants.CMS_READ_ITEM); - FilterFactory ff = query.getFilterFactory(); - OID partyOID = user.getOID(); - return PermissionService.getFilterQuery(ff, "objectId", privilege, partyOID); - } - - protected DataTable getDataTable() { - if (dataTable == null) { - dataTable = new DataTable(new ContentSoonExpiredQueryBuilder()); - dataTable.addColumn(GlobalizationUtil.globalize("cms.ui.cse.authorName").localize() - .toString(), - "authorName", true); - dataTable.addColumn(GlobalizationUtil.globalize("cms.ui.cse.itemName").localize() - .toString(), - "objectId", true, new ItemTitleCellRender()); - dataTable - .addColumn(GlobalizationUtil.globalize("cms.ui.cse.view").localize().toString(), - "objectId", false, new ItemViewLinkCellRender()); - dataTable - .addColumn(GlobalizationUtil.globalize("cms.ui.cse.edit").localize().toString(), - "objectId", false, new ItemEditLinkCellRender()); - dataTable.addColumn(GlobalizationUtil.globalize("cms.ui.cse.endDateTime").localize() - .toString(), - "endDateTime", true); - - dataTable.setEmptyView(new Label(GlobalizationUtil.globalize("cms.ui.cse.none"))); - } - - return dataTable; - } - - private static boolean hasSiteWideAdmin(User user) { - Application adminApp = Admin.getInstance(); - if (adminApp == null) { - return false; - } - - PermissionDescriptor admin = new PermissionDescriptor(PrivilegeDescriptor.ADMIN, adminApp, - user); - return PermissionService.checkPermission(admin); - } - - private static GlobalizedMessage gz(final String key) { - return GlobalizationUtil.globalize(key); - } - - private static String lz(final String key) { - return (String) gz(key).localize(); - } - - private class ContentSoonExpiredQueryBuilder implements DataQueryBuilder { - - public String getKeyColumn() { - return "objectId"; - } - - public DataQuery makeDataQuery(DataTable t, PageState s) { - Session ses = SessionManager.getSession(); - DataQuery query = ses.retrieveQuery( - "com.arsdigita.cms.getContentItemExpiredBeforeInSection"); - - int months = ContentSection.getConfig().getSoonExpiredMonths(); - int days = ContentSection.getConfig().getSoonExpiredDays(); - - Calendar now = Calendar.getInstance(); - now.add(Calendar.DAY_OF_YEAR, days); - now.add(Calendar.MONTH, months); - query.setParameter("endDateTime", now.getTime()); - - ContentSection section = CMS.getContext().getContentSection(); - query.setParameter("sectionId", section.getID()); - - return query; - } - - public void lock() { - } - - public boolean isLocked() { - return false; - } - - } - - private class ItemTitleCellRender implements TableCellRenderer { - - private ThreadLocal threadLocal; - - public ItemTitleCellRender() { - threadLocal = new ThreadLocal() { - - protected Object initialValue() { - return new Label(""); - } - - }; - } - - public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, - int row, int column) { - BigDecimal id = (BigDecimal) key; - Label l = (Label) threadLocal.get(); - l.setLabel(ContentSoonExpiredPane.getItemFromIdString(id.toString()).getDisplayName()); - return l; - } - - } - - private class ItemEditLinkCellRender implements TableCellRenderer { - - private ThreadLocal threadLocal; - - public ItemEditLinkCellRender() { - threadLocal = new ThreadLocal() { - - protected Object initialValue() { - return new Link(new Label(), ""); - } - - }; - } - - public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, - int row, int column) { - boolean canEdit = false; - BigDecimal id = (BigDecimal) key; - User user = Web.getWebContext().getUser(); - ContentItem ci = getItemFromIdString(id.toString()); - Iterator permissions = PermissionService - .getImpliedPrivileges(ci.getOID(), user.getOID()); - while (permissions.hasNext()) { - PrivilegeDescriptor permission = (PrivilegeDescriptor) permissions.next(); - if (permission.equals(PrivilegeDescriptor.ADMIN) || permission.equals( - PrivilegeDescriptor.EDIT)) { - canEdit = true; - break; - } - } - - if (!canEdit) { - return new Label(""); - } - - Link l = (Link) threadLocal.get(); -// l.setTarget(ContentItemPage.getRelativeItemURL(ContentSoonExpiredPane.getItemDraft(id.toString()), ContentItemPage.AUTHORING_TAB)); - l.setTarget(ContentItemPage.getItemURL(ContentSoonExpiredPane.getItemFromIdString(id - .toString()), ContentItemPage.AUTHORING_TAB)); - ((Label) l.getChild()).setLabel(GlobalizationUtil.globalize("cms.ui.cse.editLink")); - - return l; - } - - } - - private class ItemViewLinkCellRender implements TableCellRenderer { - - private ThreadLocal threadLocal; - - public ItemViewLinkCellRender() { - threadLocal = new ThreadLocal() { - - protected Object initialValue() { - return new Link(new Label(), ""); - } - - }; - } - - public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, - int row, int column) { - BigDecimal id = (BigDecimal) key; - Link l = (Link) threadLocal.get(); - - ContentItem item = getItemFromIdString(id.toString()); - String url = ".jsp"; - while (item.getParent() != null) { - if (item.getParent() instanceof ContentItem) { - item = (ContentItem) item.getParent(); - if (!"/".equals(item.getName())) { - url = "/" + item.getName() + url; - } else { - break; - } - } - } - ContentSection section = CMS.getContext().getContentSection(); - l.setTarget("/" + section.getName() + url); - - ((Label) l.getChild()).setLabel(GlobalizationUtil.globalize("cms.ui.cse.viewLink")); - return l; - } - - } - - private static ContentItem getItemFromIdString(String idString) { - return new ContentItem(new OID(ContentItem.class.getName(), Integer.parseInt(idString))); - } - - private static BigDecimal getItemDraft(String idString) { - ContentItem item = getItemFromIdString(idString); - return item.getDraftVersion().getID(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java new file mode 100644 index 000000000..42da3e254 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.cse; + +import com.arsdigita.bebop.table.RowData; + +import org.arsdigita.cms.CMSConfig; +import org.libreccm.auditing.CcmRevision; +import org.libreccm.configuration.ConfigurationManager; +import org.libreccm.l10n.GlobalizationHelper; +import org.libreccm.security.PermissionChecker; +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentItemRepository; +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.privileges.ItemPrivileges; + +import java.text.DateFormat; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; +import javax.transaction.Transactional; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class ContentSoonExpiredPaneController { + + @Inject + private EntityManager entityManager; + + @Inject + private ConfigurationManager confManager; + + @Inject + private ContentItemRepository itemRepo; + + @Inject + private GlobalizationHelper globalizationHelper; + + @Inject + private PermissionChecker permissionChecker; + + @Transactional(Transactional.TxType.REQUIRED) + public List> getSoonExpiredItems( + final ContentSection section) { + final TypedQuery query = entityManager.createQuery( + "SELECT i FROM ContentItem i " + + "WHERE i.contentType.contentSection = :section " + + "AND :endDateTime <= i.lifecycle.endDateTime", + ContentItem.class); + + final CMSConfig cmsConfig = confManager.findConfiguration( + CMSConfig.class); + final int months = cmsConfig.getSoonExpiredTimespanMonths(); + final int days = cmsConfig.getSoonExpiredTimespanDays(); + + final Calendar date = Calendar.getInstance(Locale.ROOT); + date.add(Calendar.DAY_OF_YEAR, days); + date.add(Calendar.MONTH, months); + query.setParameter("endDateTime", date.getTime()); + + query.setParameter("section", section); + + final List result = query.getResultList(); + + return result.stream() + .map(item -> createRow(item)) + .collect(Collectors.toList()); + + } + + private RowData createRow(final ContentItem item) { + final RowData row = new RowData<>(5); + row.setRowKey(item.getObjectId()); + + final CcmRevision current = itemRepo.retrieveCurrentRevision( + item, item.getObjectId()); + row.setColData(ContentSoonExpiredTable.COL_AUTHOR_NAME, + current.getUserName()); + + row.setColData(ContentSoonExpiredTable.COL_ITEM_NAME, + item.getDisplayName()); + + row.setColData(ContentSoonExpiredTable.COL_VIEW, + item.getUuid()); + + if (permissionChecker.isPermitted(ItemPrivileges.EDIT, item)) { + row.setColData(ContentSoonExpiredTable.COL_EDIT, + item.getUuid()); + } else { + row.setColData(ContentSoonExpiredTable.COL_EDIT, + "--"); + } + + final DateFormat dateFormat = DateFormat.getDateTimeInstance( + DateFormat.LONG, + DateFormat.LONG, + globalizationHelper.getNegotiatedLocale()); + row.setColData(ContentSoonExpiredTable.COL_END_DATE_TIME, + dateFormat.format(item.getLifecycle().getEndDateTime())); + + return row; + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java new file mode 100644 index 000000000..7d1316ed2 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.cse; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.Link; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.Text; +import com.arsdigita.bebop.table.TableCellRenderer; +import com.arsdigita.bebop.table.TableColumn; +import com.arsdigita.bebop.table.TableColumnModel; +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ui.ContentItemPage; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.web.Web; + +import org.librecms.CmsConstants; +import org.librecms.contentsection.ContentSection; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +/** + * + * @author Jens Pelzetter + */ +public class ContentSoonExpiredTable extends Table { + + protected static final int COL_AUTHOR_NAME = 0; + protected static final int COL_ITEM_NAME = 1; + protected static final int COL_VIEW = 2; + protected static final int COL_EDIT = 3; + protected static final int COL_END_DATE_TIME = 4; + + public ContentSoonExpiredTable() { + super(); + + final ContentSection section = CMS.getContext().getContentSection(); + + setModelBuilder(new ContentSoonExpiredTableModelBuilder()); + + final TableColumnModel columnModel = getColumnModel(); + columnModel.add(new TableColumn( + COL_AUTHOR_NAME, + new Label(new GlobalizedMessage("cms.ui.cse.authorName", + CmsConstants.CMS_BUNDLE)))); + columnModel.add(new TableColumn( + COL_ITEM_NAME, + new Label(new GlobalizedMessage("cms.ui.cse.itemName", + CmsConstants.CMS_BUNDLE)))); + columnModel.add(new TableColumn( + COL_VIEW, + new Label(new GlobalizedMessage("cms.ui.cse.view", + CmsConstants.CMS_BUNDLE)))); + columnModel.add(new TableColumn( + COL_EDIT, + new Label(new GlobalizedMessage("cms.ui.cse.edit", + CmsConstants.CMS_BUNDLE)))); + columnModel.add(new TableColumn( + COL_END_DATE_TIME, + new Label(new GlobalizedMessage("cms.ui.cse.endDateTime", + CmsConstants.CMS_BUNDLE)))); + + columnModel.get(COL_VIEW).setCellRenderer(new TableCellRenderer() { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + try { + final Link link = new Link( + new Label(new GlobalizedMessage( + "cms.ui.cse.viewLink", + CmsConstants.CMS_BUNDLE)), + String.format( + "%s/redirect/?oid=%s", + Web.getWebappContextPath(), + URLEncoder.encode( + (String) value, "UTF-8"))); + return link; + } catch (UnsupportedEncodingException ex) { + throw new UncheckedWrapperException(ex); + } + } + + }); + + columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + if ("--".equals(value)) { + //No access for current user + return new Text(""); + } else { + return new Link(new Label(new GlobalizedMessage( + "cms.ui.cse.editLink", + CmsConstants.CMS_BUNDLE)), + ContentItemPage.getItemURL( + (Long) key, + ContentItemPage.AUTHORING_TAB)); + } + } + + }); + + setEmptyView(new Label(new GlobalizedMessage("cms.ui.cse.none", + CmsConstants.CMS_BUNDLE))); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java new file mode 100644 index 000000000..b7f4b5e33 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.cse; + +import com.arsdigita.bebop.table.RowData; +import com.arsdigita.bebop.table.TableModel; + +import java.util.Iterator; +import java.util.List; + +/** + * + * @author Jens Pelzetter + */ +class ContentSoonExpiredTableModel implements TableModel { + + private final Iterator> iterator; + private RowData currentRow; + + protected ContentSoonExpiredTableModel(final List> rows) { + iterator = rows.iterator(); + } + + @Override + public int getColumnCount() { + return 5; + } + + @Override + public boolean nextRow() { + if (iterator.hasNext()) { + currentRow = iterator.next(); + return true; + } else { + return false; + } + } + + @Override + public Object getElementAt(final int columnIndex) { + switch (columnIndex) { + case ContentSoonExpiredTable.COL_AUTHOR_NAME: + return currentRow.getColData( + ContentSoonExpiredTable.COL_AUTHOR_NAME); + case ContentSoonExpiredTable.COL_ITEM_NAME: + return currentRow.getColData( + ContentSoonExpiredTable.COL_ITEM_NAME); + case ContentSoonExpiredTable.COL_VIEW: + return currentRow.getColData(ContentSoonExpiredTable.COL_VIEW); + case ContentSoonExpiredTable.COL_EDIT: + return currentRow.getColData(ContentSoonExpiredTable.COL_EDIT); + case ContentSoonExpiredTable.COL_END_DATE_TIME: + return currentRow.getColData( + ContentSoonExpiredTable.COL_END_DATE_TIME); + default: + throw new IllegalArgumentException("Invalid column index."); + } + } + + @Override + public Object getKeyAt(final int columnIndex) { + return currentRow.getRowKey(); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java new file mode 100644 index 000000000..abd71f357 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.cse; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.table.RowData; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.CMS; +import com.arsdigita.util.LockableImpl; + +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentSection; + +import java.util.List; + +/** + * + * @author Jens Pelzetter + */ +class ContentSoonExpiredTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + @Override + public TableModel makeModel(final Table table, final PageState state) { + + final ContentSection section = CMS.getContext().getContentSection(); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentSoonExpiredPaneController controller = cdiUtil.findBean( + ContentSoonExpiredPaneController.class); + + final List> rows = controller.getSoonExpiredItems(section); + + return new ContentSoonExpiredTableModel(rows); + } + +}