Removed depcrecated package com/arsdigita/cms/ui/report

pull/28/head
Jens Pelzetter 2022-03-16 19:57:38 +01:00
parent 7e3b0821bb
commit d73bfd03b5
6 changed files with 0 additions and 552 deletions

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class ContentSectionSummaryController {
@Inject
private ContentSectionRepository sectionRepo;
@Inject
private ContentItemManager itemManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Transactional(Transactional.TxType.REQUIRED)
public List<RowData<Long>> createReportData(final ContentSection section) {
final ContentSection contentSection = sectionRepo.findById(
section.getObjectId()).get();
final List<Folder> rootFolders = contentSection.getRootDocumentsFolder()
.getSubFolders();
final List<RowData<Long>> data = new ArrayList<>();
for (final Folder folder : rootFolders) {
data.addAll(createFolderData(folder));
}
return data;
}
private List<RowData<Long>> createFolderData(final Folder folder) {
final List<RowData<Long>> data = new ArrayList<>();
final long subFolderCount = countSubFolders(folder);
final List<ContentTypeFolderInfo> contentTypeInfo = generateContentTypeInfoForFolder(
folder);
final RowData<Long> 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<Long> createRow(final ContentTypeFolderInfo info) {
final RowData<Long> 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<ContentTypeFolderInfo> generateContentTypeInfoForFolder(
final Folder folder) {
final Map<String, ContentTypeFolderInfo> dataMap = new HashMap<>();
generateContentTypeInfoForFolder(folder, dataMap);
final List<ContentTypeFolderInfo> 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<String, ContentTypeFolderInfo> 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++;
}
}
}

View File

@ -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
* <a href="https://sourceforge.net/users/thomas-buckel/">thomas-buckel</a>
*/
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)));
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class ContentSectionSummaryTableModel implements TableModel {
private final Iterator<RowData<Long>> iterator;
private RowData<Long> currentRow;
protected ContentSectionSummaryTableModel(final List<RowData<Long>> 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();
}
}

View File

@ -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
* <a href="https://sourceforge.net/users/thomas-buckel/">thomas-buckel</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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<RowData<Long>> rows = controller.createReportData(section);
return new ContentSectionSummaryTableModel(rows);
}
}

View File

@ -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 <a href="https://sourceforge.net/users/thomas-buckel/">thomas-buckel</a>
* @author <a href="https://sourceforge.net/users/tim-permeance/">tim-permeance</a>
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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);
}
}

View File

@ -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 <a href="https://sourceforge.net/users/thomas-buckel/">thomas-buckel</a>
* @author <a href="https://sourceforge.net/users/tim-permeance/">tim-permeance</a>
*/
public class ReportListModel implements ListModel {
private int m_index = -1;
private final List<Report> m_reports;
public ReportListModel(List<Report> 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);
}
}