mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 20:43:18 +00:00
Merge branch 'DS-3580_workspaceitem' of https://github.com/4Science/DSpace into inputform-rows
This commit is contained in:
@@ -51,6 +51,10 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<debug>true</debug>
|
<debug>true</debug>
|
||||||
<showDeprecation>true</showDeprecation>
|
<showDeprecation>true</showDeprecation>
|
||||||
|
<compilerArguments>
|
||||||
|
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
|
||||||
|
</compilerArguments>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -308,6 +312,10 @@
|
|||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-ehcache</artifactId>
|
<artifactId>hibernate-ehcache</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-validator-cdi</artifactId>
|
<artifactId>hibernate-validator-cdi</artifactId>
|
||||||
|
@@ -143,7 +143,7 @@ public abstract class ImageMagickThumbnailFilter extends MediaFilter {
|
|||||||
// PDFs using the CMYK color system can be handled specially if
|
// PDFs using the CMYK color system can be handled specially if
|
||||||
// profiles are defined
|
// profiles are defined
|
||||||
if (cmyk_profile != null && srgb_profile != null) {
|
if (cmyk_profile != null && srgb_profile != null) {
|
||||||
Info imageInfo = new Info(f.getAbsolutePath(), true);
|
Info imageInfo = new Info(f.getAbsolutePath() + s, true);
|
||||||
String imageClass = imageInfo.getImageClass();
|
String imageClass = imageInfo.getImageClass();
|
||||||
if (imageClass.contains("CMYK")) {
|
if (imageClass.contains("CMYK")) {
|
||||||
op.profile(cmyk_profile);
|
op.profile(cmyk_profile);
|
||||||
|
@@ -8,13 +8,15 @@
|
|||||||
package org.dspace.app.requestitem.dao.impl;
|
package org.dspace.app.requestitem.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.app.requestitem.RequestItem;
|
import org.dspace.app.requestitem.RequestItem;
|
||||||
|
import org.dspace.app.requestitem.RequestItem_;
|
||||||
import org.dspace.app.requestitem.dao.RequestItemDAO;
|
import org.dspace.app.requestitem.dao.RequestItemDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the RequestItem object.
|
* Hibernate implementation of the Database Access Object interface class for the RequestItem object.
|
||||||
@@ -30,9 +32,12 @@ public class RequestItemDAOImpl extends AbstractHibernateDAO<RequestItem> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RequestItem findByToken(Context context, String token) throws SQLException {
|
public RequestItem findByToken(Context context, String token) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, RequestItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("token", token));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, RequestItem.class);
|
||||||
return uniqueResult(criteria);
|
Root<RequestItem> requestItemRoot = criteriaQuery.from(RequestItem.class);
|
||||||
|
criteriaQuery.select(requestItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(requestItemRoot.get(RequestItem_.token), token));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, RequestItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -9,17 +9,19 @@ package org.dspace.authorize.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.authorize.ResourcePolicy;
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
|
import org.dspace.authorize.ResourcePolicy_;
|
||||||
import org.dspace.authorize.dao.ResourcePolicyDAO;
|
import org.dspace.authorize.dao.ResourcePolicyDAO;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the ResourcePolicy object.
|
* Hibernate implementation of the Database Access Object interface class for the ResourcePolicy object.
|
||||||
@@ -36,79 +38,104 @@ public class ResourcePolicyDAOImpl extends AbstractHibernateDAO<ResourcePolicy>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePolicy> findByDso(Context context, DSpaceObject dso) throws SQLException {
|
public List<ResourcePolicy> findByDso(Context context, DSpaceObject dso) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
Restrictions.eq("dSpaceObject", dso)
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
));
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
return list(criteria);
|
criteriaQuery.where(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.dSpaceObject), dso));
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePolicy> findByDsoAndType(Context context, DSpaceObject dso, String type) throws SQLException {
|
public List<ResourcePolicy> findByDsoAndType(Context context, DSpaceObject dso, String type) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
Restrictions.eq("dSpaceObject", dso),
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
Restrictions.eq("rptype", type)
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
));
|
criteriaQuery
|
||||||
return list(criteria);
|
.where(criteriaBuilder.and(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.dSpaceObject), dso),
|
||||||
|
criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.rptype), type)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePolicy> findByGroup(Context context, Group group) throws SQLException {
|
public List<ResourcePolicy> findByGroup(Context context, Group group) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("epersonGroup", group));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
return list(criteria);
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.epersonGroup), group));
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePolicy> findByDSoAndAction(Context context, DSpaceObject dso, int actionId)
|
public List<ResourcePolicy> findByDSoAndAction(Context context, DSpaceObject dso, int actionId)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
Restrictions.eq("dSpaceObject", dso),
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
Restrictions.eq("actionId", actionId)
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
));
|
criteriaQuery
|
||||||
return list(criteria);
|
.where(criteriaBuilder.and(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.dSpaceObject), dso),
|
||||||
|
criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.actionId), actionId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePolicy> findByTypeGroupAction(Context context, DSpaceObject dso, Group group, int action)
|
public List<ResourcePolicy> findByTypeGroupAction(Context context, DSpaceObject dso, Group group, int action)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
Restrictions.eq("dSpaceObject", dso),
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
Restrictions.eq("epersonGroup", group),
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
Restrictions.eq("actionId", action)
|
criteriaQuery
|
||||||
));
|
.where(criteriaBuilder.and(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.dSpaceObject), dso),
|
||||||
criteria.setMaxResults(1);
|
criteriaBuilder
|
||||||
return list(criteria);
|
.equal(resourcePolicyRoot.get(ResourcePolicy_.epersonGroup), group),
|
||||||
|
criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.actionId), action)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, 1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePolicy> findByTypeGroupActionExceptId(Context context, DSpaceObject dso, Group group,
|
public List<ResourcePolicy> findByTypeGroupActionExceptId(Context context, DSpaceObject dso, Group group,
|
||||||
int action, int notPolicyID) throws SQLException {
|
int action, int notPolicyID) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
Restrictions.eq("dSpaceObject", dso),
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
Restrictions.eq("epersonGroup", group),
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
Restrictions.eq("actionId", action)
|
criteriaQuery
|
||||||
));
|
.where(criteriaBuilder.and(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.dSpaceObject), dso),
|
||||||
criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("id", notPolicyID))));
|
criteriaBuilder
|
||||||
return list(criteria);
|
.equal(resourcePolicyRoot.get(ResourcePolicy_.epersonGroup), group),
|
||||||
|
criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.actionId), action),
|
||||||
|
criteriaBuilder.notEqual(resourcePolicyRoot.get(ResourcePolicy_.id), notPolicyID)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, 1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResourcePolicy> findByEPersonGroupTypeIdAction(Context context, EPerson e, List<Group> groups,
|
public List<ResourcePolicy> findByEPersonGroupTypeIdAction(Context context, EPerson e, List<Group> groups,
|
||||||
int action, int type_id) throws SQLException {
|
int action, int type_id) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ResourcePolicy.class);
|
||||||
Restrictions.eq("resourceTypeId", type_id),
|
Root<ResourcePolicy> resourcePolicyRoot = criteriaQuery.from(ResourcePolicy.class);
|
||||||
Restrictions.eq("actionId", action),
|
criteriaQuery.select(resourcePolicyRoot);
|
||||||
(Restrictions.or(
|
criteriaQuery.where(
|
||||||
Restrictions.eq("eperson", e),
|
criteriaBuilder.and(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.resourceTypeId), type_id),
|
||||||
Restrictions.in("epersonGroup", groups)
|
criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.actionId), action),
|
||||||
))
|
criteriaBuilder
|
||||||
));
|
.or(criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.eperson), e),
|
||||||
return list(criteria);
|
criteriaBuilder
|
||||||
|
.in(resourcePolicyRoot.get(ResourcePolicy_.epersonGroup).in(groups)))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ResourcePolicy.class, 1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,7 +151,7 @@ public class ResourcePolicyDAOImpl extends AbstractHibernateDAO<ResourcePolicy>
|
|||||||
String queryString = "delete from ResourcePolicy where dSpaceObject= :dSpaceObject AND actionId= :actionId";
|
String queryString = "delete from ResourcePolicy where dSpaceObject= :dSpaceObject AND actionId= :actionId";
|
||||||
Query query = createQuery(context, queryString);
|
Query query = createQuery(context, queryString);
|
||||||
query.setParameter("dSpaceObject", dso);
|
query.setParameter("dSpaceObject", dso);
|
||||||
query.setInteger("actionId", actionId);
|
query.setParameter("actionId", actionId);
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +160,7 @@ public class ResourcePolicyDAOImpl extends AbstractHibernateDAO<ResourcePolicy>
|
|||||||
String queryString = "delete from ResourcePolicy where dSpaceObject.id = :dsoId AND rptype = :rptype";
|
String queryString = "delete from ResourcePolicy where dSpaceObject.id = :dsoId AND rptype = :rptype";
|
||||||
Query query = createQuery(context, queryString);
|
Query query = createQuery(context, queryString);
|
||||||
query.setParameter("dsoId", dso.getID());
|
query.setParameter("dsoId", dso.getID());
|
||||||
query.setString("rptype", type);
|
query.setParameter("rptype", type);
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,8 @@ package org.dspace.checker.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.dspace.checker.ChecksumHistory;
|
import org.dspace.checker.ChecksumHistory;
|
||||||
import org.dspace.checker.ChecksumResultCode;
|
import org.dspace.checker.ChecksumResultCode;
|
||||||
@@ -16,7 +18,6 @@ import org.dspace.checker.dao.ChecksumHistoryDAO;
|
|||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Query;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -29,6 +30,8 @@ import org.hibernate.Query;
|
|||||||
* @author Grace Carpenter
|
* @author Grace Carpenter
|
||||||
* @author Nathan Sarr
|
* @author Nathan Sarr
|
||||||
* @author kevinvandevelde at atmire.com
|
* @author kevinvandevelde at atmire.com
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class ChecksumHistoryDAOImpl extends AbstractHibernateDAO<ChecksumHistory> implements ChecksumHistoryDAO {
|
public class ChecksumHistoryDAOImpl extends AbstractHibernateDAO<ChecksumHistory> implements ChecksumHistoryDAO {
|
||||||
|
|
||||||
@@ -42,7 +45,7 @@ public class ChecksumHistoryDAOImpl extends AbstractHibernateDAO<ChecksumHistory
|
|||||||
String hql = "delete from ChecksumHistory where processEndDate < :processEndDate AND checksumResult" +
|
String hql = "delete from ChecksumHistory where processEndDate < :processEndDate AND checksumResult" +
|
||||||
".resultCode=:resultCode";
|
".resultCode=:resultCode";
|
||||||
Query query = createQuery(context, hql);
|
Query query = createQuery(context, hql);
|
||||||
query.setTimestamp("processEndDate", retentionDate);
|
query.setParameter("processEndDate", retentionDate, TemporalType.TIMESTAMP);
|
||||||
query.setParameter("resultCode", resultCode);
|
query.setParameter("resultCode", resultCode);
|
||||||
return query.executeUpdate();
|
return query.executeUpdate();
|
||||||
}
|
}
|
||||||
|
@@ -8,14 +8,16 @@
|
|||||||
package org.dspace.checker.dao.impl;
|
package org.dspace.checker.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.checker.ChecksumResult;
|
import org.dspace.checker.ChecksumResult;
|
||||||
import org.dspace.checker.ChecksumResultCode;
|
import org.dspace.checker.ChecksumResultCode;
|
||||||
|
import org.dspace.checker.ChecksumResult_;
|
||||||
import org.dspace.checker.dao.ChecksumResultDAO;
|
import org.dspace.checker.dao.ChecksumResultDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the ChecksumResult object.
|
* Hibernate implementation of the Database Access Object interface class for the ChecksumResult object.
|
||||||
@@ -32,8 +34,11 @@ public class ChecksumResultDAOImpl extends AbstractHibernateDAO<ChecksumResult>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChecksumResult findByCode(Context context, ChecksumResultCode code) throws SQLException {
|
public ChecksumResult findByCode(Context context, ChecksumResultCode code) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ChecksumResult.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("resultCode", code));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ChecksumResult.class);
|
||||||
return uniqueResult(criteria);
|
Root<ChecksumResult> checksumResultRoot = criteriaQuery.from(ChecksumResult.class);
|
||||||
|
criteriaQuery.select(checksumResultRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(checksumResultRoot.get(ChecksumResult_.resultCode), code));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, ChecksumResult.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,22 +9,27 @@ package org.dspace.checker.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Order;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
import javax.persistence.criteria.Subquery;
|
||||||
|
|
||||||
import org.dspace.checker.ChecksumHistory;
|
import org.dspace.checker.ChecksumHistory;
|
||||||
|
import org.dspace.checker.ChecksumHistory_;
|
||||||
|
import org.dspace.checker.ChecksumResult;
|
||||||
import org.dspace.checker.ChecksumResultCode;
|
import org.dspace.checker.ChecksumResultCode;
|
||||||
|
import org.dspace.checker.ChecksumResult_;
|
||||||
import org.dspace.checker.MostRecentChecksum;
|
import org.dspace.checker.MostRecentChecksum;
|
||||||
|
import org.dspace.checker.MostRecentChecksum_;
|
||||||
import org.dspace.checker.dao.MostRecentChecksumDAO;
|
import org.dspace.checker.dao.MostRecentChecksumDAO;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.DetachedCriteria;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Projections;
|
|
||||||
import org.hibernate.criterion.Property;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the MostRecentChecksum object.
|
* Hibernate implementation of the Database Access Object interface class for the MostRecentChecksum object.
|
||||||
@@ -43,58 +48,58 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
|
|||||||
@Override
|
@Override
|
||||||
public List<MostRecentChecksum> findByNotProcessedInDateRange(Context context, Date startDate, Date endDate)
|
public List<MostRecentChecksum> findByNotProcessedInDateRange(Context context, Date startDate, Date endDate)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// + "most_recent_checksum.last_process_start_date, most_recent_checksum.last_process_end_date, "
|
|
||||||
// + "most_recent_checksum.expected_checksum, most_recent_checksum.current_checksum, "
|
|
||||||
// + "result_description "
|
|
||||||
// + "from checksum_results, most_recent_checksum "
|
|
||||||
// + "where most_recent_checksum.to_be_processed = false "
|
|
||||||
// + "and most_recent_checksum.result = checksum_results.result_code "
|
|
||||||
// + "and most_recent_checksum.last_process_start_date >= ? "
|
|
||||||
// + "and most_recent_checksum.last_process_start_date < ? "
|
|
||||||
// + "order by most_recent_checksum.bitstream_id
|
|
||||||
|
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
|
||||||
Restrictions.and(
|
Root<MostRecentChecksum> mostRecentChecksumRoot = criteriaQuery.from(MostRecentChecksum.class);
|
||||||
Restrictions.eq("toBeProcessed", false),
|
criteriaQuery.select(mostRecentChecksumRoot);
|
||||||
Restrictions.le("processStartDate", startDate),
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
Restrictions.gt("processStartDate", endDate)
|
criteriaBuilder.equal(mostRecentChecksumRoot.get(MostRecentChecksum_.toBeProcessed), false),
|
||||||
|
criteriaBuilder
|
||||||
|
.lessThanOrEqualTo(mostRecentChecksumRoot.get(MostRecentChecksum_.processStartDate), startDate),
|
||||||
|
criteriaBuilder.greaterThan(mostRecentChecksumRoot.get(MostRecentChecksum_.processStartDate), endDate)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
criteria.addOrder(Order.asc("bitstream.id"));
|
List<Order> orderList = new LinkedList<>();
|
||||||
return list(criteria);
|
orderList.add(criteriaBuilder.asc(mostRecentChecksumRoot.get(MostRecentChecksum_.bitstream)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
return list(context, criteriaQuery, false, MostRecentChecksum.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MostRecentChecksum findByBitstream(Context context, Bitstream bitstream) throws SQLException {
|
public MostRecentChecksum findByBitstream(Context context, Bitstream bitstream) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("bitstream", bitstream));
|
CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
|
||||||
return singleResult(criteria);
|
Root<MostRecentChecksum> mostRecentChecksumRoot = criteriaQuery.from(MostRecentChecksum.class);
|
||||||
|
criteriaQuery.select(mostRecentChecksumRoot);
|
||||||
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.equal(mostRecentChecksumRoot.get(MostRecentChecksum_.bitstream), bitstream));
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MostRecentChecksum> findByResultTypeInDateRange(Context context, Date startDate, Date endDate,
|
public List<MostRecentChecksum> findByResultTypeInDateRange(Context context, Date startDate, Date endDate,
|
||||||
ChecksumResultCode resultCode) throws SQLException {
|
ChecksumResultCode resultCode) throws SQLException {
|
||||||
// "select bitstream_id, last_process_start_date, last_process_end_date, "
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// + "expected_checksum, current_checksum, result_description "
|
CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
|
||||||
// + "from most_recent_checksum, checksum_results "
|
Root<MostRecentChecksum> mostRecentChecksumRoot = criteriaQuery.from(MostRecentChecksum.class);
|
||||||
// + "where most_recent_checksum.result = checksum_results.result_code "
|
Join<MostRecentChecksum, ChecksumResult> mostRecentResult =
|
||||||
// + "and most_recent_checksum.result= ? "
|
mostRecentChecksumRoot.join(MostRecentChecksum_.checksumResult);
|
||||||
// + "and most_recent_checksum.last_process_start_date >= ? "
|
|
||||||
// + "and most_recent_checksum.last_process_start_date < ? "
|
criteriaQuery.select(mostRecentChecksumRoot);
|
||||||
// + "order by bitstream_id";
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
criteriaBuilder.equal(mostRecentResult.get(ChecksumResult_.resultCode), resultCode),
|
||||||
criteria.add(
|
criteriaBuilder.lessThanOrEqualTo(
|
||||||
Restrictions.and(
|
mostRecentChecksumRoot.get(MostRecentChecksum_.processStartDate), startDate),
|
||||||
Restrictions.eq("checksumResult.resultCode", resultCode),
|
criteriaBuilder.greaterThan(mostRecentChecksumRoot.get(MostRecentChecksum_.processStartDate), endDate)
|
||||||
Restrictions.le("processStartDate", startDate),
|
|
||||||
Restrictions.gt("processStartDate", endDate)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
criteria.addOrder(Order.asc("bitstream.id"));
|
List<Order> orderList = new LinkedList<>();
|
||||||
return list(criteria);
|
orderList.add(criteriaBuilder.asc(mostRecentChecksumRoot.get(MostRecentChecksum_.bitstream)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
return list(context, criteriaQuery, false, MostRecentChecksum.class, -1, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,42 +113,52 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MostRecentChecksum getOldestRecord(Context context) throws SQLException {
|
public MostRecentChecksum getOldestRecord(Context context) throws SQLException {
|
||||||
// "select bitstream_id "
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// + "from most_recent_checksum " + "where to_be_processed = true "
|
CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
|
||||||
// + "order by date_trunc('milliseconds', last_process_end_date), "
|
Root<MostRecentChecksum> mostRecentChecksumRoot = criteriaQuery.from(MostRecentChecksum.class);
|
||||||
// + "bitstream_id " + "ASC LIMIT 1";
|
criteriaQuery.select(mostRecentChecksumRoot);
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
criteriaQuery.where(criteriaBuilder.equal(mostRecentChecksumRoot.get(MostRecentChecksum_.toBeProcessed), true));
|
||||||
criteria.add(Restrictions.eq("toBeProcessed", true));
|
List<Order> orderList = new LinkedList<>();
|
||||||
criteria.addOrder(Order.asc("processEndDate")).addOrder(Order.asc("bitstream.id"));
|
orderList.add(criteriaBuilder.asc(mostRecentChecksumRoot.get(MostRecentChecksum_.processEndDate)));
|
||||||
criteria.setMaxResults(1);
|
orderList.add(criteriaBuilder.asc(mostRecentChecksumRoot.get(MostRecentChecksum_.bitstream)));
|
||||||
return singleResult(criteria);
|
criteriaQuery.orderBy(orderList);
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MostRecentChecksum getOldestRecord(Context context, Date lessThanDate) throws SQLException {
|
public MostRecentChecksum getOldestRecord(Context context, Date lessThanDate) throws SQLException {
|
||||||
// "select bitstream_id "
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// + "from most_recent_checksum "
|
CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
|
||||||
// + "where to_be_processed = true "
|
Root<MostRecentChecksum> mostRecentChecksumRoot = criteriaQuery.from(MostRecentChecksum.class);
|
||||||
// + "and last_process_start_date < ? "
|
criteriaQuery.select(mostRecentChecksumRoot);
|
||||||
// + "order by date_trunc('milliseconds', last_process_end_date), "
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
// + "bitstream_id " + "ASC LIMIT 1";
|
criteriaBuilder.equal(mostRecentChecksumRoot.get(MostRecentChecksum_.toBeProcessed), true),
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
criteriaBuilder.lessThan(mostRecentChecksumRoot.get(MostRecentChecksum_.processStartDate), lessThanDate)
|
||||||
criteria.add(
|
)
|
||||||
Restrictions.and(
|
);
|
||||||
Restrictions.eq("toBeProcessed", true),
|
|
||||||
Restrictions.lt("processStartDate", lessThanDate)
|
List<Order> orderList = new LinkedList<>();
|
||||||
));
|
orderList.add(criteriaBuilder.asc(mostRecentChecksumRoot.get(MostRecentChecksum_.processEndDate)));
|
||||||
criteria.addOrder(Order.asc("processEndDate")).addOrder(Order.asc("bitstream.id"));
|
orderList.add(criteriaBuilder.asc(mostRecentChecksumRoot.get(MostRecentChecksum_.bitstream)));
|
||||||
criteria.setMaxResults(1);
|
criteriaQuery.orderBy(orderList);
|
||||||
return singleResult(criteria);
|
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MostRecentChecksum> findNotInHistory(Context context) throws SQLException {
|
public List<MostRecentChecksum> findNotInHistory(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
|
||||||
DetachedCriteria subCriteria = DetachedCriteria.forClass(ChecksumHistory.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
subCriteria.setProjection(Projections.property("bitstream.id"));
|
CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
|
||||||
criteria.add(Property.forName("bitstreamId").notIn(subCriteria));
|
Root<MostRecentChecksum> checksumRoot = criteriaQuery.from(MostRecentChecksum.class);
|
||||||
return list(criteria);
|
|
||||||
|
Subquery<Bitstream> subQuery = criteriaQuery.subquery(Bitstream.class);
|
||||||
|
Root<ChecksumHistory> historyRoot = subQuery.from(ChecksumHistory.class);
|
||||||
|
subQuery.select(historyRoot.get(ChecksumHistory_.bitstream));
|
||||||
|
|
||||||
|
criteriaQuery.where(
|
||||||
|
criteriaBuilder.not(checksumRoot.get(MostRecentChecksum_.bitstream).in(subQuery)));
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, MostRecentChecksum.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,10 +8,17 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
|
import org.dspace.content.Bitstream_;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
@@ -19,9 +26,6 @@ import org.dspace.content.dao.BitstreamDAO;
|
|||||||
import org.dspace.core.AbstractHibernateDSODAO;
|
import org.dspace.core.AbstractHibernateDSODAO;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Bitstream object.
|
* Hibernate implementation of the Database Access Object interface class for the Bitstream object.
|
||||||
@@ -38,40 +42,35 @@ public class BitstreamDAOImpl extends AbstractHibernateDSODAO<Bitstream> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Bitstream> findDeletedBitstreams(Context context) throws SQLException {
|
public List<Bitstream> findDeletedBitstreams(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Bitstream.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("deleted", true));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Bitstream.class);
|
||||||
|
Root<Bitstream> bitstreamRoot = criteriaQuery.from(Bitstream.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(bitstreamRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(bitstreamRoot.get(Bitstream_.deleted), true));
|
||||||
|
return list(context, criteriaQuery, false, Bitstream.class, -1, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Bitstream> findDuplicateInternalIdentifier(Context context, Bitstream bitstream) throws SQLException {
|
public List<Bitstream> findDuplicateInternalIdentifier(Context context, Bitstream bitstream) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Bitstream.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Bitstream.class);
|
||||||
Restrictions.eq("internalId", bitstream.getInternalId()),
|
Root<Bitstream> bitstreamRoot = criteriaQuery.from(Bitstream.class);
|
||||||
Restrictions.not(Restrictions.eq("id", bitstream.getID()))
|
criteriaQuery.select(bitstreamRoot);
|
||||||
));
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.equal(bitstreamRoot.get(Bitstream_.internalId), bitstream.getInternalId()),
|
||||||
return list(criteria);
|
criteriaBuilder.notEqual(bitstreamRoot.get(Bitstream_.id), bitstream.getID())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, Bitstream.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Bitstream> findBitstreamsWithNoRecentChecksum(Context context) throws SQLException {
|
public List<Bitstream> findBitstreamsWithNoRecentChecksum(Context context) throws SQLException {
|
||||||
// "select bitstream.deleted, bitstream.store_number, bitstream.size_bytes, "
|
|
||||||
// + "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
|
|
||||||
// + "bitstream.user_format_description, bitstream.internal_id, "
|
|
||||||
// + "bitstream.source, bitstream.checksum_algorithm, bitstream.checksum, "
|
|
||||||
// + "bitstream.name, bitstream.description "
|
|
||||||
// + "from bitstream left outer join bitstreamformatregistry on "
|
|
||||||
// + "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
|
|
||||||
// + "where not exists( select 'x' from most_recent_checksum "
|
|
||||||
// + "where most_recent_checksum.bitstream_id = bitstream.bitstream_id )"
|
|
||||||
|
|
||||||
Query query = createQuery(context,
|
Query query = createQuery(context,
|
||||||
"select b from Bitstream b where b not in (select c.bitstream from " +
|
"select b from Bitstream b where b not in (select c.bitstream from " +
|
||||||
"MostRecentChecksum c)");
|
"MostRecentChecksum c)");
|
||||||
return query.list();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,9 +121,14 @@ public class BitstreamDAOImpl extends AbstractHibernateDSODAO<Bitstream> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long countByStoreNumber(Context context, Integer storeNumber) throws SQLException {
|
public Long countByStoreNumber(Context context, Integer storeNumber) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Bitstream.class);
|
|
||||||
criteria.add(Restrictions.eq("storeNumber", storeNumber));
|
|
||||||
return countLong(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
|
|
||||||
|
Root<Bitstream> bitstreamRoot = criteriaQuery.from(Bitstream.class);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(bitstreamRoot.get(Bitstream_.storeNumber), storeNumber));
|
||||||
|
return countLong(context, criteriaQuery, criteriaBuilder, bitstreamRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -158,9 +162,8 @@ public class BitstreamDAOImpl extends AbstractHibernateDSODAO<Bitstream> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException {
|
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException {
|
||||||
Query query = createQuery(context, "select b FROM Bitstream b");
|
Map<String, Object> map = new HashMap<>();
|
||||||
query.setFirstResult(offset);
|
return findByX(context, Bitstream.class, map, true, limit, offset).iterator();
|
||||||
query.setMaxResults(limit);
|
|
||||||
return iterate(query);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,16 +8,18 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.BitstreamFormat;
|
import org.dspace.content.BitstreamFormat;
|
||||||
|
import org.dspace.content.BitstreamFormat_;
|
||||||
import org.dspace.content.dao.BitstreamFormatDAO;
|
import org.dspace.content.dao.BitstreamFormatDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the BitstreamFormat object.
|
* Hibernate implementation of the Database Access Object interface class for the BitstreamFormat object.
|
||||||
@@ -37,9 +39,12 @@ public class BitstreamFormatDAOImpl extends AbstractHibernateDAO<BitstreamFormat
|
|||||||
* If more than one bitstream format has the same MIME type, the
|
* If more than one bitstream format has the same MIME type, the
|
||||||
* one returned is unpredictable.
|
* one returned is unpredictable.
|
||||||
*
|
*
|
||||||
* @param context DSpace context object
|
* @param context
|
||||||
* @param mimeType MIME type value
|
* DSpace context object
|
||||||
|
* @param mimeType
|
||||||
|
* MIME type value
|
||||||
* @param includeInternal whether to include internal mimetypes
|
* @param includeInternal whether to include internal mimetypes
|
||||||
|
*
|
||||||
* @return the corresponding bitstream format, or <code>null</code> if
|
* @return the corresponding bitstream format, or <code>null</code> if
|
||||||
* there's no bitstream format with the given MIMEtype.
|
* there's no bitstream format with the given MIMEtype.
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
@@ -49,20 +54,26 @@ public class BitstreamFormatDAOImpl extends AbstractHibernateDAO<BitstreamFormat
|
|||||||
throws SQLException {
|
throws SQLException {
|
||||||
// NOTE: Avoid internal formats since e.g. "License" also has
|
// NOTE: Avoid internal formats since e.g. "License" also has
|
||||||
// a MIMEtype of text/plain.
|
// a MIMEtype of text/plain.
|
||||||
Criteria criteria = createCriteria(context, BitstreamFormat.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BitstreamFormat.class);
|
||||||
Restrictions.eq("internal", includeInternal),
|
Root<BitstreamFormat> bitstreamFormatRoot = criteriaQuery.from(BitstreamFormat.class);
|
||||||
Restrictions.like("mimetype", mimeType)
|
criteriaQuery.select(bitstreamFormatRoot);
|
||||||
));
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.equal(bitstreamFormatRoot.get(BitstreamFormat_.internal), includeInternal),
|
||||||
return singleResult(criteria);
|
criteriaBuilder.like(bitstreamFormatRoot.get(BitstreamFormat_.mimetype), mimeType)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a bitstream format by its (unique) short description
|
* Find a bitstream format by its (unique) short description
|
||||||
*
|
*
|
||||||
* @param context DSpace context object
|
* @param context
|
||||||
* @param desc the short description
|
* DSpace context object
|
||||||
|
* @param desc
|
||||||
|
* the short description
|
||||||
|
*
|
||||||
* @return the corresponding bitstream format, or <code>null</code> if
|
* @return the corresponding bitstream format, or <code>null</code> if
|
||||||
* there's no bitstream format with the given short description
|
* there's no bitstream format with the given short description
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
@@ -70,12 +81,12 @@ public class BitstreamFormatDAOImpl extends AbstractHibernateDAO<BitstreamFormat
|
|||||||
@Override
|
@Override
|
||||||
public BitstreamFormat findByShortDescription(Context context,
|
public BitstreamFormat findByShortDescription(Context context,
|
||||||
String desc) throws SQLException {
|
String desc) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BitstreamFormat.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BitstreamFormat.class);
|
||||||
Restrictions.eq("shortDescription", desc)
|
Root<BitstreamFormat> bitstreamFormatRoot = criteriaQuery.from(BitstreamFormat.class);
|
||||||
));
|
criteriaQuery.select(bitstreamFormatRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(bitstreamFormatRoot.get(BitstreamFormat_.shortDescription), desc));
|
||||||
return uniqueResult(criteria);
|
return uniqueResult(context, criteriaQuery, false, BitstreamFormat.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,14 +104,28 @@ public class BitstreamFormatDAOImpl extends AbstractHibernateDAO<BitstreamFormat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BitstreamFormat> findNonInternal(Context context) throws SQLException {
|
public List<BitstreamFormat> findNonInternal(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BitstreamFormat.class);
|
|
||||||
criteria.add(Restrictions.and(
|
|
||||||
Restrictions.eq("internal", false),
|
|
||||||
Restrictions.not(Restrictions.like("shortDescription", "Unknown"))
|
|
||||||
));
|
|
||||||
criteria.addOrder(Order.desc("supportLevel")).addOrder(Order.asc("shortDescription"));
|
|
||||||
|
|
||||||
return list(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BitstreamFormat.class);
|
||||||
|
Root<BitstreamFormat> bitstreamFormatRoot = criteriaQuery.from(BitstreamFormat.class);
|
||||||
|
criteriaQuery.select(bitstreamFormatRoot);
|
||||||
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.and(criteriaBuilder.equal(bitstreamFormatRoot.get(BitstreamFormat_.internal), false),
|
||||||
|
criteriaBuilder.not(
|
||||||
|
criteriaBuilder
|
||||||
|
.like(bitstreamFormatRoot.get(BitstreamFormat_.shortDescription),
|
||||||
|
"Unknown"))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.desc(bitstreamFormatRoot.get(BitstreamFormat_.supportLevel)));
|
||||||
|
orderList.add(criteriaBuilder.asc(bitstreamFormatRoot.get(BitstreamFormat_.shortDescription)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, BitstreamFormat.class, -1, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,17 +135,22 @@ public class BitstreamFormatDAOImpl extends AbstractHibernateDAO<BitstreamFormat
|
|||||||
Query query = createQuery(context, "from BitstreamFormat bf where :extension in elements(bf.fileExtensions)");
|
Query query = createQuery(context, "from BitstreamFormat bf where :extension in elements(bf.fileExtensions)");
|
||||||
query.setParameter("extension", extension);
|
query.setParameter("extension", extension);
|
||||||
|
|
||||||
// Criteria criteria = createCriteria(context, BitstreamFormat.class, "bitstreamFormat");
|
|
||||||
// criteria.createAlias("bitstreamFormat.fileExtensions", "extension");
|
|
||||||
// criteria.add(Restrictions.eq("extension",extension ));
|
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BitstreamFormat> findAll(Context context, Class clazz) throws SQLException {
|
public List<BitstreamFormat> findAll(Context context, Class clazz) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BitstreamFormat.class);
|
|
||||||
criteria.addOrder(Order.asc("id"));
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
return list(criteria);
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BitstreamFormat.class);
|
||||||
|
Root<BitstreamFormat> bitstreamFormatRoot = criteriaQuery.from(BitstreamFormat.class);
|
||||||
|
criteriaQuery.select(bitstreamFormatRoot);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(bitstreamFormatRoot.get(BitstreamFormat_.id)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, BitstreamFormat.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,11 +8,22 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
|
import org.dspace.authorize.ResourcePolicy_;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.Collection_;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.content.dao.CollectionDAO;
|
import org.dspace.content.dao.CollectionDAO;
|
||||||
@@ -21,11 +32,6 @@ import org.dspace.core.Constants;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Disjunction;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
import org.hibernate.transform.BasicTransformerAdapter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Collection object.
|
* Hibernate implementation of the Database Access Object interface class for the Collection object.
|
||||||
@@ -43,7 +49,8 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
|
|||||||
* Get all collections in the system. These are alphabetically sorted by
|
* Get all collections in the system. These are alphabetically sorted by
|
||||||
* collection name.
|
* collection name.
|
||||||
*
|
*
|
||||||
* @param context DSpace context object
|
* @param context
|
||||||
|
* DSpace context object
|
||||||
* @param order order by MetadataField
|
* @param order order by MetadataField
|
||||||
* @return the collections in the system
|
* @return the collections in the system
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
@@ -75,77 +82,54 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection findByTemplateItem(Context context, Item item) throws SQLException {
|
public Collection findByTemplateItem(Context context, Item item) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Collection.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("template_item", item));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Collection.class);
|
||||||
return uniqueResult(criteria);
|
Root<Collection> collectionRoot = criteriaQuery.from(Collection.class);
|
||||||
|
criteriaQuery.select(collectionRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(collectionRoot.get(Collection_.template), item));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, Collection.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection findByGroup(Context context, Group group) throws SQLException {
|
public Collection findByGroup(Context context, Group group) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Collection.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Collection.class);
|
||||||
Restrictions.or(
|
Root<Collection> collectionRoot = criteriaQuery.from(Collection.class);
|
||||||
Restrictions.eq("workflowStep1", group),
|
criteriaQuery.select(collectionRoot);
|
||||||
Restrictions.eq("workflowStep2", group),
|
criteriaQuery
|
||||||
Restrictions.eq("workflowStep3", group),
|
.where(criteriaBuilder.or(criteriaBuilder.equal(collectionRoot.get(Collection_.workflowStep1), group),
|
||||||
Restrictions.eq("submitters", group),
|
criteriaBuilder.equal(collectionRoot.get(Collection_.workflowStep2), group),
|
||||||
Restrictions.eq("admins", group)
|
criteriaBuilder.equal(collectionRoot.get(Collection_.workflowStep3), group),
|
||||||
|
criteriaBuilder.equal(collectionRoot.get(Collection_.submitters), group),
|
||||||
|
criteriaBuilder.equal(collectionRoot.get(Collection_.admins), group)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return singleResult(criteria);
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Collection> findAuthorized(Context context, EPerson ePerson, List<Integer> actions)
|
public List<Collection> findAuthorized(Context context, EPerson ePerson, List<Integer> actions)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// TableRowIterator tri = DatabaseManager.query(context,
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// "SELECT * FROM collection, resourcepolicy, eperson " +
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Collection.class);
|
||||||
// "WHERE resourcepolicy.resource_id = collection.collection_id AND " +
|
Root<Collection> collectionRoot = criteriaQuery.from(Collection.class);
|
||||||
// "eperson.eperson_id = resourcepolicy.eperson_id AND "+
|
Join<Collection, ResourcePolicy> join = collectionRoot.join("resourcePolicies");
|
||||||
// "resourcepolicy.resource_type_id = 3 AND "+
|
List<Predicate> orPredicates = new LinkedList<Predicate>();
|
||||||
// "( resourcepolicy.action_id = 3 OR resourcepolicy.action_id = 11 ) AND "+
|
|
||||||
// "eperson.eperson_id = ?", context.getCurrentUser().getID());
|
|
||||||
|
|
||||||
Criteria criteria = createCriteria(context, Collection.class);
|
|
||||||
criteria.createAlias("resourcePolicies", "resourcePolicy");
|
|
||||||
|
|
||||||
Disjunction actionQuery = Restrictions.or();
|
|
||||||
for (Integer action : actions) {
|
for (Integer action : actions) {
|
||||||
actionQuery.add(Restrictions.eq("resourcePolicy.actionId", action));
|
orPredicates.add(criteriaBuilder.equal(join.get(ResourcePolicy_.actionId), action));
|
||||||
}
|
}
|
||||||
criteria.add(Restrictions.and(
|
Predicate orPredicate = criteriaBuilder.or(orPredicates.toArray(new Predicate[] {}));
|
||||||
Restrictions.eq("resourcePolicy.resourceTypeId", Constants.COLLECTION),
|
criteriaQuery.select(collectionRoot);
|
||||||
Restrictions.eq("resourcePolicy.eperson", ePerson),
|
criteriaQuery.where(
|
||||||
actionQuery
|
criteriaBuilder.and(criteriaBuilder.equal(join.get(ResourcePolicy_.resourceTypeId), Constants.COLLECTION),
|
||||||
));
|
criteriaBuilder.equal(join.get(ResourcePolicy_.eperson), ePerson),
|
||||||
criteria.setCacheable(true);
|
orPredicate));
|
||||||
|
return list(context, criteriaQuery, true, Collection.class, -1, -1);
|
||||||
return list(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Collection> findAuthorizedByGroup(Context context, EPerson ePerson, List<Integer> actions)
|
public List<Collection> findAuthorizedByGroup(Context context, EPerson ePerson, List<Integer> actions)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// TableRowIterator tri = DatabaseManager.query(context,
|
|
||||||
// "SELECT \n" +
|
|
||||||
// " * \n" +
|
|
||||||
// "FROM \n" +
|
|
||||||
// " public.eperson, \n" +
|
|
||||||
// " public.epersongroup2eperson, \n" +
|
|
||||||
// " public.epersongroup, \n" +
|
|
||||||
// " public.group2group, \n" +
|
|
||||||
// " public.resourcepolicy rp_parent, \n" +
|
|
||||||
// " public.collection\n" +
|
|
||||||
// "WHERE \n" +
|
|
||||||
// " epersongroup2eperson.eperson_id = eperson.eperson_id AND\n" +
|
|
||||||
// " epersongroup.eperson_group_id = epersongroup2eperson.eperson_group_id AND\n" +
|
|
||||||
// " group2group.child_id = epersongroup.eperson_group_id AND\n" +
|
|
||||||
// " rp_parent.epersongroup_id = group2group.parent_id AND\n" +
|
|
||||||
// " collection.collection_id = rp_parent.resource_id AND\n" +
|
|
||||||
// " eperson.eperson_id = ? AND \n" +
|
|
||||||
// " (rp_parent.action_id = 3 OR \n" +
|
|
||||||
// " rp_parent.action_id = 11 \n" +
|
|
||||||
// " ) AND rp_parent.resource_type_id = 3;", context.getCurrentUser().getID());
|
|
||||||
StringBuilder query = new StringBuilder();
|
StringBuilder query = new StringBuilder();
|
||||||
query.append("select c from Collection c join c.resourcePolicies rp join rp.epersonGroup rpGroup WHERE ");
|
query.append("select c from Collection c join c.resourcePolicies rp join rp.epersonGroup rpGroup WHERE ");
|
||||||
for (int i = 0; i < actions.size(); i++) {
|
for (int i = 0; i < actions.size(); i++) {
|
||||||
@@ -159,11 +143,11 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
|
|||||||
query.append(
|
query.append(
|
||||||
" AND rp.epersonGroup.id IN (select g.id from Group g where (from EPerson e where e.id = :eperson_id) in " +
|
" AND rp.epersonGroup.id IN (select g.id from Group g where (from EPerson e where e.id = :eperson_id) in " +
|
||||||
"elements(epeople))");
|
"elements(epeople))");
|
||||||
Query hibernateQuery = createQuery(context, query.toString());
|
Query persistenceQuery = createQuery(context, query.toString());
|
||||||
hibernateQuery.setParameter("eperson_id", ePerson.getID());
|
persistenceQuery.setParameter("eperson_id", ePerson.getID());
|
||||||
hibernateQuery.setCacheable(true);
|
persistenceQuery.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
return list(hibernateQuery);
|
return list(persistenceQuery);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -185,12 +169,12 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
|
|||||||
String q = "select col as collection, sum(bit.sizeBytes) as totalBytes from Item i join i.collections col " +
|
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";
|
"join i.bundles bun join bun.bitstreams bit group by col";
|
||||||
Query query = createQuery(context, q);
|
Query query = createQuery(context, q);
|
||||||
query.setResultTransformer(new BasicTransformerAdapter() {
|
|
||||||
@Override
|
List<Object[]> list = query.getResultList();
|
||||||
public Object transformTuple(Object[] tuple, String[] aliases) {
|
List<Map.Entry<Collection, Long>> returnList = new LinkedList<>();
|
||||||
return new java.util.AbstractMap.SimpleImmutableEntry<>((Collection) tuple[0], (Long) tuple[1]);
|
for (Object[] o : list) {
|
||||||
|
returnList.add(new AbstractMap.SimpleEntry<>((Collection) o[0], (Long) o[1]));
|
||||||
}
|
}
|
||||||
});
|
return returnList;
|
||||||
return ((List<Map.Entry<Collection, Long>>) query.list());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -10,9 +10,19 @@ package org.dspace.content.dao.impl;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
|
import org.dspace.authorize.ResourcePolicy_;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
|
import org.dspace.content.Community_;
|
||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.content.dao.CommunityDAO;
|
import org.dspace.content.dao.CommunityDAO;
|
||||||
import org.dspace.core.AbstractHibernateDSODAO;
|
import org.dspace.core.AbstractHibernateDSODAO;
|
||||||
@@ -20,10 +30,6 @@ import org.dspace.core.Constants;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Disjunction;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Community object.
|
* Hibernate implementation of the Database Access Object interface class for the Community object.
|
||||||
@@ -43,6 +49,7 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
|||||||
*
|
*
|
||||||
* @param context DSpace context object
|
* @param context DSpace context object
|
||||||
* @param sortField sort field
|
* @param sortField sort field
|
||||||
|
*
|
||||||
* @return the communities in the system
|
* @return the communities in the system
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
@@ -73,9 +80,12 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Community findByAdminGroup(Context context, Group group) throws SQLException {
|
public Community findByAdminGroup(Context context, Group group) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Community.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("admins", group));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Community.class);
|
||||||
return singleResult(criteria);
|
Root<Community> communityRoot = criteriaQuery.from(Community.class);
|
||||||
|
criteriaQuery.select(communityRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(communityRoot.get(Community_.admins), group));
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,7 +98,8 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
|||||||
|
|
||||||
Query query = createQuery(context, queryBuilder.toString());
|
Query query = createQuery(context, queryBuilder.toString());
|
||||||
query.setParameter(sortField.toString(), sortField.getID());
|
query.setParameter(sortField.toString(), sortField.getID());
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
|
|
||||||
return findMany(context, query);
|
return findMany(context, query);
|
||||||
}
|
}
|
||||||
@@ -115,42 +126,29 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
|||||||
" resourcepolicy.resource_type_id = 4 AND eperson.eperson_id = ?", context.getCurrentUser()
|
" resourcepolicy.resource_type_id = 4 AND eperson.eperson_id = ?", context.getCurrentUser()
|
||||||
.getID());
|
.getID());
|
||||||
*/
|
*/
|
||||||
Criteria criteria = createCriteria(context, Community.class);
|
|
||||||
criteria.createAlias("resourcePolicies", "resourcePolicy");
|
|
||||||
|
|
||||||
Disjunction actionQuery = Restrictions.or();
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Community.class);
|
||||||
|
Root<Community> communityRoot = criteriaQuery.from(Community.class);
|
||||||
|
Join<Community, ResourcePolicy> join = communityRoot.join("resourcePolicies");
|
||||||
|
List<Predicate> orPredicates = new LinkedList<Predicate>();
|
||||||
for (Integer action : actions) {
|
for (Integer action : actions) {
|
||||||
actionQuery.add(Restrictions.eq("resourcePolicy.actionId", action));
|
orPredicates.add(criteriaBuilder.equal(join.get(ResourcePolicy_.actionId), action));
|
||||||
}
|
}
|
||||||
criteria.add(Restrictions.and(
|
Predicate orPredicate = criteriaBuilder.or(orPredicates.toArray(new Predicate[] {}));
|
||||||
Restrictions.eq("resourcePolicy.resourceTypeId", Constants.COMMUNITY),
|
criteriaQuery.select(communityRoot);
|
||||||
Restrictions.eq("resourcePolicy.eperson", ePerson),
|
criteriaQuery.where(
|
||||||
actionQuery
|
criteriaBuilder.and(criteriaBuilder.equal(join.get(ResourcePolicy_.resourceTypeId), Constants.COMMUNITY),
|
||||||
));
|
criteriaBuilder.equal(join.get(ResourcePolicy_.eperson), ePerson),
|
||||||
criteria.setCacheable(true);
|
orPredicate
|
||||||
|
)
|
||||||
return list(criteria);
|
);
|
||||||
|
return list(context, criteriaQuery, true, Community.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Community> findAuthorizedByGroup(Context context, EPerson ePerson, List<Integer> actions)
|
public List<Community> findAuthorizedByGroup(Context context, EPerson ePerson, List<Integer> actions)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// "SELECT \n" +
|
|
||||||
// " * \n" +
|
|
||||||
// "FROM \n" +
|
|
||||||
// " public.eperson, \n" +
|
|
||||||
// " public.epersongroup2eperson, \n" +
|
|
||||||
// " public.epersongroup, \n" +
|
|
||||||
// " public.community, \n" +
|
|
||||||
// " public.resourcepolicy\n" +
|
|
||||||
// "WHERE \n" +
|
|
||||||
// " epersongroup2eperson.eperson_id = eperson.eperson_id AND\n" +
|
|
||||||
// " epersongroup.eperson_group_id = epersongroup2eperson.eperson_group_id AND\n" +
|
|
||||||
// " resourcepolicy.epersongroup_id = epersongroup.eperson_group_id AND\n" +
|
|
||||||
// " resourcepolicy.resource_id = community.community_id AND\n" +
|
|
||||||
// " ( resourcepolicy.action_id = 3 OR \n" +
|
|
||||||
// " resourcepolicy.action_id = 11) AND \n" +
|
|
||||||
// " resourcepolicy.resource_type_id = 4 AND eperson.eperson_id = ?", context.getCurrentUser().getID());
|
|
||||||
StringBuilder query = new StringBuilder();
|
StringBuilder query = new StringBuilder();
|
||||||
query.append("select c from Community c join c.resourcePolicies rp join rp.epersonGroup rpGroup WHERE ");
|
query.append("select c from Community c join c.resourcePolicies rp join rp.epersonGroup rpGroup WHERE ");
|
||||||
for (int i = 0; i < actions.size(); i++) {
|
for (int i = 0; i < actions.size(); i++) {
|
||||||
@@ -164,11 +162,12 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
|||||||
query.append(
|
query.append(
|
||||||
" AND rp.epersonGroup.id IN (select g.id from Group g where (from EPerson e where e.id = :eperson_id) in " +
|
" AND rp.epersonGroup.id IN (select g.id from Group g where (from EPerson e where e.id = :eperson_id) in " +
|
||||||
"elements(epeople))");
|
"elements(epeople))");
|
||||||
Query hibernateQuery = createQuery(context, query.toString());
|
Query persistenceQuery = createQuery(context, query.toString());
|
||||||
hibernateQuery.setParameter("eperson_id", ePerson.getID());
|
persistenceQuery.setParameter("eperson_id", ePerson.getID());
|
||||||
hibernateQuery.setCacheable(true);
|
|
||||||
|
|
||||||
return list(hibernateQuery);
|
persistenceQuery.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
|
return list(persistenceQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -13,6 +13,8 @@ import java.util.Date;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
@@ -24,7 +26,7 @@ import org.dspace.core.AbstractHibernateDSODAO;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.criterion.Criterion;
|
||||||
import org.hibernate.criterion.DetachedCriteria;
|
import org.hibernate.criterion.DetachedCriteria;
|
||||||
import org.hibernate.criterion.Projections;
|
import org.hibernate.criterion.Projections;
|
||||||
import org.hibernate.criterion.Property;
|
import org.hibernate.criterion.Property;
|
||||||
@@ -89,7 +91,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
|
|||||||
query.setParameter("withdrawn", withdrawn);
|
query.setParameter("withdrawn", withdrawn);
|
||||||
query.setParameter("discoverable", discoverable);
|
query.setParameter("discoverable", discoverable);
|
||||||
if (lastModified != null) {
|
if (lastModified != null) {
|
||||||
query.setTimestamp("last_modified", lastModified);
|
query.setParameter("last_modified", lastModified, TemporalType.TIMESTAMP);
|
||||||
}
|
}
|
||||||
return iterate(query);
|
return iterate(query);
|
||||||
}
|
}
|
||||||
@@ -139,14 +141,68 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
|
|||||||
return iterate(query);
|
return iterate(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum OP { equals, not_equals, like, not_like, contains, doesnt_contain, exists, doesnt_exist, matches,
|
enum OP {
|
||||||
doesnt_match }
|
equals {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return Property.forName("mv.value").eq(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
not_equals {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return OP.equals.buildPredicate(val, regexClause);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
like {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return Property.forName("mv.value").like(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
not_like {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return OP.like.buildPredicate(val, regexClause);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
contains {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return Property.forName("mv.value").like("%" + val + "%");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
doesnt_contain {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return OP.contains.buildPredicate(val, regexClause);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exists {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return Property.forName("mv.value").isNotNull();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
doesnt_exist {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return OP.exists.buildPredicate(val, regexClause);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
matches {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return Restrictions.sqlRestriction(regexClause, val, StandardBasicTypes.STRING);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
doesnt_match {
|
||||||
|
public Criterion buildPredicate(String val, String regexClause) {
|
||||||
|
return OP.matches.buildPredicate(val, regexClause);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
public abstract Criterion buildPredicate(String val, String regexClause);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public Iterator<Item> findByMetadataQuery(Context context, List<List<MetadataField>> listFieldList,
|
public Iterator<Item> findByMetadataQuery(Context context, List<List<MetadataField>> listFieldList,
|
||||||
List<String> query_op, List<String> query_val, List<UUID> collectionUuids,
|
List<String> query_op, List<String> query_val, List<UUID> collectionUuids,
|
||||||
String regexClause, int offset, int limit) throws SQLException {
|
String regexClause, int offset, int limit) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Item.class, "item");
|
|
||||||
|
Criteria criteria = getHibernateSession(context).createCriteria(Item.class, "item");
|
||||||
criteria.setFirstResult(offset);
|
criteria.setFirstResult(offset);
|
||||||
criteria.setMaxResults(limit);
|
criteria.setMaxResults(limit);
|
||||||
|
|
||||||
@@ -183,20 +239,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
|
|||||||
subcriteria.add(Restrictions.in("metadataField", listFieldList.get(i)));
|
subcriteria.add(Restrictions.in("metadataField", listFieldList.get(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(op.name() + " ");
|
subcriteria.add(op.buildPredicate(query_val.get(i), regexClause));
|
||||||
if (op == OP.equals || op == OP.not_equals) {
|
|
||||||
subcriteria.add(Property.forName("mv.value").eq(query_val.get(i)));
|
|
||||||
sb.append(query_val.get(i));
|
|
||||||
} else if (op == OP.like || op == OP.not_like) {
|
|
||||||
subcriteria.add(Property.forName("mv.value").like(query_val.get(i)));
|
|
||||||
sb.append(query_val.get(i));
|
|
||||||
} else if (op == OP.contains || op == OP.doesnt_contain) {
|
|
||||||
subcriteria.add(Property.forName("mv.value").like("%" + query_val.get(i) + "%"));
|
|
||||||
sb.append(query_val.get(i));
|
|
||||||
} else if (op == OP.matches || op == OP.doesnt_match) {
|
|
||||||
subcriteria.add(Restrictions.sqlRestriction(regexClause, query_val.get(i), StandardBasicTypes.STRING));
|
|
||||||
sb.append(query_val.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (op == OP.exists || op == OP.equals || op == OP.like || op == OP.contains || op == OP.matches) {
|
if (op == OP.exists || op == OP.equals || op == OP.like || op == OP.contains || op == OP.matches) {
|
||||||
criteria.add(Subqueries.exists(subcriteria));
|
criteria.add(Subqueries.exists(subcriteria));
|
||||||
@@ -206,7 +249,8 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
|
|||||||
}
|
}
|
||||||
log.debug(String.format("Running custom query with %d filters", index));
|
log.debug(String.format("Running custom query with %d filters", index));
|
||||||
|
|
||||||
return list(criteria).iterator();
|
return ((List<Item>) criteria.list()).iterator();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -285,7 +329,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
|
|||||||
Query query = createQuery(context, "select count(distinct i) from Item i " +
|
Query query = createQuery(context, "select count(distinct i) from Item i " +
|
||||||
"join i.collections collection " +
|
"join i.collections collection " +
|
||||||
"WHERE collection IN (:collections) AND i.inArchive=:in_archive AND i.withdrawn=:withdrawn");
|
"WHERE collection IN (:collections) AND i.inArchive=:in_archive AND i.withdrawn=:withdrawn");
|
||||||
query.setParameterList("collections", collections);
|
query.setParameter("collections", collections);
|
||||||
query.setParameter("in_archive", includeArchived);
|
query.setParameter("in_archive", includeArchived);
|
||||||
query.setParameter("withdrawn", includeWithdrawn);
|
query.setParameter("withdrawn", includeWithdrawn);
|
||||||
|
|
||||||
@@ -296,7 +340,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
|
|||||||
public Iterator<Item> findByLastModifiedSince(Context context, Date since)
|
public Iterator<Item> findByLastModifiedSince(Context context, Date since)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Query query = createQuery(context, "SELECT i FROM item i WHERE last_modified > :last_modified");
|
Query query = createQuery(context, "SELECT i FROM item i WHERE last_modified > :last_modified");
|
||||||
query.setTimestamp("last_modified", since);
|
query.setParameter("last_modified", since, TemporalType.TIMESTAMP);
|
||||||
return iterate(query);
|
return iterate(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,18 +8,22 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
|
import org.dspace.content.MetadataField_;
|
||||||
import org.dspace.content.MetadataSchema;
|
import org.dspace.content.MetadataSchema;
|
||||||
|
import org.dspace.content.MetadataSchema_;
|
||||||
import org.dspace.content.dao.MetadataFieldDAO;
|
import org.dspace.content.dao.MetadataFieldDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.FetchMode;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the MetadataField object.
|
* Hibernate implementation of the Database Access Object interface class for the MetadataField object.
|
||||||
@@ -61,8 +65,8 @@ public class MetadataFieldDAOImpl extends AbstractHibernateDAO<MetadataField> im
|
|||||||
if (qualifier != null) {
|
if (qualifier != null) {
|
||||||
query.setParameter("qualifier", qualifier);
|
query.setParameter("qualifier", qualifier);
|
||||||
}
|
}
|
||||||
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
query.setCacheable(true);
|
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,19 +101,27 @@ public class MetadataFieldDAOImpl extends AbstractHibernateDAO<MetadataField> im
|
|||||||
if (StringUtils.isNotBlank(qualifier)) {
|
if (StringUtils.isNotBlank(qualifier)) {
|
||||||
query.setParameter("qualifier", qualifier);
|
query.setParameter("qualifier", qualifier);
|
||||||
}
|
}
|
||||||
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
query.setCacheable(true);
|
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MetadataField> findAll(Context context, Class<MetadataField> clazz) throws SQLException {
|
public List<MetadataField> findAll(Context context, Class<MetadataField> clazz) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, MetadataField.class);
|
|
||||||
criteria.createAlias("metadataSchema", "s").addOrder(Order.asc("s.name")).addOrder(Order.asc("element"))
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
.addOrder(Order.asc("qualifier"));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, MetadataField.class);
|
||||||
criteria.setFetchMode("metadataSchema", FetchMode.JOIN);
|
Root<MetadataField> metadataFieldRoot = criteriaQuery.from(MetadataField.class);
|
||||||
criteria.setCacheable(true);
|
Join<MetadataField, MetadataSchema> join = metadataFieldRoot.join("metadataSchema");
|
||||||
return list(criteria);
|
criteriaQuery.select(metadataFieldRoot);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(join.get(MetadataSchema_.name)));
|
||||||
|
orderList.add(criteriaBuilder.asc(metadataFieldRoot.get(MetadataField_.element)));
|
||||||
|
orderList.add(criteriaBuilder.asc(metadataFieldRoot.get(MetadataField_.qualifier)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, true, MetadataField.class, -1, -1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -123,8 +135,8 @@ public class MetadataFieldDAOImpl extends AbstractHibernateDAO<MetadataField> im
|
|||||||
|
|
||||||
query.setParameter("name", metadataSchema);
|
query.setParameter("name", metadataSchema);
|
||||||
query.setParameter("element", element);
|
query.setParameter("element", element);
|
||||||
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
query.setCacheable(true);
|
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +152,8 @@ public class MetadataFieldDAOImpl extends AbstractHibernateDAO<MetadataField> im
|
|||||||
|
|
||||||
query.setParameter("name", metadataSchema.getName());
|
query.setParameter("name", metadataSchema.getName());
|
||||||
|
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,15 +8,18 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.MetadataSchema;
|
import org.dspace.content.MetadataSchema;
|
||||||
|
import org.dspace.content.MetadataSchema_;
|
||||||
import org.dspace.content.dao.MetadataSchemaDAO;
|
import org.dspace.content.dao.MetadataSchemaDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the MetadataSchema object.
|
* Hibernate implementation of the Database Access Object interface class for the MetadataSchema object.
|
||||||
@@ -46,19 +49,25 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
"WHERE ms.namespace = :namespace ");
|
"WHERE ms.namespace = :namespace ");
|
||||||
|
|
||||||
query.setParameter("namespace", namespace);
|
query.setParameter("namespace", namespace);
|
||||||
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
query.setCacheable(true);
|
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MetadataSchema> findAll(Context context, Class clazz) throws SQLException {
|
public List<MetadataSchema> findAll(Context context, Class clazz) throws SQLException {
|
||||||
// Get all the metadataschema rows
|
// Get all the metadataschema rows
|
||||||
Criteria criteria = createCriteria(context, MetadataSchema.class);
|
|
||||||
criteria.addOrder(Order.asc("id"));
|
|
||||||
criteria.setCacheable(true);
|
|
||||||
|
|
||||||
return list(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, MetadataSchema.class);
|
||||||
|
Root<MetadataSchema> metadataSchemaRoot = criteriaQuery.from(MetadataSchema.class);
|
||||||
|
criteriaQuery.select(metadataSchemaRoot);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(metadataSchemaRoot.get(MetadataSchema_.id)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, true, MetadataSchema.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,7 +89,7 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
query.setParameter("namespace", namespace);
|
query.setParameter("namespace", namespace);
|
||||||
query.setParameter("id", metadataSchemaId);
|
query.setParameter("id", metadataSchemaId);
|
||||||
|
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
return singleResult(query) == null;
|
return singleResult(query) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,15 +111,17 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
query.setParameter("name", name);
|
query.setParameter("name", name);
|
||||||
query.setParameter("id", metadataSchemaId);
|
query.setParameter("id", metadataSchemaId);
|
||||||
|
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
return singleResult(query) == null;
|
return singleResult(query) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the schema corresponding with this short name.
|
* Get the schema corresponding with this short name.
|
||||||
*
|
*
|
||||||
* @param context context, in case we need to read it in from DB
|
* @param context
|
||||||
* @param shortName the short name for the schema
|
* context, in case we need to read it in from DB
|
||||||
|
* @param shortName
|
||||||
|
* the short name for the schema
|
||||||
* @return the metadata schema object
|
* @return the metadata schema object
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
@@ -122,7 +133,7 @@ public class MetadataSchemaDAOImpl extends AbstractHibernateDAO<MetadataSchema>
|
|||||||
|
|
||||||
query.setParameter("name", shortName);
|
query.setParameter("name", shortName);
|
||||||
|
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,16 +10,18 @@ package org.dspace.content.dao.impl;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
|
import org.dspace.content.MetadataField_;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
import org.dspace.content.dao.MetadataValueDAO;
|
import org.dspace.content.dao.MetadataValueDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.FetchMode;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the MetadataValue object.
|
* Hibernate implementation of the Database Access Object interface class for the MetadataValue object.
|
||||||
@@ -36,13 +38,15 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MetadataValue> findByField(Context context, MetadataField metadataField) throws SQLException {
|
public List<MetadataValue> findByField(Context context, MetadataField metadataField) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, MetadataValue.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, MetadataValue.class);
|
||||||
Restrictions.eq("metadataField.id", metadataField.getID())
|
Root<MetadataValue> metadataValueRoot = criteriaQuery.from(MetadataValue.class);
|
||||||
);
|
Join<MetadataValue, MetadataField> join = metadataValueRoot.join("metadataField");
|
||||||
criteria.setFetchMode("metadataField", FetchMode.JOIN);
|
criteriaQuery.select(metadataValueRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(join.get(MetadataField_.id), metadataField.getID()));
|
||||||
|
|
||||||
return list(criteria);
|
|
||||||
|
return list(context, criteriaQuery, false, MetadataValue.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,7 +55,7 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
|
|||||||
"WHERE m.value like concat('%', concat(:searchString,'%')) ORDER BY m.id ASC";
|
"WHERE m.value like concat('%', concat(:searchString,'%')) ORDER BY m.id ASC";
|
||||||
|
|
||||||
Query query = createQuery(context, queryString);
|
Query query = createQuery(context, queryString);
|
||||||
query.setString("searchString", value);
|
query.setParameter("searchString", value);
|
||||||
|
|
||||||
return iterate(query);
|
return iterate(query);
|
||||||
}
|
}
|
||||||
@@ -72,7 +76,7 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
|
|||||||
Query query = createQuery(context, queryString);
|
Query query = createQuery(context, queryString);
|
||||||
query.setParameter("metadata_field_id", metadataFieldId);
|
query.setParameter("metadata_field_id", metadataFieldId);
|
||||||
query.setMaxResults(1);
|
query.setMaxResults(1);
|
||||||
return (MetadataValue) query.uniqueResult();
|
return (MetadataValue) query.getSingleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -8,12 +8,14 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Site;
|
import org.dspace.content.Site;
|
||||||
import org.dspace.content.dao.SiteDAO;
|
import org.dspace.content.dao.SiteDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Site object.
|
* Hibernate implementation of the Database Access Object interface class for the Site object.
|
||||||
@@ -29,8 +31,10 @@ public class SiteDAOImpl extends AbstractHibernateDAO<Site> implements SiteDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Site findSite(Context context) throws SQLException {
|
public Site findSite(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Site.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.setCacheable(true);
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Site.class);
|
||||||
return uniqueResult(criteria);
|
Root<Site> siteRoot = criteriaQuery.from(Site.class);
|
||||||
|
criteriaQuery.select(siteRoot);
|
||||||
|
return uniqueResult(context, criteriaQuery, true, Site.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,21 +8,26 @@
|
|||||||
package org.dspace.content.dao.impl;
|
package org.dspace.content.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
|
import org.dspace.content.WorkspaceItem_;
|
||||||
import org.dspace.content.dao.WorkspaceItemDAO;
|
import org.dspace.content.dao.WorkspaceItemDAO;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.hibernate.Criteria;
|
import org.dspace.eperson.EPerson_;
|
||||||
import org.hibernate.Query;
|
import org.dspace.eperson.Group;
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
import org.hibernate.transform.BasicTransformerAdapter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the WorkspaceItem object.
|
* Hibernate implementation of the Database Access Object interface class for the WorkspaceItem object.
|
||||||
@@ -49,63 +54,91 @@ public class WorkspaceItemDAOImpl extends AbstractHibernateDAO<WorkspaceItem> im
|
|||||||
@Override
|
@Override
|
||||||
public List<WorkspaceItem> findByEPerson(Context context, EPerson ep, Integer limit, Integer offset)
|
public List<WorkspaceItem> findByEPerson(Context context, EPerson ep, Integer limit, Integer offset)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class, "wi");
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.addOrder(Order.asc("workspaceItemId"));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
criteria.createAlias("wi.item", "item");
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
criteria.createAlias("item.submitter", "submitter");
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(workspaceItemRoot.get(WorkspaceItem_.item).get("submitter"), ep));
|
||||||
criteria.add(Restrictions.eq("submitter.id", ep.getID()));
|
criteriaQuery.orderBy(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
|
||||||
criteria.setFirstResult(offset);
|
return list(context, criteriaQuery, false, WorkspaceItem.class, limit, offset);
|
||||||
criteria.setMaxResults(limit);
|
|
||||||
return list(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkspaceItem> findByCollection(Context context, Collection c) throws SQLException {
|
public List<WorkspaceItem> findByCollection(Context context, Collection c) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("collection", c));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
return list(criteria);
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(workspaceItemRoot.get(WorkspaceItem_.collection), c));
|
||||||
|
criteriaQuery.orderBy(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
|
||||||
|
return list(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkspaceItem findByItem(Context context, Item i) throws SQLException {
|
public WorkspaceItem findByItem(Context context, Item i) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("item", i));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
// Look for the unique workspaceitem entry where 'item_id' references this item
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
return uniqueResult(criteria);
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(workspaceItemRoot.get(WorkspaceItem_.item), i));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkspaceItem> findAll(Context context) throws SQLException {
|
public List<WorkspaceItem> findAll(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.addOrder(Order.asc("item"));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
return list(criteria);
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException {
|
public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.addOrder(Order.asc("item"));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
criteria.setFirstResult(offset);
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
criteria.setMaxResults(limit);
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
return list(criteria);
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, WorkspaceItem.class, limit, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkspaceItem> findWithSupervisedGroup(Context context) throws SQLException {
|
public List<WorkspaceItem> findWithSupervisedGroup(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.isNotEmpty("supervisorGroups"));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
criteria.addOrder(Order.asc("workspaceItemId"));
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.isNotEmpty(workspaceItemRoot.get(WorkspaceItem_.supervisorGroups)));
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
return list(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkspaceItem> findBySupervisedGroupMember(Context context, EPerson ePerson) throws SQLException {
|
public List<WorkspaceItem> findBySupervisedGroupMember(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkspaceItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.createAlias("supervisorGroups", "supervisorGroup");
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
|
||||||
criteria.createAlias("supervisorGroup.epeople", "person");
|
Root<WorkspaceItem> workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
|
||||||
criteria.add(Restrictions.eq("person.id", ePerson.getID()));
|
Join<WorkspaceItem, Group> join = workspaceItemRoot.join("supervisorGroups");
|
||||||
return list(criteria);
|
Join<Group, EPerson> secondJoin = join.join("epeople");
|
||||||
|
criteriaQuery.select(workspaceItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(secondJoin.get(EPerson_.id), ePerson.getID()));
|
||||||
|
criteriaQuery.orderBy(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
|
||||||
|
return list(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,13 +160,13 @@ public class WorkspaceItemDAOImpl extends AbstractHibernateDAO<WorkspaceItem> im
|
|||||||
Query query = createQuery(context,
|
Query query = createQuery(context,
|
||||||
"SELECT wi.stageReached as stage_reached, count(*) as cnt from WorkspaceItem wi" +
|
"SELECT wi.stageReached as stage_reached, count(*) as cnt from WorkspaceItem wi" +
|
||||||
" group by wi.stageReached order by wi.stageReached");
|
" group by wi.stageReached order by wi.stageReached");
|
||||||
query.setResultTransformer(new BasicTransformerAdapter() {
|
|
||||||
@Override
|
List<Object[]> list = query.getResultList();
|
||||||
public Object transformTuple(Object[] tuple, String[] aliases) {
|
List<Map.Entry<Integer, Long>> returnList = new LinkedList<>();
|
||||||
return new java.util.AbstractMap.SimpleImmutableEntry((Integer) tuple[0], (Long) tuple[1]);
|
for (Object[] o : list) {
|
||||||
|
returnList.add(new AbstractMap.SimpleEntry<>((Integer) o[0], (Long) o[1]));
|
||||||
}
|
}
|
||||||
});
|
return returnList;
|
||||||
return (List<Map.Entry<Integer, Long>>) query.list();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -10,21 +10,24 @@ package org.dspace.core;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Expression;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Projections;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation for generic DAO interface. Also includes additional
|
* Hibernate implementation for generic DAO interface. Also includes additional
|
||||||
* Hibernate calls that are commonly used.
|
* Hibernate calls that are commonly used.
|
||||||
* Each DAO should extend this class to prevent code duplication.
|
* Each DAO should extend this class to prevent code duplication.
|
||||||
*
|
*
|
||||||
* @param <T> class type
|
|
||||||
* @author kevinvandevelde at atmire.com
|
* @author kevinvandevelde at atmire.com
|
||||||
|
* @param <T> class type
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
||||||
|
|
||||||
@@ -61,13 +64,16 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<T> findAll(Context context, Class<T> clazz) throws SQLException {
|
public List<T> findAll(Context context, Class<T> clazz) throws SQLException {
|
||||||
return list(createCriteria(context, clazz));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(getCriteriaBuilder(context), clazz);
|
||||||
|
Root<T> root = criteriaQuery.from(clazz);
|
||||||
|
criteriaQuery.select(root);
|
||||||
|
return executeCriteriaQuery(context, criteriaQuery, false, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T findUnique(Context context, String query) throws SQLException {
|
public T findUnique(Context context, String query) throws SQLException {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
T result = (T) createQuery(context, query).uniqueResult();
|
T result = (T) createQuery(context, query).getSingleResult();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,51 +97,26 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
|||||||
@Override
|
@Override
|
||||||
public List<T> findMany(Context context, String query) throws SQLException {
|
public List<T> findMany(Context context, String query) throws SQLException {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<T> result = (List<T>) createQuery(context, query).list();
|
List<T> result = (List<T>) createQuery(context, query).getResultList();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a JPA Criteria query and return a collection of results.
|
* Execute a JPA Criteria query and return a collection of results.
|
||||||
*
|
*
|
||||||
* @param context The relevant DSpace Context.
|
* @param context
|
||||||
* @param query JPQL query string
|
* The relevant DSpace Context.
|
||||||
|
* @param query
|
||||||
|
* JPQL query string
|
||||||
* @return list of DAOs specified by the query string
|
* @return list of DAOs specified by the query string
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
public List<T> findMany(Context context, Query query) throws SQLException {
|
public List<T> findMany(Context context, Query query) throws SQLException {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<T> result = (List<T>) query.list();
|
List<T> result = (List<T>) query.getResultList();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create criteria matching an entity type or a supertype thereof.
|
|
||||||
* Use when building a criteria query.
|
|
||||||
*
|
|
||||||
* @param context current DSpace context.
|
|
||||||
* @param persistentClass specifies the type to be matched by the criteria.
|
|
||||||
* @return criteria concerning the type to be found.
|
|
||||||
* @throws SQLException passed through.
|
|
||||||
*/
|
|
||||||
public Criteria createCriteria(Context context, Class<T> persistentClass) throws SQLException {
|
|
||||||
return getHibernateSession(context).createCriteria(persistentClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create criteria matching an entity type or a supertype thereof.
|
|
||||||
* Use when building a criteria query.
|
|
||||||
*
|
|
||||||
* @param context current DSpace context.
|
|
||||||
* @param persistentClass specifies the type to be matched by the criteria.
|
|
||||||
* @param alias alias for the type.
|
|
||||||
* @return criteria concerning the type to be found.
|
|
||||||
* @throws SQLException passed through.
|
|
||||||
*/
|
|
||||||
public Criteria createCriteria(Context context, Class<T> persistentClass, String alias) throws SQLException {
|
|
||||||
return getHibernateSession(context).createCriteria(persistentClass, alias);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a parsed query from a query expression.
|
* Create a parsed query from a query expression.
|
||||||
*
|
*
|
||||||
@@ -149,82 +130,111 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the entities matched by the given Criteria.
|
* This method will return a list with unique results, no duplicates, made by the given CriteriaQuery and parameters
|
||||||
* Use this if you need all results together.
|
|
||||||
*
|
*
|
||||||
* @param criteria description of desired entities.
|
* @param context
|
||||||
* @return the entities matched.
|
* The standard DSpace context object
|
||||||
|
* @param criteriaQuery
|
||||||
|
* The CriteriaQuery for which this list will be retrieved
|
||||||
|
* @param cacheable
|
||||||
|
* Whether or not this query should be cacheable
|
||||||
|
* @param clazz
|
||||||
|
* The clazz for which this CriteriaQuery will be executed on
|
||||||
|
* @param maxResults
|
||||||
|
* The maxmimum amount of results that will be returned for this CriteriaQuery
|
||||||
|
* @param offset
|
||||||
|
* The offset to be used for the CriteriaQuery
|
||||||
|
* @return A list of distinct results as depicted by the CriteriaQuery and parameters
|
||||||
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public List<T> list(Criteria criteria) {
|
public List<T> list(Context context, CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults,
|
||||||
|
int offset) throws SQLException {
|
||||||
|
criteriaQuery.distinct(true);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<T> result = (List<T>) criteria.list();
|
List<T> result = (List<T>) executeCriteriaQuery(context, criteriaQuery, cacheable, maxResults, offset);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the entities matching a given parsed query.
|
* This method will return a list of results for the given CriteriaQuery and parameters
|
||||||
* Use this if you need all results together.
|
|
||||||
*
|
*
|
||||||
* @param query the query to be executed.
|
* @param context
|
||||||
* @return entities matching the query.
|
* The standard DSpace context object
|
||||||
|
* @param criteriaQuery
|
||||||
|
* The CriteriaQuery to be used to find the list of results
|
||||||
|
* @param cacheable
|
||||||
|
* A boolean value indicating whether this query should be cached or not
|
||||||
|
* @param clazz
|
||||||
|
* The class on which the CriteriaQuery will search
|
||||||
|
* @param maxResults
|
||||||
|
* The maximum amount of results to be returned
|
||||||
|
* @param offset
|
||||||
|
* The offset to be used for the CriteriaQuery
|
||||||
|
* @param distinct
|
||||||
|
* A boolean value indicating whether this list should be distinct or not
|
||||||
|
* @return A list of results determined by the CriteriaQuery and parameters
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public List<T> list(Context context, CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults,
|
||||||
|
int offset, boolean distinct) throws SQLException {
|
||||||
|
criteriaQuery.distinct(distinct);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<T> result = (List<T>) executeCriteriaQuery(context, criteriaQuery, cacheable, maxResults, offset);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be used to return a list of results for the given query
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* The query for which the resulting list will be returned
|
||||||
|
* @return The list of results for the given query
|
||||||
*/
|
*/
|
||||||
public List<T> list(Query query) {
|
public List<T> list(Query query) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<T> result = (List<T>) query.list();
|
List<T> result = (List<T>) query.getResultList();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a unique result selected by criteria. If multiple results CAN be
|
* Retrieve a unique result from the query. If multiple results CAN be
|
||||||
* retrieved an exception will be thrown,
|
* retrieved an exception will be thrown,
|
||||||
* so only use when the criteria state uniqueness in the database.
|
* so only use when the criteria state uniqueness in the database.
|
||||||
*
|
* @param criteriaQuery JPA criteria
|
||||||
* @param criteria description of the desired entity.
|
|
||||||
* @return a DAO specified by the criteria
|
* @return a DAO specified by the criteria
|
||||||
*/
|
*/
|
||||||
public T uniqueResult(Criteria criteria) {
|
public T uniqueResult(Context context, CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz,
|
||||||
@SuppressWarnings("unchecked")
|
int maxResults, int offset) throws SQLException {
|
||||||
T result = (T) criteria.uniqueResult();
|
List<T> list = list(context, criteriaQuery, cacheable, clazz, maxResults, offset);
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a unique result selected by a query. If multiple results CAN be
|
|
||||||
* retrieved then an exception will be thrown, so only use when the query
|
|
||||||
* states uniqueness in the database.
|
|
||||||
*
|
|
||||||
* @param query description of the desired entity.
|
|
||||||
* @return the found entity.
|
|
||||||
*/
|
|
||||||
public T uniqueResult(Query query) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
T result = (T) query.uniqueResult();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a single result selected by criteria. Best used if you expect a
|
|
||||||
* single result, but this isn't enforced on the database.
|
|
||||||
*
|
|
||||||
* @param criteria description of the desired entities.
|
|
||||||
* @return a DAO specified by the criteria
|
|
||||||
*/
|
|
||||||
public T singleResult(Criteria criteria) {
|
|
||||||
criteria.setMaxResults(1);
|
|
||||||
List<T> list = list(criteria);
|
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
if (list.size() == 1) {
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("More than one result found");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a single result matching a query. Best used if you expect a
|
* Retrieve a single result from the query. Best used if you expect a
|
||||||
* single result, but this isn't enforced on the database.
|
* single result, but this isn't enforced on the database.
|
||||||
|
* @param criteriaQuery JPA criteria
|
||||||
|
* @return a DAO specified by the criteria
|
||||||
|
*/
|
||||||
|
public T singleResult(Context context, CriteriaQuery criteriaQuery) throws SQLException {
|
||||||
|
Query query = this.getHibernateSession(context).createQuery(criteriaQuery);
|
||||||
|
return singleResult(query);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will return the first result from the given query or null if no results were found
|
||||||
*
|
*
|
||||||
* @param query description of desired entities.
|
* @param query
|
||||||
* @return matched entities.
|
* The query that is to be executed
|
||||||
|
* @return One result from the given query or null if none was found
|
||||||
*/
|
*/
|
||||||
public T singleResult(final Query query) {
|
public T singleResult(final Query query) {
|
||||||
query.setMaxResults(1);
|
query.setMaxResults(1);
|
||||||
@@ -234,49 +244,179 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an iterator over a stream of query results.
|
* This method will return a singular result for the given query
|
||||||
* Use this when consuming results one at a time.
|
|
||||||
*
|
*
|
||||||
* @param query description of desired entities.
|
* @param query
|
||||||
* @return iterator over the results of the query.
|
* The query for which a single result will be given
|
||||||
|
* @return The single result for this query
|
||||||
*/
|
*/
|
||||||
public Iterator<T> iterate(Query query) {
|
public T uniqueResult(Query query) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Iterator<T> result = (Iterator<T>) query.iterate();
|
T result = (T) query.getSingleResult();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many rows match these criteria?
|
* This method will return an Iterator for the given Query
|
||||||
* The same value as {@link countLong(Criteria)}, coerced to {@code int}.
|
|
||||||
*
|
*
|
||||||
* @param criteria description of the rows.
|
* @param query
|
||||||
* @return count of matching rows.
|
* The query for which an Iterator will be made
|
||||||
|
* @return The Iterator for the results of this query
|
||||||
*/
|
*/
|
||||||
public int count(Criteria criteria) {
|
public Iterator<T> iterate(Query query) {
|
||||||
return ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
|
@SuppressWarnings("unchecked")
|
||||||
|
Iterator<T> result = (Iterator<T>) query.getResultList().iterator();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many rows match this query?
|
* This method will return the amount of results that would be generated for this CriteriaQuery as an integer
|
||||||
*
|
*
|
||||||
* @param query description of the rows.
|
* @param context
|
||||||
* @return count of matching rows.
|
* The standard DSpace Context object
|
||||||
|
* @param criteriaQuery
|
||||||
|
* The CriteriaQuery for which this result will be retrieved
|
||||||
|
* @param criteriaBuilder
|
||||||
|
* The CriteriaBuilder that accompagnies the CriteriaQuery
|
||||||
|
* @param root
|
||||||
|
* The root that'll determine on which class object we need to calculate the result
|
||||||
|
* @return The amount of results that would be found by this CriteriaQuery as an integer value
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public int count(Context context, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder, Root<T> root)
|
||||||
|
throws SQLException {
|
||||||
|
return Math.toIntExact(countLong(context, criteriaQuery, criteriaBuilder, root));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will return the count of items for this query as an integer
|
||||||
|
* This query needs to already be in a formate that'll return one record that contains the amount
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* The query for which the amount of results will be returned.
|
||||||
|
* @return The amount of results
|
||||||
*/
|
*/
|
||||||
public int count(Query query) {
|
public int count(Query query) {
|
||||||
return ((Long) query.uniqueResult()).intValue();
|
return ((Long) query.getSingleResult()).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many rows match these criteria?
|
* This method will return the count of items for this query as a long
|
||||||
*
|
*
|
||||||
* @param criteria description of the rows.
|
* @param context
|
||||||
* @return count of matching rows.
|
* The standard DSpace Context object
|
||||||
|
* @param criteriaQuery
|
||||||
|
* The CriteriaQuery for which the amount of results will be retrieved
|
||||||
|
* @param criteriaBuilder
|
||||||
|
* The CriteriaBuilder that goes along with this CriteriaQuery
|
||||||
|
* @param root
|
||||||
|
* The root created for a DSpace class on which this query will search
|
||||||
|
* @return A long value that depicts the amount of results this query has found
|
||||||
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public long countLong(Criteria criteria) {
|
public long countLong(Context context, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder, Root<T> root)
|
||||||
return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
|
throws SQLException {
|
||||||
|
Expression<Long> countExpression = criteriaBuilder.countDistinct(root);
|
||||||
|
criteriaQuery.select(countExpression);
|
||||||
|
return (Long) this.getHibernateSession(context).createQuery(criteriaQuery).getSingleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should always be used in order to retrieve the CriteriaQuery in order to
|
||||||
|
* start creating a query that has to be executed
|
||||||
|
*
|
||||||
|
* @param criteriaBuilder
|
||||||
|
* The CriteriaBuilder for which this CriteriaQuery will be constructed
|
||||||
|
* @param clazz
|
||||||
|
* The class that this CriteriaQuery will be constructed for
|
||||||
|
* @return A CriteriaQuery on which a query can be built
|
||||||
|
*/
|
||||||
|
public CriteriaQuery<T> getCriteriaQuery(CriteriaBuilder criteriaBuilder, Class<T> clazz) {
|
||||||
|
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(clazz);
|
||||||
|
return criteriaQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should always be used in order to retrieve a CriteriaBuilder for the given context
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* The standard DSpace Context class for which a CriteriaBuilder will be made
|
||||||
|
* @return A CriteriaBuilder that can be used to create the query
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public CriteriaBuilder getCriteriaBuilder(Context context) throws SQLException {
|
||||||
|
return this.getHibernateSession(context).getCriteriaBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will return a list of objects to be returned that match the given criteriaQuery and parameters.
|
||||||
|
* The maxResults and offSet can be circumvented by entering the value -1 for them.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* The standard context DSpace object
|
||||||
|
* @param criteriaQuery
|
||||||
|
* The CriteriaQuery that will be used for executing the query
|
||||||
|
* @param cacheable
|
||||||
|
* Whether or not this query is able to be cached
|
||||||
|
* @param maxResults
|
||||||
|
* The maximum amount of results that this query will return
|
||||||
|
* This can be circumvented by passing along -1 as the value
|
||||||
|
* @param offset
|
||||||
|
* The offset to be used in this query
|
||||||
|
* This can be circumvented by passing along -1 as the value
|
||||||
|
* @return This will return a list of objects that conform to the made query
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public List<T> executeCriteriaQuery(Context context, CriteriaQuery<T> criteriaQuery, boolean cacheable,
|
||||||
|
int maxResults, int offset) throws SQLException {
|
||||||
|
Query query = this.getHibernateSession(context).createQuery(criteriaQuery);
|
||||||
|
|
||||||
|
query.setHint("org.hibernate.cacheable", cacheable);
|
||||||
|
if (maxResults != -1) {
|
||||||
|
query.setMaxResults(maxResults);
|
||||||
|
}
|
||||||
|
if (offset != -1) {
|
||||||
|
query.setFirstResult(offset);
|
||||||
|
}
|
||||||
|
return query.getResultList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method can be used to construct a query for which there needs to be a bunch of equal properties
|
||||||
|
* These properties can be passed along in the equals hashmap
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* The standard DSpace context object
|
||||||
|
* @param clazz
|
||||||
|
* The class on which the criteriaQuery will be built
|
||||||
|
* @param equals
|
||||||
|
* A hashmap that can be used to store the String representation of the column
|
||||||
|
* and the value that should match that in the DB
|
||||||
|
* @param cacheable
|
||||||
|
* A boolean indicating whether this query should be cacheable or not
|
||||||
|
* @param maxResults
|
||||||
|
* The max amount of results to be returned by this query
|
||||||
|
* @param offset
|
||||||
|
* The offset to be used in this query
|
||||||
|
* @return Will return a list of objects that correspond with the constructed query and parameters
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public List<T> findByX(Context context, Class clazz, Map<String, Object> equals, boolean cacheable, int maxResults,
|
||||||
|
int offset) throws SQLException {
|
||||||
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery<T> criteria = getCriteriaQuery(criteriaBuilder, clazz);
|
||||||
|
Root root = criteria.from(clazz);
|
||||||
|
criteria.select(root);
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : equals.entrySet()) {
|
||||||
|
criteria.where(criteriaBuilder.equal(root.get(entry.getKey()), entry.getValue()));
|
||||||
|
}
|
||||||
|
return executeCriteriaQuery(context, criteria, cacheable, maxResults, offset);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,15 +9,16 @@ package org.dspace.core;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections.ListUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation used by DSpaceObject Database Access Objects.
|
* Hibernate implementation used by DSpaceObject Database Access Objects.
|
||||||
@@ -26,8 +27,8 @@ import org.hibernate.criterion.Restrictions;
|
|||||||
* <p>
|
* <p>
|
||||||
* Each DSO Database Access Object should extend this class to prevent code duplication.
|
* Each DSO Database Access Object should extend this class to prevent code duplication.
|
||||||
*
|
*
|
||||||
* @param <T> type of DSO represented.
|
|
||||||
* @author kevinvandevelde at atmire.com
|
* @author kevinvandevelde at atmire.com
|
||||||
|
* @param <T> type of DSO represented.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHibernateDSODAO<T extends DSpaceObject> extends AbstractHibernateDAO<T> {
|
public abstract class AbstractHibernateDSODAO<T extends DSpaceObject> extends AbstractHibernateDAO<T> {
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +37,6 @@ public abstract class AbstractHibernateDSODAO<T extends DSpaceObject> extends Ab
|
|||||||
* All DSOs now have UUID primary keys, and those should be used when available.
|
* All DSOs now have UUID primary keys, and those should be used when available.
|
||||||
* Each type derived from DSpaceObject had its own stream of record IDs, so
|
* Each type derived from DSpaceObject had its own stream of record IDs, so
|
||||||
* it is also necessary to know the specific type.
|
* it is also necessary to know the specific type.
|
||||||
*
|
|
||||||
* @param context current DSpace context.
|
* @param context current DSpace context.
|
||||||
* @param legacyId the old integer record identifier.
|
* @param legacyId the old integer record identifier.
|
||||||
* @param clazz DSO subtype of record identified by {@link legacyId}.
|
* @param clazz DSO subtype of record identified by {@link legacyId}.
|
||||||
@@ -44,16 +44,17 @@ public abstract class AbstractHibernateDSODAO<T extends DSpaceObject> extends Ab
|
|||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public T findByLegacyId(Context context, int legacyId, Class<T> clazz) throws SQLException {
|
public T findByLegacyId(Context context, int legacyId, Class<T> clazz) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, clazz);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("legacyId", legacyId));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, clazz);
|
||||||
return uniqueResult(criteria);
|
Root<T> root = criteriaQuery.from(clazz);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(root.get("legacyId"), legacyId));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, clazz, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add left outer join on all metadata fields which are passed to this function.
|
* Add left outer join on all metadata fields which are passed to this function.
|
||||||
* The identifier of the join will be the toString() representation of the metadata field.
|
* The identifier of the join will be the toString() representation of the metadata field.
|
||||||
* The joined metadata fields can then be used to query or sort.
|
* The joined metadata fields can then be used to query or sort.
|
||||||
*
|
|
||||||
* @param query the query string being built.
|
* @param query the query string being built.
|
||||||
* @param tableIdentifier name of the table to be joined.
|
* @param tableIdentifier name of the table to be joined.
|
||||||
* @param metadataFields names of the desired fields.
|
* @param metadataFields names of the desired fields.
|
||||||
@@ -108,19 +109,17 @@ public abstract class AbstractHibernateDSODAO<T extends DSpaceObject> extends Ab
|
|||||||
/**
|
/**
|
||||||
* Append ORDER BY clause based on metadata fields or column names.
|
* Append ORDER BY clause based on metadata fields or column names.
|
||||||
* All fields will be in ascending order.
|
* All fields will be in ascending order.
|
||||||
*
|
|
||||||
* @param query the query being built.
|
* @param query the query being built.
|
||||||
* @param metadataSortFields fields on which to sort -- use this OR columnSortFields.
|
* @param metadataSortFields fields on which to sort -- use this OR columnSortFields.
|
||||||
* @param columnSortFields columns on which to sort -- use this OR metadataSortFields.
|
* @param columnSortFields columns on which to sort -- use this OR metadataSortFields.
|
||||||
*/
|
*/
|
||||||
protected void addMetadataSortQuery(StringBuilder query, List<MetadataField> metadataSortFields,
|
protected void addMetadataSortQuery(StringBuilder query, List<MetadataField> metadataSortFields,
|
||||||
List<String> columnSortFields) {
|
List<String> columnSortFields) {
|
||||||
addMetadataSortQuery(query, metadataSortFields, columnSortFields, Collections.EMPTY_LIST);
|
addMetadataSortQuery(query, metadataSortFields, columnSortFields, ListUtils.EMPTY_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append ORDER BY clause based on metadata fields or column names.
|
* Append ORDER BY clause based on metadata fields or column names.
|
||||||
*
|
|
||||||
* @param query the query being built.
|
* @param query the query being built.
|
||||||
* @param metadataSortFields fields on which to sort -- use this OR columnSortFields.
|
* @param metadataSortFields fields on which to sort -- use this OR columnSortFields.
|
||||||
* @param columnSortFields columns on which to sort -- use this OR metadataSortFields.
|
* @param columnSortFields columns on which to sort -- use this OR metadataSortFields.
|
||||||
|
@@ -15,18 +15,21 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections.ListUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.core.AbstractHibernateDSODAO;
|
import org.dspace.core.AbstractHibernateDSODAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.eperson.EPerson_;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.eperson.dao.EPersonDAO;
|
import org.dspace.eperson.dao.EPersonDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the EPerson object.
|
* Hibernate implementation of the Database Access Object interface class for the EPerson object.
|
||||||
@@ -42,22 +45,23 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EPerson findByEmail(Context context, String email) throws SQLException {
|
public EPerson findByEmail(Context context, String email) throws SQLException {
|
||||||
// All email addresses are stored as lowercase, so ensure that the email address is lowercased for the lookup
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Criteria criteria = createCriteria(context, EPerson.class);
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, EPerson.class);
|
||||||
criteria.add(Restrictions.eq("email", email.toLowerCase()));
|
Root<EPerson> ePersonRoot = criteriaQuery.from(EPerson.class);
|
||||||
|
criteriaQuery.select(ePersonRoot);
|
||||||
criteria.setCacheable(true);
|
criteriaQuery.where(criteriaBuilder.equal(ePersonRoot.get(EPerson_.email), email.toLowerCase()));
|
||||||
return uniqueResult(criteria);
|
return uniqueResult(context, criteriaQuery, true, EPerson.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EPerson findByNetid(Context context, String netid) throws SQLException {
|
public EPerson findByNetid(Context context, String netid) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, EPerson.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("netid", netid));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, EPerson.class);
|
||||||
|
Root<EPerson> ePersonRoot = criteriaQuery.from(EPerson.class);
|
||||||
criteria.setCacheable(true);
|
criteriaQuery.select(ePersonRoot);
|
||||||
return uniqueResult(criteria);
|
criteriaQuery.where((criteriaBuilder.equal(ePersonRoot.get(EPerson_.netid), netid)));
|
||||||
|
return uniqueResult(context, criteriaQuery, true, EPerson.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,8 +105,8 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
sortFields = Collections.singletonList(metadataSortField);
|
sortFields = Collections.singletonList(metadataSortField);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query query = getSearchQuery(context, queryString, null, Collections.EMPTY_LIST, sortFields,
|
Query query = getSearchQuery(context, queryString, null, ListUtils.EMPTY_LIST, sortFields, sortField, pageSize,
|
||||||
sortField, pageSize, offset);
|
offset);
|
||||||
return list(query);
|
return list(query);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -119,26 +123,32 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
idList.add(group.getID());
|
idList.add(group.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
query.setParameterList("idList", idList);
|
query.setParameter("idList", idList);
|
||||||
|
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EPerson> findWithPasswordWithoutDigestAlgorithm(Context context) throws SQLException {
|
public List<EPerson> findWithPasswordWithoutDigestAlgorithm(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, EPerson.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, EPerson.class);
|
||||||
Restrictions.isNotNull("password"),
|
Root<EPerson> ePersonRoot = criteriaQuery.from(EPerson.class);
|
||||||
Restrictions.isNull("digestAlgorithm")
|
criteriaQuery.select(ePersonRoot);
|
||||||
));
|
criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.isNotNull(ePersonRoot.get(EPerson_.password)),
|
||||||
return list(criteria);
|
criteriaBuilder.isNull(ePersonRoot.get(EPerson_.digestAlgorithm))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, EPerson.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EPerson> findNotActiveSince(Context context, Date date) throws SQLException {
|
public List<EPerson> findNotActiveSince(Context context, Date date) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, EPerson.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.le("lastActive", date));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, EPerson.class);
|
||||||
return list(criteria);
|
Root<EPerson> ePersonRoot = criteriaQuery.from(EPerson.class);
|
||||||
|
criteriaQuery.select(ePersonRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.lessThanOrEqualTo(ePersonRoot.get(EPerson_.lastActive), date));
|
||||||
|
return list(context, criteriaQuery, false, EPerson.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Query getSearchQuery(Context context, String queryString, String queryParam,
|
protected Query getSearchQuery(Context context, String queryString, String queryParam,
|
||||||
|
@@ -8,17 +8,20 @@
|
|||||||
package org.dspace.eperson.dao.impl;
|
package org.dspace.eperson.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.eperson.Group2GroupCache;
|
import org.dspace.eperson.Group2GroupCache;
|
||||||
|
import org.dspace.eperson.Group2GroupCache_;
|
||||||
import org.dspace.eperson.dao.Group2GroupCacheDAO;
|
import org.dspace.eperson.dao.Group2GroupCacheDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Disjunction;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Group2GroupCache object.
|
* Hibernate implementation of the Database Access Object interface class for the Group2GroupCache object.
|
||||||
@@ -34,26 +37,27 @@ public class Group2GroupCacheDAOImpl extends AbstractHibernateDAO<Group2GroupCac
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Group2GroupCache> findByParent(Context context, Group group) throws SQLException {
|
public List<Group2GroupCache> findByParent(Context context, Group group) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Group2GroupCache.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("parent.id", group.getID()));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Group2GroupCache.class);
|
||||||
criteria.setCacheable(true);
|
Root<Group2GroupCache> group2GroupCacheRoot = criteriaQuery.from(Group2GroupCache.class);
|
||||||
|
criteriaQuery.select(group2GroupCacheRoot);
|
||||||
return list(criteria);
|
criteriaQuery.where(criteriaBuilder.equal(group2GroupCacheRoot.get(Group2GroupCache_.parent), group));
|
||||||
|
return list(context, criteriaQuery, true, Group2GroupCache.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Group2GroupCache> findByChildren(Context context, Iterable<Group> groups) throws SQLException {
|
public List<Group2GroupCache> findByChildren(Context context, Iterable<Group> groups) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Group2GroupCache.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Group2GroupCache.class);
|
||||||
Disjunction orDisjunction = Restrictions.or();
|
Root<Group2GroupCache> group2GroupCacheRoot = criteriaQuery.from(Group2GroupCache.class);
|
||||||
|
List<Predicate> eqPredicates = new LinkedList<>();
|
||||||
for (Group group : groups) {
|
for (Group group : groups) {
|
||||||
orDisjunction.add(Restrictions.eq("child.id", group.getID()));
|
eqPredicates.add(criteriaBuilder.equal(group2GroupCacheRoot.get(Group2GroupCache_.child), group));
|
||||||
}
|
}
|
||||||
|
Predicate orPredicate = criteriaBuilder.or(eqPredicates.toArray(new Predicate[] {}));
|
||||||
criteria.add(orDisjunction);
|
criteriaQuery.select(group2GroupCacheRoot);
|
||||||
criteria.setCacheable(true);
|
criteriaQuery.where(orPredicate);
|
||||||
|
return list(context, criteriaQuery, true, Group2GroupCache.class, -1, -1);
|
||||||
return list(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,19 +67,23 @@ public class Group2GroupCacheDAOImpl extends AbstractHibernateDAO<Group2GroupCac
|
|||||||
|
|
||||||
query.setParameter("parentGroup", parent);
|
query.setParameter("parentGroup", parent);
|
||||||
query.setParameter("childGroup", child);
|
query.setParameter("childGroup", child);
|
||||||
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
query.setCacheable(true);
|
|
||||||
|
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group2GroupCache find(Context context, Group parent, Group child) throws SQLException {
|
public Group2GroupCache find(Context context, Group parent, Group child) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Group2GroupCache.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("parent.id", parent.getID()));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Group2GroupCache.class);
|
||||||
criteria.add(Restrictions.eq("child.id", child.getID()));
|
Root<Group2GroupCache> group2GroupCacheRoot = criteriaQuery.from(Group2GroupCache.class);
|
||||||
criteria.setCacheable(true);
|
criteriaQuery.select(group2GroupCacheRoot);
|
||||||
return uniqueResult(criteria);
|
criteriaQuery.where(
|
||||||
|
criteriaBuilder.and(criteriaBuilder.equal(group2GroupCacheRoot.get(Group2GroupCache_.parent), parent),
|
||||||
|
criteriaBuilder.equal(group2GroupCacheRoot.get(Group2GroupCache_.child), child)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return uniqueResult(context, criteriaQuery, true, Group2GroupCache.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -11,6 +11,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
@@ -20,7 +21,6 @@ import org.dspace.core.Context;
|
|||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.eperson.dao.GroupDAO;
|
import org.dspace.eperson.dao.GroupDAO;
|
||||||
import org.hibernate.Query;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Group object.
|
* Hibernate implementation of the Database Access Object interface class for the Group object.
|
||||||
@@ -84,7 +84,7 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
query.setFirstResult(offset);
|
query.setFirstResult(offset);
|
||||||
}
|
}
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
Query query = createQuery(context,
|
Query query = createQuery(context,
|
||||||
"from Group where (from EPerson e where e.id = :eperson_id) in elements(epeople)");
|
"from Group where (from EPerson e where e.id = :eperson_id) in elements(epeople)");
|
||||||
query.setParameter("eperson_id", ePerson.getID());
|
query.setParameter("eperson_id", ePerson.getID());
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
"where g.name = :name ");
|
"where g.name = :name ");
|
||||||
|
|
||||||
query.setParameter("name", name);
|
query.setParameter("name", name);
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
|
|
||||||
query.setParameter("id", id);
|
query.setParameter("id", id);
|
||||||
query.setParameter("eperson_id", ePerson.getID());
|
query.setParameter("eperson_id", ePerson.getID());
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
|
|
||||||
return singleResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
"JOIN g.groups c ");
|
"JOIN g.groups c ");
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Pair<UUID, UUID>> results = query.list();
|
List<Pair<UUID, UUID>> results = query.getResultList();
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,14 +8,16 @@
|
|||||||
package org.dspace.eperson.dao.impl;
|
package org.dspace.eperson.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.RegistrationData;
|
import org.dspace.eperson.RegistrationData;
|
||||||
|
import org.dspace.eperson.RegistrationData_;
|
||||||
import org.dspace.eperson.dao.RegistrationDataDAO;
|
import org.dspace.eperson.dao.RegistrationDataDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the RegistrationData object.
|
* Hibernate implementation of the Database Access Object interface class for the RegistrationData object.
|
||||||
@@ -32,16 +34,22 @@ public class RegistrationDataDAOImpl extends AbstractHibernateDAO<RegistrationDa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RegistrationData findByEmail(Context context, String email) throws SQLException {
|
public RegistrationData findByEmail(Context context, String email) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, RegistrationData.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("email", email));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, RegistrationData.class);
|
||||||
return uniqueResult(criteria);
|
Root<RegistrationData> registrationDataRoot = criteriaQuery.from(RegistrationData.class);
|
||||||
|
criteriaQuery.select(registrationDataRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(registrationDataRoot.get(RegistrationData_.email), email));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, RegistrationData.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RegistrationData findByToken(Context context, String token) throws SQLException {
|
public RegistrationData findByToken(Context context, String token) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, RegistrationData.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("token", token));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, RegistrationData.class);
|
||||||
return uniqueResult(criteria);
|
Root<RegistrationData> registrationDataRoot = criteriaQuery.from(RegistrationData.class);
|
||||||
|
criteriaQuery.select(registrationDataRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(registrationDataRoot.get(RegistrationData_.token), token));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, RegistrationData.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -8,18 +8,20 @@
|
|||||||
package org.dspace.eperson.dao.impl;
|
package org.dspace.eperson.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.Subscription;
|
import org.dspace.eperson.Subscription;
|
||||||
|
import org.dspace.eperson.Subscription_;
|
||||||
import org.dspace.eperson.dao.SubscriptionDAO;
|
import org.dspace.eperson.dao.SubscriptionDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Subscription object.
|
* Hibernate implementation of the Database Access Object interface class for the Subscription object.
|
||||||
@@ -35,27 +37,28 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findByEPerson(Context context, EPerson eperson) throws SQLException {
|
public List<Subscription> findByEPerson(Context context, EPerson eperson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Subscription.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
javax.persistence.criteria.CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class);
|
||||||
Restrictions.and(
|
Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class);
|
||||||
Restrictions.eq("ePerson", eperson)
|
criteriaQuery.select(subscriptionRoot);
|
||||||
)
|
criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson));
|
||||||
);
|
return list(context, criteriaQuery, false, Subscription.class, -1, -1);
|
||||||
return list(criteria);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Subscription findByCollectionAndEPerson(Context context, EPerson eperson, Collection collection)
|
public Subscription findByCollectionAndEPerson(Context context, EPerson eperson, Collection collection)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Subscription.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
javax.persistence.criteria.CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class);
|
||||||
Restrictions.and(
|
Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class);
|
||||||
Restrictions.eq("ePerson", eperson),
|
criteriaQuery.select(subscriptionRoot);
|
||||||
Restrictions.eq("collection", collection)
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.and(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson),
|
||||||
|
criteriaBuilder.equal(subscriptionRoot.get(Subscription_.collection), collection)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return singleResult(criteria);
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,8 +90,17 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException {
|
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Subscription.class);
|
|
||||||
criteria.addOrder(Order.asc("ePerson"));
|
|
||||||
return list(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class);
|
||||||
|
Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class);
|
||||||
|
criteriaQuery.select(subscriptionRoot);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(subscriptionRoot.get(Subscription_.ePerson)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, Subscription.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -13,15 +13,17 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.handle.Handle;
|
import org.dspace.handle.Handle;
|
||||||
|
import org.dspace.handle.Handle_;
|
||||||
import org.dspace.handle.dao.HandleDAO;
|
import org.dspace.handle.dao.HandleDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.dialect.internal.StandardDialectResolver;
|
import org.hibernate.engine.jdbc.dialect.internal.StandardDialectResolver;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter;
|
import org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter;
|
||||||
@@ -56,7 +58,7 @@ public class HandleDAOImpl extends AbstractHibernateDAO<Handle> implements Handl
|
|||||||
|
|
||||||
query.setParameter("id", dso.getID());
|
query.setParameter("id", dso.getID());
|
||||||
|
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,22 +73,32 @@ public class HandleDAOImpl extends AbstractHibernateDAO<Handle> implements Handl
|
|||||||
|
|
||||||
query.setParameter("handle", handle);
|
query.setParameter("handle", handle);
|
||||||
|
|
||||||
query.setCacheable(true);
|
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
|
||||||
return uniqueResult(query);
|
return singleResult(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Handle> findByPrefix(Context context, String prefix) throws SQLException {
|
public List<Handle> findByPrefix(Context context, String prefix) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Handle.class);
|
|
||||||
criteria.add(Restrictions.like("handle", prefix + "%"));
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
return list(criteria);
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Handle.class);
|
||||||
|
Root<Handle> handleRoot = criteriaQuery.from(Handle.class);
|
||||||
|
criteriaQuery.select(handleRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.like(handleRoot.get(Handle_.handle), prefix + "%"));
|
||||||
|
return list(context, criteriaQuery, false, Handle.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long countHandlesByPrefix(Context context, String prefix) throws SQLException {
|
public long countHandlesByPrefix(Context context, String prefix) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Handle.class);
|
|
||||||
criteria.add(Restrictions.like("handle", prefix + "%"));
|
|
||||||
return countLong(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
|
|
||||||
|
Root<Handle> handleRoot = criteriaQuery.from(Handle.class);
|
||||||
|
criteriaQuery.select(criteriaBuilder.count(criteriaQuery.from(Handle.class)));
|
||||||
|
criteriaQuery.where(criteriaBuilder.like(handleRoot.get(Handle_.handle), prefix + "%"));
|
||||||
|
return countLong(context, criteriaQuery, criteriaBuilder, handleRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,9 +106,9 @@ public class HandleDAOImpl extends AbstractHibernateDAO<Handle> implements Handl
|
|||||||
String hql = "UPDATE Handle set handle = concat(:newPrefix, '/', substring(handle, :oldPrefixLength + 2)) " +
|
String hql = "UPDATE Handle set handle = concat(:newPrefix, '/', substring(handle, :oldPrefixLength + 2)) " +
|
||||||
"WHERE handle like concat(:oldPrefix,'%')";
|
"WHERE handle like concat(:oldPrefix,'%')";
|
||||||
Query query = createQuery(context, hql);
|
Query query = createQuery(context, hql);
|
||||||
query.setString("newPrefix", newPrefix);
|
query.setParameter("newPrefix", newPrefix);
|
||||||
query.setInteger("oldPrefixLength", oldPrefix.length());
|
query.setParameter("oldPrefixLength", oldPrefix.length());
|
||||||
query.setString("oldPrefix", oldPrefix);
|
query.setParameter("oldPrefix", oldPrefix);
|
||||||
return query.executeUpdate();
|
return query.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +119,6 @@ public class HandleDAOImpl extends AbstractHibernateDAO<Handle> implements Handl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return next available value of Handle suffix (based on DB sequence).
|
* Return next available value of Handle suffix (based on DB sequence).
|
||||||
*
|
|
||||||
* @param context Current DSpace Context
|
* @param context Current DSpace Context
|
||||||
* @return next available Handle suffix (as a Long)
|
* @return next available Handle suffix (as a Long)
|
||||||
* @throws SQLException if database error or sequence doesn't exist
|
* @throws SQLException if database error or sequence doesn't exist
|
||||||
|
@@ -9,18 +9,19 @@ package org.dspace.harvest.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.harvest.HarvestedCollection;
|
import org.dspace.harvest.HarvestedCollection;
|
||||||
|
import org.dspace.harvest.HarvestedCollection_;
|
||||||
import org.dspace.harvest.dao.HarvestedCollectionDAO;
|
import org.dspace.harvest.dao.HarvestedCollectionDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Disjunction;
|
|
||||||
import org.hibernate.criterion.LogicalExpression;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the HarvestedCollection object.
|
* Hibernate implementation of the Database Access Object interface class for the HarvestedCollection object.
|
||||||
@@ -39,98 +40,136 @@ public class HarvestedCollectionDAOImpl extends AbstractHibernateDAO<HarvestedCo
|
|||||||
@Override
|
@Override
|
||||||
public HarvestedCollection findByStatusAndMinimalTypeOrderByLastHarvestedDesc(Context context, int status, int type,
|
public HarvestedCollection findByStatusAndMinimalTypeOrderByLastHarvestedDesc(Context context, int status, int type,
|
||||||
int limit) throws SQLException {
|
int limit) throws SQLException {
|
||||||
// Old query: "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ?
|
|
||||||
// order by last_harvested desc limit 1";
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Criteria criteria = getByStatusAndMinimalTypeCriteria(context, status, type, limit);
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedCollection.class);
|
||||||
criteria.addOrder(Order.desc("lastHarvested"));
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
return singleResult(criteria);
|
criteriaQuery.select(harvestedCollectionRoot);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.desc(harvestedCollectionRoot.get(HarvestedCollection_.lastHarvested)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HarvestedCollection findByStatusAndMinimalTypeOrderByLastHarvestedAsc(Context context, int status, int type,
|
public HarvestedCollection findByStatusAndMinimalTypeOrderByLastHarvestedAsc(Context context, int status, int type,
|
||||||
int limit) throws SQLException {
|
int limit) throws SQLException {
|
||||||
// Old query: "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ?
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// order by last_harvested asc limit 1";
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedCollection.class);
|
||||||
Criteria criteria = getByStatusAndMinimalTypeCriteria(context, status, type, limit);
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
criteria.addOrder(Order.asc("lastHarvested"));
|
criteriaQuery.select(harvestedCollectionRoot);
|
||||||
return singleResult(criteria);
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(harvestedCollectionRoot.get(HarvestedCollection_.lastHarvested)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HarvestedCollection> findByStatus(Context context, int status) throws SQLException {
|
public List<HarvestedCollection> findByStatus(Context context, int status) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, HarvestedCollection.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("harvestStatus", status));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedCollection.class);
|
||||||
return list(criteria);
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
|
criteriaQuery.select(harvestedCollectionRoot);
|
||||||
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.equal(harvestedCollectionRoot.get(HarvestedCollection_.harvestStatus), status));
|
||||||
|
return list(context, criteriaQuery, false, HarvestedCollection.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HarvestedCollection findByCollection(Context context, Collection collection) throws SQLException {
|
public HarvestedCollection findByCollection(Context context, Collection collection) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, HarvestedCollection.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("collection", collection));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedCollection.class);
|
||||||
return singleResult(criteria);
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
|
criteriaQuery.select(harvestedCollectionRoot);
|
||||||
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.equal(harvestedCollectionRoot.get(HarvestedCollection_.collection), collection));
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HarvestedCollection>
|
public List<HarvestedCollection>
|
||||||
findByLastHarvestedAndHarvestTypeAndHarvestStatusesAndHarvestTime(Context context, Date startTime,
|
findByLastHarvestedAndHarvestTypeAndHarvestStatusesAndHarvestTime(Context context,
|
||||||
int minimalType, int[] statuses,
|
Date startTime,
|
||||||
int expirationStatus, Date expirationTime)
|
int minimalType,
|
||||||
|
int[] statuses,
|
||||||
|
int expirationStatus,
|
||||||
|
Date expirationTime)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// Old query: "SELECT * FROM harvested_collection WHERE
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// (last_harvested < ? or last_harvested is null) and harvest_type > ? and (harvest_status = ? or harvest_status = ?
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedCollection.class);
|
||||||
// or (harvest_status=? and harvest_start_time < ?)) ORDER BY last_harvested",
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
// new java.sql.Timestamp(startTime.getTime()), 0, HarvestedCollection.STATUS_READY,
|
criteriaQuery.select(harvestedCollectionRoot);
|
||||||
// HarvestedCollection.STATUS_OAI_ERROR, HarvestedCollection.STATUS_BUSY, new java.sql.Timestamp(expirationTime
|
|
||||||
// .getTime()));
|
Predicate wasNotHarvestedInCurrentRun = criteriaBuilder
|
||||||
Criteria criteria = createCriteria(context, HarvestedCollection.class);
|
.or(criteriaBuilder.lessThan(harvestedCollectionRoot.get(HarvestedCollection_.lastHarvested), startTime),
|
||||||
LogicalExpression lastHarvestedRestriction = Restrictions.or(
|
criteriaBuilder.isNull(harvestedCollectionRoot.get(HarvestedCollection_.lastHarvested))
|
||||||
Restrictions.lt("lastHarvested", startTime),
|
|
||||||
Restrictions.isNull("lastHarvested")
|
|
||||||
);
|
);
|
||||||
Disjunction statusRestriction = Restrictions.or();
|
|
||||||
|
List<Predicate> hasCorrectStatusOrIsExpiredRestrictions = new LinkedList<>();
|
||||||
|
|
||||||
for (int status : statuses) {
|
for (int status : statuses) {
|
||||||
statusRestriction.add(Restrictions.eq("harvestStatus", status));
|
hasCorrectStatusOrIsExpiredRestrictions
|
||||||
|
.add(criteriaBuilder.equal(harvestedCollectionRoot.get(HarvestedCollection_.harvestStatus), status));
|
||||||
}
|
}
|
||||||
statusRestriction.add(
|
|
||||||
Restrictions.and(
|
Predicate harvestExpiredRestriction = criteriaBuilder.and(
|
||||||
Restrictions.eq("harvestStatus", expirationStatus),
|
criteriaBuilder.equal(harvestedCollectionRoot.get(HarvestedCollection_.harvestStatus), expirationStatus),
|
||||||
Restrictions.gt("harvestStartTime", expirationTime)
|
criteriaBuilder
|
||||||
|
.greaterThan(harvestedCollectionRoot.get(HarvestedCollection_.harvestStartTime), expirationTime)
|
||||||
|
);
|
||||||
|
|
||||||
|
hasCorrectStatusOrIsExpiredRestrictions.add(harvestExpiredRestriction);
|
||||||
|
|
||||||
|
Predicate hasCorrectStatusOrIsExpiredPredicate = criteriaBuilder.or(hasCorrectStatusOrIsExpiredRestrictions
|
||||||
|
.toArray(new Predicate[] {}));
|
||||||
|
|
||||||
|
Predicate hasMinimalType = criteriaBuilder.greaterThan(
|
||||||
|
harvestedCollectionRoot.get(HarvestedCollection_.harvestType),
|
||||||
|
minimalType);
|
||||||
|
|
||||||
|
criteriaQuery.where(criteriaBuilder.and(wasNotHarvestedInCurrentRun,
|
||||||
|
hasMinimalType,
|
||||||
|
hasCorrectStatusOrIsExpiredPredicate
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
criteria.add(
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
Restrictions.and(
|
orderList.add(criteriaBuilder.asc(harvestedCollectionRoot.get(HarvestedCollection_.lastHarvested)));
|
||||||
lastHarvestedRestriction,
|
criteriaQuery.orderBy(orderList);
|
||||||
Restrictions.gt("harvestType", minimalType),
|
|
||||||
statusRestriction
|
|
||||||
|
return list(context, criteriaQuery, false, HarvestedCollection.class, -1, -1);
|
||||||
|
|
||||||
)
|
|
||||||
);
|
|
||||||
criteria.addOrder(Order.asc("lastHarvested"));
|
|
||||||
return list(criteria);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(Context context) throws SQLException {
|
public int count(Context context) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, HarvestedCollection.class);
|
|
||||||
return count(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
|
|
||||||
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
|
return count(context, criteriaQuery, criteriaBuilder, harvestedCollectionRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Criteria getByStatusAndMinimalTypeCriteria(Context context, int status, int type, int limit)
|
protected CriteriaQuery getByStatusAndMinimalTypeCriteria(Context context, int status, int type)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, HarvestedCollection.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedCollection.class);
|
||||||
Restrictions.and(
|
Root<HarvestedCollection> harvestedCollectionRoot = criteriaQuery.from(HarvestedCollection.class);
|
||||||
Restrictions.gt("harvestType", type),
|
criteriaQuery.select(harvestedCollectionRoot);
|
||||||
Restrictions.eq("harvestStatus", status)
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.greaterThan(harvestedCollectionRoot.get(HarvestedCollection_.harvestType), type),
|
||||||
|
criteriaBuilder.equal(harvestedCollectionRoot.get(HarvestedCollection_.harvestStatus), status)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (limit != -1) {
|
return criteriaQuery;
|
||||||
criteria.setMaxResults(1);
|
|
||||||
}
|
|
||||||
return criteria;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,15 +8,19 @@
|
|||||||
package org.dspace.harvest.dao.impl;
|
package org.dspace.harvest.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.Item_;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.harvest.HarvestedItem;
|
import org.dspace.harvest.HarvestedItem;
|
||||||
|
import org.dspace.harvest.HarvestedItem_;
|
||||||
import org.dspace.harvest.dao.HarvestedItemDAO;
|
import org.dspace.harvest.dao.HarvestedItemDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the HarvestedItem object.
|
* Hibernate implementation of the Database Access Object interface class for the HarvestedItem object.
|
||||||
@@ -32,21 +36,28 @@ public class HarvestedItemDAOImpl extends AbstractHibernateDAO<HarvestedItem> im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HarvestedItem findByItem(Context context, Item item) throws SQLException {
|
public HarvestedItem findByItem(Context context, Item item) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, HarvestedItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("item", item));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedItem.class);
|
||||||
return singleResult(criteria);
|
Root<HarvestedItem> harvestedItemRoot = criteriaQuery.from(HarvestedItem.class);
|
||||||
|
criteriaQuery.select(harvestedItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(harvestedItemRoot.get(HarvestedItem_.item), item));
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HarvestedItem findByOAIId(Context context, String itemOaiID, Collection collection) throws SQLException {
|
public HarvestedItem findByOAIId(Context context, String itemOaiID, Collection collection) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, HarvestedItem.class);
|
|
||||||
criteria.createAlias("item", "i");
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, HarvestedItem.class);
|
||||||
Restrictions.and(
|
Root<HarvestedItem> harvestedItemRoot = criteriaQuery.from(HarvestedItem.class);
|
||||||
Restrictions.eq("oaiId", itemOaiID),
|
Join<HarvestedItem, Item> join = harvestedItemRoot.join("item");
|
||||||
Restrictions.eq("i.owningCollection", collection)
|
criteriaQuery.select(harvestedItemRoot);
|
||||||
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.and(criteriaBuilder.equal(harvestedItemRoot.get(HarvestedItem_.oaiId), itemOaiID),
|
||||||
|
criteriaBuilder.equal(join.get(Item_.owningCollection), collection)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return singleResult(criteria);
|
return singleResult(context, criteriaQuery);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,17 +8,19 @@
|
|||||||
package org.dspace.identifier.dao.impl;
|
package org.dspace.identifier.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.identifier.DOI;
|
import org.dspace.identifier.DOI;
|
||||||
|
import org.dspace.identifier.DOI_;
|
||||||
import org.dspace.identifier.dao.DOIDAO;
|
import org.dspace.identifier.dao.DOIDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Conjunction;
|
|
||||||
import org.hibernate.criterion.Disjunction;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the DOI object.
|
* Hibernate implementation of the Database Access Object interface class for the DOI object.
|
||||||
@@ -34,74 +36,88 @@ public class DOIDAOImpl extends AbstractHibernateDAO<DOI> implements DOIDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DOI findByDoi(Context context, String doi) throws SQLException {
|
public DOI findByDoi(Context context, String doi) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, DOI.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("doi", doi));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class);
|
||||||
return uniqueResult(criteria);
|
Root<DOI> doiRoot = criteriaQuery.from(DOI.class);
|
||||||
|
criteriaQuery.select(doiRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(doiRoot.get(DOI_.doi), doi));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, DOI.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List<Integer> statusToExclude)
|
public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List<Integer> statusToExclude)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
//SELECT * FROM Doi WHERE resource_type_id = ? AND resource_id = ? AND resource_id = ? AND ((status != ? AND
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// status != ?) OR status IS NULL)
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class);
|
||||||
Criteria criteria = createCriteria(context, DOI.class);
|
Root<DOI> doiRoot = criteriaQuery.from(DOI.class);
|
||||||
Disjunction statusQuery = Restrictions.or();
|
criteriaQuery.select(doiRoot);
|
||||||
Conjunction statusConjunctionAnd = Restrictions.and();
|
|
||||||
for (Integer status : statusToExclude) {
|
|
||||||
statusConjunctionAnd.add(Restrictions.not(Restrictions.eq("status", status)));
|
|
||||||
}
|
|
||||||
statusQuery.add(statusConjunctionAnd);
|
|
||||||
statusQuery.add(Restrictions.isNull("status"));
|
|
||||||
criteria.add(
|
|
||||||
Restrictions.and(
|
|
||||||
Restrictions.eq("dSpaceObject", dso),
|
|
||||||
statusQuery
|
|
||||||
|
|
||||||
|
List<Predicate> listToIncludeInOrPredicate = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Integer status : statusToExclude) {
|
||||||
|
listToIncludeInOrPredicate.add(criteriaBuilder.notEqual(doiRoot.get(DOI_.status), status));
|
||||||
|
}
|
||||||
|
listToIncludeInOrPredicate.add(criteriaBuilder.isNull(doiRoot.get(DOI_.status)));
|
||||||
|
|
||||||
|
Predicate orPredicate = criteriaBuilder.or(listToIncludeInOrPredicate.toArray(new Predicate[] {}));
|
||||||
|
|
||||||
|
criteriaQuery.where(criteriaBuilder.and(orPredicate,
|
||||||
|
criteriaBuilder.equal(doiRoot.get(DOI_.dSpaceObject), dso)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return singleResult(criteria);
|
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DOI> findByStatus(Context context, List<Integer> statuses) throws SQLException {
|
public List<DOI> findByStatus(Context context, List<Integer> statuses) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, DOI.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Disjunction statusQuery = Restrictions.or();
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class);
|
||||||
|
Root<DOI> doiRoot = criteriaQuery.from(DOI.class);
|
||||||
|
criteriaQuery.select(doiRoot);
|
||||||
|
List<Predicate> orPredicates = new LinkedList<>();
|
||||||
for (Integer status : statuses) {
|
for (Integer status : statuses) {
|
||||||
statusQuery.add(Restrictions.eq("status", status));
|
orPredicates.add(criteriaBuilder.equal(doiRoot.get(DOI_.status), status));
|
||||||
}
|
}
|
||||||
criteria.add(statusQuery);
|
criteriaQuery.where(criteriaBuilder.or(orPredicates.toArray(new Predicate[] {})));
|
||||||
return list(criteria);
|
return list(context, criteriaQuery, false, DOI.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DOI> findSimilarNotInState(Context context, String doi, List<Integer> excludedStatuses,
|
public List<DOI> findSimilarNotInState(Context context, String doi, List<Integer> excludedStatuses,
|
||||||
boolean dsoNotNull)
|
boolean dsoNotNull)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// SELECT * FROM Doi WHERE doi LIKE ? AND resource_type_id = ? AND resource_id IS NOT NULL AND status != ?
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
// AND status != ?
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class);
|
||||||
Criteria criteria = createCriteria(context, DOI.class);
|
Root<DOI> doiRoot = criteriaQuery.from(DOI.class);
|
||||||
Conjunction conjunctionAnd = Restrictions.and();
|
criteriaQuery.select(doiRoot);
|
||||||
Disjunction statusQuery = Restrictions.or();
|
|
||||||
|
List<Predicate> listToIncludeInOrPredicate = new LinkedList<>();
|
||||||
|
|
||||||
for (Integer status : excludedStatuses) {
|
for (Integer status : excludedStatuses) {
|
||||||
statusQuery.add(Restrictions.ne("status", status));
|
listToIncludeInOrPredicate.add(criteriaBuilder.notEqual(doiRoot.get(DOI_.status), status));
|
||||||
}
|
}
|
||||||
conjunctionAnd.add(Restrictions.like("doi", doi));
|
|
||||||
conjunctionAnd.add(statusQuery);
|
List<Predicate> listToIncludeInAndPredicate = new LinkedList<>();
|
||||||
|
|
||||||
|
listToIncludeInAndPredicate.add(criteriaBuilder.like(doiRoot.get(DOI_.doi), doi));
|
||||||
|
listToIncludeInAndPredicate.add(criteriaBuilder.or(listToIncludeInOrPredicate.toArray(new Predicate[] {})));
|
||||||
if (dsoNotNull) {
|
if (dsoNotNull) {
|
||||||
conjunctionAnd.add(Restrictions.isNotNull("dSpaceObject"));
|
listToIncludeInAndPredicate.add(criteriaBuilder.isNotNull(doiRoot.get(DOI_.dSpaceObject)));
|
||||||
}
|
}
|
||||||
criteria.add(conjunctionAnd);
|
criteriaQuery.where(listToIncludeInAndPredicate.toArray(new Predicate[] {}));
|
||||||
return list(criteria);
|
return list(context, criteriaQuery, false, DOI.class, -1, -1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso) throws SQLException {
|
public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, DOI.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class);
|
||||||
Restrictions.and(
|
Root<DOI> doiRoot = criteriaQuery.from(DOI.class);
|
||||||
Restrictions.eq("dSpaceObject", dso)
|
criteriaQuery.select(doiRoot);
|
||||||
)
|
criteriaQuery.where(criteriaBuilder.equal(doiRoot.get(DOI_.dSpaceObject), dso));
|
||||||
);
|
return singleResult(context, criteriaQuery);
|
||||||
return singleResult(criteria);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,11 @@ import gr.ekt.bte.dataloader.FileDataLoader;
|
|||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Configuration bean to associate a BTE FileDataLoader with a specific list of format identified by the file
|
||||||
|
* extensions. See config/spring/api/metadata-extractor.xml
|
||||||
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
*/
|
*/
|
||||||
public class MetadataExtractor {
|
public class MetadataExtractor {
|
||||||
|
|
||||||
|
@@ -12,12 +12,26 @@ import java.util.Map;
|
|||||||
import gr.ekt.bte.core.DataLoader;
|
import gr.ekt.bte.core.DataLoader;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration bean to map metadata to identifiers (i.e dc.identifier.doi -> doi, dc.identifier.isbn -> isbn) and
|
||||||
|
* alias to BTE Data Loader. See config/spring/api/step-processing.xml
|
||||||
|
*
|
||||||
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class MetadataListener {
|
public class MetadataListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata to identifier map
|
||||||
|
*/
|
||||||
private Map<String, String> metadata;
|
private Map<String, String> metadata;
|
||||||
|
|
||||||
private ConfigurationService configurationService;
|
private ConfigurationService configurationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias to data loader map
|
||||||
|
*/
|
||||||
private Map<String, DataLoader> dataloadersMap;
|
private Map<String, DataLoader> dataloadersMap;
|
||||||
|
|
||||||
public ConfigurationService getConfigurationService() {
|
public ConfigurationService getConfigurationService() {
|
||||||
|
@@ -33,6 +33,7 @@ import org.dspace.submit.AbstractProcessingStep;
|
|||||||
import org.dspace.submit.listener.MetadataListener;
|
import org.dspace.submit.listener.MetadataListener;
|
||||||
import org.dspace.submit.lookup.SubmissionLookupDataLoader;
|
import org.dspace.submit.lookup.SubmissionLookupDataLoader;
|
||||||
|
|
||||||
|
//FIXME move to the ExtractionStep
|
||||||
/**
|
/**
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
*/
|
*/
|
||||||
|
@@ -8,18 +8,20 @@
|
|||||||
package org.dspace.versioning.dao.impl;
|
package org.dspace.versioning.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.versioning.Version;
|
import org.dspace.versioning.Version;
|
||||||
import org.dspace.versioning.VersionHistory;
|
import org.dspace.versioning.VersionHistory;
|
||||||
|
import org.dspace.versioning.Version_;
|
||||||
import org.dspace.versioning.dao.VersionDAO;
|
import org.dspace.versioning.dao.VersionDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the Version object.
|
* Hibernate implementation of the Database Access Object interface class for the Version object.
|
||||||
@@ -39,9 +41,12 @@ public class VersionDAOImpl extends AbstractHibernateDAO<Version> implements Ver
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version findByItem(Context context, Item item) throws SQLException {
|
public Version findByItem(Context context, Item item) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Version.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("item", item));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Version.class);
|
||||||
return singleResult(criteria);
|
Root<Version> versionRoot = criteriaQuery.from(Version.class);
|
||||||
|
criteriaQuery.select(versionRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(versionRoot.get(Version_.item), item));
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,17 +56,28 @@ public class VersionDAOImpl extends AbstractHibernateDAO<Version> implements Ver
|
|||||||
+ "FROM Version WHERE versionHistory.id = :historyId");
|
+ "FROM Version WHERE versionHistory.id = :historyId");
|
||||||
q.setParameter("historyId", vh.getID());
|
q.setParameter("historyId", vh.getID());
|
||||||
|
|
||||||
int next = (Integer) q.uniqueResult();
|
int next = (Integer) q.getSingleResult();
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Version> findVersionsWithItems(Context context, VersionHistory versionHistory)
|
public List<Version> findVersionsWithItems(Context context, VersionHistory versionHistory)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, Version.class);
|
|
||||||
criteria.add(Restrictions.eq("versionHistory", versionHistory));
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(Restrictions.isNotNull("item")));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Version.class);
|
||||||
criteria.addOrder(Order.desc("versionNumber"));
|
Root<Version> versionRoot = criteriaQuery.from(Version.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(versionRoot);
|
||||||
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.and(criteriaBuilder.equal(versionRoot.get(Version_.versionHistory), versionHistory),
|
||||||
|
criteriaBuilder.isNotNull(versionRoot.get(Version_.item))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.desc(versionRoot.get(Version_.versionNumber)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, Version.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,15 +8,20 @@
|
|||||||
package org.dspace.versioning.dao.impl;
|
package org.dspace.versioning.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.versioning.Version;
|
||||||
import org.dspace.versioning.VersionHistory;
|
import org.dspace.versioning.VersionHistory;
|
||||||
|
import org.dspace.versioning.Version_;
|
||||||
import org.dspace.versioning.dao.VersionHistoryDAO;
|
import org.dspace.versioning.dao.VersionHistoryDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the VersionHistory object.
|
* Hibernate implementation of the Database Access Object interface class for the VersionHistory object.
|
||||||
@@ -35,10 +40,17 @@ public class VersionHistoryDAOImpl extends AbstractHibernateDAO<VersionHistory>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VersionHistory findByItem(Context context, Item item) throws SQLException {
|
public VersionHistory findByItem(Context context, Item item) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, VersionHistory.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.createAlias("versions", "v");
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, VersionHistory.class);
|
||||||
criteria.add(Restrictions.eq("v.item", item));
|
Root<VersionHistory> versionHistoryRoot = criteriaQuery.from(VersionHistory.class);
|
||||||
criteria.addOrder(Order.desc("v.versionNumber"));
|
Join<VersionHistory, Version> join = versionHistoryRoot.join("versions");
|
||||||
return singleResult(criteria);
|
criteriaQuery.select(versionHistoryRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(join.get(Version_.item), item));
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.desc(join.get(Version_.versionNumber)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
return singleResult(context, criteriaQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,19 +8,23 @@
|
|||||||
package org.dspace.workflowbasic.dao.impl;
|
package org.dspace.workflowbasic.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.Item_;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.workflowbasic.BasicWorkflowItem;
|
import org.dspace.workflowbasic.BasicWorkflowItem;
|
||||||
|
import org.dspace.workflowbasic.BasicWorkflowItem_;
|
||||||
import org.dspace.workflowbasic.dao.BasicWorkflowItemDAO;
|
import org.dspace.workflowbasic.dao.BasicWorkflowItemDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the BasicWorkflowItem object.
|
* Hibernate implementation of the Database Access Object interface class for the BasicWorkflowItem object.
|
||||||
@@ -37,27 +41,42 @@ public class BasicWorkflowItemDAOImpl extends AbstractHibernateDAO<BasicWorkflow
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BasicWorkflowItem findByItem(Context context, Item i) throws SQLException {
|
public BasicWorkflowItem findByItem(Context context, Item i) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BasicWorkflowItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("item", i));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BasicWorkflowItem.class);
|
||||||
// Look for the unique WorkflowItem entry where 'item_id' references this item
|
Root<BasicWorkflowItem> basicWorkflowItemRoot = criteriaQuery.from(BasicWorkflowItem.class);
|
||||||
return uniqueResult(criteria);
|
criteriaQuery.select(basicWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(basicWorkflowItemRoot.get(BasicWorkflowItem_.item), i));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, BasicWorkflowItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BasicWorkflowItem> findBySubmitter(Context context, EPerson ep) throws SQLException {
|
public List<BasicWorkflowItem> findBySubmitter(Context context, EPerson ep) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BasicWorkflowItem.class);
|
|
||||||
criteria.createAlias("item", "i");
|
|
||||||
criteria.add(Restrictions.eq("i.submitter", ep));
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.addOrder(Order.asc("workflowitemId"));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BasicWorkflowItem.class);
|
||||||
return list(criteria);
|
Root<BasicWorkflowItem> basicWorkflowItemRoot = criteriaQuery.from(BasicWorkflowItem.class);
|
||||||
|
Join<BasicWorkflowItem, Item> join = basicWorkflowItemRoot.join("item");
|
||||||
|
criteriaQuery.select(basicWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(join.get(Item_.submitter), ep));
|
||||||
|
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(basicWorkflowItemRoot.get(BasicWorkflowItem_.workflowitemId)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
|
|
||||||
|
|
||||||
|
return list(context, criteriaQuery, false, BasicWorkflowItem.class, -1, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BasicWorkflowItem> findByCollection(Context context, Collection c) throws SQLException {
|
public List<BasicWorkflowItem> findByCollection(Context context, Collection c) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BasicWorkflowItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("collection", c));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BasicWorkflowItem.class);
|
||||||
return list(criteria);
|
Root<BasicWorkflowItem> basicWorkflowItemRoot = criteriaQuery.from(BasicWorkflowItem.class);
|
||||||
|
criteriaQuery.select(basicWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(basicWorkflowItemRoot.get(BasicWorkflowItem_.collection), c));
|
||||||
|
return list(context, criteriaQuery, false, BasicWorkflowItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,9 +90,12 @@ public class BasicWorkflowItemDAOImpl extends AbstractHibernateDAO<BasicWorkflow
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BasicWorkflowItem> findByOwner(Context context, EPerson ePerson) throws SQLException {
|
public List<BasicWorkflowItem> findByOwner(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, BasicWorkflowItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("owner", ePerson));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, BasicWorkflowItem.class);
|
||||||
return list(criteria);
|
Root<BasicWorkflowItem> basicWorkflowItemRoot = criteriaQuery.from(BasicWorkflowItem.class);
|
||||||
|
criteriaQuery.select(basicWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(basicWorkflowItemRoot.get(BasicWorkflowItem_.owner), ePerson));
|
||||||
|
return list(context, criteriaQuery, false, BasicWorkflowItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,16 +9,18 @@ package org.dspace.workflowbasic.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.workflowbasic.BasicWorkflowItem;
|
import org.dspace.workflowbasic.BasicWorkflowItem;
|
||||||
import org.dspace.workflowbasic.TaskListItem;
|
import org.dspace.workflowbasic.TaskListItem;
|
||||||
|
import org.dspace.workflowbasic.TaskListItem_;
|
||||||
import org.dspace.workflowbasic.dao.TaskListItemDAO;
|
import org.dspace.workflowbasic.dao.TaskListItemDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the TaskListItem object.
|
* Hibernate implementation of the Database Access Object interface class for the TaskListItem object.
|
||||||
@@ -42,8 +44,11 @@ public class TaskListItemDAOImpl extends AbstractHibernateDAO<TaskListItem> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TaskListItem> findByEPerson(Context context, EPerson ePerson) throws SQLException {
|
public List<TaskListItem> findByEPerson(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, TaskListItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("ePerson", ePerson));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, TaskListItem.class);
|
||||||
return list(criteria);
|
Root<TaskListItem> taskListItemRoot = criteriaQuery.from(TaskListItem.class);
|
||||||
|
criteriaQuery.select(taskListItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(taskListItemRoot.get(TaskListItem_.ePerson), ePerson));
|
||||||
|
return list(context, criteriaQuery, false, TaskListItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,15 +9,17 @@ package org.dspace.xmlworkflow.storedcomponents.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
|
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask_;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.dao.ClaimedTaskDAO;
|
import org.dspace.xmlworkflow.storedcomponents.dao.ClaimedTaskDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the ClaimedTask object.
|
* Hibernate implementation of the Database Access Object interface class for the ClaimedTask object.
|
||||||
@@ -33,79 +35,99 @@ public class ClaimedTaskDAOImpl extends AbstractHibernateDAO<ClaimedTask> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClaimedTask> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
public List<ClaimedTask> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("workflowItem", workflowItem));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.workflowItem), workflowItem));
|
||||||
|
return list(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClaimedTask findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
|
public ClaimedTask findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
Restrictions.eq("owner", ePerson)
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
));
|
criteriaQuery.where(
|
||||||
|
criteriaBuilder.and(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.owner), ePerson)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return uniqueResult(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
|
|
||||||
|
|
||||||
return uniqueResult(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClaimedTask> findByEperson(Context context, EPerson ePerson) throws SQLException {
|
public List<ClaimedTask> findByEperson(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("owner", ePerson));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.owner), ePerson));
|
||||||
|
return list(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClaimedTask> findByWorkflowItemAndStepId(Context context, XmlWorkflowItem workflowItem, String stepID)
|
public List<ClaimedTask> findByWorkflowItemAndStepId(Context context, XmlWorkflowItem workflowItem, String stepID)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
Restrictions.eq("stepId", stepID)
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
));
|
criteriaQuery.where(
|
||||||
|
criteriaBuilder.and(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.workflowItem), workflowItem),
|
||||||
return list(criteria);
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.stepId), stepID)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClaimedTask findByEPersonAndWorkflowItemAndStepIdAndActionId(Context context, EPerson ePerson,
|
public ClaimedTask findByEPersonAndWorkflowItemAndStepIdAndActionId(Context context, EPerson ePerson,
|
||||||
XmlWorkflowItem workflowItem, String stepID,
|
XmlWorkflowItem workflowItem, String stepID,
|
||||||
String actionID) throws SQLException {
|
String actionID) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
Restrictions.eq("owner", ePerson),
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
Restrictions.eq("stepId", stepID),
|
criteriaQuery.where(
|
||||||
Restrictions.eq("actionId", actionID)
|
criteriaBuilder.and(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.workflowItem), workflowItem),
|
||||||
));
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.stepId), stepID),
|
||||||
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.owner), ePerson),
|
||||||
return uniqueResult(criteria);
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.actionId), actionID)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return uniqueResult(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClaimedTask> findByWorkflowItemAndStepIdAndActionId(Context context, XmlWorkflowItem workflowItem,
|
public List<ClaimedTask> findByWorkflowItemAndStepIdAndActionId(Context context, XmlWorkflowItem workflowItem,
|
||||||
String stepID, String actionID)
|
String stepID, String actionID)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
Restrictions.eq("stepId", stepID),
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
Restrictions.eq("actionId", actionID)
|
criteriaQuery.where(
|
||||||
));
|
criteriaBuilder.and(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.stepId), stepID),
|
||||||
return list(criteria);
|
criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.actionId), actionID)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClaimedTask> findByStep(Context context, String stepID) throws SQLException {
|
public List<ClaimedTask> findByStep(Context context, String stepID) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, ClaimedTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("stepId", stepID));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClaimedTask.class);
|
||||||
|
Root<ClaimedTask> claimedTaskRoot = criteriaQuery.from(ClaimedTask.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(claimedTaskRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(claimedTaskRoot.get(ClaimedTask_.stepId), stepID));
|
||||||
|
return list(context, criteriaQuery, false, ClaimedTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,15 +9,17 @@ package org.dspace.xmlworkflow.storedcomponents.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
|
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.CollectionRole_;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.dao.CollectionRoleDAO;
|
import org.dspace.xmlworkflow.storedcomponents.dao.CollectionRoleDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the CollectionRole object.
|
* Hibernate implementation of the Database Access Object interface class for the CollectionRole object.
|
||||||
@@ -33,23 +35,27 @@ public class CollectionRoleDAOImpl extends AbstractHibernateDAO<CollectionRole>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CollectionRole> findByCollection(Context context, Collection collection) throws SQLException {
|
public List<CollectionRole> findByCollection(Context context, Collection collection) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, CollectionRole.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("collection", collection));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, CollectionRole.class);
|
||||||
|
Root<CollectionRole> collectionRoleRoot = criteriaQuery.from(CollectionRole.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(collectionRoleRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(collectionRoleRoot.get(CollectionRole_.collection), collection));
|
||||||
|
return list(context, criteriaQuery, false, CollectionRole.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CollectionRole findByCollectionAndRole(Context context, Collection collection, String role)
|
public CollectionRole findByCollectionAndRole(Context context, Collection collection, String role)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, CollectionRole.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, CollectionRole.class);
|
||||||
Restrictions.eq("collection", collection),
|
Root<CollectionRole> collectionRoleRoot = criteriaQuery.from(CollectionRole.class);
|
||||||
Restrictions.eq("roleId", role)
|
criteriaQuery.select(collectionRoleRoot);
|
||||||
|
criteriaQuery.where(
|
||||||
|
criteriaBuilder.and(criteriaBuilder.equal(collectionRoleRoot.get(CollectionRole_.collection), collection),
|
||||||
|
criteriaBuilder.equal(collectionRoleRoot.get(CollectionRole_.roleId), role)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return uniqueResult(context, criteriaQuery, false, CollectionRole.class, -1, -1);
|
||||||
return uniqueResult(criteria);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,15 +9,17 @@ package org.dspace.xmlworkflow.storedcomponents.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.InProgressUser;
|
import org.dspace.xmlworkflow.storedcomponents.InProgressUser;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.InProgressUser_;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.dao.InProgressUserDAO;
|
import org.dspace.xmlworkflow.storedcomponents.dao.InProgressUserDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the InProgressUser object.
|
* Hibernate implementation of the Database Access Object interface class for the InProgressUser object.
|
||||||
@@ -34,54 +36,70 @@ public class InProgressUserDAOImpl extends AbstractHibernateDAO<InProgressUser>
|
|||||||
@Override
|
@Override
|
||||||
public InProgressUser findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
|
public InProgressUser findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, InProgressUser.class);
|
|
||||||
criteria.add(
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Restrictions.and(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, InProgressUser.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
Root<InProgressUser> inProgressUserRoot = criteriaQuery.from(InProgressUser.class);
|
||||||
Restrictions.eq("ePerson", ePerson)
|
criteriaQuery.select(inProgressUserRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.ePerson), ePerson)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return uniqueResult(criteria);
|
return uniqueResult(context, criteriaQuery, false, InProgressUser.class, -1, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<InProgressUser> findByEperson(Context context, EPerson ePerson) throws SQLException {
|
public List<InProgressUser> findByEperson(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, InProgressUser.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("ePerson", ePerson));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, InProgressUser.class);
|
||||||
|
Root<InProgressUser> inProgressUserRoot = criteriaQuery.from(InProgressUser.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(inProgressUserRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.ePerson), ePerson));
|
||||||
|
return list(context, criteriaQuery, false, InProgressUser.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<InProgressUser> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
public List<InProgressUser> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, InProgressUser.class);
|
|
||||||
criteria.add(Restrictions.eq("workflowItem", workflowItem));
|
|
||||||
|
|
||||||
return list(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, InProgressUser.class);
|
||||||
|
Root<InProgressUser> inProgressUserRoot = criteriaQuery.from(InProgressUser.class);
|
||||||
|
criteriaQuery.select(inProgressUserRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.workflowItem), workflowItem));
|
||||||
|
return list(context, criteriaQuery, false, InProgressUser.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int countInProgressUsers(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
public int countInProgressUsers(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, InProgressUser.class);
|
|
||||||
criteria.add(
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Restrictions.and(
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
|
||||||
Restrictions.eq("finished", false)
|
Root<InProgressUser> inProgressUserRoot = criteriaQuery.from(InProgressUser.class);
|
||||||
|
|
||||||
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.finished), false)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return count(context, criteriaQuery, criteriaBuilder, inProgressUserRoot);
|
||||||
return count(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int countFinishedUsers(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
public int countFinishedUsers(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, InProgressUser.class);
|
|
||||||
criteria.add(
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Restrictions.and(
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
|
||||||
Restrictions.eq("finished", true)
|
Root<InProgressUser> inProgressUserRoot = criteriaQuery.from(InProgressUser.class);
|
||||||
|
|
||||||
|
criteriaQuery.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(inProgressUserRoot.get(InProgressUser_.finished), true)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return count(criteria);
|
return count(context, criteriaQuery, criteriaBuilder, inProgressUserRoot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,16 +9,18 @@ package org.dspace.xmlworkflow.storedcomponents.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.PoolTask;
|
import org.dspace.xmlworkflow.storedcomponents.PoolTask;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.PoolTask_;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.dao.PoolTaskDAO;
|
import org.dspace.xmlworkflow.storedcomponents.dao.PoolTaskDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the PoolTask object.
|
* Hibernate implementation of the Database Access Object interface class for the PoolTask object.
|
||||||
@@ -34,53 +36,62 @@ public class PoolTaskDAOImpl extends AbstractHibernateDAO<PoolTask> implements P
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PoolTask> findByEPerson(Context context, EPerson ePerson) throws SQLException {
|
public List<PoolTask> findByEPerson(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, PoolTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("ePerson", ePerson));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, PoolTask.class);
|
||||||
|
Root<PoolTask> poolTaskRoot = criteriaQuery.from(PoolTask.class);
|
||||||
|
criteriaQuery.select(poolTaskRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.ePerson), ePerson));
|
||||||
|
return list(context, criteriaQuery, false, PoolTask.class, -1, -1);
|
||||||
|
|
||||||
return list(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PoolTask> findByGroup(Context context, Group group) throws SQLException {
|
public List<PoolTask> findByGroup(Context context, Group group) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, PoolTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("group", group));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, PoolTask.class);
|
||||||
|
Root<PoolTask> poolTaskRoot = criteriaQuery.from(PoolTask.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(poolTaskRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.group), group));
|
||||||
|
return list(context, criteriaQuery, false, PoolTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PoolTask> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
public List<PoolTask> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, PoolTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("workflowItem", workflowItem));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, PoolTask.class);
|
||||||
|
Root<PoolTask> poolTaskRoot = criteriaQuery.from(PoolTask.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(poolTaskRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.workflowItem), workflowItem));
|
||||||
|
return list(context, criteriaQuery, false, PoolTask.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PoolTask findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
|
public PoolTask findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, PoolTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, PoolTask.class);
|
||||||
Restrictions.and(
|
Root<PoolTask> poolTaskRoot = criteriaQuery.from(PoolTask.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
criteriaQuery.select(poolTaskRoot);
|
||||||
Restrictions.eq("ePerson", ePerson)
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.and(criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.ePerson), ePerson)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return uniqueResult(context, criteriaQuery, false, PoolTask.class, -1, -1);
|
||||||
return uniqueResult(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PoolTask findByWorkflowItemAndGroup(Context context, Group group, XmlWorkflowItem workflowItem)
|
public PoolTask findByWorkflowItemAndGroup(Context context, Group group, XmlWorkflowItem workflowItem)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, PoolTask.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, PoolTask.class);
|
||||||
Restrictions.and(
|
Root<PoolTask> poolTaskRoot = criteriaQuery.from(PoolTask.class);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
criteriaQuery.select(poolTaskRoot);
|
||||||
Restrictions.eq("group", group)
|
criteriaQuery
|
||||||
|
.where(criteriaBuilder.and(criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.workflowItem), workflowItem),
|
||||||
|
criteriaBuilder.equal(poolTaskRoot.get(PoolTask_.group), group)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return uniqueResult(context, criteriaQuery, false, PoolTask.class, -1, -1);
|
||||||
return uniqueResult(criteria);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,15 +9,17 @@ package org.dspace.xmlworkflow.storedcomponents.dao.impl;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.WorkflowItemRole;
|
import org.dspace.xmlworkflow.storedcomponents.WorkflowItemRole;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.WorkflowItemRole_;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.dao.WorkflowItemRoleDAO;
|
import org.dspace.xmlworkflow.storedcomponents.dao.WorkflowItemRoleDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the WorkflowItemRole object.
|
* Hibernate implementation of the Database Access Object interface class for the WorkflowItemRole object.
|
||||||
@@ -27,37 +29,49 @@ import org.hibernate.criterion.Restrictions;
|
|||||||
* @author kevinvandevelde at atmire.com
|
* @author kevinvandevelde at atmire.com
|
||||||
*/
|
*/
|
||||||
public class WorkflowItemRoleDAOImpl extends AbstractHibernateDAO<WorkflowItemRole> implements WorkflowItemRoleDAO {
|
public class WorkflowItemRoleDAOImpl extends AbstractHibernateDAO<WorkflowItemRole> implements WorkflowItemRoleDAO {
|
||||||
|
|
||||||
protected WorkflowItemRoleDAOImpl() {
|
protected WorkflowItemRoleDAOImpl() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkflowItemRole> findByWorkflowItemAndRole(Context context, XmlWorkflowItem workflowItem, String role)
|
public List<WorkflowItemRole> findByWorkflowItemAndRole(Context context,
|
||||||
throws SQLException {
|
XmlWorkflowItem workflowItem,
|
||||||
Criteria criteria = createCriteria(context, WorkflowItemRole.class);
|
String role) throws SQLException {
|
||||||
criteria.add(Restrictions.and(
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
Restrictions.eq("workflowItem", workflowItem),
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkflowItemRole.class);
|
||||||
Restrictions.eq("role", role)
|
Root<WorkflowItemRole> workflowItemRoleRoot = criteriaQuery.from(WorkflowItemRole.class);
|
||||||
|
criteriaQuery.select(workflowItemRoleRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.and(criteriaBuilder
|
||||||
|
.equal(workflowItemRoleRoot.get(WorkflowItemRole_.workflowItem),
|
||||||
|
workflowItem),
|
||||||
|
criteriaBuilder
|
||||||
|
.equal(workflowItemRoleRoot.get(WorkflowItemRole_.roleId),
|
||||||
|
role)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return list(context, criteriaQuery, false, WorkflowItemRole.class, -1, -1);
|
||||||
return list(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkflowItemRole> findByWorkflowItem(Context context, XmlWorkflowItem workflowItem)
|
public List<WorkflowItemRole> findByWorkflowItem(Context context,
|
||||||
throws SQLException {
|
XmlWorkflowItem workflowItem) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkflowItemRole.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("workflowItem", workflowItem));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkflowItemRole.class);
|
||||||
|
Root<WorkflowItemRole> workflowItemRoleRoot = criteriaQuery.from(WorkflowItemRole.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(workflowItemRoleRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(workflowItemRoleRoot.get(WorkflowItemRole_.workflowItem),
|
||||||
|
workflowItem));
|
||||||
|
return list(context, criteriaQuery, false, WorkflowItemRole.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkflowItemRole> findByEPerson(Context context, EPerson ePerson) throws SQLException {
|
public List<WorkflowItemRole> findByEPerson(Context context, EPerson ePerson) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, WorkflowItemRole.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("ePerson", ePerson));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkflowItemRole.class);
|
||||||
|
Root<WorkflowItemRole> workflowItemRoleRoot = criteriaQuery.from(WorkflowItemRole.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(workflowItemRoleRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(workflowItemRoleRoot.get(WorkflowItemRole_.ePerson), ePerson));
|
||||||
|
return list(context, criteriaQuery, false, WorkflowItemRole.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,15 +10,20 @@ package org.dspace.xmlworkflow.storedcomponents.dao.impl;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.Item_;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem_;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.dao.XmlWorkflowItemDAO;
|
import org.dspace.xmlworkflow.storedcomponents.dao.XmlWorkflowItemDAO;
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the Database Access Object interface class for the XmlWorkflowItem object.
|
* Hibernate implementation of the Database Access Object interface class for the XmlWorkflowItem object.
|
||||||
@@ -34,21 +39,24 @@ public class XmlWorkflowItemDAOImpl extends AbstractHibernateDAO<XmlWorkflowItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<XmlWorkflowItem> findAllInCollection(Context context, Integer offset, Integer limit,
|
public List<XmlWorkflowItem> findAllInCollection(Context context, Integer offset,
|
||||||
|
Integer limit,
|
||||||
Collection collection) throws SQLException {
|
Collection collection) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, XmlWorkflowItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, XmlWorkflowItem.class);
|
||||||
|
Root<XmlWorkflowItem> xmlWorkflowItemRoot = criteriaQuery.from(XmlWorkflowItem.class);
|
||||||
|
criteriaQuery.select(xmlWorkflowItemRoot);
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
criteria.add(Restrictions.eq("collection", collection));
|
criteriaQuery.where(criteriaBuilder.equal(xmlWorkflowItemRoot.get(XmlWorkflowItem_.collection),
|
||||||
|
collection));
|
||||||
}
|
}
|
||||||
|
if (offset == null) {
|
||||||
if (offset != null) {
|
offset = -1;
|
||||||
criteria.setFirstResult(offset);
|
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
if (limit == null) {
|
||||||
criteria.setMaxResults(limit);
|
limit = -1;
|
||||||
}
|
}
|
||||||
|
return list(context, criteriaQuery, false, XmlWorkflowItem.class, limit, offset);
|
||||||
return list(criteria);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,35 +66,48 @@ public class XmlWorkflowItemDAOImpl extends AbstractHibernateDAO<XmlWorkflowItem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int countAllInCollection(Context context, Collection collection) throws SQLException {
|
public int countAllInCollection(Context context, Collection collection) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, XmlWorkflowItem.class);
|
|
||||||
|
|
||||||
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
|
|
||||||
|
Root<XmlWorkflowItem> xmlWorkflowItemRoot = criteriaQuery.from(XmlWorkflowItem.class);
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
criteria.add(Restrictions.eq("collection", collection));
|
criteriaQuery.where(criteriaBuilder.equal(xmlWorkflowItemRoot.get(XmlWorkflowItem_.collection),
|
||||||
|
collection));
|
||||||
}
|
}
|
||||||
return count(criteria);
|
return count(context, criteriaQuery, criteriaBuilder, xmlWorkflowItemRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<XmlWorkflowItem> findBySubmitter(Context context, EPerson ep) throws SQLException {
|
public List<XmlWorkflowItem> findBySubmitter(Context context, EPerson ep) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, XmlWorkflowItem.class);
|
|
||||||
criteria.createAlias("item", "i");
|
|
||||||
criteria.add(Restrictions.eq("i.submitter", ep));
|
|
||||||
|
|
||||||
return list(criteria);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, XmlWorkflowItem.class);
|
||||||
|
Root<XmlWorkflowItem> xmlWorkflowItemRoot = criteriaQuery.from(XmlWorkflowItem.class);
|
||||||
|
Join<XmlWorkflowItem, Item> join = xmlWorkflowItemRoot.join("item");
|
||||||
|
criteriaQuery.select(xmlWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(join.get(Item_.submitter), ep));
|
||||||
|
return list(context, criteriaQuery, false, XmlWorkflowItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<XmlWorkflowItem> findByCollection(Context context, Collection collection) throws SQLException {
|
public List<XmlWorkflowItem> findByCollection(Context context, Collection collection) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, XmlWorkflowItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("collection", collection));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, XmlWorkflowItem.class);
|
||||||
|
Root<XmlWorkflowItem> xmlWorkflowItemRoot = criteriaQuery.from(XmlWorkflowItem.class);
|
||||||
return list(criteria);
|
criteriaQuery.select(xmlWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(xmlWorkflowItemRoot.get(XmlWorkflowItem_.collection), collection));
|
||||||
|
return list(context, criteriaQuery, false, XmlWorkflowItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlWorkflowItem findByItem(Context context, Item item) throws SQLException {
|
public XmlWorkflowItem findByItem(Context context, Item item) throws SQLException {
|
||||||
Criteria criteria = createCriteria(context, XmlWorkflowItem.class);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
criteria.add(Restrictions.eq("item", item));
|
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, XmlWorkflowItem.class);
|
||||||
|
Root<XmlWorkflowItem> xmlWorkflowItemRoot = criteriaQuery.from(XmlWorkflowItem.class);
|
||||||
return uniqueResult(criteria);
|
criteriaQuery.select(xmlWorkflowItemRoot);
|
||||||
|
criteriaQuery.where(criteriaBuilder.equal(xmlWorkflowItemRoot.get(XmlWorkflowItem_.item), item));
|
||||||
|
return uniqueResult(context, criteriaQuery, false, XmlWorkflowItem.class, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.dspace.AbstractUnitTest;
|
import org.dspace.AbstractUnitTest;
|
||||||
import org.dspace.checker.ChecksumResultCode;
|
import org.dspace.checker.ChecksumResultCode;
|
||||||
@@ -23,7 +24,6 @@ import org.dspace.content.factory.ContentServiceFactory;
|
|||||||
import org.dspace.content.service.BitstreamService;
|
import org.dspace.content.service.BitstreamService;
|
||||||
import org.dspace.core.CoreHelpers;
|
import org.dspace.core.CoreHelpers;
|
||||||
import org.dspace.core.HibernateDBConnection;
|
import org.dspace.core.HibernateDBConnection;
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -87,9 +87,9 @@ public class ChecksumHistoryDAOImplTest
|
|||||||
cal.add(Calendar.DATE, -1);
|
cal.add(Calendar.DATE, -1);
|
||||||
Date matchDate = cal.getTime();
|
Date matchDate = cal.getTime();
|
||||||
checkId++;
|
checkId++;
|
||||||
qry.setInteger("id", checkId);
|
qry.setParameter("id", checkId);
|
||||||
qry.setDate("date", matchDate);
|
qry.setParameter("date", matchDate);
|
||||||
qry.setString("result", ChecksumResultCode.CHECKSUM_MATCH.name());
|
qry.setParameter("result", ChecksumResultCode.CHECKSUM_MATCH.name());
|
||||||
qry.setParameter("bitstream", bs.getID()); // FIXME identifier not being set???
|
qry.setParameter("bitstream", bs.getID()); // FIXME identifier not being set???
|
||||||
qry.executeUpdate();
|
qry.executeUpdate();
|
||||||
|
|
||||||
@@ -97,9 +97,9 @@ public class ChecksumHistoryDAOImplTest
|
|||||||
cal.add(Calendar.DATE, -1);
|
cal.add(Calendar.DATE, -1);
|
||||||
Date noMatchDate = cal.getTime();
|
Date noMatchDate = cal.getTime();
|
||||||
checkId++;
|
checkId++;
|
||||||
qry.setInteger("id", checkId);
|
qry.setParameter("id", checkId);
|
||||||
qry.setDate("date", noMatchDate);
|
qry.setParameter("date", noMatchDate);
|
||||||
qry.setString("result", ChecksumResultCode.CHECKSUM_NO_MATCH.name());
|
qry.setParameter("result", ChecksumResultCode.CHECKSUM_NO_MATCH.name());
|
||||||
qry.setParameter("bitstream", bs.getID()); // FIXME identifier not being set???
|
qry.setParameter("bitstream", bs.getID()); // FIXME identifier not being set???
|
||||||
qry.executeUpdate();
|
qry.executeUpdate();
|
||||||
|
|
||||||
@@ -107,9 +107,9 @@ public class ChecksumHistoryDAOImplTest
|
|||||||
cal.add(Calendar.DATE, +3);
|
cal.add(Calendar.DATE, +3);
|
||||||
Date futureDate = cal.getTime();
|
Date futureDate = cal.getTime();
|
||||||
checkId++;
|
checkId++;
|
||||||
qry.setInteger("id", checkId);
|
qry.setParameter("id", checkId);
|
||||||
qry.setDate("date", new java.sql.Date(futureDate.getTime()));
|
qry.setParameter("date", new java.sql.Date(futureDate.getTime()));
|
||||||
qry.setString("result", ChecksumResultCode.CHECKSUM_MATCH.name());
|
qry.setParameter("result", ChecksumResultCode.CHECKSUM_MATCH.name());
|
||||||
qry.setParameter("bitstream", bs.getID()); // FIXME identifier not being set???
|
qry.setParameter("bitstream", bs.getID()); // FIXME identifier not being set???
|
||||||
qry.executeUpdate();
|
qry.executeUpdate();
|
||||||
|
|
||||||
@@ -125,18 +125,18 @@ public class ChecksumHistoryDAOImplTest
|
|||||||
"SELECT COUNT(*) FROM ChecksumHistory WHERE process_end_date = :date");
|
"SELECT COUNT(*) FROM ChecksumHistory WHERE process_end_date = :date");
|
||||||
long count;
|
long count;
|
||||||
|
|
||||||
qry.setDate("date", matchDate);
|
qry.setParameter("date", matchDate);
|
||||||
count = (Long) qry.uniqueResult();
|
count = (Long) qry.getSingleResult();
|
||||||
assertEquals("Should find no row at matchDate", count, 0);
|
assertEquals("Should find no row at matchDate", count, 0);
|
||||||
|
|
||||||
// See if nonmatching old row is still present.
|
// See if nonmatching old row is still present.
|
||||||
qry.setDate("date", noMatchDate);
|
qry.setParameter("date", noMatchDate);
|
||||||
count = (Long) qry.uniqueResult();
|
count = (Long) qry.getSingleResult();
|
||||||
assertEquals("Should find one row at noMatchDate", count, 1);
|
assertEquals("Should find one row at noMatchDate", count, 1);
|
||||||
|
|
||||||
// See if new row is still present.
|
// See if new row is still present.
|
||||||
qry.setDate("date", futureDate);
|
qry.setParameter("date", futureDate);
|
||||||
count = (Long) qry.uniqueResult();
|
count = (Long) qry.getSingleResult();
|
||||||
assertEquals("Should find one row at futureDate", count, 1);
|
assertEquals("Should find one row at futureDate", count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@ import org.dspace.content.BitstreamFormat;
|
|||||||
import org.dspace.content.service.BitstreamService;
|
import org.dspace.content.service.BitstreamService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.disseminate.service.CitationDocumentService;
|
import org.dspace.disseminate.service.CitationDocumentService;
|
||||||
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.dspace.services.EventService;
|
import org.dspace.services.EventService;
|
||||||
import org.dspace.usage.UsageEvent;
|
import org.dspace.usage.UsageEvent;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -70,6 +71,9 @@ public class BitstreamContentRestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CitationDocumentService citationDocumentService;
|
private CitationDocumentService citationDocumentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurationService configurationService;
|
||||||
|
|
||||||
@PreAuthorize("hasPermission(#uuid, 'BITSTREAM', 'READ')")
|
@PreAuthorize("hasPermission(#uuid, 'BITSTREAM', 'READ')")
|
||||||
@RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD})
|
@RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD})
|
||||||
public void retrieve(@PathVariable UUID uuid, HttpServletResponse response,
|
public void retrieve(@PathVariable UUID uuid, HttpServletResponse response,
|
||||||
@@ -104,6 +108,12 @@ public class BitstreamContentRestController {
|
|||||||
.with(request)
|
.with(request)
|
||||||
.with(response);
|
.with(response);
|
||||||
|
|
||||||
|
//Determine if we need to send the file as a download or if the browser can open it inline
|
||||||
|
long dispositionThreshold = configurationService.getLongProperty("webui.content_disposition_threshold");
|
||||||
|
if (dispositionThreshold >= 0 && bitstreamTuple.getRight() > dispositionThreshold) {
|
||||||
|
sender.withDisposition(MultipartFileSender.CONTENT_DISPOSITION_ATTACHMENT);
|
||||||
|
}
|
||||||
|
|
||||||
if (sender.isNoRangeRequest() && isNotAnErrorResponse(response)) {
|
if (sender.isNoRangeRequest() && isNotAnErrorResponse(response)) {
|
||||||
//We only log a download request when serving a request without Range header. This is because
|
//We only log a download request when serving a request without Range header. This is because
|
||||||
//a browser always sends a regular request first to check for Range support.
|
//a browser always sends a regular request first to check for Range support.
|
||||||
|
@@ -10,18 +10,22 @@ package org.dspace.app.rest;
|
|||||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -46,6 +50,7 @@ import org.dspace.app.rest.repository.DSpaceRestRepository;
|
|||||||
import org.dspace.app.rest.repository.LinkRestRepository;
|
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||||
import org.dspace.app.rest.utils.RestRepositoryUtils;
|
import org.dspace.app.rest.utils.RestRepositoryUtils;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -60,6 +65,7 @@ import org.springframework.hateoas.Link;
|
|||||||
import org.springframework.hateoas.PagedResources;
|
import org.springframework.hateoas.PagedResources;
|
||||||
import org.springframework.hateoas.Resource;
|
import org.springframework.hateoas.Resource;
|
||||||
import org.springframework.hateoas.ResourceSupport;
|
import org.springframework.hateoas.ResourceSupport;
|
||||||
|
import org.springframework.hateoas.Resources;
|
||||||
import org.springframework.hateoas.UriTemplate;
|
import org.springframework.hateoas.UriTemplate;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -426,17 +432,23 @@ public class RestResourceController implements InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called in POST, multipart, upload a resource passed into "file" request parameter
|
* Called in POST, multipart, upload to a specific rest resource the file passed as "file" request parameter
|
||||||
*
|
*
|
||||||
* Note that the regular expression in the request mapping accept a number as identifier;
|
* Note that the regular expression in the request mapping accept a number as identifier;
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
|
* the http request
|
||||||
* @param apiCategory
|
* @param apiCategory
|
||||||
|
* the api category
|
||||||
* @param model
|
* @param model
|
||||||
|
* the rest model that identify the REST resource collection
|
||||||
* @param id
|
* @param id
|
||||||
|
* the id of the specific rest resource
|
||||||
* @param extraField
|
* @param extraField
|
||||||
|
* the original name of the uploaded file
|
||||||
* @param uploadfile
|
* @param uploadfile
|
||||||
* @return
|
* the file to upload
|
||||||
|
* @return the created resource
|
||||||
* @throws HttpRequestMethodNotSupportedException
|
* @throws HttpRequestMethodNotSupportedException
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_DIGIT, headers =
|
@RequestMapping(method = RequestMethod.POST, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_DIGIT, headers =
|
||||||
@@ -454,17 +466,23 @@ public class RestResourceController implements InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called in POST, multipart, upload a resource passed into "file" request parameter
|
* Called in POST, multipart, upload to a specific rest resource the file passed as "file" request parameter
|
||||||
*
|
*
|
||||||
* Note that the regular expression in the request mapping accept a UUID as identifier;
|
* Note that the regular expression in the request mapping accept a UUID as identifier;
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
|
* the http request
|
||||||
* @param apiCategory
|
* @param apiCategory
|
||||||
|
* the api category
|
||||||
* @param model
|
* @param model
|
||||||
|
* the rest model that identify the REST resource collection
|
||||||
* @param id
|
* @param id
|
||||||
|
* the id of the specific rest resource
|
||||||
* @param extraField
|
* @param extraField
|
||||||
|
* the original name of the uploaded file
|
||||||
* @param uploadfile
|
* @param uploadfile
|
||||||
* @return
|
* the file to upload
|
||||||
|
* @return the created resource
|
||||||
* @throws HttpRequestMethodNotSupportedException
|
* @throws HttpRequestMethodNotSupportedException
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID, headers =
|
@RequestMapping(method = RequestMethod.POST, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID, headers =
|
||||||
@@ -512,6 +530,48 @@ public class RestResourceController implements InitializingBean {
|
|||||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload a file against the collection resource endpoint. This is typically used for bulk creation of resources
|
||||||
|
* such for instance multiple workspaceitems from a CSV or bibliographic file
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the http request
|
||||||
|
* @param apiCategory
|
||||||
|
* the api category
|
||||||
|
* @param model
|
||||||
|
* the rest model that identify the REST resource collection
|
||||||
|
* @param uploadfile
|
||||||
|
* the bulk file
|
||||||
|
* @return the list of generated resources
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
* @throws AuthorizeException
|
||||||
|
*/
|
||||||
|
@RequestMapping(method = { RequestMethod.POST }, headers = "content-type=multipart/form-data")
|
||||||
|
public <T extends RestAddressableModel> ResponseEntity<ResourceSupport> upload(HttpServletRequest request,
|
||||||
|
@PathVariable String apiCategory,
|
||||||
|
@PathVariable String model,
|
||||||
|
@RequestParam(required = false)
|
||||||
|
String extraField,
|
||||||
|
@RequestParam("file") MultipartFile
|
||||||
|
uploadfile)
|
||||||
|
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
||||||
|
|
||||||
|
checkModelPluralForm(apiCategory, model);
|
||||||
|
DSpaceRestRepository repository = utils.getResourceRepository(apiCategory, model);
|
||||||
|
|
||||||
|
Iterable<T> content = repository.upload(request, extraField, uploadfile);
|
||||||
|
|
||||||
|
List<DSpaceResource> resources = new ArrayList<>();
|
||||||
|
for (T modelObject : content) {
|
||||||
|
DSpaceResource result = repository.wrapResource(modelObject);
|
||||||
|
linkService.addLinks(result);
|
||||||
|
resources.add(result);
|
||||||
|
}
|
||||||
|
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, Resources.wrap(resources));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PATCH method, using operation on the resources following (JSON) Patch notation (https://tools.ietf
|
* PATCH method, using operation on the resources following (JSON) Patch notation (https://tools.ietf
|
||||||
* .org/html/rfc6902)
|
* .org/html/rfc6902)
|
||||||
@@ -573,7 +633,6 @@ public class RestResourceController implements InitializingBean {
|
|||||||
String model, ID id,
|
String model, ID id,
|
||||||
JsonNode jsonNode)
|
JsonNode jsonNode)
|
||||||
throws HttpRequestMethodNotSupportedException {
|
throws HttpRequestMethodNotSupportedException {
|
||||||
|
|
||||||
checkModelPluralForm(apiCategory, model);
|
checkModelPluralForm(apiCategory, model);
|
||||||
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||||
RestAddressableModel modelObject = null;
|
RestAddressableModel modelObject = null;
|
||||||
|
@@ -12,7 +12,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.rest.converter.query.SearchQueryConverter;
|
import org.dspace.app.rest.converter.query.SearchQueryConverter;
|
||||||
import org.dspace.app.rest.model.DSpaceObjectRest;
|
import org.dspace.app.rest.model.DSpaceObjectRest;
|
||||||
|
@@ -85,6 +85,10 @@ public class WorkspaceItemConverter
|
|||||||
// info
|
// info
|
||||||
|
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
|
// we set the status to true as we will discover validation error later in this block
|
||||||
|
// we could eventually leave the status to empty if we don't have collection information, this could be
|
||||||
|
// eventually the case when projection support will be included
|
||||||
|
witem.setStatus(true);
|
||||||
SubmissionDefinitionRest def = submissionDefinitionConverter
|
SubmissionDefinitionRest def = submissionDefinitionConverter
|
||||||
.convert(submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
|
.convert(submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
|
||||||
witem.setSubmissionDefinition(def);
|
witem.setSubmissionDefinition(def);
|
||||||
@@ -108,6 +112,7 @@ public class WorkspaceItemConverter
|
|||||||
(AbstractRestProcessingStep) stepClass.newInstance();
|
(AbstractRestProcessingStep) stepClass.newInstance();
|
||||||
for (ErrorRest error : stepProcessing.validate(submissionService, obj, stepConfig)) {
|
for (ErrorRest error : stepProcessing.validate(submissionService, obj, stepConfig)) {
|
||||||
addError(witem.getErrors(), error);
|
addError(witem.getErrors(), error);
|
||||||
|
witem.setStatus(false);
|
||||||
}
|
}
|
||||||
witem.getSections()
|
witem.getSections()
|
||||||
.put(sections.getId(), stepProcessing.getData(submissionService, obj, stepConfig));
|
.put(sections.getId(), stepProcessing.getData(submissionService, obj, stepConfig));
|
||||||
|
@@ -21,6 +21,11 @@ public class ErrorRest {
|
|||||||
|
|
||||||
private List<String> paths;
|
private List<String> paths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error message as i18key
|
||||||
|
*
|
||||||
|
* @return The message as i18key
|
||||||
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
@@ -29,6 +34,13 @@ public class ErrorRest {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The json paths where the error message apply. They can be as detailed as a specific value in a multivalues
|
||||||
|
* attributes (i.e. sections.traditionalpageone['dc.contributor.author'][1] to identify the second author - 0 based)
|
||||||
|
* or generic to apply to a whole section (sections.license)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public List<String> getPaths() {
|
public List<String> getPaths() {
|
||||||
if (this.paths == null) {
|
if (this.paths == null) {
|
||||||
this.paths = new ArrayList<String>();
|
this.paths = new ArrayList<String>();
|
||||||
|
@@ -68,48 +68,94 @@ public abstract class DSpaceRestRepository<T extends RestAddressableModel, ID ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to support full update of a REST object. This is usually required by a PUT request.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the dspace context
|
||||||
|
* @param entity
|
||||||
|
* the REST object to update
|
||||||
|
* @return the new state of the REST object after persistence
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws RepositoryMethodNotImplementedException
|
||||||
|
* returned by the default implementation when the operation is not supported for the entity
|
||||||
|
*/
|
||||||
protected <S extends T> S save(Context context, S entity) throws AuthorizeException,
|
protected <S extends T> S save(Context context, S entity) throws AuthorizeException,
|
||||||
RepositoryMethodNotImplementedException {
|
RepositoryMethodNotImplementedException {
|
||||||
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Method to implement to support bulk update of a REST objects via a PUT request
|
||||||
|
*/
|
||||||
public <S extends T> Iterable<S> save(Iterable<S> entities) {
|
public <S extends T> Iterable<S> save(Iterable<S> entities) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Return a specific REST object
|
||||||
|
*
|
||||||
|
* @return the REST object identified by its ID
|
||||||
|
*/
|
||||||
public T findOne(ID id) {
|
public T findOne(ID id) {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
return thisRepository.findOne(context, id);
|
return thisRepository.findOne(context, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to support retrieval of a specific REST object instance
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the dspace context
|
||||||
|
* @param id
|
||||||
|
* the rest object id
|
||||||
|
* @return the REST object identified by its ID
|
||||||
|
*/
|
||||||
public abstract T findOne(Context context, ID id);
|
public abstract T findOne(Context context, ID id);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Return true if an object exist for the specified ID. The default implementation is inefficient as it retrieves
|
||||||
|
* the actual object to state that it exists. This could lead to retrieve and inizialize lot of linked objects
|
||||||
|
*/
|
||||||
public boolean exists(ID id) {
|
public boolean exists(ID id) {
|
||||||
// TODO Auto-generated method stub
|
return findOne(id) != null;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<T> findAll() {
|
/**
|
||||||
|
* This method cannot be implemented we required all the find method to be paginated
|
||||||
|
*/
|
||||||
|
public final Iterable<T> findAll() {
|
||||||
throw new RuntimeException("findAll MUST be paginated");
|
throw new RuntimeException("findAll MUST be paginated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* This method could be implemented to support bulk retrieval of specific object by their IDs. Unfortunately, this
|
||||||
|
* method doesn't allow pagination and it could be misused to retrieve thousand objects at once
|
||||||
|
*/
|
||||||
public Iterable<T> findAll(Iterable<ID> ids) {
|
public Iterable<T> findAll(Iterable<ID> ids) {
|
||||||
throw new RuntimeException("findAll MUST be paginated");
|
throw new RuntimeException("findAll MUST be paginated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* This method return the number of object instances of the type managed by the repository class available in the
|
||||||
|
* system
|
||||||
|
*/
|
||||||
public long count() {
|
public long count() {
|
||||||
// TODO Auto-generated method stub
|
// FIXME DS-4038
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Delete the object identified by its ID
|
||||||
|
*/
|
||||||
public void delete(ID id) {
|
public void delete(ID id) {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
try {
|
try {
|
||||||
@@ -122,44 +168,96 @@ public abstract class DSpaceRestRepository<T extends RestAddressableModel, ID ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to support delete of a single object instance
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the dspace context
|
||||||
|
* @param id
|
||||||
|
* the id of the rest object to delete
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws RepositoryMethodNotImplementedException
|
||||||
|
* returned by the default implementation when the operation is not supported for the entity
|
||||||
|
*/
|
||||||
protected void delete(Context context, ID id) throws AuthorizeException, RepositoryMethodNotImplementedException {
|
protected void delete(Context context, ID id) throws AuthorizeException, RepositoryMethodNotImplementedException {
|
||||||
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Method to implement to allow delete of a specific entity instance
|
||||||
|
*/
|
||||||
public void delete(T entity) {
|
public void delete(T entity) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Method to implement to support bulk delete of multiple entity instances
|
||||||
|
*/
|
||||||
public void delete(Iterable<? extends T> entities) {
|
public void delete(Iterable<? extends T> entities) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Method to implement to support bulk delete of ALL entity instances
|
||||||
|
*/
|
||||||
public void deleteAll() {
|
public void deleteAll() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<T> findAll(Sort sort) {
|
/**
|
||||||
|
* This method cannot be implemented we required all the find method to be paginated
|
||||||
|
*/
|
||||||
|
public final Iterable<T> findAll(Sort sort) {
|
||||||
throw new RuntimeException("findAll MUST be paginated");
|
throw new RuntimeException("findAll MUST be paginated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* Provide access to the manage entity instances in a paginated way
|
||||||
|
*/
|
||||||
public Page<T> findAll(Pageable pageable) {
|
public Page<T> findAll(Pageable pageable) {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
return thisRepository.findAll(context, pageable);
|
return thisRepository.findAll(context, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to support scroll of entity instances from the collection resource endpoin
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the dspace context
|
||||||
|
* @param pageable
|
||||||
|
* object embedding the requested pagination info
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public abstract Page<T> findAll(Context context, Pageable pageable);
|
public abstract Page<T> findAll(Context context, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The REST model supported by the repository
|
||||||
|
*/
|
||||||
public abstract Class<T> getDomainClass();
|
public abstract Class<T> getDomainClass();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap the REST model in a REST HAL Resource
|
||||||
|
*
|
||||||
|
* @param model
|
||||||
|
* the rest model instance
|
||||||
|
* @param rels
|
||||||
|
* the HAL links
|
||||||
|
* @return the REST Resource
|
||||||
|
*/
|
||||||
public abstract DSpaceResource<T> wrapResource(T model, String... rels);
|
public abstract DSpaceResource<T> wrapResource(T model, String... rels);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and return a new instance. Data are usually retrieved from the thread bound http request
|
||||||
|
*
|
||||||
|
* @return the created REST object
|
||||||
|
*/
|
||||||
public T createAndReturn() {
|
public T createAndReturn() {
|
||||||
Context context = null;
|
Context context = null;
|
||||||
try {
|
try {
|
||||||
@@ -174,16 +272,60 @@ public abstract class DSpaceRestRepository<T extends RestAddressableModel, ID ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to support the creation of a new instance. Usually require to retrieve the http request from
|
||||||
|
* the thread bound attribute
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the dspace context
|
||||||
|
* @return the created REST object
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws RepositoryMethodNotImplementedException
|
||||||
|
* returned by the default implementation when the operation is not supported for the entity
|
||||||
|
*/
|
||||||
protected T createAndReturn(Context context)
|
protected T createAndReturn(Context context)
|
||||||
throws AuthorizeException, SQLException, RepositoryMethodNotImplementedException {
|
throws AuthorizeException, SQLException, RepositoryMethodNotImplementedException {
|
||||||
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to attach/upload a file to a specific REST object
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the http request
|
||||||
|
* @param apiCategory
|
||||||
|
* @param model
|
||||||
|
* @param id
|
||||||
|
* the ID of the target REST object
|
||||||
|
* @param extraField
|
||||||
|
* the original name of the uploaded file
|
||||||
|
* @param file
|
||||||
|
* the uploaded file
|
||||||
|
* @return the new state of the REST object
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public T upload(HttpServletRequest request, String apiCategory, String model,
|
public T upload(HttpServletRequest request, String apiCategory, String model,
|
||||||
ID id, String extraField, MultipartFile file) throws Exception {
|
ID id, String extraField, MultipartFile file) throws Exception {
|
||||||
throw new RuntimeException("No implementation found; Method not allowed!");
|
throw new RuntimeException("No implementation found; Method not allowed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a partial update to the REST object via JSON Patch
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the http request
|
||||||
|
* @param apiCategory
|
||||||
|
* @param model
|
||||||
|
* @param id
|
||||||
|
* the ID of the target REST object
|
||||||
|
* @param patch
|
||||||
|
* the JSON Patch (https://tools.ietf.org/html/rfc6902) operation
|
||||||
|
* @return
|
||||||
|
* @throws HttpRequestMethodNotSupportedException
|
||||||
|
* @throws UnprocessableEntityException
|
||||||
|
* @throws PatchBadRequestException
|
||||||
|
*/
|
||||||
public T patch(HttpServletRequest request, String apiCategory, String model, ID id, Patch patch)
|
public T patch(HttpServletRequest request, String apiCategory, String model, ID id, Patch patch)
|
||||||
throws HttpRequestMethodNotSupportedException, UnprocessableEntityException, PatchBadRequestException {
|
throws HttpRequestMethodNotSupportedException, UnprocessableEntityException, PatchBadRequestException {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
@@ -198,23 +340,77 @@ public abstract class DSpaceRestRepository<T extends RestAddressableModel, ID ex
|
|||||||
return findOne(id);
|
return findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to implement to allow partial update of the REST object via JSON Patch
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the http request
|
||||||
|
* @param apiCategory
|
||||||
|
* @param model
|
||||||
|
* @param id
|
||||||
|
* the ID of the target REST object
|
||||||
|
* @param patch
|
||||||
|
* the JSON Patch (https://tools.ietf.org/html/rfc6902) operation
|
||||||
|
* @return the full new state of the REST object after patching
|
||||||
|
* @throws HttpRequestMethodNotSupportedException
|
||||||
|
* @throws UnprocessableEntityException
|
||||||
|
* @throws PatchBadRequestException
|
||||||
|
* @throws RepositoryMethodNotImplementedException
|
||||||
|
* returned by the default implementation when the operation is not supported for the entity
|
||||||
|
*
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws DCInputsReaderException
|
||||||
|
*/
|
||||||
protected void patch(Context context, HttpServletRequest request, String apiCategory, String model, ID id,
|
protected void patch(Context context, HttpServletRequest request, String apiCategory, String model, ID id,
|
||||||
Patch patch)
|
Patch patch)
|
||||||
throws RepositoryMethodNotImplementedException, SQLException, AuthorizeException, DCInputsReaderException {
|
throws RepositoryMethodNotImplementedException, SQLException, AuthorizeException, DCInputsReaderException {
|
||||||
throw new RepositoryMethodNotImplementedException(apiCategory, model);
|
throw new RepositoryMethodNotImplementedException(apiCategory, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<T> upload(HttpServletRequest request, MultipartFile uploadfile)
|
/**
|
||||||
|
* Bulk create object instances from an uploaded file
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the http request
|
||||||
|
* @param extraField
|
||||||
|
* the original name of the uploaded file
|
||||||
|
* @param uploadfile
|
||||||
|
* the file to process
|
||||||
|
* @return the created objects
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
* @throws AuthorizeException
|
||||||
|
*/
|
||||||
|
public Iterable<T> upload(HttpServletRequest request, String extraField, MultipartFile uploadfile)
|
||||||
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
Iterable<T> entity = upload(context, request, uploadfile);
|
Iterable<T> entity = upload(context, request, extraField, uploadfile);
|
||||||
context.commit();
|
context.commit();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Iterable<T> upload(Context context, HttpServletRequest request, MultipartFile uploadfile)
|
/**
|
||||||
|
* Method to implement to support bulk creation of objects from a file
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the http request
|
||||||
|
* @param extraField
|
||||||
|
* the original name of the uploaded file
|
||||||
|
* @param uploadfile
|
||||||
|
* the file to process
|
||||||
|
* @return the created objects
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws RepositoryMethodNotImplementedException
|
||||||
|
*/
|
||||||
|
protected Iterable<T> upload(Context context, HttpServletRequest request, String extraField,
|
||||||
|
MultipartFile uploadfile)
|
||||||
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
||||||
throw new RuntimeException("No implementation found; Method not allowed!");
|
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.rest.webmvc.json.patch.PatchException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -325,6 +326,7 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
|
throw new PatchException("Error processing the patch request", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,7 +347,8 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<WorkspaceItemRest> upload(Context context, HttpServletRequest request, MultipartFile uploadfile)
|
public Iterable<WorkspaceItemRest> upload(Context context, HttpServletRequest request, String extraField,
|
||||||
|
MultipartFile uploadfile)
|
||||||
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
throws SQLException, FileNotFoundException, IOException, AuthorizeException {
|
||||||
File file = Utils.getFile(uploadfile, "upload-loader", "filedataloader");
|
File file = Utils.getFile(uploadfile, "upload-loader", "filedataloader");
|
||||||
List<WorkspaceItemRest> results = new ArrayList<>();
|
List<WorkspaceItemRest> results = new ArrayList<>();
|
||||||
@@ -360,7 +363,7 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
if (StringUtils.isNotBlank(uuid)) {
|
if (StringUtils.isNotBlank(uuid)) {
|
||||||
collection = collectionService.find(context, UUID.fromString(uuid));
|
collection = collectionService.find(context, UUID.fromString(uuid));
|
||||||
} else {
|
} else {
|
||||||
collection = collectionService.findAll(context, 1, 0).get(0);
|
collection = collectionService.findAuthorizedOptimized(context, Constants.ADD).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SubmissionConfig submissionConfig =
|
SubmissionConfig submissionConfig =
|
||||||
@@ -370,6 +373,13 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
List<ItemSubmissionLookupDTO> tmpResult = new ArrayList<ItemSubmissionLookupDTO>();
|
List<ItemSubmissionLookupDTO> tmpResult = new ArrayList<ItemSubmissionLookupDTO>();
|
||||||
|
|
||||||
TransformationEngine transformationEngine1 = submissionLookupService.getPhase1TransformationEngine();
|
TransformationEngine transformationEngine1 = submissionLookupService.getPhase1TransformationEngine();
|
||||||
|
TransformationSpec spec = new TransformationSpec();
|
||||||
|
// FIXME this is mostly due to the need to test. The BTE framework has an assert statement that check if the
|
||||||
|
// number of found record is less than the requested and treat 0 as is, instead, the implementation assume
|
||||||
|
// 0=unlimited this lead to test failure.
|
||||||
|
// It is unclear if BTE really respect values other than 0/MAX allowing us to put a protection against heavy
|
||||||
|
// load
|
||||||
|
spec.setNumberOfRecords(Integer.MAX_VALUE);
|
||||||
if (transformationEngine1 != null) {
|
if (transformationEngine1 != null) {
|
||||||
MultipleSubmissionLookupDataLoader dataLoader =
|
MultipleSubmissionLookupDataLoader dataLoader =
|
||||||
(MultipleSubmissionLookupDataLoader) transformationEngine1.getDataLoader();
|
(MultipleSubmissionLookupDataLoader) transformationEngine1.getDataLoader();
|
||||||
@@ -383,7 +393,7 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
(SubmissionLookupOutputGenerator) transformationEngine1.getOutputGenerator();
|
(SubmissionLookupOutputGenerator) transformationEngine1.getOutputGenerator();
|
||||||
outputGenerator.setDtoList(new ArrayList<ItemSubmissionLookupDTO>());
|
outputGenerator.setDtoList(new ArrayList<ItemSubmissionLookupDTO>());
|
||||||
log.debug("BTE transformation is about to start!");
|
log.debug("BTE transformation is about to start!");
|
||||||
transformationEngine1.transform(new TransformationSpec());
|
transformationEngine1.transform(spec);
|
||||||
log.debug("BTE transformation finished!");
|
log.debug("BTE transformation finished!");
|
||||||
tmpResult.addAll(outputGenerator.getDtoList());
|
tmpResult.addAll(outputGenerator.getDtoList());
|
||||||
if (!tmpResult.isEmpty()) {
|
if (!tmpResult.isEmpty()) {
|
||||||
@@ -417,7 +427,7 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
outputGenerator.setDto(tmpResult.get(0));
|
outputGenerator.setDto(tmpResult.get(0));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
transformationEngine2.transform(new TransformationSpec());
|
transformationEngine2.transform(spec);
|
||||||
result = outputGenerator.getWitems();
|
result = outputGenerator.getWitems();
|
||||||
} catch (BadTransformationSpec e1) {
|
} catch (BadTransformationSpec e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
@@ -456,9 +466,8 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
Object stepInstance = stepClass.newInstance();
|
Object stepInstance = stepClass.newInstance();
|
||||||
if (UploadableStep.class.isAssignableFrom(stepClass)) {
|
if (UploadableStep.class.isAssignableFrom(stepClass)) {
|
||||||
UploadableStep uploadableStep = (UploadableStep) stepInstance;
|
UploadableStep uploadableStep = (UploadableStep) stepInstance;
|
||||||
ErrorRest err = uploadableStep
|
ErrorRest err = uploadableStep.upload(context, submissionService, stepConfig, wi,
|
||||||
.upload(context, submissionService, stepConfig, wi, uploadfile,
|
uploadfile, extraField);
|
||||||
file.getAbsolutePath());
|
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
errors.add(err);
|
errors.add(err);
|
||||||
}
|
}
|
||||||
|
@@ -21,9 +21,10 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
|||||||
import org.dspace.services.model.Request;
|
import org.dspace.services.model.Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to retrieve information about section
|
* Interface for the submission steps to populate sections in the in progress submission and react to patch requests.
|
||||||
*
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
*/
|
*/
|
||||||
public interface AbstractRestProcessingStep extends ListenerProcessingStep {
|
public interface AbstractRestProcessingStep extends ListenerProcessingStep {
|
||||||
|
|
||||||
@@ -37,9 +38,33 @@ public interface AbstractRestProcessingStep extends ListenerProcessingStep {
|
|||||||
|
|
||||||
public static final String UPLOAD_STEP_METADATA_PATH = "metadata";
|
public static final String UPLOAD_STEP_METADATA_PATH = "metadata";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to expose data in the a dedicated section of the in progress submission. The step needs to return a
|
||||||
|
* serializable object that will be included in a section with the name (id) assigned to the step in the
|
||||||
|
* item-submission.xml file
|
||||||
|
*
|
||||||
|
* @param submissionService
|
||||||
|
* the submission service
|
||||||
|
* @param obj
|
||||||
|
* the in progress submission
|
||||||
|
* @param config
|
||||||
|
* the submission step configuration
|
||||||
|
* @return the serializable object to include in the step generated section
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public <T extends Serializable> T getData(SubmissionService submissionService, WorkspaceItem obj,
|
public <T extends Serializable> T getData(SubmissionService submissionService, WorkspaceItem obj,
|
||||||
SubmissionStepConfig config) throws Exception;
|
SubmissionStepConfig config) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method will expose the list of validation errors identified by the step. The default implementation will
|
||||||
|
* found a {@link Validation} spring bean in the context with the same name that the step id
|
||||||
|
*
|
||||||
|
* @param submissionService
|
||||||
|
* @param obj
|
||||||
|
* @param config
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
default public List<ErrorRest> validate(SubmissionService submissionService, WorkspaceItem obj,
|
default public List<ErrorRest> validate(SubmissionService submissionService, WorkspaceItem obj,
|
||||||
SubmissionStepConfig config) throws Exception {
|
SubmissionStepConfig config) throws Exception {
|
||||||
List<ErrorRest> errors = new ArrayList<ErrorRest>();
|
List<ErrorRest> errors = new ArrayList<ErrorRest>();
|
||||||
@@ -55,6 +80,19 @@ public interface AbstractRestProcessingStep extends ListenerProcessingStep {
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to react to a patch request against the step managed section data
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the DSpace context
|
||||||
|
* @param currentRequest
|
||||||
|
* the http request
|
||||||
|
* @param source
|
||||||
|
* the in progress submission
|
||||||
|
* @param op
|
||||||
|
* the json patch operation
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, Operation op)
|
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, Operation op)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
@@ -11,7 +11,13 @@ import org.dspace.content.InProgressSubmission;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This interface allows a submission step to access and modify if needed an inprogress submission also when changes are
|
||||||
|
* requested to sections other than the one managed by the step itself.
|
||||||
|
*
|
||||||
|
* This could be useful to allow a step wide validations or changes over multiple sections.
|
||||||
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
*/
|
*/
|
||||||
public interface ListenerProcessingStep {
|
public interface ListenerProcessingStep {
|
||||||
|
|
||||||
|
@@ -18,12 +18,14 @@ import org.apache.log4j.Logger;
|
|||||||
import org.atteo.evo.inflector.English;
|
import org.atteo.evo.inflector.English;
|
||||||
import org.dspace.app.rest.converter.BitstreamFormatConverter;
|
import org.dspace.app.rest.converter.BitstreamFormatConverter;
|
||||||
import org.dspace.app.rest.converter.ResourcePolicyConverter;
|
import org.dspace.app.rest.converter.ResourcePolicyConverter;
|
||||||
|
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
||||||
import org.dspace.app.rest.model.BitstreamRest;
|
import org.dspace.app.rest.model.BitstreamRest;
|
||||||
import org.dspace.app.rest.model.CheckSumRest;
|
import org.dspace.app.rest.model.CheckSumRest;
|
||||||
import org.dspace.app.rest.model.MetadataValueRest;
|
import org.dspace.app.rest.model.MetadataValueRest;
|
||||||
import org.dspace.app.rest.model.ResourcePolicyRest;
|
import org.dspace.app.rest.model.ResourcePolicyRest;
|
||||||
import org.dspace.app.rest.model.step.UploadBitstreamRest;
|
import org.dspace.app.rest.model.step.UploadBitstreamRest;
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.ResourcePolicy;
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
@@ -31,12 +33,14 @@ import org.dspace.content.MetadataValue;
|
|||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
import org.dspace.content.service.CollectionService;
|
import org.dspace.content.service.CollectionService;
|
||||||
import org.dspace.content.service.WorkspaceItemService;
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.Utils;
|
import org.dspace.core.Utils;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.dspace.services.RequestService;
|
import org.dspace.services.RequestService;
|
||||||
import org.dspace.services.model.Request;
|
import org.dspace.services.model.Request;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.datasource.init.UncategorizedScriptException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,23 +68,35 @@ public class SubmissionService {
|
|||||||
|
|
||||||
public WorkspaceItem createWorkspaceItem(Context context, Request request) {
|
public WorkspaceItem createWorkspaceItem(Context context, Request request) {
|
||||||
WorkspaceItem wsi = null;
|
WorkspaceItem wsi = null;
|
||||||
String collectionUUID = request.getHttpServletRequest().getParameter("collection");
|
|
||||||
if (StringUtils.isBlank(collectionUUID)) {
|
|
||||||
String uuid = configurationService.getProperty("submission.default.collection");
|
|
||||||
Collection collection = null;
|
Collection collection = null;
|
||||||
|
String collectionUUID = request.getHttpServletRequest().getParameter("collection");
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(collectionUUID)) {
|
||||||
|
collectionUUID = configurationService.getProperty("submission.default.collection");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isNotBlank(uuid)) {
|
if (StringUtils.isNotBlank(collectionUUID)) {
|
||||||
collection = collectionService.find(context, UUID.fromString(uuid));
|
collection = collectionService.find(context, UUID.fromString(collectionUUID));
|
||||||
} else {
|
} else {
|
||||||
collection = collectionService.findAll(context, 1, 0).get(0);
|
final List<Collection> findAuthorizedOptimized = collectionService.findAuthorizedOptimized(context,
|
||||||
|
Constants.ADD);
|
||||||
|
if (findAuthorizedOptimized != null && findAuthorizedOptimized.size() > 0) {
|
||||||
|
collection = findAuthorizedOptimized.get(0);
|
||||||
|
} else {
|
||||||
|
throw new RESTAuthorizationException("No collection suitable for submission for the current user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collection == null) {
|
||||||
|
throw new RESTAuthorizationException("collectionUUID=" + collectionUUID + " not found");
|
||||||
}
|
}
|
||||||
wsi = workspaceItemService.create(context, collection, true);
|
wsi = workspaceItemService.create(context, collection, true);
|
||||||
} catch (Exception e) {
|
} catch (SQLException e) {
|
||||||
log.error(e.getMessage(), e);
|
// wrap in a runtime exception as we cannot change the method signature
|
||||||
}
|
throw new UncategorizedScriptException(e.getMessage(), e);
|
||||||
} else {
|
} catch (AuthorizeException ae) {
|
||||||
//TODO manage setup of default collection in the case WSI it is not null
|
throw new RESTAuthorizationException(ae);
|
||||||
//TODO manage setup of collection discovered into request
|
|
||||||
}
|
}
|
||||||
return wsi;
|
return wsi;
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,10 @@ import org.dspace.core.Context;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The interface for submission Steps that need to deal with file upload
|
||||||
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
*/
|
*/
|
||||||
public interface UploadableStep extends ListenerProcessingStep {
|
public interface UploadableStep extends ListenerProcessingStep {
|
||||||
|
|
||||||
|
@@ -52,7 +52,13 @@ public class LicenseAddPatchOperation extends AddPatchOperation<String> {
|
|||||||
void add(Context context, Request currentRequest, WorkspaceItem source, String path, Object value)
|
void add(Context context, Request currentRequest, WorkspaceItem source, String path, Object value)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Boolean grant = BooleanUtils.toBooleanObject((String) value);
|
Boolean grant = null;
|
||||||
|
// we are friendly with the client and accept also a string representation for the boolean
|
||||||
|
if (value instanceof String) {
|
||||||
|
grant = BooleanUtils.toBooleanObject((String) value);
|
||||||
|
} else {
|
||||||
|
grant = (Boolean) value;
|
||||||
|
}
|
||||||
|
|
||||||
if (grant == null) {
|
if (grant == null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@@ -33,7 +33,13 @@ public class LicenseReplacePatchOperation extends ReplacePatchOperation<String>
|
|||||||
void replace(Context context, Request currentRequest, WorkspaceItem source, String path, Object value)
|
void replace(Context context, Request currentRequest, WorkspaceItem source, String path, Object value)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Boolean grant = BooleanUtils.toBooleanObject((String) value);
|
Boolean grant = null;
|
||||||
|
// we are friendly with the client and accept also a string representation for the boolean
|
||||||
|
if (value instanceof String) {
|
||||||
|
grant = BooleanUtils.toBooleanObject((String) value);
|
||||||
|
} else {
|
||||||
|
grant = (Boolean) value;
|
||||||
|
}
|
||||||
|
|
||||||
if (grant == null) {
|
if (grant == null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@@ -31,9 +31,11 @@ import org.dspace.core.Utils;
|
|||||||
import org.dspace.services.model.Request;
|
import org.dspace.services.model.Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describe step for DSpace Spring Rest. Handle the exposition of metadata own by the in progress submission.
|
* Describe step for DSpace Spring Rest. Expose and allow patching of the in progress submission metadata. It is
|
||||||
|
* configured via the config/submission-forms.xml file
|
||||||
*
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
*/
|
*/
|
||||||
public class DescribeStep extends org.dspace.submit.step.DescribeStep implements AbstractRestProcessingStep {
|
public class DescribeStep extends org.dspace.submit.step.DescribeStep implements AbstractRestProcessingStep {
|
||||||
|
|
||||||
|
@@ -35,6 +35,10 @@ import org.dspace.submit.step.ExtractionStep;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This submission step allows to extract metadata from an uploaded file to enrich or initialize a submission. The
|
||||||
|
* processing is delegated to a list of extractor specialized by format (i.e. a Grobid extractor to get data from a PDF
|
||||||
|
* file, an extractor to get data from bibliographic file such as BibTeX, etc)
|
||||||
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
*/
|
*/
|
||||||
public class ExtractMetadataStep extends ExtractionStep implements UploadableStep {
|
public class ExtractMetadataStep extends ExtractionStep implements UploadableStep {
|
||||||
@@ -81,7 +85,7 @@ public class ExtractMetadataStep extends ExtractionStep implements UploadableSte
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecordSet convertFields(RecordSet recordSet, Map<String, String> fieldMap) {
|
private RecordSet convertFields(RecordSet recordSet, Map<String, String> fieldMap) {
|
||||||
RecordSet result = new RecordSet();
|
RecordSet result = new RecordSet();
|
||||||
for (Record publication : recordSet.getRecords()) {
|
for (Record publication : recordSet.getRecords()) {
|
||||||
for (String fieldName : fieldMap.keySet()) {
|
for (String fieldName : fieldMap.keySet()) {
|
||||||
|
@@ -7,22 +7,32 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.submit.step;
|
package org.dspace.app.rest.submit.step;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.app.rest.model.ErrorRest;
|
||||||
import org.dspace.app.rest.model.patch.Operation;
|
import org.dspace.app.rest.model.patch.Operation;
|
||||||
import org.dspace.app.rest.model.step.DataUpload;
|
import org.dspace.app.rest.model.step.DataUpload;
|
||||||
import org.dspace.app.rest.model.step.UploadBitstreamRest;
|
import org.dspace.app.rest.model.step.UploadBitstreamRest;
|
||||||
|
import org.dspace.app.rest.repository.WorkspaceItemRestRepository;
|
||||||
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
|
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
|
||||||
import org.dspace.app.rest.submit.SubmissionService;
|
import org.dspace.app.rest.submit.SubmissionService;
|
||||||
|
import org.dspace.app.rest.submit.UploadableStep;
|
||||||
import org.dspace.app.rest.submit.factory.PatchOperationFactory;
|
import org.dspace.app.rest.submit.factory.PatchOperationFactory;
|
||||||
import org.dspace.app.rest.submit.factory.impl.PatchOperation;
|
import org.dspace.app.rest.submit.factory.impl.PatchOperation;
|
||||||
import org.dspace.app.util.SubmissionStepConfig;
|
import org.dspace.app.util.SubmissionStepConfig;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
|
import org.dspace.content.BitstreamFormat;
|
||||||
import org.dspace.content.Bundle;
|
import org.dspace.content.Bundle;
|
||||||
|
import org.dspace.content.InProgressSubmission;
|
||||||
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.services.model.Request;
|
import org.dspace.services.model.Request;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload step for DSpace Spring Rest. Expose information about the bitstream
|
* Upload step for DSpace Spring Rest. Expose information about the bitstream
|
||||||
@@ -30,8 +40,10 @@ import org.dspace.services.model.Request;
|
|||||||
*
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
*/
|
*/
|
||||||
public class UploadStep extends org.dspace.submit.step.UploadStep implements AbstractRestProcessingStep {
|
public class UploadStep extends org.dspace.submit.step.UploadStep
|
||||||
|
implements AbstractRestProcessingStep, UploadableStep {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(UploadStep.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataUpload getData(SubmissionService submissionService, WorkspaceItem obj, SubmissionStepConfig config)
|
public DataUpload getData(SubmissionService submissionService, WorkspaceItem obj, SubmissionStepConfig config)
|
||||||
@@ -79,4 +91,54 @@ public class UploadStep extends org.dspace.submit.step.UploadStep implements Abs
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ErrorRest upload(Context context, SubmissionService submissionService, SubmissionStepConfig stepConfig,
|
||||||
|
InProgressSubmission wsi, MultipartFile file, String extraField) {
|
||||||
|
|
||||||
|
Bitstream source = null;
|
||||||
|
BitstreamFormat bf = null;
|
||||||
|
|
||||||
|
Item item = wsi.getItem();
|
||||||
|
List<Bundle> bundles = null;
|
||||||
|
try {
|
||||||
|
// do we already have a bundle?
|
||||||
|
bundles = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);
|
||||||
|
|
||||||
|
InputStream inputStream = new BufferedInputStream(file.getInputStream());
|
||||||
|
if (bundles.size() < 1) {
|
||||||
|
// set bundle's name to ORIGINAL
|
||||||
|
source = itemService.createSingleBitstream(context, inputStream, item, Constants.CONTENT_BUNDLE_NAME);
|
||||||
|
} else {
|
||||||
|
// we have a bundle already, just add bitstream
|
||||||
|
source = bitstreamService.create(context, bundles.get(0), inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
source.setName(context, extraField);
|
||||||
|
source.setSource(context, file.getOriginalFilename());
|
||||||
|
|
||||||
|
// Identify the format
|
||||||
|
bf = bitstreamFormatService.guessFormat(context, source);
|
||||||
|
source.setFormat(context, bf);
|
||||||
|
|
||||||
|
// Update to DB
|
||||||
|
bitstreamService.update(context, source);
|
||||||
|
itemService.update(context, item);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
ErrorRest result = new ErrorRest();
|
||||||
|
result.setMessage(e.getMessage());
|
||||||
|
if (bundles != null && bundles.size() > 0) {
|
||||||
|
result.getPaths().add(
|
||||||
|
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + stepConfig.getId() + "/files/" +
|
||||||
|
bundles.get(0).getBitstreams().size());
|
||||||
|
} else {
|
||||||
|
result.getPaths()
|
||||||
|
.add("/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + stepConfig.getId());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.dspace.app.rest.model.ErrorRest;
|
import org.dspace.app.rest.model.ErrorRest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class to manage errors on validation during submission process
|
* Abstract class to provide basic management of errors resulting from a validation on a submission
|
||||||
*
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
*/
|
*/
|
||||||
@@ -24,6 +24,9 @@ public abstract class AbstractValidation implements Validation {
|
|||||||
|
|
||||||
private List<ErrorRest> errors = new ArrayList<ErrorRest>();
|
private List<ErrorRest> errors = new ArrayList<ErrorRest>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An unique name to identify the validation implementation
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -32,6 +35,15 @@ public abstract class AbstractValidation implements Validation {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an error message (i18nKey) for a specific json path
|
||||||
|
*
|
||||||
|
* @param i18nKey
|
||||||
|
* the validation error message as a key to internationalize
|
||||||
|
* @param path
|
||||||
|
* the json path that identify the wrong data in the submission. It could be as specific as a single
|
||||||
|
* value in a multivalued attribute or general of a "whole" section
|
||||||
|
*/
|
||||||
public void addError(String i18nKey, String path) {
|
public void addError(String i18nKey, String path) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
if (StringUtils.isNotBlank(i18nKey)) {
|
if (StringUtils.isNotBlank(i18nKey)) {
|
||||||
@@ -51,6 +63,11 @@ public abstract class AbstractValidation implements Validation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose the identified errors
|
||||||
|
*
|
||||||
|
* @return the list of identified {@link ErrorRest}
|
||||||
|
*/
|
||||||
public List<ErrorRest> getErrors() {
|
public List<ErrorRest> getErrors() {
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,8 @@ import org.dspace.core.Constants;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute check on license bundle
|
* This submission validation check that the license has been grant for the inprogress submission looking for the
|
||||||
|
* presence of a license bitstream in the license bundle,
|
||||||
*
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
*/
|
*/
|
||||||
|
@@ -41,8 +41,8 @@ public class MultipartFileSender {
|
|||||||
private static final String MULTIPART_BOUNDARY = "MULTIPART_BYTERANGES";
|
private static final String MULTIPART_BOUNDARY = "MULTIPART_BYTERANGES";
|
||||||
private static final String CONTENT_TYPE_MULTITYPE_WITH_BOUNDARY = "multipart/byteranges; boundary=" +
|
private static final String CONTENT_TYPE_MULTITYPE_WITH_BOUNDARY = "multipart/byteranges; boundary=" +
|
||||||
MULTIPART_BOUNDARY;
|
MULTIPART_BOUNDARY;
|
||||||
private static final String CONTENT_DISPOSITION_INLINE = "inline";
|
public static final String CONTENT_DISPOSITION_INLINE = "inline";
|
||||||
private static final String CONTENT_DISPOSITION_ATTACHMENT = "attachment";
|
public static final String CONTENT_DISPOSITION_ATTACHMENT = "attachment";
|
||||||
private static final String IF_NONE_MATCH = "If-None-Match";
|
private static final String IF_NONE_MATCH = "If-None-Match";
|
||||||
private static final String IF_MODIFIED_SINCE = "If-Modified-Since";
|
private static final String IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||||
private static final String ETAG = "ETag";
|
private static final String ETAG = "ETag";
|
||||||
@@ -134,6 +134,10 @@ public class MultipartFileSender {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public MultipartFileSender withDisposition(String contentDisposition) {
|
||||||
|
this.disposition = contentDisposition;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void serveResource() throws IOException {
|
public void serveResource() throws IOException {
|
||||||
|
|
||||||
@@ -172,9 +176,9 @@ public class MultipartFileSender {
|
|||||||
CONTENT_DISPOSITION_ATTACHMENT;
|
CONTENT_DISPOSITION_ATTACHMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
response.setHeader(CONTENT_DISPOSITION, String.format(CONTENT_DISPOSITION_FORMAT, disposition, fileName));
|
response.setHeader(CONTENT_DISPOSITION, String.format(CONTENT_DISPOSITION_FORMAT, disposition, fileName));
|
||||||
log.debug("Content-Disposition : {}", disposition);
|
log.debug("Content-Disposition : {}", disposition);
|
||||||
}
|
|
||||||
|
|
||||||
// Content phase
|
// Content phase
|
||||||
if (METHOD_HEAD.equals(request.getMethod())) {
|
if (METHOD_HEAD.equals(request.getMethod())) {
|
||||||
|
@@ -7,13 +7,55 @@
|
|||||||
*/
|
*/
|
||||||
HAL.Http.Client = function(opts) {
|
HAL.Http.Client = function(opts) {
|
||||||
this.vent = opts.vent;
|
this.vent = opts.vent;
|
||||||
this.defaultHeaders = { 'Accept': 'application/hal+json, application/json, */*; q=0.01' };
|
this.defaultHeaders = {'Accept': 'application/hal+json, application/json, */*; q=0.01'};
|
||||||
cookie = document.cookie.match('(^|;)\\s*' + 'MyHalBrowserToken' + '\\s*=\\s*([^;]+)');
|
var authorizationHeader = getAuthorizationHeader();
|
||||||
cookie ? this.defaultHeaders.Authorization = 'Bearer ' + cookie.pop() : '';
|
authorizationHeader ? this.defaultHeaders.Authorization = authorizationHeader : '';
|
||||||
console.log(this.defaultHeaders);
|
console.log(this.defaultHeaders);
|
||||||
this.headers = this.defaultHeaders;
|
this.headers = this.defaultHeaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getAuthorizationHeader() {
|
||||||
|
var cookie = document.cookie.match('(^|;)\\s*' + 'MyHalBrowserToken' + '\\s*=\\s*([^;]+)');
|
||||||
|
if(cookie != undefined) {
|
||||||
|
return 'Bearer ' + cookie.pop();
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function downloadFile(url) {
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
request.open('GET', url, true);
|
||||||
|
request.responseType = 'blob';
|
||||||
|
var authorizationHeader = getAuthorizationHeader();
|
||||||
|
if (authorizationHeader != undefined) {
|
||||||
|
request.setRequestHeader("Authorization", authorizationHeader);
|
||||||
|
}
|
||||||
|
request.onload = function () {
|
||||||
|
// Only handle status code 200
|
||||||
|
if (request.status === 200) {
|
||||||
|
// Try to find out the filename from the content disposition `filename` value
|
||||||
|
var disposition = request.getResponseHeader('content-disposition');
|
||||||
|
var matches = /"([^"]*)"/.exec(disposition);
|
||||||
|
var filename = (matches != null && matches[1] ? matches[1] : 'content');
|
||||||
|
// The actual download
|
||||||
|
var contentTypeHeader = request.getResponseHeader("content-type");
|
||||||
|
if (contentTypeHeader === undefined || contentTypeHeader === "") {
|
||||||
|
contentTypeHeader = "application/octet-stream";
|
||||||
|
}
|
||||||
|
var blob = new Blob([request.response], {type: contentTypeHeader});
|
||||||
|
var link = document.createElement('a');
|
||||||
|
link.href = window.URL.createObjectURL(blob);
|
||||||
|
link.download = filename;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}
|
||||||
|
// some error handling should be done here...
|
||||||
|
};
|
||||||
|
request.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HAL.Http.Client.prototype.get = function(url) {
|
HAL.Http.Client.prototype.get = function(url) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.vent.trigger('location-change', { url: url });
|
this.vent.trigger('location-change', { url: url });
|
||||||
@@ -31,9 +73,14 @@ HAL.Http.Client.prototype.get = function(url) {
|
|||||||
headers: jqXHR.getAllResponseHeaders()
|
headers: jqXHR.getAllResponseHeaders()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).error(function() {
|
}).error(function (response) {
|
||||||
self.vent.trigger('fail-response', { jqxhr: jqxhr });
|
self.vent.trigger('fail-response', {jqxhr: jqxhr});
|
||||||
});
|
var contentTypeResponseHeader = jqxhr.getResponseHeader("content-type");
|
||||||
|
if (contentTypeResponseHeader != undefined
|
||||||
|
&& !contentTypeResponseHeader.startsWith("application/hal")
|
||||||
|
&& !contentTypeResponseHeader.startsWith("application/json")) {
|
||||||
|
downloadFile(url);
|
||||||
|
}});
|
||||||
};
|
};
|
||||||
|
|
||||||
HAL.Http.Client.prototype.request = function(opts) {
|
HAL.Http.Client.prototype.request = function(opts) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -7,10 +7,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.builder;
|
package org.dspace.app.rest.builder;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.DCDate;
|
||||||
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.LicenseUtils;
|
||||||
|
import org.dspace.content.MetadataSchema;
|
||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
import org.dspace.content.service.WorkspaceItemService;
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder to construct WorkspaceItem objects
|
* Builder to construct WorkspaceItem objects
|
||||||
@@ -70,4 +78,68 @@ public class WorkspaceItemBuilder extends AbstractBuilder<WorkspaceItem, Workspa
|
|||||||
return workspaceItemService;
|
return workspaceItemService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected WorkspaceItemBuilder addMetadataValue(final String schema,
|
||||||
|
final String element, final String qualifier, final String value) {
|
||||||
|
try {
|
||||||
|
itemService.addMetadata(context, workspaceItem.getItem(), schema, element, qualifier, Item.ANY, value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return handleException(e);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected WorkspaceItemBuilder setMetadataSingleValue(final String schema,
|
||||||
|
final String element, final String qualifier, final String value) {
|
||||||
|
try {
|
||||||
|
itemService.setMetadataSingleValue(context, workspaceItem.getItem(), schema, element, qualifier, Item.ANY,
|
||||||
|
value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return handleException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkspaceItemBuilder withTitle(final String title) {
|
||||||
|
return setMetadataSingleValue(MetadataSchema.DC_SCHEMA, "title", null, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkspaceItemBuilder withIssueDate(final String issueDate) {
|
||||||
|
return addMetadataValue(MetadataSchema.DC_SCHEMA, "date", "issued", new DCDate(issueDate).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkspaceItemBuilder withAuthor(final String authorName) {
|
||||||
|
return addMetadataValue(MetadataSchema.DC_SCHEMA, "contributor", "author", authorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkspaceItemBuilder withSubject(final String subject) {
|
||||||
|
return addMetadataValue(MetadataSchema.DC_SCHEMA, "subject", null, subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkspaceItemBuilder grantLicense() {
|
||||||
|
Item item = workspaceItem.getItem();
|
||||||
|
String license;
|
||||||
|
try {
|
||||||
|
EPerson submitter = workspaceItem.getSubmitter();
|
||||||
|
submitter = context.reloadEntity(submitter);
|
||||||
|
license = LicenseUtils.getLicenseText(context.getCurrentLocale(), workspaceItem.getCollection(), item,
|
||||||
|
submitter);
|
||||||
|
LicenseUtils.grantLicense(context, item, license, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
handleException(e);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkspaceItemBuilder withFulltext(String name, String source, InputStream is) {
|
||||||
|
try {
|
||||||
|
Item item = workspaceItem.getItem();
|
||||||
|
Bitstream b = itemService.createSingleBitstream(context, is, item);
|
||||||
|
b.setName(context, name);
|
||||||
|
b.setSource(context, source);
|
||||||
|
} catch (Exception e) {
|
||||||
|
handleException(e);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.matcher;
|
||||||
|
|
||||||
|
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||||
|
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
|
||||||
|
import static org.dspace.app.rest.test.AbstractControllerIntegrationTest.REST_SERVER_URL;
|
||||||
|
import static org.hamcrest.Matchers.allOf;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
|
||||||
|
import org.dspace.content.WorkspaceItem;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class to construct a Matcher for a Workspace item
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*/
|
||||||
|
public class WorkspaceItemMatcher {
|
||||||
|
|
||||||
|
private WorkspaceItemMatcher() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the returned json expose all the required links and properties and the title and dateIssued are present
|
||||||
|
* in the traditionalpageone section as by the default configuration (form-submission.xml)
|
||||||
|
*
|
||||||
|
* @param witem
|
||||||
|
* the workspaceitem
|
||||||
|
* @param title
|
||||||
|
* the dc.title
|
||||||
|
* @param dateIssued
|
||||||
|
* the dc.date.issued
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher matchItemWithTitleAndDateIssued(WorkspaceItem witem, String title,
|
||||||
|
String dateIssued) {
|
||||||
|
return allOf(
|
||||||
|
// Check workspaceitem properties
|
||||||
|
matchProperties(witem),
|
||||||
|
// Check core metadata all appear in the first describe panel "traditionalpageone"
|
||||||
|
hasJsonPath("$.sections.traditionalpageone['dc.title'][0].value", is(title)),
|
||||||
|
hasJsonPath("$.sections.traditionalpageone['dc.date.issued'][0].value", is(dateIssued)),
|
||||||
|
// Check links
|
||||||
|
matchLinks(witem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the returned json expose all the required links and properties and the title and dateIssued are present
|
||||||
|
* in the traditionalpageone section and the subject in the traditionalpagetwo section as by the default
|
||||||
|
* configuration (form-submission.xml)
|
||||||
|
*
|
||||||
|
* @param witem
|
||||||
|
* the workspaceitem
|
||||||
|
* @param title
|
||||||
|
* the dc.title
|
||||||
|
* @param dateIssued
|
||||||
|
* the dc.date.issued * @param subject the dc.subject
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher matchItemWithTitleAndDateIssuedAndSubject(WorkspaceItem witem, String title,
|
||||||
|
String dateIssued,
|
||||||
|
String subject) {
|
||||||
|
return allOf(
|
||||||
|
// Check workspaceitem properties
|
||||||
|
matchProperties(witem),
|
||||||
|
// Check core metadata all appear in the first describe panel "traditionalpageone"
|
||||||
|
title != null ?
|
||||||
|
hasJsonPath("$.sections.traditionalpageone['dc.title'][0].value", is(title)) :
|
||||||
|
hasNoJsonPath("$.sections.traditionalpageone['dc.title']"),
|
||||||
|
hasJsonPath("$.sections.traditionalpageone['dc.date.issued'][0].value", is(dateIssued)),
|
||||||
|
// Check keywords they appear in the second describe panel "traditionalpagetwo"
|
||||||
|
hasJsonPath("$.sections.traditionalpagetwo['dc.subject'][0].value", is(subject)),
|
||||||
|
// Check links
|
||||||
|
matchLinks(witem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the id and type are exposed
|
||||||
|
*
|
||||||
|
* @param witem
|
||||||
|
* the workspaceitem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher<? super Object> matchProperties(WorkspaceItem witem) {
|
||||||
|
return allOf(
|
||||||
|
hasJsonPath("$.id", is(witem.getID())),
|
||||||
|
hasJsonPath("$.type", is("workspaceitem"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the required links are present
|
||||||
|
*
|
||||||
|
* @param witem
|
||||||
|
* the workspaceitem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher<? super Object> matchLinks(WorkspaceItem witem) {
|
||||||
|
return allOf(
|
||||||
|
hasJsonPath("$._links.self.href", is(REST_SERVER_URL + "submission/workspaceitems/" + witem.getID())),
|
||||||
|
hasJsonPath("$._links.item.href", startsWith(REST_SERVER_URL)),
|
||||||
|
hasJsonPath("$._links.collection.href", startsWith(REST_SERVER_URL)),
|
||||||
|
hasJsonPath("$._links.submitter.href", startsWith(REST_SERVER_URL)),
|
||||||
|
hasJsonPath("$._links.submissionDefinition.href", startsWith(REST_SERVER_URL)));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,14 @@
|
|||||||
|
@misc{ Nobody01,
|
||||||
|
author = "Nobody Jr",
|
||||||
|
title = "My Article",
|
||||||
|
year = "2006" }
|
||||||
|
|
||||||
|
@misc{ Nobody02,
|
||||||
|
author = "Nobody Jr",
|
||||||
|
title = "My Article 2",
|
||||||
|
year = "2006" }
|
||||||
|
|
||||||
|
@misc{ Nobody03,
|
||||||
|
author = "Nobody Jr",
|
||||||
|
title = "My Article 3",
|
||||||
|
year = "2018" }
|
Binary file not shown.
@@ -1368,7 +1368,6 @@ websvc.opensearch.formats = html,atom,rss
|
|||||||
# The 'webui.*' setting is for the JSPUI, and
|
# The 'webui.*' setting is for the JSPUI, and
|
||||||
# the 'xmlui.*' setting is for the XMLUI
|
# the 'xmlui.*' setting is for the XMLUI
|
||||||
webui.content_disposition_threshold = 8388608
|
webui.content_disposition_threshold = 8388608
|
||||||
xmlui.content_disposition_threshold = 8388608
|
|
||||||
|
|
||||||
|
|
||||||
#### Multi-file HTML document/site settings #####
|
#### Multi-file HTML document/site settings #####
|
||||||
|
@@ -44,6 +44,7 @@ rest.report-url.item-query = static/reports/query.html
|
|||||||
# The following configuration setting will construct a SQL regular expression test appropriate to your database engine
|
# The following configuration setting will construct a SQL regular expression test appropriate to your database engine
|
||||||
rest.regex-clause = text_value ~ ?
|
rest.regex-clause = text_value ~ ?
|
||||||
|
|
||||||
|
|
||||||
##### Configure REST Report Filters #####
|
##### Configure REST Report Filters #####
|
||||||
# A filter contains a set of tests that will be applied to an item to determine its inclusion in a particular report.
|
# A filter contains a set of tests that will be applied to an item to determine its inclusion in a particular report.
|
||||||
# Private items and withdrawn items are frequently excluded from DSpace reports.
|
# Private items and withdrawn items are frequently excluded from DSpace reports.
|
||||||
|
@@ -213,6 +213,7 @@
|
|||||||
</jacocoReports>
|
</jacocoReports>
|
||||||
<sourceDirectories>
|
<sourceDirectories>
|
||||||
<sourceDirectory>${project.parent.basedir}/dspace-api/src/main/java</sourceDirectory>
|
<sourceDirectory>${project.parent.basedir}/dspace-api/src/main/java</sourceDirectory>
|
||||||
|
<sourceDirectory>${project.parent.basedir}/dspace-api/target/generated-sources/annotations</sourceDirectory>
|
||||||
<sourceDirectory>${project.parent.basedir}/dspace-oai/src/main/java</sourceDirectory>
|
<sourceDirectory>${project.parent.basedir}/dspace-oai/src/main/java</sourceDirectory>
|
||||||
<sourceDirectory>${project.parent.basedir}/dspace-rdf/src/main/java</sourceDirectory>
|
<sourceDirectory>${project.parent.basedir}/dspace-rdf/src/main/java</sourceDirectory>
|
||||||
<sourceDirectory>${project.parent.basedir}/dspace-rest/src/main/java</sourceDirectory>
|
<sourceDirectory>${project.parent.basedir}/dspace-rest/src/main/java</sourceDirectory>
|
||||||
|
9
pom.xml
9
pom.xml
@@ -196,6 +196,9 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<sourceDirectories>
|
||||||
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
|
</sourceDirectories>
|
||||||
<configLocation>${root.basedir}/checkstyle.xml</configLocation>
|
<configLocation>${root.basedir}/checkstyle.xml</configLocation>
|
||||||
<encoding>${project.build.sourceEncoding}</encoding>
|
<encoding>${project.build.sourceEncoding}</encoding>
|
||||||
<logViolationsToConsole>true</logViolationsToConsole>
|
<logViolationsToConsole>true</logViolationsToConsole>
|
||||||
@@ -1037,6 +1040,12 @@
|
|||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||||
|
<version>${hibernate.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-ehcache</artifactId>
|
<artifactId>hibernate-ehcache</artifactId>
|
||||||
|
Reference in New Issue
Block a user