@ -3,14 +3,16 @@ package de.srsoftware.umbrella.task;
@@ -3,14 +3,16 @@ package de.srsoftware.umbrella.task;
import static de.srsoftware.tools.jdbc.Condition.* ;
import static de.srsoftware.tools.jdbc.Query.* ;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL ;
import static de.srsoftware.tools.jdbc.Query.select ;
import static de.srsoftware.umbrella.core.Constants.* ;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED ;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR ;
import static de.srsoftware.umbrella.project.Constants.* ;
import static de.srsoftware.umbrella.task.Constants.* ;
import static java.lang.System.Logger.Level.WARNING ;
import de.srsoftware.tools.jdbc.Query ;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException ;
import de.srsoftware.umbrella.core.model.* ;
import java.sql.Connection ;
@ -110,4 +112,33 @@ public class SqliteDb implements TaskDb {
@@ -110,4 +112,33 @@ public class SqliteDb implements TaskDb {
throw new UmbrellaException ( HTTP_SERVER_ERROR , "Failed to load task from database" ) ;
}
}
@Override
public Task save ( Task task ) {
try {
if ( task . id ( ) = = 0 ) { // new task
var rs = insertInto ( TABLE_TASKS , PROJECT_ID , PARENT_TASK_ID , NAME , DESCRIPTION , STATUS , EST_TIME , START_DATE , DUE_DATE , SHOW_CLOSED , NO_INDEX )
. values ( task . projectId ( ) , task . parentTaskId ( ) , task . name ( ) , task . description ( ) , task . status ( ) . code ( ) , task . estimatedTime ( ) , task . start ( ) , task . dueDate ( ) , task . showClosed ( ) , task . noIndex ( ) )
. execute ( db )
. getGeneratedKeys ( ) ;
Long taskId = null ;
if ( rs . next ( ) ) taskId = rs . getLong ( 1 ) ;
rs . close ( ) ;
if ( taskId = = null ) throw new UmbrellaException ( "Failed to save task {0}" , task . name ( ) ) ;
return new Task ( taskId , task . projectId ( ) , task . parentTaskId ( ) , task . name ( ) , task . description ( ) , task . status ( ) , task . estimatedTime ( ) , task . start ( ) , task . dueDate ( ) , task . showClosed ( ) , task . noIndex ( ) , task . members ( ) ) ;
}
throw new UmbrellaException ( HTTP_NOT_IMPLEMENTED , "updating task in SqliteDb.save(task) not implemented" ) ;
} catch ( SQLException e ) {
throw new UmbrellaException ( HTTP_SERVER_ERROR , "Failed to save task {0}" , task . name ( ) ) ;
}
}
@Override
public void setMember ( long taskId , long userId , Permission permission ) {
try {
replaceInto ( TABLE_TASKS_USERS , TASK_ID , USER_ID , PERMISSIONS ) . values ( taskId , userId , permission . code ( ) ) . execute ( db ) . close ( ) ;
} catch ( SQLException e ) {
throw new UmbrellaException ( HTTP_SERVER_ERROR , "Failed to store permissions" ) ;
}
}
}