Minna Lesonen
Hannu Pekkanen
Tuukka Tawast
Heikki Uuksulainen
Java-papu-raportti 1.6.2001
Jyväskylän
yliopisto
tietotekniikan
laitos
Tekijät: Minna Lesonen (minles@st.jyu.fi)
Hannu
Pekkanen (krimu@st.jyu.fi)
Tuukka
Tawast (tutawast@mit.jyu.fi)
Heikki
Uuksulainen (heuuksul@st.jyu.fi)
Työn nimi: KORPPI-projekti,
Java-papu-raportti
Työ: Java-papu-raportti tietotekniikan cum
laude-työprojektiin
Tiivistelmä: Java-papu-raportissa kuvataan Jyväskylän yliopiston KURKI-järjestelmän seuraajan KORPPI-järjestelmän sovelluslogiikan toteutusta.
Avainsanat: Java,
Java-pavut, sovelluslogiikka, lähdekoodi
KOTKA-järjestelmän sovelluslogiikka päätettiin vallitsevan tavan mukaan sijoittaa käyttöliittymästä erilleen omiksi Java-pavuikseen. Koodit kirjoitettiin tavallisilla tekstieditoreilla ja ne on käännetty Sun Microsystemsin Java2 Developers Kitillä.
Dokumentissa esitellään kaikki uudet Korppi-projektin tekemät JavaBeanit, sekä ne Kotka-projektin tekemät JavaBeanit, joita on muutettu. Dokumentissa on myös listattu Korppi-projektin Java-papujen lähdekoodit sekä ne Kotka-projektin Java-pavut, joihin on tullut muutoksia. Kaikki koodit on kommentoitu projektisuunnitelmassa sovitulla tavalla. Jatkokäyttäjän kannattaa huomioida myös dokumenttina olevat JavaDoc-ohjelmalla laaditut dokumentit, joista on helpompi lukea luokkarakenteita ja metodeja.
Tämä papu päättää mihinkä moduleihin kullakin käyttäjällä on oikeuksia ja millaisia nämä oikeudet ovat. Korppi-projekti lisäsi papuun kaksi metodia courseRight ja rightLevel.
/*****************************************************************************
* MODULE
DESCRIPTION
******************************************************************************
*
* NAME: UseModule
* LANGUAGE: JavaBean
* DATE: 4.12.2000
*
AUTHOR: Markku Vire, Jyväskylän
yliopisto
*
******************************************************************************
*
COPYRIGHT (C) KOTKA-PROJEKTIRYHMÄ
* Limited rights granted. Please
refer to license
*****************************************************************************/
/*****************************************************************************
* UPDATES
******************************************************************************
*
*
4.12.2000
* - First version
*
*
11.12.2000
* - Javadoc comments
added
*
*
21.12.2000
* - Clean-up inspection by Markku M.
*
*
Changes by KORPPI
*
*
15.3.2001
* - Added method rightLevel.
* 16.3.2001
* - Added method courseRight.
*
*****************************************************************************/
package
kotkabeans;
import
java.lang.Integer;
import
java.sql.*;
/**
* is a class which is used to encapsulate
permisson checkings. This class provides information if the user has
* permission to enter the specific site.
*/
public
class UseModule extends DB {
/**
*
This method decides weather or not to the user has permission to use spesific
module.
* Because there are no use-case level
accessrights implemented in the database, the permissions
*
are hardcoded here.
*
*
@param personID Person who tries to access module
*
@param moduleID Module which is accessed. Only identifier 1 is used at this
time.
*
@return Returns <code>true</code> if user is allowed to use module,
otherwise <code>false</code>
*/
public boolean allowedUser(int personID,
int moduleID) throws Exception
{
//
This bean decides weather the user may use the requested module or not.
if
(moduleID != 1) return false;
//
Only person who has admin and secretary privileges in some organisation may use
personmanagement
connect();
ResultSet
rs = executeQuery("SELECT * FROM AccessRight WHERE Deleted = FALSE AND
PersonID = " + personID + " AND AccessRightLevelID > 3");
disconnect();
return
rs.next();
}
/**
* @param personID Person whos
accessrightlevel we are looking for.
* @return Returns Persons
accessrightlevel.
*/
public int rightLevel(int personID) throws
Exception
{
int
level = 0;
connect();
ResultSet
rs = executeQuery("SELECT accessrightlevelid FROM AccessRight WHERE
Deleted = FALSE AND PersonID = " + personID + " ;");
disconnect();
if(rs.next())
{
String dblevel =
rs.getString("accessrightlevelid");
level = Integer.parseInt(dblevel);
}
return level;
}
/**
* This method checks persons
kurkiusergrouplevel. Needed when we must know if the person is student or
*
lecturer at given course.
*
* @param personID Person who is
checked.
* @param courseInstanceID Course
which is checked.
* @return Returns Persons
kurkiusergroupid from CourseParticipant
*/
public int courseRight(int personID, int
courseinstanceID) throws Exception
{
int
level = 0;
connect();
ResultSet
rs = executeQuery("SELECT usergroupid FROM CourseParticipant WHERE Deleted
= FALSE AND PersonID = " + personID + " AND CourseInstanceID = "
+ courseinstanceID +";");
disconnect();
if(rs.next())
{
String dblevel =
rs.getString("usergroupid");
level = Integer.parseInt(dblevel);
}
return level;
}
}
Tämä papu toimii käyttöliittymän istunnon valvojana ja tallennuspaikkana. Kullekin käyttäjälle tehdään pavusta käytönajaksi oma esiintymä. Korppi-projekti lisäsi papuun ylläpitäjälle näytettäviä tietoja varten muutamia attribuutteja sekä niille saanti- ja asetusmetodit.
/*****************************************************************************
* MODULE DESCRIPTION
******************************************************************************
*
* NAME: UseModule
* LANGUAGE: JavaBean
* DATE: 4.12.2000
*
AUTHOR: Markku Vire, Jyväskylän
yliopisto
*
******************************************************************************
*
COPYRIGHT (C) KOTKA-PROJEKTIRYHMÄ
* Limited rights granted. Please
refer to license
*****************************************************************************/
/*****************************************************************************
* UPDATES
******************************************************************************
*
*
4.12.2000
* - First version
*
* 11.12.2000
* - Javadoc comments
added
*
*
21.12.2000
* - Clean-up inspection by Markku M.
*
*
Changes by KORPPI
*
*
15.3.2001
* - Added method rightLevel.
* 16.3.2001
* - Added method courseRight.
*
*****************************************************************************/
package
kotkabeans;
import
java.lang.Integer;
import
java.sql.*;
/**
* is a class which is used to encapsulate
permisson checkings. This class provides information if the user has
* permission to enter the specific site.
*/
public
class UseModule extends DB {
/**
*
This method decides weather or not to the user has permission to use spesific
module.
* Because there are no use-case level
accessrights implemented in the database, the permissions
*
are hardcoded here.
*
*
@param personID Person who tries to access module
*
@param moduleID Module which is accessed. Only identifier 1 is used at this
time.
*
@return Returns <code>true</code> if user is allowed to use module,
otherwise <code>false</code>
*/
public boolean allowedUser(int personID,
int moduleID) throws Exception
{
//
This bean decides weather the user may use the requested module or not.
if
(moduleID != 1) return false;
//
Only person who has admin and secretary privileges in some organisation may use
personmanagement
connect();
ResultSet
rs = executeQuery("SELECT * FROM AccessRight WHERE Deleted = FALSE AND
PersonID = " + personID + " AND AccessRightLevelID > 3");
disconnect();
return
rs.next();
}
/**
* @param personID Person whos accessrightlevel we are looking
for.
* @return Returns Persons
accessrightlevel.
*/
public int rightLevel(int personID) throws
Exception
{
int
level = 0;
connect();
ResultSet
rs = executeQuery("SELECT accessrightlevelid FROM AccessRight WHERE
Deleted = FALSE AND PersonID = " + personID + " ;");
disconnect();
if(rs.next())
{
String dblevel =
rs.getString("accessrightlevelid");
level = Integer.parseInt(dblevel);
}
return level;
}
/**
* This method checks persons
kurkiusergrouplevel. Needed when we must know if the person is student or
*
lecturer at given course.
*
* @param personID Person who is
checked.
* @param courseInstanceID Course which is checked.
* @return Returns Persons
kurkiusergroupid from CourseParticipant
*/
public int courseRight(int personID, int
courseinstanceID) throws Exception
{
int
level = 0;
connect();
ResultSet
rs = executeQuery("SELECT usergroupid FROM CourseParticipant WHERE Deleted
= FALSE AND PersonID = " + personID + " AND CourseInstanceID = "
+ courseinstanceID +";");
disconnect();
if(rs.next())
{
String dblevel = rs.getString("usergroupid");
level = Integer.parseInt(dblevel);
}
return level;
}
}
Tämä papu hoitaa kursseille ilmoittautumisen sekä ilmoittautumisen poistot.
/*****************************************************************************
* MODULE
DESCRIPTION
******************************************************************************
*
* NAME: AddUserToCourse
* LANGUAGE: JavaBean
* DATE: 16.3.2000
* AUTHOR:
Heikki Uuksulainen, Jyväskylän yliopisto
*
******************************************************************************
*
COPYRIGHT (C) KORPPI-PROJEKTIRYHMÄ
* Limited rights granted. Please
refer to license
*****************************************************************************/
/*****************************************************************************
* UPDATES
******************************************************************************
*
*
16.3.2000
* - First version
*
4.5.2001
* - method registerUser
changed
*****************************************************************************/
package
kotkabeans;
import
java.sql.*;
/**
*
*
*/
public
class AddUserToCourse extends DB {
/**
* @param personID Person who is
checked
* @param courseID Course
*
@param deleted
* @return Returns
<code>true</code> if user has been registered to course, otherwise
<code>false</code>
*/
public boolean checkUser(String
personID, String courseID, boolean deleted) throws Exception
{
// This method checks if user
has registered to course
connect();
ResultSet rs =
executeQuery("SELECT * FROM courseparticipant WHERE
deleted="+deleted+" AND personid=" + personID + " AND
courseinstanceid=" + courseID + ";");
disconnect();
return rs.next();
}
/**
* @param personID Person who wants to
register to course
* @param courseID Course that person
wants to register
*
@param userGroup Users group, student, teacher etc..
* @return Returns
<code>true</code> if user is registeration is completed OK,
otherwise <code>false</code>
*/
public boolean registerUser(String
personID, String courseID, String userGroup) throws Exception
{
// This method registers user
to given course.
int
Index;
ResultSet
rs;
ResultSet
myResult;
ResultSet
myTempResult;
AutoNumber
autonumber = new AutoNumber();
connect();
rs
= executeQuery("SELECT * FROM courseinstance WHERE deleted='f' AND
courseinstanceid=" + courseID + ";");
if(!rs.next())
{ //Check if there is such a course
disconnect();
return
false;
}
if(checkUser(personID,courseID,false))
{
disconnect();
return
false; // check if person has allready
registered to course
}
if(checkUser(personID,courseID,true))
{ // check if person wants to register
again after he has removed his registration
executeUpdate("UPDATE
courseparticipant SET deleted='f',registratedon='now' WHERE
personid="+personID+" AND courseinstanceid="+courseID+" AND
usergroupid="+userGroup+";");
//
we must update result also
rs =
executeQuery("SELECT * FROM fieldgroup WHERE deleted='f' AND
courseinstanceid="+courseID+";");
while(rs.next()) {
myResult =
executeQuery("SELECT * FROM field WHERE
fieldgroupid="+rs.getString("fieldgroupid")+";");
while(myResult.next()) {
myTempResult = executeQuery("SELECT *
FROM result WHERE fieldid="+myResult.getString("fieldid")+"
AND personid="+personID+";");
if(myTempResult.next()) {
executeUpdate("UPDATE
result SET deleted=false WHERE
fieldid="+myResult.getString("fieldid")+" AND
personid="+personID+";");
} else {
executeUpdate("INSERT
INTO result VALUES(false,"+personID+","+personID+","+myResult.getString("fieldid")+",'now','"+myResult.getString("defaultvalue")+"');");
}
}
}
}
else
{ // set new entry to CourseParticipant
and result
Index
= autonumber.getNumber("CourseParticipant");
executeUpdate("INSERT
INTO
Courseparticipant(Deleted,courseparticipantid,Personid,Courseinstanceid,usergroupid,registratedon)
VALUES(false,'"+Index+"',"+personID+","+courseID+","+userGroup+",'now');");
rs
= executeQuery("SELECT * FROM fieldgroup WHERE courseinstanceid="+courseID+";");
while(rs.next())
{
myResult = executeQuery("SELECT *
FROM field WHERE
fieldgroupid="+rs.getString("fieldgroupid")+";");
while(myResult.next()) {
executeUpdate("INSERT INTO result
VALUES(false,"+personID+","+personID+","+myResult.getString("fieldid")+",'now','"+myResult.getString("defaultvalue")+"');");
}
}
}
disconnect();
return true;
}
/**
* @param personID Person who wants to
unregister from course
* @param courseID Course that person
wants to unregister
* @param userGroup Users group,
student, teacher etc..
* @return Returns
<code>true</code> if user is registeration is completed OK,
otherwise <code>false</code>
*/
public boolean unregisterUser(String
personID, String courseID, String userGroup) throws Exception
{
UserToGroup
group = new UserToGroup();
ResultSet
rs;
ResultSet
myResult;
connect();
if(!checkUser(personID,courseID,false))
{ disconnect(); return false; } //user does not have registered to course
if(executeUpdate("UPDATE
courseparticipant SET deleted='t' WHERE personid="+personID+" AND
courseinstanceid="+courseID+" AND
usergroupid="+userGroup+";") == 0) {
disconnect();
return
false;
}
rs
= executeQuery("SELECT * FROM eventgroup WHERE
courseinstanceid="+courseID+" AND
groupparticipant.eventgroupid=eventgroup.eventgroupid AND
groupparticipant.personid="+personID+" AND
groupparticipant.deleted='f' AND eventgroup.grouptypeid NOT IN (3);");
while(rs.next())
{ // lets unregister user from groups
he/she has registered
group.unregisterUser(personID,rs.getString("eventgroupid"));
}
/* // and delete rows from result
rs = executeQuery("SELECT
* FROM fieldgroup WHERE deleted='f' AND
courseinstanceid="+courseID+";");
while(rs.next()) {
myResult =
executeQuery("SELECT * FROM field WHERE
fieldgroupid="+rs.getString("fieldgroupid")+";");
while(myResult.next())
{
executeUpdate("UPDATE result SET deleted='t' WHERE
fieldid="+myResult.getString("fieldid")+" AND
personid="+personID+";");
}
}
*/
disconnect();
return
true;
}
}
Tämä papu hoitaa opetusryhmiin ilmoittautumisen sekä ilmoittautumisen poistot.
/*****************************************************************************
* MODULE
DESCRIPTION
******************************************************************************
*
* NAME: UserToGroup
* LANGUAGE: JavaBean
* DATE: 29.3.2000
*
AUTHOR: Heikki Uuksulainen,
Jyväskylän yliopisto
*
******************************************************************************
*
COPYRIGHT (C) KORPPI-PROJEKTIRYHMÄ
* Limited rights granted. Please
refer to license
*****************************************************************************/
/*****************************************************************************
* UPDATES
******************************************************************************
*
*
29.3.2000
* - First version
*
*****************************************************************************/
package
kotkabeans;
import
java.sql.*;
/**
*
*
*/
public
class UserToGroup extends DB {
/**
* @param personID Person who wants to
register to group
* @param groupID EventGroup that is
checked
*
@param deleted
* @return Returns
<code>true</code> if user has registered to group, otherwise
<code>false</code>
*/
public boolean checkUser(String personID,
String groupID, boolean deleted) throws Exception
{
connect();
ResultSet
rs = executeQuery("SELECT * FROM groupparticipant WHERE
deleted="+deleted+" AND personid="+personID+" AND
eventgroupid="+groupID+";");
return
rs.next();
}
/**
* @param personID Person who wants to
register to group
* @param groupID EventGroup that person wants to register
* @return Returns
<code>true</code> if user is registeration is completed OK,
otherwise <code>false</code>
*/
public boolean registerUser(String
personID, String groupID, String comment) throws Exception
{
// This method registers user
to given eventgroup.
ResultSet
myResult;
AutoNumber
autoNumber = new AutoNumber();
int
Index;
try
{
connect();
ResultSet
rs = executeQuery("SELECT * FROM eventgroup WHERE deleted='f' AND
eventgroupid=" + groupID + ";");
if(!rs.next())
{ //Check if there is such a group
disconnect();
return
false;
}
if(checkUser(personID,groupID,false))
{ disconnect(); return false; } //
check if person has allready registered to group
//
check if there is room
rs
= executeQuery("SELECT COUNT(personid) FROM groupparticipant WHERE
eventgroupid="+groupID+" AND deleted='f';");
myResult
= executeQuery("SELECT maxparticipants FROM eventgroup WHERE eventgroupid="+groupID+"
AND deleted='f';");
if(rs.next())
{
if(myResult.next())
{
if(
(myResult.getInt("maxparticipants") - rs.getInt("count"))
<= 0) {
return false;
}
}
}
// unregister user from other
groups // lets check courseinstanceid that we are dealing
with
rs = executeQuery("SELECT
courseinstanceid, grouptypeid FROM eventgroup WHERE deleted='f' AND
eventgroupid="+groupID+";");
if(rs.next()) { // and then fetch all same kind of
groups of that course
myResult =
executeQuery("SELECT eventgroupid FROM eventgroup where deleted='f' AND
courseinstanceid='"+rs.getString("courseinstanceid")+"' AND
grouptypeid='"+rs.getString("grouptypeid")+"';");
while(myResult.next())
{ // and then
unregister
unregisterUser(personID,myResult.getString("eventgroupid"));
}
}
if(checkUser(personID,groupID,true))
{ // check if person wants to register
again after he has removed his registration
executeUpdate("UPDATE
groupparticipant SET
deleted=false,comment='"+comment+"',registeredon='now' WHERE
personid="+personID+" AND eventgroupid="+groupID+";");
}
else
{ // set new entry to table
Index
= autoNumber.getNumber("GroupParticipant");
executeUpdate("INSERT
INTO groupparticipant
VALUES(false,"+personID+","+groupID+","+ Index
+",'"+comment+"','now');");
}
disconnect();
}
catch(Exception exeption) {
return false;
}
return true;
}
/**
* @param personID Person who wants to
unregister from group
* @param groupID EventGroup that
person wants to unregister
* @return Returns
<code>true</code> if user is unregisteration is completed OK, otherwise
<code>false</code>
*/
public boolean unregisterUser(String
personID, String groupID) throws Exception
{
connect();
if(!checkUser(personID,groupID,false))
{disconnect(); return false;} //user
does not have registered to group
executeUpdate("UPDATE
groupparticipant SET deleted='t' WHERE personid="+personID+" AND eventgroupid="+groupID+";");
disconnect();
return
true;
}
}