diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java deleted file mode 100644 index b5da98d2c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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.report; - -import com.arsdigita.bebop.table.RowData; - -import org.libreccm.categorization.Categorization; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemManager; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionRepository; -import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.Folder; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class ContentSectionSummaryController { - - @Inject - private ContentSectionRepository sectionRepo; - - @Inject - private ContentItemManager itemManager; - - @Inject - private GlobalizationHelper globalizationHelper; - - @Transactional(Transactional.TxType.REQUIRED) - public List> createReportData(final ContentSection section) { - final ContentSection contentSection = sectionRepo.findById( - section.getObjectId()).get(); - - final List rootFolders = contentSection.getRootDocumentsFolder() - .getSubFolders(); - - final List> data = new ArrayList<>(); - - for (final Folder folder : rootFolders) { - data.addAll(createFolderData(folder)); - } - - return data; - } - - private List> createFolderData(final Folder folder) { - final List> data = new ArrayList<>(); - - final long subFolderCount = countSubFolders(folder); - final List contentTypeInfo = generateContentTypeInfoForFolder( - folder); - - final RowData firstRow = new RowData<>(5); - firstRow.setRowKey(-1L); - firstRow.setColData(ContentSectionSummaryTable.COL_FOLDER_NAME, - folder.getDisplayName()); - firstRow.setColData(ContentSectionSummaryTable.COL_SUBFOLDER_COUNT, - Long.toString(subFolderCount)); - firstRow.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - contentTypeInfo.get(0).getTypeName()); - firstRow.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - Long.toString(contentTypeInfo.get(0).getDraftCount())); - firstRow.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - Long.toString(contentTypeInfo.get(0).getLiveCount())); - data.add(firstRow); - - for(int i = 1; i < contentTypeInfo.size(); i++) { - data.add(createRow(contentTypeInfo.get(i))); - } - - return data; - } - - private RowData createRow(final ContentTypeFolderInfo info) { - final RowData row = new RowData<>(5); - - row.setRowKey(-1L); - row.setColData(ContentSectionSummaryTable.COL_FOLDER_NAME, ""); - row.setColData(ContentSectionSummaryTable.COL_SUBFOLDER_COUNT, ""); - row.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - info.getTypeClassName()); - row.setColData(ContentSectionSummaryTable.COL_DRAFT_COUNT, - Long.toString(info.getDraftCount())); - row.setColData(ContentSectionSummaryTable.COL_LIVE_COUNT, - Long.toString(info.getLiveCount())); - - return row; - } - - private long countSubFolders(final Folder folder) { - long count = 0; - for (final Folder subFolder : folder.getSubFolders()) { - count++; - count += countSubFolders(subFolder); - } - - return count; - } - - private List generateContentTypeInfoForFolder( - final Folder folder) { - - final Map dataMap = new HashMap<>(); - generateContentTypeInfoForFolder(folder, dataMap); - final List data = new ArrayList<>(dataMap - .values()); - Collections.sort( - data, - (info1, info2) -> { - return info1.getTypeName().compareTo(info2.getTypeName()); - }); - return data; - } - - private void generateContentTypeInfoForFolder( - final Folder folder, final Map data) { - - for (final Categorization categorization : folder.getObjects()) { - if (!(categorization.getCategorizedObject() instanceof ContentItem)) { - continue; - } - - final ContentItem item = (ContentItem) categorization - .getCategorizedObject(); - final ContentType type = item.getContentType(); - - final ContentTypeFolderInfo info; - if (data.containsKey(type.getContentItemClass())) { - info = data.get(type.getContentItemClass()); - } else { - info = new ContentTypeFolderInfo( - type.getContentItemClass(), - type.getLabel().getValue(globalizationHelper - .getNegotiatedLocale())); - } - info.increaseDraftCount(); - if (itemManager.isLive(item)) { - info.increaseLiveCount(); - } - } - - for (final Folder subFolder : folder.getSubFolders()) { - generateContentTypeInfoForFolder(subFolder, data); - } - } - - private class ContentTypeFolderInfo { - - private final String typeClassName; - private final String typeName; - private long draftCount = 0; - private long liveCount = 0; - - public ContentTypeFolderInfo(final String typeClassName, - final String typeName) { - this.typeClassName = typeClassName; - this.typeName = typeName; - } - - public String getTypeClassName() { - return typeClassName; - } - - public String getTypeName() { - return typeName; - } - - public long getDraftCount() { - return draftCount; - } - - public void increaseDraftCount() { - draftCount++; - } - - public long getLiveCount() { - return liveCount; - } - - public void increaseLiveCount() { - liveCount++; - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java deleted file mode 100644 index a1c7b27a6..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty 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.report; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.globalization.GlobalizedMessage; -import org.librecms.CmsConstants; - -/** - * Table component for content section summary report. - * - * @author - * thomas-buckel - */ -public class ContentSectionSummaryTable extends Table { - - public static final int COL_FOLDER_NAME = 0; - public static final int COL_SUBFOLDER_COUNT = 1; - public static final int COL_CONTENT_TYPE = 2; - public static final int COL_DRAFT_COUNT = 3; - public static final int COL_LIVE_COUNT = 4; - - public ContentSectionSummaryTable() { - super(); - - setModelBuilder(new ContentSectionSummaryTableModelBuilder()); - - final TableColumnModel columnModel = getColumnModel(); - columnModel.add(new TableColumn( - COL_FOLDER_NAME, - new Label(new GlobalizedMessage("cms.ui.reports.css.folder", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_SUBFOLDER_COUNT, - new Label(new GlobalizedMessage( - "cms.ui.reports.css.subfolderCount", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_CONTENT_TYPE, - new Label( - new GlobalizedMessage("cms.ui.reports.css.contentType", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_DRAFT_COUNT, - new Label(new GlobalizedMessage("cms.ui.reports.css.draft", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_LIVE_COUNT, - new Label(new GlobalizedMessage("cms.ui.reports.css.live", - CmsConstants.CMS_BUNDLE)))); - - setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.reports.css.emptyResult", - CmsConstants.CMS_BUNDLE))); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java deleted file mode 100644 index 82a36270d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.report; - -import com.arsdigita.bebop.table.RowData; -import com.arsdigita.bebop.table.TableModel; -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class ContentSectionSummaryTableModel implements TableModel { - - private final Iterator> iterator; - private RowData currentRow; - - protected ContentSectionSummaryTableModel(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 ContentSectionSummaryTable.COL_FOLDER_NAME: - return currentRow.getColData( - ContentSectionSummaryTable.COL_FOLDER_NAME); - case ContentSectionSummaryTable.COL_SUBFOLDER_COUNT: - return currentRow.getColData( - ContentSectionSummaryTable.COL_SUBFOLDER_COUNT); - case ContentSectionSummaryTable.COL_CONTENT_TYPE: - return currentRow.getColData( - ContentSectionSummaryTable.COL_CONTENT_TYPE); - case ContentSectionSummaryTable.COL_DRAFT_COUNT: - return currentRow.getColData( - ContentSectionSummaryTable.COL_DRAFT_COUNT); - case ContentSectionSummaryTable.COL_LIVE_COUNT: - return currentRow.getColData( - ContentSectionSummaryTable.COL_LIVE_COUNT); - 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/report/ContentSectionSummaryTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModelBuilder.java deleted file mode 100644 index 92c180cc7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModelBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty 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.report; - -import java.util.List; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.AbstractTableModelBuilder; -import com.arsdigita.bebop.table.RowData; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.CMS; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentSection; - -/** - * TableModelBuilder that creates a model for the content section summary - * report. - * - * @author - * thomas-buckel - * @author Jens Pelzetter - */ -class ContentSectionSummaryTableModelBuilder - extends AbstractTableModelBuilder { - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentSectionSummaryController controller = cdiUtil.findBean( - ContentSectionSummaryController.class); - - final List> rows = controller.createReportData(section); - - return new ContentSectionSummaryTableModel(rows); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java deleted file mode 100644 index f3bb4d558..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty 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.report; - -import com.arsdigita.bebop.Component; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.Assert; - -import org.librecms.CmsConstants; - -/** - * UI model for a report. - * A report has a name and a component that displays the report. - * - * @author thomas-buckel - * @author tim-permeance - * @author Jens Pelzetter - */ -public class Report { - - private final String key; - private final String name; - private final Component component; - - public Report(final String key, final Component component) { - Assert.exists(key, "Key for report is required"); - Assert.isTrue(key.length() > 0, "Key for report must not be empty"); - Assert.exists(component, "Component for report is required"); - - this.key = key; - name = gz(key).localize().toString(); - this.component = component; - } - - public String getKey() { - return key; - } - - public String getName() { - return name; - } - - public Component getComponent() { - return component; - } - - protected final static GlobalizedMessage gz(final String key) { - return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java deleted file mode 100644 index ebcca8a84..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty 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.report; - -import java.util.List; - -import com.arsdigita.bebop.list.ListModel; -import com.arsdigita.util.Assert; - -/** - * ListModel for Reports. - * - * @author thomas-buckel - * @author tim-permeance - */ -public class ReportListModel implements ListModel { - - private int m_index = -1; - private final List m_reports; - - public ReportListModel(List reports) { - Assert.exists(reports); - m_reports = reports; - } - - @Override - public Object getElement() { - return m_reports.get(m_index).getName(); - } - - @Override - public String getKey() { - return m_reports.get(m_index).getKey(); - } - - @Override - public boolean next() { - m_index++; - return (m_reports.size() > m_index); - } - -}