summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-11 18:40:49 +0200
committerSimon Rettberg2015-06-11 18:40:49 +0200
commite0005ceecfd9281230c4add7575b18ee88307774 (patch)
treea73bbcfc213df478c701aac120ae2b7c6e52bb1b /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java
parent[server] db stuff, new interface, ... (diff)
downloadtutor-module-e0005ceecfd9281230c4add7575b18ee88307774.tar.gz
tutor-module-e0005ceecfd9281230c4add7575b18ee88307774.tar.xz
tutor-module-e0005ceecfd9281230c4add7575b18ee88307774.zip
[server] On mah way (lots of restructuring, some early db classes, sql dump of current schema)
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java
new file mode 100644
index 00000000..e254b085
--- /dev/null
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImagePermissions.java
@@ -0,0 +1,64 @@
+package org.openslx.bwlp.sat.database.mappers;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.openslx.bwlp.thrift.iface.ImagePermissions;
+
+public class DbImagePermissions {
+
+ /**
+ * Build an instance of {@link ImagePermissions} by reading the given
+ * columns from the given {@link ResultSet}. If there are no permissions
+ * given in the ResultSet, <code>null</code> is returned.
+ *
+ * @param rs the {@link ResultSet} to read from
+ * @param canLink Name of the column to read the "can link" permission from
+ * @param canDownload Name of the column to read the "can download"
+ * permission from
+ * @param canEdit Name of the column to read the "can edit" permission from
+ * @param canAdmin Name of the column to read the "can admin" permission
+ * from
+ * @return instance of {@link ImagePermissions}, or <code>null</code>
+ * @throws SQLException
+ */
+ private static ImagePermissions fromResultSet(ResultSet rs, String canLink, String canDownload,
+ String canEdit, String canAdmin) throws SQLException {
+ byte link = rs.getByte(canLink);
+ if (rs.wasNull())
+ return null;
+ return new ImagePermissions(link != 0, rs.getByte(canDownload) != 0, rs.getByte(canEdit) != 0,
+ rs.getByte(canAdmin) != 0);
+ }
+
+ /**
+ * Build an instance of {@link ImagePermissions} by reading the
+ * columns <code>canlink</code>, <code>candownload</code>,
+ * <code>canedit</code>, <code>canadmin</code> from the given
+ * {@link ResultSet}. If there are no permissions
+ * given in the ResultSet, <code>null</code> is returned.
+ *
+ * @param rs the {@link ResultSet} to read from
+ * @return instance of {@link ImagePermissions}, or <code>null</code>
+ * @throws SQLException
+ */
+ public static ImagePermissions fromResultSetUser(ResultSet rs) throws SQLException {
+ return fromResultSet(rs, "canlink", "candownload", "canedit", "canadmin");
+ }
+
+ /**
+ * Build an instance of {@link ImagePermissions} by reading the
+ * columns <code>canlinkdefault</code>, <code>candownloaddefault</code>,
+ * <code>caneditdefault</code>, <code>canadmindefault</code> from the given
+ * {@link ResultSet}. If there are no permissions
+ * given in the ResultSet, <code>null</code> is returned.
+ *
+ * @param rs the {@link ResultSet} to read from
+ * @return instance of {@link ImagePermissions}, or <code>null</code>
+ * @throws SQLException
+ */
+ public static ImagePermissions fromResultSetDefault(ResultSet rs) throws SQLException {
+ return fromResultSet(rs, "canlinkdefault", "candownloaddefault", "caneditdefault", "canadmindefault");
+ }
+
+}