@ -2,11 +2,12 @@
package de.srsoftware.umbrella.legacy ;
package de.srsoftware.umbrella.legacy ;
import static de.srsoftware.tools.Optionals.nullable ;
import static de.srsoftware.tools.Optionals.nullable ;
import static de.srsoftware.umbrella.core.Constants.TOKEN ;
import static de.srsoftware.umbrella.core.Constants.TOKEN ;
import static de.srsoftware.umbrella.core.Constants.USERS ;
import static de.srsoftware.umbrella.core.Paths.JSON ;
import static de.srsoftware.umbrella.core.Paths.JSON ;
import static de.srsoftware.umbrella.core.Util.mapValues ;
import static de.srsoftware.umbrella.core.Util.mapValues ;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable ;
import com.sun.net.httpserver.HttpExchange ;
import com.sun.net.httpserver.HttpExchange ;
import de.srsoftware.configuration.Configuration ;
import de.srsoftware.configuration.Configuration ;
@ -28,11 +29,6 @@ public class TaskLegacy extends BaseHandler {
this . config = config . subset ( "umbrella.modules" ) . orElseThrow ( ( ) - > new RuntimeException ( "Missing configuration: umbrella.modules" ) ) ;
this . config = config . subset ( "umbrella.modules" ) . orElseThrow ( ( ) - > new RuntimeException ( "Missing configuration: umbrella.modules" ) ) ;
}
}
@Override
public boolean doDelete ( Path path , HttpExchange ex ) throws IOException {
return super . doDelete ( path , ex ) ;
}
@Override
@Override
public boolean doGet ( Path path , HttpExchange ex ) throws IOException {
public boolean doGet ( Path path , HttpExchange ex ) throws IOException {
if ( path . empty ( ) ) return sendRedirect ( ex , url ( ex ) . replaceAll ( "/legacy/" , "/" ) ) ;
if ( path . empty ( ) ) return sendRedirect ( ex , url ( ex ) . replaceAll ( "/legacy/" , "/" ) ) ;
@ -40,17 +36,7 @@ public class TaskLegacy extends BaseHandler {
}
}
@Override
@Override
public boolean doOptions ( Path path , HttpExchange ex ) throws IOException {
public boolean doPost ( Path path , HttpExchange ex ) throws IOException {
return super . doOptions ( path , ex ) ;
}
@Override
public boolean doPatch ( Path path , HttpExchange ex ) throws IOException {
return super . doPatch ( path , ex ) ;
}
@Override
public boolean doPost ( Path path , HttpExchange ex ) throws IOException {
var params = formData ( ex ) ;
var params = formData ( ex ) ;
Optional < Token > token = SessionToken . from ( ex ) . map ( Token : : of ) ;
Optional < Token > token = SessionToken . from ( ex ) . map ( Token : : of ) ;
@ -59,14 +45,17 @@ public class TaskLegacy extends BaseHandler {
if ( user . isEmpty ( ) ) return unauthorized ( ex ) ;
if ( user . isEmpty ( ) ) return unauthorized ( ex ) ;
return switch ( path . pop ( ) ) {
return switch ( path . pop ( ) ) {
case JSON - > postProject Json ( ex , params , user . get ( ) ) ;
case JSON - > postJson ( user . get ( ) , params , ex ) ;
default - > super . doPost ( path , ex ) ;
case null , default - > super . doPost ( path , ex ) ;
} ;
} ;
}
}
private boolean postProjectJson ( HttpExchange ex , Map < String , Object > params , UmbrellaUser user ) throws IOException {
private boolean postJson ( UmbrellaUser umbrellaUser , Map < String , Object > params , HttpExchange ex ) throws IOException {
var includeUsers = "1" . equals ( params . get ( USERS ) ) ;
LOG . log ( System . Logger . Level . DEBUG , params ) ;
var projects = projectService ( ) . listUserProjects ( user . id ( ) , false ) ;
if ( params . get ( "ids" ) instanceof Map < ? , ? > taskIdMap ) {
return sendContent ( ex , mapValues ( projects ) ) ;
var taskIds = taskIdMap . values ( ) . stream ( ) . map ( Object : : toString ) . map ( Long : : parseLong ) . toList ( ) ;
return sendContent ( ex , mapValues ( taskService ( ) . load ( taskIds ) ) ) ;
}
throw unprocessable ( "Invalid request" ) ;
}
}
}
}