%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.DocumentGroup" %>
<%@ page import="com.liferay.portal.model.UserGroup" %>
<%@ page import="com.liferay.portal.model.User" %>
<%@ page import="com.liferay.portal.service.UserGroupLocalServiceUtil" %>
<%@ page import="com.liferay.portal.service.UserLocalServiceUtil" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.xml.XMLDataElement" %>
<%@ page import="org.crosswire.data.DataObject" %>
<%@ page import="org.crosswire.utils.Utils" %>
<%@ page import="org.crosswire.utils.HTTPUtils" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="java.util.Vector" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%!
@Description(value = "Retrieve list of available projects.", name = "projectmanagement/project/list")
public static class MyParameters extends Parameters {
@Description(value = "show usage for this web service", defaultValue = "false", example = "true")
public Boolean usage = false;
@Description(value = "limit project list to this user name", example = "joe")
public String userName;
@Description(value = "limit project list to projects configure for this task id", example = "1")
public Integer taskTypeID;
@Description(value = "progressively more detail: [header,users,documents,tasks,scope,progress]", defaultValue = "header", example = "users")
public String detail;
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0 && !params.usage) {
int companyID = Integer.parseInt(Utils.getSysConfig(session).getProperty("LiferayCompanyDefault"));
int detail = 1;
if ("users".equals(params.detail)) detail = 2;
else if ("documents".equals(params.detail)) detail = 3;
else if ("tasks".equals(params.detail)) detail = 4;
else if ("scope".equals(params.detail)) detail = 5;
else if ("progress".equals(params.detail)) detail = 6;
ProjectManagement.Project projects[] = ProjectManagement.getProjects();
Set userGroups = null;
if (params.userName != null) {
userGroups = getUserGroups(companyID, params.userName, session);
}
Vector result = new Vector();
for (ProjectManagement.Project p : projects) {
if (userGroups == null || userGroups.contains(p.getUserGroup())) {
if (params.taskTypeID == null || params.taskTypeID == -1 || params.taskTypeID == p.getTaskTypeID()) {
result.add(p);
}
}
}
projects = result.toArray(new ProjectManagement.Project[0]);
StringBuffer retVal = new StringBuffer();
retVal.append("");
for (ProjectManagement.Project p : projects) {
if (detail == 1) {
retVal.append(p.toFormattedXML());
}
else {
XMLBlock project = XMLBlock.createXMLBlock(p.toFormattedXML());
if (detail > 1) {
UserGroup u = UserGroupLocalServiceUtil.getUserGroup(companyID, project.getAttribute("userGroup"));
project.addBlock(getUserGroup(u, session));
if (detail > 2) {
DocumentGroup dg = DocumentGroup.getDocumentGroup(Integer.parseInt(project.getAttribute("documentGroupID")));
project.addBlock(XMLBlock.createXMLBlock(dg.toFormattedXML()));
if (detail > 3) {
XMLBlock docs = project.getBlock("documentGroup").getBlock("documents");
for (ProjectManagement.Task t : ProjectManagement.getProjectAssignments(p.getProjectID(), false)) {
XMLBlock b = docs.getBlock("document", "docID", Integer.toString(t.getObjectID()));
if (b != null) {
b.addBlock(XMLBlock.createXMLBlock(t.toFormattedXML()));
}
}
if (detail > 4) {
for (XMLBlock d : docs.getBlocks("document")) {
ProjectManagement.Task t = new ProjectManagement.Task(-1, p.getProjectID(), Integer.parseInt(d.getAttribute("docID")), p.getTaskTypeID(), "", p.getObjectPart(), -1);
ProjectManagement.computeAssignment(t);
d.setAttribute("totalUnits", Integer.toString(t.getTotalUnits()));
}
}
}
}
}
retVal.append(project.formattedString());
}
}
retVal.append("");
Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString()));
return;
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>
<%!
private XMLBlock getUserGroup(UserGroup ug, HttpSession session) {
XMLBlock userGroup = XMLBlock.createXMLBlock("");
try {
userGroup.setAttribute("userGroupID", Long.toString(ug.getUserGroupId()));
userGroup.setAttribute("name", ug.getName());
userGroup.setValue("description", ug.getDescription());
for (User u : UserLocalServiceUtil.getUserGroupUsers(ug.getUserGroupId())) {
userGroup.createValue("user", u.getScreenName());
}
}
catch (Exception e) {e.printStackTrace();}
return userGroup;
}
Set getUserGroups(int companyID, String userName, HttpSession session) {
Set userGroups = new HashSet();
try {
User u = UserLocalServiceUtil.getUserByScreenName(companyID, userName);
for (UserGroup ug : UserGroupLocalServiceUtil.getUserUserGroups(u.getUserId())) {
userGroups.add(ug.getName());
}
}
catch (Exception e) {}
return userGroups;
}
%>