summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-16 18:22:54 +0200
committerSimon Rettberg2015-06-16 18:22:54 +0200
commit9085dcdcb35ae1f9e3a592c8cd5dfecdd4e9bde1 (patch)
treeb7fb7612f4319943426d8ca30d1a8a7fb68b4208 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
parent[server] On mah way (lots of restructuring, some early db classes, sql dump o... (diff)
downloadtutor-module-9085dcdcb35ae1f9e3a592c8cd5dfecdd4e9bde1.tar.gz
tutor-module-9085dcdcb35ae1f9e3a592c8cd5dfecdd4e9bde1.tar.xz
tutor-module-9085dcdcb35ae1f9e3a592c8cd5dfecdd4e9bde1.zip
[server] Add script field to lecture table; implement getImageDetails method to get detailed information about an image from the database
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java73
1 files changed, 71 insertions, 2 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
index b772edb4..bbb5dad9 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
@@ -9,16 +9,31 @@ import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.database.Database;
import org.openslx.bwlp.sat.database.MysqlConnection;
import org.openslx.bwlp.sat.database.MysqlStatement;
+import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.ShareMode;
+import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.UserInfo;
public class DbImage {
private static final Logger LOGGER = Logger.getLogger(DbImage.class);
- public static List<ImageSummaryRead> getAllVisible(UserInfo user, List<String> tagSearch) {
+ /**
+ * Get list of all images visible to the given user, optionally filtered by
+ * the given list of tags.
+ *
+ * @param user Instance of {@link UserInfo} representing the user in
+ * question
+ * @param tagSearch list of tags an image must have to be included in the
+ * list.
+ * @return {@link List} of {@link ImageSummaryRead}
+ * @throws SQLException
+ */
+ public static List<ImageSummaryRead> getAllVisible(UserInfo user, List<String> tagSearch)
+ throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
MysqlStatement stmt = connection.prepareStatement("SELECT"
+ " i.imagebaseid, i.currentversionid, i.latestversionid, i.displayname,"
@@ -51,10 +66,64 @@ public class DbImage {
return list;
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.getAllVisible()", e);
- return null;
+ throw e;
}
}
+ public static ImageDetailsRead getImageDetails(UserInfo user, String imageBaseId)
+ throws TNotFoundException, SQLException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement stmt = connection.prepareStatement("SELECT imagebaseid, currentversionid, latestversionid,"
+ + " displayname, description, osid, virtid, createtime, updatetime, ownerid, updaterid,"
+ + " sharemode, istemplate,"
+ + " canlinkdefault, candownloaddefault, caneditdefault, canadmindefault,"
+ + " perm.canlink, perm.candownload, perm.canedit, perm.canadmin"
+ + " FROM imagebase i"
+ + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
+ + " WHERE i.imagebaseid = :imagebaseid");
+ stmt.setString("userid", user.userId);
+ stmt.setString("imagebaseid", imageBaseId);
+ ResultSet rs = stmt.executeQuery();
+ if (!rs.next())
+ throw new TNotFoundException();
+ // Exists:
+ List<String> tags = DbSoftwareTag.getImageTags(connection, imageBaseId);
+ List<ImageVersionDetails> versions = getImageVersions(connection, imageBaseId);
+ ImagePermissions defaultPermissions = DbImagePermissions.fromResultSetDefault(rs);
+ ImageDetailsRead image = new ImageDetailsRead(rs.getString("imagebaseid"),
+ rs.getString("currentversionid"), rs.getString("latestversionid"), versions,
+ rs.getString("displayname"), rs.getString("description"), tags, rs.getInt("osid"),
+ rs.getString("virtid"), rs.getLong("createtime"), rs.getLong("updatetime"),
+ rs.getString("ownerid"), rs.getString("updaterid"),
+ toShareMode(rs.getString("sharemode")), rs.getByte("istemplate") != 0, defaultPermissions);
+ return image;
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in DbImage.getImage()", e);
+ throw e;
+ }
+ }
+
+ public static List<ImageVersionDetails> getImageVersions(MysqlConnection connection, String imageBaseId)
+ throws SQLException {
+ List<ImageVersionDetails> versionList = new ArrayList<>();
+ MysqlStatement stmt = connection.prepareStatement("SELECT"
+ + " imageversionid, createtime, expiretime, filesize, uploaderid, isenabled,"
+ + " isrestricted, isvalid, isprocessed" + " FROM imageversion"
+ + " WHERE imagebaseid = :imagebaseid");
+ stmt.setString("imagebaseid", imageBaseId);
+ ResultSet rs = stmt.executeQuery();
+ while (rs.next()) {
+ String imageVersionId = rs.getString("imageversionid");
+ versionList.add(new ImageVersionDetails(imageVersionId, rs.getLong("createtime"),
+ rs.getLong("expiretime"), rs.getLong("filesize"), rs.getString("uploaderid"),
+ rs.getByte("isenabled") != 0, rs.getByte("isrestricted") != 0,
+ rs.getByte("isvalid") != 0, rs.getByte("isprocessed") != 0,
+ DbSoftwareTag.getImageVersionSoftwareList(connection, imageVersionId)));
+ }
+ stmt.close();
+ return versionList;
+ }
+
private static ShareMode toShareMode(String string) {
return ShareMode.valueOf(string);
}