-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/web_server/codeine/servlets/api_servlets/NodesCsvApiServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package codeine.servlets.api_servlets; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.List; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import codeine.api.NodeGetter; | ||
import codeine.api.NodeWithMonitorsInfo; | ||
import codeine.model.Constants; | ||
import codeine.servlet.AbstractApiServlet; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class NodesCsvApiServlet extends AbstractApiServlet { | ||
private static final Logger log = Logger.getLogger(NodesCsvApiServlet.class); | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Inject private NodeGetter nodeGetter; | ||
|
||
@Override | ||
protected boolean checkPermissions(HttpServletRequest request) { | ||
return canReadProject(request); | ||
} | ||
|
||
@Override | ||
protected void myGet(HttpServletRequest request, HttpServletResponse response) { | ||
log.info("myGet"); | ||
String project = getProjectName(request); | ||
List<NodeWithMonitorsInfo> nodes = nodeGetter.getNodes(project); | ||
response.setContentType("text/csv"); | ||
PrintWriter writer = getWriter(response); | ||
writer.println("name,alias"); | ||
for (NodeWithMonitorsInfo n : nodes) { | ||
writer.println(n.name() + "," + n.alias()); | ||
} | ||
} | ||
|
||
private String getProjectName(HttpServletRequest request) { | ||
String projectName = getParameter(request, Constants.UrlParameters.PROJECT_NAME); | ||
return projectName; | ||
} | ||
|
||
|
||
} |