|
|
|
|
@ -9,7 +9,6 @@ import static de.srsoftware.umbrella.core.model.Permission.OWNER;
@@ -9,7 +9,6 @@ import static de.srsoftware.umbrella.core.model.Permission.OWNER;
|
|
|
|
|
import static de.srsoftware.umbrella.core.model.Status.OPEN; |
|
|
|
|
import static de.srsoftware.umbrella.project.Constants.CONFIG_DATABASE; |
|
|
|
|
import static java.lang.Boolean.TRUE; |
|
|
|
|
import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED; |
|
|
|
|
import static java.net.HttpURLConnection.HTTP_OK; |
|
|
|
|
import static java.util.Comparator.comparing; |
|
|
|
|
|
|
|
|
|
@ -54,7 +53,6 @@ public class ProjectModule extends BaseHandler implements ProjectService {
@@ -54,7 +53,6 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
|
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
|
var head = path.pop(); |
|
|
|
|
return switch (head) { |
|
|
|
|
case LIST -> listUserProjects(ex,user.get()); |
|
|
|
|
case null -> postProject(ex,user.get()); |
|
|
|
|
default -> { |
|
|
|
|
var projectId = Long.parseLong(head); |
|
|
|
|
@ -108,7 +106,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
@@ -108,7 +106,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
|
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
|
var head = path.pop(); |
|
|
|
|
return switch (head) { |
|
|
|
|
case LIST -> listCompanyProjects(ex,user.get()); |
|
|
|
|
case LIST -> postProjectList(ex,user.get()); |
|
|
|
|
case null -> postProject(ex,user.get()); |
|
|
|
|
default -> super.doGet(path,ex); |
|
|
|
|
}; |
|
|
|
|
@ -132,15 +130,20 @@ public class ProjectModule extends BaseHandler implements ProjectService {
@@ -132,15 +130,20 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
|
|
|
|
return sendContent(ex,map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean postProjectList(HttpExchange ex, UmbrellaUser user) throws IOException { |
|
|
|
|
var json = json(ex); |
|
|
|
|
var showClosed = json.has(SHOW_CLOSED) && json.get(SHOW_CLOSED) instanceof Boolean bool ? bool : false; |
|
|
|
|
if (json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number companyId) return listCompanyProjects(ex, user, companyId.longValue()); |
|
|
|
|
return listUserProjects(ex,user,showClosed); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Collection<Project> listCompanyProjects(long companyId, boolean includeClosed) throws UmbrellaException { |
|
|
|
|
return projects.ofCompany(companyId, includeClosed).values().stream().sorted(comparing(Project::name)).toList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean listCompanyProjects(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException { |
|
|
|
|
var json = json(ex); |
|
|
|
|
if (!(json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number cid)) throw missingFieldException(COMPANY_ID); |
|
|
|
|
var companyId = cid.longValue(); |
|
|
|
|
private boolean listCompanyProjects(HttpExchange ex, UmbrellaUser user, long companyId) throws IOException, UmbrellaException { |
|
|
|
|
var company = companies.get(companyId); |
|
|
|
|
if (!companies.membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company.name()); |
|
|
|
|
var projects = listCompanyProjects(companyId,false) |
|
|
|
|
@ -155,9 +158,9 @@ public class ProjectModule extends BaseHandler implements ProjectService {
@@ -155,9 +158,9 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
|
|
|
|
return projects.ofUser(userId, includeClosed); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean listUserProjects(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException { |
|
|
|
|
private boolean listUserProjects(HttpExchange ex, UmbrellaUser user, boolean showClosed) throws IOException, UmbrellaException { |
|
|
|
|
var projects = new HashMap<Long,Map<String,Object>>(); |
|
|
|
|
for (var entry : listUserProjects(user.id(),false).entrySet()) { |
|
|
|
|
for (var entry : listUserProjects(user.id(),showClosed).entrySet()) { |
|
|
|
|
var project = entry.getValue(); |
|
|
|
|
var map = project.toMap(); |
|
|
|
|
var members = new HashMap<Long,Map<String,Object>>(); |
|
|
|
|
|