Skip to content

Commit

Permalink
Create domain objects and dao's for PeerGroup #38
Browse files Browse the repository at this point in the history
Requires creating new tables in the database (see wise_db_init.sql).
Domain objects include PeerGroupActivity and PeerGroup.
Add unit tests.
  • Loading branch information
hirokiterashima committed Oct 12, 2021
1 parent b7b921d commit 960e332
Show file tree
Hide file tree
Showing 15 changed files with 797 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**/org/wise/portal/domain/authentication/**/*.java|**/org/wise/portal/domain/newsitem/**/*.java|**/org/wise/portal/domain/run/**/*.java|**/org/wise/portal/domain/webservice/**/*.java|**/org/wise/portal/presentation/web/controllers/general/contactwise/*.java|**/org/wise/portal/presentation/web/controllers/teacher/management/BatchStudentChangePasswordControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/management/StudentListControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/management/UpdateMyAccountInfoControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/project/**/*.java|**/org/wise/portal/presentation/web/controllers/teacher/run/ShareProjectRunControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/RegisterTeacherControllerTest.java|**/org/wise/portal/presentation/web/controllers/IndexControllerTest.java|**/org/wise/portal/presentation/web/controllers/LoginControllerTest.java|**/org/wise/portal/presentation/web/controllers/RegisterStudentControllerTest.java|**/org/wise/portal/presentation/validators/teacher/*.java|**/org/wise/portal/dao/*.java|**/org/wise/portal/dao/authentication/impl/AllTests.java|**/org/wise/portal/dao/authentication/impl/HibernateAclEntryDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateAclSidDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateAclTargetObjectDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateAclTargetObjectIdentityDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateGrantedAuthorityDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateStudentUserDetailsDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateTeacherUserDetailsDaoTest.java|**/org/wise/portal/dao/group/**/*.java|**/org/wise/portal/dao/premadecomment/**/*.java" kind="src" output="target/test-classes" path="src/test/java">
<classpathentry excluding="**/org/wise/portal/domain/authentication/**/*.java|**/org/wise/portal/domain/newsitem/**/*.java|**/org/wise/portal/domain/run/**/*.java|**/org/wise/portal/domain/webservice/**/*.java|**/org/wise/portal/presentation/web/controllers/general/contactwise/*.java|**/org/wise/portal/presentation/web/controllers/teacher/management/BatchStudentChangePasswordControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/management/StudentListControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/management/UpdateMyAccountInfoControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/project/**/*.java|**/org/wise/portal/presentation/web/controllers/teacher/run/ShareProjectRunControllerTest.java|**/org/wise/portal/presentation/web/controllers/teacher/RegisterTeacherControllerTest.java|**/org/wise/portal/presentation/web/controllers/IndexControllerTest.java|**/org/wise/portal/presentation/web/controllers/LoginControllerTest.java|**/org/wise/portal/presentation/web/controllers/RegisterStudentControllerTest.java|**/org/wise/portal/presentation/validators/teacher/*.java|**/org/wise/portal/dao/AbstractTransactionalDaoTests.java|**/org/wise/portal/dao/authentication/impl/AllTests.java|**/org/wise/portal/dao/authentication/impl/HibernateAclEntryDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateAclSidDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateAclTargetObjectDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateAclTargetObjectIdentityDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateGrantedAuthorityDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateStudentUserDetailsDaoTest.java|**/org/wise/portal/dao/authentication/impl/HibernateTeacherUserDetailsDaoTest.java|**/org/wise/portal/dao/group/**/*.java|**/org/wise/portal/dao/premadecomment/**/*.java" kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<exclude>**/org/wise/portal/presentation/web/controllers/LoginControllerTest.java</exclude>
<exclude>**/org/wise/portal/presentation/web/controllers/RegisterStudentControllerTest.java</exclude>
<exclude>**/org/wise/portal/presentation/validators/teacher/*.java</exclude>
<exclude>**/org/wise/portal/dao/*.java</exclude>
<exclude>**/org/wise/portal/dao/AbstractTransactionalDaoTests.java</exclude>
<exclude>**/org/wise/portal/dao/authentication/impl/AllTests.java</exclude>
<exclude>**/org/wise/portal/dao/authentication/impl/HibernateAclEntryDaoTest.java</exclude>
<exclude>**/org/wise/portal/dao/authentication/impl/HibernateAclSidDaoTest.java</exclude>
Expand Down Expand Up @@ -208,7 +208,7 @@
<exclude>**/org/wise/portal/presentation/web/controllers/LoginControllerTest.java</exclude>
<exclude>**/org/wise/portal/presentation/web/controllers/RegisterStudentControllerTest.java</exclude>
<exclude>**/org/wise/portal/presentation/validators/teacher/*.java</exclude>
<exclude>**/org/wise/portal/dao/*.java</exclude>
<exclude>**/org/wise/portal/dao/AbstractTransactionalDaoTests.java</exclude>
<exclude>**/org/wise/portal/dao/authentication/impl/AllTests.java</exclude>
<exclude>**/org/wise/portal/dao/authentication/impl/HibernateAclEntryDaoTest.java</exclude>
<exclude>**/org/wise/portal/dao/authentication/impl/HibernateAclSidDaoTest.java</exclude>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/wise/portal/dao/peergroup/PeerGroupDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2008-2021 Regents of the University of California (Regents).
* Created by WISE, Graduate School of Education, University of California, Berkeley.
*
* This software is distributed under the GNU General Public License, v3,
* or (at your option) any later version.
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, provided that the above copyright notice and
* the following two paragraphs appear in all copies of this software.
*
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.wise.portal.dao.peergroup;

