Skip to content

Commit

Permalink
feat(Run): Allow teachers to archive runs (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan authored Sep 18, 2023
1 parent 4b8dd6d commit fe5ac0d
Show file tree
Hide file tree
Showing 20 changed files with 826 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
*/
package org.wise.portal.dao.authentication.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
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;
Expand All @@ -44,9 +47,9 @@
* @author Cynick Young
*/
@Repository
public class HibernateAclTargetObjectIdentityDao extends
AbstractHibernateDao<MutableAclTargetObjectIdentity> implements
AclTargetObjectIdentityDao<MutableAclTargetObjectIdentity> {
public class HibernateAclTargetObjectIdentityDao
extends AbstractHibernateDao<MutableAclTargetObjectIdentity>
implements AclTargetObjectIdentityDao<MutableAclTargetObjectIdentity> {

@PersistenceContext
private EntityManager entityManager;
Expand All @@ -56,20 +59,23 @@ public class HibernateAclTargetObjectIdentityDao extends
public MutableAclTargetObjectIdentity retrieveByObjectIdentity(ObjectIdentity objectIdentity) {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<PersistentAclTargetObjectIdentity> cq =
cb.createQuery(PersistentAclTargetObjectIdentity.class);
Root<PersistentAclTargetObjectIdentity> persistentAclTargetObjectIdentityRoot =
cq.from(PersistentAclTargetObjectIdentity.class);
cq.select(persistentAclTargetObjectIdentityRoot).where(
cb.equal(persistentAclTargetObjectIdentityRoot.get("classname"), objectIdentity.getType()));
cq.select(persistentAclTargetObjectIdentityRoot).where(
cb.equal(persistentAclTargetObjectIdentityRoot.get("id"), objectIdentity.getIdentifier()));
CriteriaQuery<PersistentAclTargetObjectIdentity> cq = cb
.createQuery(PersistentAclTargetObjectIdentity.class);
Root<PersistentAclTargetObjectIdentity> persistentAclTargetObjectIdentityRoot = cq
.from(PersistentAclTargetObjectIdentity.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(persistentAclTargetObjectIdentityRoot.get("aclTargetObjectId"),
objectIdentity.getIdentifier()));
predicates
.add(cb.equal(persistentAclTargetObjectIdentityRoot.get("aclTargetObject").get("classname"),
objectIdentity.getType()));
cq.select(persistentAclTargetObjectIdentityRoot)
.where(predicates.toArray(new Predicate[predicates.size()]));
TypedQuery<PersistentAclTargetObjectIdentity> query = entityManager.createQuery(cq);
return query.getResultStream().findFirst().orElse(null);
}

public MutableAclTargetObjectIdentity[] findChildren(
ObjectIdentity parentIdentity) {
public MutableAclTargetObjectIdentity[] findChildren(ObjectIdentity parentIdentity) {
throw new UnsupportedOperationException();
// TODO CY - not really sure what the requirements are for this method
// List<?> list = this
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/wise/portal/dao/usertags/UserTagsDao.java
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);
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
*/
package org.wise.portal.domain.authentication;

import java.util.Set;

import org.springframework.security.acls.model.ObjectIdentity;
import org.wise.portal.domain.Persistable;
import org.wise.portal.domain.usertag.UserTag;

/**
* Mutable extension of <code>ObjectIdentity</code>. Represents the object
Expand Down Expand Up @@ -83,4 +86,6 @@ public interface MutableAclTargetObjectIdentity extends ObjectIdentity, Persista
* @param parent the parent to set
*/
void setParent(MutableAclTargetObjectIdentity parent);

Set<UserTag> getTags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public class PersistentAclTargetObject implements MutableAclTargetObject {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((classname == null) ? 0 : classname.hashCode());
result = prime * result + ((classname == null) ? 0 : classname.hashCode());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
package org.wise.portal.domain.authentication.impl;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
Expand All @@ -41,6 +46,8 @@
import org.wise.portal.domain.authentication.MutableAclSid;
import org.wise.portal.domain.authentication.MutableAclTargetObject;
import org.wise.portal.domain.authentication.MutableAclTargetObjectIdentity;
import org.wise.portal.domain.usertag.UserTag;
import org.wise.portal.domain.usertag.impl.UserTagImpl;

/**
* Concrete implementation of <code>MutableAclTargetObjectIdentity</code>
Expand All @@ -50,9 +57,9 @@
* @see org.springframework.security.acls.model.ObjectIdentity
*/
@Entity
@Table(name = PersistentAclTargetObjectIdentity.DATA_STORE_NAME, uniqueConstraints = { @UniqueConstraint(columnNames = {
PersistentAclTargetObjectIdentity.COLUMN_NAME_TARGET_OBJECT,
PersistentAclTargetObjectIdentity.COLUMN_NAME_TARGET_OBJECT_ID }) })
@Table(name = PersistentAclTargetObjectIdentity.DATA_STORE_NAME, uniqueConstraints = {
@UniqueConstraint(columnNames = { PersistentAclTargetObjectIdentity.COLUMN_NAME_TARGET_OBJECT,
PersistentAclTargetObjectIdentity.COLUMN_NAME_TARGET_OBJECT_ID }) })
public class PersistentAclTargetObjectIdentity implements MutableAclTargetObjectIdentity {

@Transient
Expand Down Expand Up @@ -108,6 +115,14 @@ public class PersistentAclTargetObjectIdentity implements MutableAclTargetObject
@Column(name = COLUMN_NAME_INHERITING, nullable = false)
private Boolean inheriting;

@ManyToMany(targetEntity = UserTagImpl.class, fetch = FetchType.LAZY)
@JoinTable(name = "acl_object_identity_to_user_tags", joinColumns = {
@JoinColumn(name = "acl_object_identity_fk", nullable = false) }, inverseJoinColumns = {
@JoinColumn(name = "user_tags_fk", nullable = false) })
@Getter
@Setter
private Set<UserTag> tags = new HashSet<UserTag>();

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Getter
Expand All @@ -116,7 +131,9 @@ public class PersistentAclTargetObjectIdentity implements MutableAclTargetObject

@Version
@Column(name = "OPTLOCK")
private Integer version = null;
@Getter
@Setter
private Integer version = 0;

@Override
public String getType() {
Expand All @@ -140,12 +157,8 @@ public void setInheriting(Boolean isInheriting) {
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result
+ ((aclTargetObject == null) ? 0 : aclTargetObject.hashCode());
result = PRIME
* result
+ ((aclTargetObjectId == null) ? 0 : aclTargetObjectId
.hashCode());
result = PRIME * result + ((aclTargetObject == null) ? 0 : aclTargetObject.hashCode());
result = PRIME * result + ((aclTargetObjectId == null) ? 0 : aclTargetObjectId.hashCode());
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/wise/portal/domain/project/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
*/
package org.wise.portal.domain.project;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import org.wise.portal.domain.Persistable;
import org.wise.portal.domain.Tag;
import org.wise.portal.domain.project.impl.ProjectType;
import org.wise.portal.domain.user.User;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
* A WISE Project domain object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class ProjectImpl implements Project {
protected String name;

@OneToOne(targetEntity = ProjectMetadataImpl.class, fetch = FetchType.LAZY)
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
@JoinColumn(name = "metadata_fk", nullable = true, unique = true)
protected ProjectMetadata metadataObj = null;

Expand All @@ -147,13 +147,15 @@ public class ProjectImpl implements Project {
private User owner;

@ManyToMany(targetEntity = UserImpl.class, fetch = FetchType.LAZY)
@JoinTable(name = SHARED_OWNERS_JOIN_TABLE_NAME, joinColumns = { @JoinColumn(name = PROJECTS_JOIN_COLUMN_NAME, nullable = false) }, inverseJoinColumns = @JoinColumn(name = SHARED_OWNERS_JOIN_COLUMN_NAME, nullable = false))
@JoinTable(name = SHARED_OWNERS_JOIN_TABLE_NAME, joinColumns = {
@JoinColumn(name = PROJECTS_JOIN_COLUMN_NAME, nullable = false) }, inverseJoinColumns = @JoinColumn(name = SHARED_OWNERS_JOIN_COLUMN_NAME, nullable = false))
@Getter
@Setter
private Set<User> sharedowners = new TreeSet<User>();

@ManyToMany(targetEntity = UserImpl.class, fetch = FetchType.LAZY)
@JoinTable(name = BOOKMARKERS_JOIN_TABLE_NAME, joinColumns = { @JoinColumn(name= PROJECTS_JOIN_COLUMN_NAME, nullable = false) }, inverseJoinColumns = @JoinColumn(name = BOOKMARKERS_JOIN_COLUMN_NAME, nullable = false))
@JoinTable(name = BOOKMARKERS_JOIN_TABLE_NAME, joinColumns = {
@JoinColumn(name = PROJECTS_JOIN_COLUMN_NAME, nullable = false) }, inverseJoinColumns = @JoinColumn(name = BOOKMARKERS_JOIN_COLUMN_NAME, nullable = false))
@Getter
@Setter
private Set<User> bookmarkers = new TreeSet<User>();
Expand Down Expand Up @@ -204,7 +206,8 @@ public class ProjectImpl implements Project {
protected Date dateCreated;

@ManyToMany(targetEntity = TagImpl.class, fetch = FetchType.LAZY)
@JoinTable(name = TAGS_JOIN_TABLE_NAME, joinColumns = { @JoinColumn(name = PROJECT_JOIN_COLUMN_NAME, nullable = false) }, inverseJoinColumns = @JoinColumn(name = TAGS_JOIN_COLUMN_NAME, nullable = false))
@JoinTable(name = TAGS_JOIN_TABLE_NAME, joinColumns = {
@JoinColumn(name = PROJECT_JOIN_COLUMN_NAME, nullable = false) }, inverseJoinColumns = @JoinColumn(name = TAGS_JOIN_COLUMN_NAME, nullable = false))
@Getter
@Setter
protected Set<Tag> tags = new TreeSet<Tag>();
Expand Down Expand Up @@ -289,7 +292,7 @@ public String getName() {
return name;
}

public void populateProjectInfo(){
public void populateProjectInfo() {
this.projectinfo = new ProjectInfoImpl();
this.projectinfo.setName(this.getName());
}
Expand Down Expand Up @@ -410,7 +413,7 @@ public boolean isCommunityProject() {

public boolean hasTag(String tag) {
Set<Tag> projectTags = this.getTags();
for (Tag projectTag: projectTags) {
for (Tag projectTag : projectTags) {
if (projectTag.getName().equals(tag)) {
return true;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/wise/portal/domain/usertag/UserTag.java
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();
}
Loading

0 comments on commit fe5ac0d

Please sign in to comment.