001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger <troger@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.quota.count; 019 020import static org.nuxeo.ecm.quota.count.Constants.DOCUMENTS_COUNT_STATISTICS_CHILDREN_COUNT_PROPERTY; 021import static org.nuxeo.ecm.quota.count.Constants.DOCUMENTS_COUNT_STATISTICS_DESCENDANTS_COUNT_PROPERTY; 022 023import org.nuxeo.ecm.core.api.DocumentModel; 024import org.nuxeo.ecm.core.api.PropertyException; 025import org.nuxeo.ecm.core.api.quota.QuotaStatsNonFolderishCount; 026 027/** 028 * Adapter implementing {@code QuotaStatsNonFolderishCount} to have information about children and descendants count. 029 * 030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 031 * @since 5.5 032 */ 033public class QuotaStatsNonFolderishCountAdapter implements QuotaStatsNonFolderishCount { 034 035 private final DocumentModel doc; 036 037 public QuotaStatsNonFolderishCountAdapter(DocumentModel doc) { 038 this.doc = doc; 039 } 040 041 @Override 042 public long getIntrinsic() { 043 return 0; 044 } 045 046 @Override 047 public long getChildren() { 048 try { 049 Long count = (Long) doc.getPropertyValue(DOCUMENTS_COUNT_STATISTICS_CHILDREN_COUNT_PROPERTY); 050 return count != null ? count : 0; 051 } catch (PropertyException e) { 052 return 0; 053 } 054 } 055 056 @Override 057 public long getTotal() { 058 try { 059 Long count = (Long) doc.getPropertyValue(DOCUMENTS_COUNT_STATISTICS_DESCENDANTS_COUNT_PROPERTY); 060 return count != null ? count : 0; 061 } catch (PropertyException e) { 062 return 0; 063 } 064 } 065 066}