*/
@GET
@Produces({"application/xml", "application/json"})
public Response getModuleList(@PathParam("state") String state) {
ModuleManager manager = ModuleManager.getModuleManager();
ModuleList moduleList = new ModuleList();
/*
* Check the state given, and fetch the modules. If the module state is
* invalid, return a BAD_REQUEST error. Otherwise fetch the module list
* according to the state and return a ModuleList object.
*/
if (state == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
else if (state.equals("installed") == true) {
Map<String, Module> modules = manager.getInstalledModules();
// sort in dependecy order
List<String> ordered = DeployManager.getDeploymentOrder(modules);
// create the list of infos in the correct order
Collection<ModuleInfo> list = new LinkedList();
for (String moduleName : ordered) {
Module module = modules.get(moduleName);
list.add(module.getInfo());
}
moduleList.setModuleInfos(list.toArray(new ModuleInfo[] {}));
return Response.ok(moduleList).build();
}
else if (state.equals("pending") == true) {
Map<String, Module> modules = manager.getPendingModules();
Collection<ModuleInfo> list = new LinkedList();
Iterator<Map.Entry<String, Module>> it = modules.entrySet().iterator();
while (it.hasNext() == true) {
Map.Entry<String, Module> entry = it.next();
list.add(entry.getValue().getInfo());
}
moduleList.setModuleInfos(list.toArray(new ModuleInfo[] {}));
return Response.ok(moduleList).build();
}
else if (state.equals("uninstall") == true) {
Map<String, ModuleInfo> modules = manager.getUninstallModuleInfos();
Collection<ModuleInfo> list = new LinkedList();
Iterator<Map.Entry<String, ModuleInfo>> it = modules.entrySet().iterator();
while (it.hasNext() == true) {
Map.Entry<String, ModuleInfo> entry = it.next();
list.add(entry.getValue());
}
moduleList.setModuleInfos(list.toArray(new ModuleInfo[] {}));
return Response.ok(moduleList).build();
}
else {
return Response.status(Response.Status.BAD_REQUEST).build();
}