mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 04:23:13 +00:00
generics
This commit is contained in:
@@ -843,7 +843,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException {
|
||||
public List<Map.Entry<Collection, Long>> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException {
|
||||
return collectionDAO.getCollectionsWithBitstreamSizesTotal(context);
|
||||
}
|
||||
}
|
||||
|
@@ -223,7 +223,7 @@ public class WorkspaceItemServiceImpl implements WorkspaceItemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getStageReachedCounts(Context context) throws SQLException {
|
||||
public List<Map.Entry<Integer, Long>> getStageReachedCounts(Context context) throws SQLException {
|
||||
return workspaceItemDAO.getStageReachedCounts(context);
|
||||
}
|
||||
|
||||
|
@@ -43,5 +43,5 @@ public interface CollectionDAO extends DSpaceObjectLegacySupportDAO<Collection>
|
||||
|
||||
int countRows(Context context) throws SQLException;
|
||||
|
||||
List<Map> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException;
|
||||
List<Map.Entry<Collection, Long>> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException;
|
||||
}
|
||||
|
@@ -41,5 +41,5 @@ public interface WorkspaceItemDAO extends GenericDAO<WorkspaceItem> {
|
||||
|
||||
int countRows(Context context) throws SQLException;
|
||||
|
||||
List<Map> getStageReachedCounts(Context context) throws SQLException;
|
||||
List<Map.Entry<Integer, Long>> getStageReachedCounts(Context context) throws SQLException;
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.criterion.Disjunction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.transform.Transformers;
|
||||
import org.hibernate.transform.BasicTransformerAdapter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
@@ -171,8 +171,16 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Map.Entry<Collection, Long>> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException {
|
||||
String q = "select col as collection, sum(bit.sizeBytes) as totalBytes from Item i join i.collections col join i.bundles bun join bun.bitstreams bit group by col";
|
||||
return createQuery(context, q).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
|
||||
Query query = createQuery(context, q);
|
||||
query.setResultTransformer(new BasicTransformerAdapter() {
|
||||
@Override
|
||||
public Object transformTuple(Object[] tuple, String[] aliases) {
|
||||
return new java.util.AbstractMap.SimpleImmutableEntry<>((Collection)tuple[0], (Long)tuple[1]);
|
||||
}
|
||||
});
|
||||
return ((List<Map.Entry<Collection, Long>>)query.list());
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.transform.Transformers;
|
||||
import org.hibernate.transform.BasicTransformerAdapter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@@ -90,10 +90,17 @@ public class WorkspaceItemDAOImpl extends AbstractHibernateDAO<WorkspaceItem> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getStageReachedCounts(Context context) throws SQLException {
|
||||
return createQuery(context,"SELECT wi.stageReached as stage_reached, count(*) as cnt from WorkspaceItem wi" +
|
||||
" group by wi.stageReached order by wi.stageReached").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
|
||||
.list();
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Map.Entry<Integer, Long>> getStageReachedCounts(Context context) throws SQLException {
|
||||
Query query = createQuery(context,"SELECT wi.stageReached as stage_reached, count(*) as cnt from WorkspaceItem wi" +
|
||||
" group by wi.stageReached order by wi.stageReached");
|
||||
query.setResultTransformer(new BasicTransformerAdapter() {
|
||||
@Override
|
||||
public Object transformTuple(Object[] tuple, String[] aliases) {
|
||||
return new java.util.AbstractMap.SimpleImmutableEntry((Integer) tuple[0], (Long) tuple[1]);
|
||||
}
|
||||
});
|
||||
return (List<Map.Entry<Integer, Long>>)query.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -302,5 +302,11 @@ public interface CollectionService extends DSpaceObjectService<Collection>, DSpa
|
||||
|
||||
int countTotal(Context context) throws SQLException;
|
||||
|
||||
List<Map> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException;
|
||||
/**
|
||||
* The map entry returned contains a collection as a key and sum of bitstream sizes in bytes as a value
|
||||
* @param context
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
List<Map.Entry<Collection, Long>> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException;
|
||||
}
|
||||
|
@@ -128,5 +128,11 @@ public interface WorkspaceItemService extends InProgressSubmissionService<Worksp
|
||||
|
||||
int countTotal(Context context) throws SQLException;
|
||||
|
||||
List<Map> getStageReachedCounts(Context context) throws SQLException;
|
||||
/**
|
||||
* The map entry returned contains stage reached as the key and count of items in that stage as a value
|
||||
* @param context
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
List<Map.Entry<Integer, Long>> getStageReachedCounts(Context context) throws SQLException;
|
||||
}
|
||||
|
@@ -76,10 +76,10 @@ public class ItemCheck extends Check {
|
||||
"Not published items (in workspace or workflow mode): %d\n",
|
||||
itemService.getNotArchivedItemsCount(context));
|
||||
|
||||
for (Map row : workspaceItemService.getStageReachedCounts(context)) {
|
||||
for (Map.Entry<Integer, Long> row : workspaceItemService.getStageReachedCounts(context)) {
|
||||
ret += String.format("\tIn Stage %s: %s\n",
|
||||
row.get("stage_reached"),
|
||||
row.get("cnt")
|
||||
row.getKey(), //"stage_reached"
|
||||
row.getValue() //"cnt"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,15 +130,15 @@ public class ItemCheck extends Check {
|
||||
|
||||
public String getCollectionSizesInfo(Context context) throws SQLException {
|
||||
final StringBuffer ret = new StringBuffer();
|
||||
List<Map> colBitSizes = collectionService.getCollectionsWithBitstreamSizesTotal(context);
|
||||
List<Map.Entry<Collection, Long>> colBitSizes = collectionService.getCollectionsWithBitstreamSizesTotal(context);
|
||||
long total_size = 0;
|
||||
|
||||
Collections.sort(colBitSizes, new Comparator<Map>() {
|
||||
Collections.sort(colBitSizes, new Comparator<Map.Entry<Collection, Long>>() {
|
||||
@Override
|
||||
public int compare(Map o1, Map o2) {
|
||||
public int compare(Map.Entry<Collection, Long> o1, Map.Entry<Collection, Long> o2) {
|
||||
try {
|
||||
return CollectionDropDown.collectionPath((Collection) o1.get("collection")).compareTo(
|
||||
CollectionDropDown.collectionPath((Collection) o2.get("collection"))
|
||||
return CollectionDropDown.collectionPath(o1.getKey()).compareTo(
|
||||
CollectionDropDown.collectionPath(o2.getKey())
|
||||
);
|
||||
} catch (Exception e) {
|
||||
ret.append(e.getMessage());
|
||||
@@ -146,10 +146,10 @@ public class ItemCheck extends Check {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
for (Map row : colBitSizes) {
|
||||
Long size = (Long) row.get("totalBytes");
|
||||
for (Map.Entry<Collection, Long> row : colBitSizes) {
|
||||
Long size = row.getValue();
|
||||
total_size += size;
|
||||
Collection col = (Collection) row.get("collection");
|
||||
Collection col = row.getKey();
|
||||
ret.append(String.format(
|
||||
"\t%s: %s\n", CollectionDropDown.collectionPath(col), FileUtils.byteCountToDisplaySize((long) size)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user