mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
Refactor other classes affected by move of item counting from CommunityService to ItemService. Also cleanup horrible spacing/alignment in ItemCounter
This commit is contained in:
@@ -15,10 +15,11 @@ import org.dspace.content.service.CommunityService;
|
|||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.dspace.services.ConfigurationService;
|
||||||
|
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a standard interface to all item counting
|
* This class provides a standard interface to all item counting
|
||||||
@@ -37,189 +38,191 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ItemCounter
|
public class ItemCounter
|
||||||
{
|
{
|
||||||
/** Log4j logger */
|
/** Log4j logger */
|
||||||
private static Logger log = Logger.getLogger(ItemCounter.class);
|
private static Logger log = Logger.getLogger(ItemCounter.class);
|
||||||
|
|
||||||
/** DAO to use to store and retrieve data */
|
/** DAO to use to store and retrieve data */
|
||||||
private ItemCountDAO dao;
|
private ItemCountDAO dao;
|
||||||
|
|
||||||
/** DSpace Context */
|
/** DSpace Context */
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
protected CommunityService communityService;
|
protected CommunityService communityService;
|
||||||
protected ItemService itemService;
|
protected ItemService itemService;
|
||||||
|
protected ConfigurationService configurationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method invoked by CLI which will result in the number of items
|
* method invoked by CLI which will result in the number of items
|
||||||
* in each community and collection being cached. These counts will
|
* in each community and collection being cached. These counts will
|
||||||
* not update themselves until this is run again.
|
* not update themselves until this is run again.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
throws ItemCountException, SQLException
|
throws ItemCountException, SQLException
|
||||||
{
|
{
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
ItemCounter ic = new ItemCounter(context);
|
ItemCounter ic = new ItemCounter(context);
|
||||||
ic.buildItemCounts();
|
ic.buildItemCounts();
|
||||||
context.complete();
|
context.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new item counter which will use the give DSpace Context
|
* Construct a new item counter which will use the give DSpace Context
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @throws ItemCountException
|
* @throws ItemCountException
|
||||||
*/
|
*/
|
||||||
public ItemCounter(Context context)
|
public ItemCounter(Context context)
|
||||||
throws ItemCountException
|
throws ItemCountException
|
||||||
|
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.dao = ItemCountDAOFactory.getInstance(this.context);
|
this.dao = ItemCountDAOFactory.getInstance(this.context);
|
||||||
this.communityService = ContentServiceFactory.getInstance().getCommunityService();
|
this.communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||||
this.itemService = ContentServiceFactory.getInstance().getItemService();
|
this.itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
}
|
this.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method does the grunt work of drilling through and iterating
|
* This method does the grunt work of drilling through and iterating
|
||||||
* over all of the communities and collections in the system and
|
* over all of the communities and collections in the system and
|
||||||
* obtaining and caching the item counts for each one.
|
* obtaining and caching the item counts for each one.
|
||||||
*
|
*
|
||||||
* @throws ItemCountException
|
* @throws ItemCountException
|
||||||
*/
|
*/
|
||||||
public void buildItemCounts()
|
public void buildItemCounts()
|
||||||
throws ItemCountException
|
throws ItemCountException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Community> tlc = communityService.findAllTop(context);
|
List<Community> tlc = communityService.findAllTop(context);
|
||||||
for (Community aTlc : tlc) {
|
for (Community aTlc : tlc) {
|
||||||
count(aTlc);
|
count(aTlc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.error("caught exception: ", e);
|
log.error("caught exception: ", e);
|
||||||
throw new ItemCountException(e);
|
throw new ItemCountException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the count of the items in the given container. If the configuration
|
* Get the count of the items in the given container. If the configuration
|
||||||
* value webui.strengths.cache is equal to 'true' this will return the
|
* value webui.strengths.cache is equal to 'true' this will return the
|
||||||
* cached value if it exists. If it is equal to 'false' it will count
|
* cached value if it exists. If it is equal to 'false' it will count
|
||||||
* the number of items in the container in real time.
|
* the number of items in the container in real time.
|
||||||
*
|
*
|
||||||
* @param dso
|
* @param dso
|
||||||
* @throws ItemCountException
|
* @throws ItemCountException
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public int getCount(DSpaceObject dso)
|
public int getCount(DSpaceObject dso)
|
||||||
throws ItemCountException
|
throws ItemCountException
|
||||||
{
|
{
|
||||||
boolean useCache = ConfigurationManager.getBooleanProperty(
|
boolean useCache = configurationService.getBooleanProperty(
|
||||||
"webui.strengths.cache", true);
|
"webui.strengths.cache", true);
|
||||||
|
|
||||||
if (useCache)
|
if (useCache)
|
||||||
{
|
{
|
||||||
return dao.getCount(dso);
|
return dao.getCount(dso);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we make it this far, we need to manually count
|
// if we make it this far, we need to manually count
|
||||||
if (dso instanceof Collection)
|
if (dso instanceof Collection)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return itemService.countItems(context, (Collection) dso);
|
return itemService.countItems(context, (Collection) dso);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("caught exception: ", e);
|
log.error("caught exception: ", e);
|
||||||
throw new ItemCountException(e);
|
throw new ItemCountException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dso instanceof Community)
|
if (dso instanceof Community)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return communityService.countItems(context, ((Community) dso));
|
return itemService.countItems(context, ((Community) dso));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("caught exception: ", e);
|
log.error("caught exception: ", e);
|
||||||
throw new ItemCountException(e);
|
throw new ItemCountException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any cached data for the given container
|
* Remove any cached data for the given container
|
||||||
*
|
*
|
||||||
* @param dso
|
* @param dso
|
||||||
* @throws ItemCountException
|
* @throws ItemCountException
|
||||||
*/
|
*/
|
||||||
public void remove(DSpaceObject dso)
|
public void remove(DSpaceObject dso)
|
||||||
throws ItemCountException
|
throws ItemCountException
|
||||||
{
|
{
|
||||||
dao.remove(dso);
|
dao.remove(dso);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* count and cache the number of items in the community. This
|
* count and cache the number of items in the community. This
|
||||||
* will include all sub-communities and collections in the
|
* will include all sub-communities and collections in the
|
||||||
* community. It will also recurse into sub-communities and
|
* community. It will also recurse into sub-communities and
|
||||||
* collections and call count() on them also.
|
* collections and call count() on them also.
|
||||||
*
|
*
|
||||||
* Therefore, the count the contents of the entire system, it is
|
* Therefore, the count the contents of the entire system, it is
|
||||||
* necessary just to call this method on each top level community
|
* necessary just to call this method on each top level community
|
||||||
*
|
*
|
||||||
* @param community
|
* @param community
|
||||||
* @throws ItemCountException
|
* @throws ItemCountException
|
||||||
*/
|
*/
|
||||||
protected void count(Community community)
|
protected void count(Community community)
|
||||||
throws ItemCountException
|
throws ItemCountException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// first count the community we are in
|
// first count the community we are in
|
||||||
int count = communityService.countItems(context, community);
|
int count = itemService.countItems(context, community);
|
||||||
dao.communityCount(community, count);
|
dao.communityCount(community, count);
|
||||||
|
|
||||||
// now get the sub-communities
|
// now get the sub-communities
|
||||||
List<Community> scs = community.getSubcommunities();
|
List<Community> scs = community.getSubcommunities();
|
||||||
for (Community sc : scs) {
|
for (Community sc : scs) {
|
||||||
count(sc);
|
count(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now get the collections
|
// now get the collections
|
||||||
List<Collection> cols = community.getCollections();
|
List<Collection> cols = community.getCollections();
|
||||||
for (Collection col : cols) {
|
for (Collection col : cols) {
|
||||||
count(col);
|
count(col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.error("caught exception: ", e);
|
log.error("caught exception: ", e);
|
||||||
throw new ItemCountException(e);
|
throw new ItemCountException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* count and cache the number of items in the given collection
|
* count and cache the number of items in the given collection
|
||||||
*
|
*
|
||||||
* @param collection
|
* @param collection
|
||||||
* @throws ItemCountException
|
* @throws ItemCountException
|
||||||
*/
|
*/
|
||||||
protected void count(Collection collection)
|
protected void count(Collection collection)
|
||||||
throws ItemCountException
|
throws ItemCountException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int ccount = itemService.countItems(context, collection);
|
int ccount = itemService.countItems(context, collection);
|
||||||
dao.collectionCount(collection, ccount);
|
dao.collectionCount(collection, ccount);
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.error("caught exception: ", e);
|
log.error("caught exception: ", e);
|
||||||
throw new ItemCountException(e);
|
throw new ItemCountException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,7 @@ public class ItemCheck extends Check {
|
|||||||
"Withdrawn items: %d\n", itemService.countWithdrawnItems(context));
|
"Withdrawn items: %d\n", itemService.countWithdrawnItems(context));
|
||||||
ret += String.format(
|
ret += String.format(
|
||||||
"Not published items (in workspace or workflow mode): %d\n",
|
"Not published items (in workspace or workflow mode): %d\n",
|
||||||
itemService.getNotArchivedItemsCount(context));
|
itemService.countNotArchivedItems(context));
|
||||||
|
|
||||||
for (Map.Entry<Integer, Long> row : workspaceItemService.getStageReachedCounts(context)) {
|
for (Map.Entry<Integer, Long> row : workspaceItemService.getStageReachedCounts(context)) {
|
||||||
ret += String.format("\tIn Stage %s: %s\n",
|
ret += String.format("\tIn Stage %s: %s\n",
|
||||||
|
@@ -21,7 +21,7 @@ import org.dspace.authorize.AuthorizeException;
|
|||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.CommunityService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +36,7 @@ public class CommunityRecentSubmissions extends AbstractRecentSubmissionTransfor
|
|||||||
private static final Message T_head_recent_submissions =
|
private static final Message T_head_recent_submissions =
|
||||||
message("xmlui.ArtifactBrowser.CommunityViewer.head_recent_submissions");
|
message("xmlui.ArtifactBrowser.CommunityViewer.head_recent_submissions");
|
||||||
|
|
||||||
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the recent submissions for this community
|
* Displays the recent submissions for this community
|
||||||
@@ -80,7 +80,7 @@ public class CommunityRecentSubmissions extends AbstractRecentSubmissionTransfor
|
|||||||
|
|
||||||
Community community = (Community) dso;
|
Community community = (Community) dso;
|
||||||
|
|
||||||
if (communityService.countItems(context, community) > maxRecentSubmissions)
|
if (itemService.countItems(context, community) > maxRecentSubmissions)
|
||||||
addViewMoreLink(lastSubmittedDiv, dso);
|
addViewMoreLink(lastSubmittedDiv, dso);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user