forked from WISE-Community/WISE-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Run): Allow teachers to archive runs (WISE-Community#225)
- Loading branch information
1 parent
4b8dd6d
commit fe5ac0d
Showing
20 changed files
with
826 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/wise/portal/dao/usertags/UserTagsDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.wise.portal.dao.usertags; | ||
|
||
import java.util.List; | ||
|
||
import org.wise.portal.dao.SimpleDao; | ||
import org.wise.portal.domain.user.User; | ||
import org.wise.portal.domain.usertag.UserTag; | ||
|
||
public interface UserTagsDao<T extends UserTag> extends SimpleDao<T> { | ||
|
||
UserTag get(Long tagId); | ||
|
||
List<UserTag> get(User user); | ||
|
||
UserTag get(User user, String text); | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/wise/portal/dao/usertags/impl/HibernateUserTagsDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.wise.portal.dao.usertags.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import javax.persistence.TypedQuery; | ||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
|
||
import org.hibernate.Session; | ||
import org.springframework.stereotype.Repository; | ||
import org.wise.portal.dao.impl.AbstractHibernateDao; | ||
import org.wise.portal.dao.usertags.UserTagsDao; | ||
import org.wise.portal.domain.user.User; | ||
import org.wise.portal.domain.usertag.UserTag; | ||
import org.wise.portal.domain.usertag.impl.UserTagImpl; | ||
|
||
@Repository | ||
public class HibernateUserTagsDao extends AbstractHibernateDao<UserTag> | ||
implements UserTagsDao<UserTag> { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
private static final String FIND_ALL_QUERY = "from TagsImpl"; | ||
|
||
@Override | ||
protected String getFindAllQuery() { | ||
return FIND_ALL_QUERY; | ||
} | ||
|
||
@Override | ||
protected Class<? extends UserTag> getDataObjectClass() { | ||
return UserTag.class; | ||
} | ||
|
||
public UserTag get(Long tagId) { | ||
CriteriaBuilder cb = getCriteriaBuilder(); | ||
CriteriaQuery<UserTagImpl> cq = cb.createQuery(UserTagImpl.class); | ||
Root<UserTagImpl> tagsRoot = cq.from(UserTagImpl.class); | ||
List<Predicate> predicates = new ArrayList<>(); | ||
predicates.add(cb.equal(tagsRoot.get("id"), tagId)); | ||
cq.select(tagsRoot).where(predicates.toArray(new Predicate[predicates.size()])); | ||
TypedQuery<UserTagImpl> query = entityManager.createQuery(cq); | ||
List<UserTagImpl> tagsResultList = query.getResultList(); | ||
return tagsResultList.isEmpty() ? null : tagsResultList.get(0); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public List<UserTag> get(User user) { | ||
CriteriaBuilder cb = getCriteriaBuilder(); | ||
CriteriaQuery<UserTagImpl> cq = cb.createQuery(UserTagImpl.class); | ||
Root<UserTagImpl> tagsRoot = cq.from(UserTagImpl.class); | ||
List<Predicate> predicates = new ArrayList<>(); | ||
predicates.add(cb.equal(tagsRoot.get("user").get("id"), user.getId())); | ||
cq.select(tagsRoot).where(predicates.toArray(new Predicate[predicates.size()])); | ||
TypedQuery<UserTagImpl> query = entityManager.createQuery(cq); | ||
List<UserTagImpl> userTagsResult = query.getResultList(); | ||
return (List<UserTag>) (Object) userTagsResult; | ||
} | ||
|
||
public UserTag get(User user, String text) { | ||
CriteriaBuilder cb = getCriteriaBuilder(); | ||
CriteriaQuery<UserTagImpl> cq = cb.createQuery(UserTagImpl.class); | ||
Root<UserTagImpl> tagsRoot = cq.from(UserTagImpl.class); | ||
List<Predicate> predicates = new ArrayList<>(); | ||
predicates.add(cb.equal(tagsRoot.get("user").get("id"), user.getId())); | ||
predicates.add(cb.equal(cb.lower(tagsRoot.get("text")), text.toLowerCase())); | ||
cq.select(tagsRoot).where(predicates.toArray(new Predicate[predicates.size()])); | ||
TypedQuery<UserTagImpl> query = entityManager.createQuery(cq); | ||
List<UserTagImpl> tagsResultList = query.getResultList(); | ||
return tagsResultList.isEmpty() ? null : tagsResultList.get(0); | ||
} | ||
|
||
private CriteriaBuilder getCriteriaBuilder() { | ||
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); | ||
return session.getCriteriaBuilder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.wise.portal.domain.usertag; | ||
|
||
import org.wise.portal.domain.Persistable; | ||
import org.wise.portal.domain.user.User; | ||
|
||
public interface UserTag extends Persistable { | ||
|
||
String getText(); | ||
|
||
void setText(String text); | ||
|
||
User getUser(); | ||
} |
Oops, something went wrong.