summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-24 18:31:59 +0200
committerSimon Rettberg2015-06-24 18:31:59 +0200
commit9ff2e9adc74f804023ed751a5afe264b596bf93a (patch)
treebbe395bc463ae0dc562f14b2c6611c726c5fac8d /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
parent[server] More methods implemented (diff)
downloadtutor-module-9ff2e9adc74f804023ed751a5afe264b596bf93a.tar.gz
tutor-module-9ff2e9adc74f804023ed751a5afe264b596bf93a.tar.xz
tutor-module-9ff2e9adc74f804023ed751a5afe264b596bf93a.zip
[server] Fnished image-related methods so far, started implementing lecture-related ones....
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.java36
1 files changed, 34 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 4dae8039..1fb19121 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
@@ -47,6 +47,7 @@ public class DbImage {
*/
public static List<ImageSummaryRead> getAllVisible(UserInfo user, List<String> tagSearch)
throws SQLException {
+ // TODO: Implement tag search functionality
try (MysqlConnection connection = Database.getConnection()) {
MysqlStatement stmt = connection.prepareStatement("SELECT"
+ " i.imagebaseid, i.currentversionid, i.latestversionid, i.displayname,"
@@ -243,7 +244,7 @@ public class DbImage {
+ " SET ownerid = :ownerid WHERE imagebaseid = :baseid");
stmt.setString("ownerid", newOwnerId);
stmt.setString("baseid", imageBaseId);
- stmt.executeQuery();
+ stmt.executeUpdate();
connection.commit();
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.setImageOwner()", e);
@@ -291,6 +292,14 @@ public class DbImage {
return ShareMode.valueOf(string);
}
+ /**
+ * Update meta data of a specific image version.
+ *
+ * @param user user doing the edit
+ * @param imageVersionId UUID of image version
+ * @param image meta data to set
+ * @throws SQLException
+ */
public static void updateImageVersion(UserInfo user, String imageVersionId, ImageVersionWrite image)
throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
@@ -302,7 +311,7 @@ public class DbImage {
stmt.setString("userid", user.userId);
stmt.setBoolean("isenabled", image.isEnabled);
stmt.setBoolean("isrestricted", image.isRestricted);
- stmt.executeQuery();
+ stmt.executeUpdate();
connection.commit();
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.updateImageVersion()", e);
@@ -310,4 +319,27 @@ public class DbImage {
}
}
+ /**
+ * Mark given image for deletion. The image is marked for deletion by
+ * setting the expire timestamp to the current date, and by setting the
+ * image disabled and invalid. Next time the cleanup task runs, the image
+ * will be deleted.
+ *
+ * @param imageVersionId UUID of image version to delete
+ * @throws SQLException
+ */
+ public static void markForDeletion(String imageVersionId) throws SQLException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion SET"
+ + " expiretime = UNIX_TIMESTAMP() - 1, isenabled = 0, isvalid = 0"
+ + " WHERE imageversionid = :versionid");
+ stmt.setString("versionid", imageVersionId);
+ stmt.executeUpdate();
+ connection.commit();
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in DbImage.markForDeletion()", e);
+ throw e;
+ }
+ }
+
}