3 import java
.sql
.ResultSet
;
8 * This is an abstract class with the generic code to assign mote usage privileges.
9 * To integrate any custom reservation system, this class must be inherited and the
10 * abstract methods implemented.
12 public abstract class AbstractMoteAccess
{
14 public boolean[] getMoteControlPrivileges(long[] mote_ids
, String session_id
) throws Exception
16 boolean[] results
= new boolean[mote_ids
.length
];
17 for (int i
=0; i
<mote_ids
.length
;i
++)
19 results
[i
] = getMoteControlPrivilege(mote_ids
[i
],session_id
);
24 protected boolean getMoteControlPrivilege(long mote_id
, String session_id
) throws Exception
26 boolean access
= false;
30 // Check for current privileged session
31 String query
= "select priv_session_id from mote " +
33 sql
= new SQLHelper();
35 ResultSet sqlres
= sql
.retrieve(query
);
37 String privsess
= sqlres
.getString("priv_session_id");
38 if (privsess
== null || privsess
.compareTo(session_id
) == 0) {
41 // check privileges with reservation system
42 if (hasReservation(mote_id
,session_id
))
49 query
= "update mote set priv_session_id="+session_id
+
61 * This method must be implemented to integrate a custom reservation system.
62 * It is also a point for integration between user account system and reservation system.
63 * @param mote_id Database key for the mote to check
64 * @param session_id Database key for the session requesting access. Note that
65 * the user model should specify the relevant reservation key upon session authentication.
66 * The details of how to do this are application specific.
67 * @return true if there is a current reservation, false otherwise
69 abstract protected boolean hasReservation(long mote_id
, String session_id
) throws Exception
;