import java.util.List;
import org.wise.portal.dao.SimpleDao;
import org.wise.portal.domain.peergroup.PeerGroup;
import org.wise.portal.domain.run.Run;
import org.wise.portal.domain.workgroup.Workgroup;

/**
* @author Hiroki Terashima
*/
public interface PeerGroupDao<T extends PeerGroup> extends SimpleDao<T> {

List<PeerGroup> getListByRun(Run run);

List<PeerGroup> getListByComponent(Run run, String nodeId, String componentId);

List<PeerGroup> getListByWorkgroup(Workgroup workgroup);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Copyright (c) 2008-2021 Regents of the University of California (Regents).
* Created by WISE, Graduate School of Education, University of California, Berkeley.
*
* This software is distributed under the GNU General Public License, v3,
* or (at your option) any later version.
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, provided that the above copyright notice and
* the following two paragraphs appear in all copies of this software.
*
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.wise.portal.dao.peergroup.impl;

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

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.peergroup.PeerGroupDao;
import org.wise.portal.domain.peergroup.PeerGroup;
import org.wise.portal.domain.peergroup.impl.PeerGroupImpl;
import org.wise.portal.domain.peergroupactivity.impl.PeerGroupActivityImpl;
import org.wise.portal.domain.run.Run;
import org.wise.portal.domain.workgroup.Workgroup;
import org.wise.portal.domain.workgroup.impl.WorkgroupImpl;

/**
* @author Hiroki Terashima
*/
@Repository
public class HibernatePeerGroupDao extends AbstractHibernateDao<PeerGroup>
implements PeerGroupDao<PeerGroup> {

@PersistenceContext
private EntityManager entityManager;

@Override
protected String getFindAllQuery() {
return "from PeerGroupImpl";
}

@Override
protected Class<? extends PeerGroup> getDataObjectClass() {
return PeerGroupImpl.class;
}

@Override
public List<PeerGroup> getListByRun(Run run) {
return getListByComponent(run, null, null);
}

@Override
@SuppressWarnings("unchecked")
public List<PeerGroup> getListByComponent(Run run, String nodeId, String componentId) {
CriteriaBuilder cb = getCriteriaBuilder();
CriteriaQuery<PeerGroupImpl> cq = cb.createQuery(PeerGroupImpl.class);
Root<PeerGroupImpl> peerGroupImplRoot = cq.from(PeerGroupImpl.class);
Root<PeerGroupActivityImpl> peerGroupActivityImplRoot = cq.from(PeerGroupActivityImpl.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(peerGroupActivityImplRoot.get("run"), run.getId()));
if (nodeId != null) {
predicates.add(cb.equal(peerGroupActivityImplRoot.get("nodeId"), nodeId));
}
if (componentId != null) {
predicates.add(cb.equal(peerGroupActivityImplRoot.get("componentId"), componentId));
}
predicates.add(cb.equal(peerGroupImplRoot.get("peerGroupActivity"), peerGroupActivityImplRoot.get("id")));
cq.select(peerGroupImplRoot).where(predicates.toArray(new Predicate[predicates.size()]));
TypedQuery<PeerGroupImpl> query = entityManager.createQuery(cq);
List<PeerGroupImpl> resultList = query.getResultList();
return (List<PeerGroup>) (Object) resultList;
}

@Override
@SuppressWarnings("unchecked")
public List<PeerGroup> getListByWorkgroup(Workgroup workgroup) {
CriteriaBuilder cb = getCriteriaBuilder();
CriteriaQuery<PeerGroupImpl> cq = cb.createQuery(PeerGroupImpl.class);
Root<PeerGroupImpl> peerGroupImplRoot = cq.from(PeerGroupImpl.class);
Root<WorkgroupImpl> workgroupImplRoot = cq.from(WorkgroupImpl.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(workgroupImplRoot.get("id"), workgroup.getId()));
predicates.add(cb.isMember(workgroupImplRoot.get("id"), peerGroupImplRoot.<Set<Workgroup>>get("members")));
cq.select(peerGroupImplRoot).where(predicates.toArray(new Predicate[predicates.size()]));
TypedQuery<PeerGroupImpl> query = entityManager.createQuery(cq);
List<PeerGroupImpl> resultList = query.getResultList();
return (List<PeerGroup>) (Object) resultList;
}

private CriteriaBuilder getCriteriaBuilder() {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
return session.getCriteriaBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2008-2021 Regents of the University of California (Regents).
* Created by WISE, Graduate School of Education, University of California, Berkeley.
*
* This software is distributed under the GNU General Public License, v3,
* or (at your option) any later version.
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, provided that the above copyright notice and
* the following two paragraphs appear in all copies of this software.
*
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.wise.portal.dao.peergroupactivity;

import org.wise.portal.dao.SimpleDao;
import org.wise.portal.domain.peergroupactivity.PeerGroupActivity;
import org.wise.portal.domain.run.Run;

/**
* @author Hiroki Terashima
*/
public interface PeerGroupActivityDao<T extends PeerGroupActivity> extends SimpleDao<T> {

PeerGroupActivity getByComponent(Run run, String nodeId, String componentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright (c) 2008-2021 Regents of the University of California (Regents).
* Created by WISE, Graduate School of Education, University of California, Berkeley.
*
* This software is distributed under the GNU General Public License, v3,
* or (at your option) any later version.
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, provided that the above copyright notice and
* the following two paragraphs appear in all copies of this software.
*
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.wise.portal.dao.peergroupactivity.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.peergroupactivity.PeerGroupActivityDao;
import org.wise.portal.domain.peergroupactivity.PeerGroupActivity;
import org.wise.portal.domain.peergroupactivity.impl.PeerGroupActivityImpl;
import org.wise.portal.domain.run.Run;

/**
* @author Hiroki Terashima
*/
@Repository
public class HibernatePeerGroupActivityDao extends AbstractHibernateDao<PeerGroupActivity>
implements PeerGroupActivityDao<PeerGroupActivity> {

@PersistenceContext
private EntityManager entityManager;

@Override
protected String getFindAllQuery() {
return "from PeerGroupActivityImpl";
}

@Override
protected Class<? extends PeerGroupActivity> getDataObjectClass() {
return PeerGroupActivityImpl.class;
}

@Override
public PeerGroupActivity getByComponent(Run run, String nodeId, String componentId) {
CriteriaBuilder cb = getCriteriaBuilder();
CriteriaQuery<PeerGroupActivityImpl> cq = cb.createQuery(PeerGroupActivityImpl.class);
Root<PeerGroupActivityImpl> peerGroupActivityImplRoot = cq.from(PeerGroupActivityImpl.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(peerGroupActivityImplRoot.get("run"), run.getId()));
predicates.add(cb.equal(peerGroupActivityImplRoot.get("nodeId"), nodeId));
predicates.add(cb.equal(peerGroupActivityImplRoot.get("componentId"), componentId));
cq.select(peerGroupActivityImplRoot).where(predicates.toArray(new Predicate[predicates.size()]));
TypedQuery<PeerGroupActivityImpl> query = entityManager.createQuery(cq);
return (PeerGroupActivityImpl) query.getResultStream().findFirst().orElse(null);
}

private CriteriaBuilder getCriteriaBuilder() {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
return session.getCriteriaBuilder();
}
}
31 changes: 31 additions & 0 deletions src/main/java/org/wise/portal/domain/peergroup/PeerGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2008-2021 Regents of the University of California (Regents).
* Created by WISE, Graduate School of Education, University of California, Berkeley.
*
* This software is distributed under the GNU General Public License, v3,
* or (at your option) any later version.
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, provided that the above copyright notice and
* the following two paragraphs appear in all copies of this software.
*
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.wise.portal.domain.peergroup;

/**
* An interface that defines a group of workgroups
* @author Hiroki Terashima
*/
public interface PeerGroup {
}
Loading

0 comments on commit 960e332

Please sign in to comment.