Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions Ira's branch .1/FeedService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package webService;

import java.util.ArrayList;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import model.ProjectManager;

import com.google.gson.Gson;

import dto.FeedObjects;

@Path("/WebService")
public class FeedService {

@GET
@Path("/GetFeeds")
@Produces("application/json")
public String feed()
{
String feeds = null;
try
{
ArrayList<FeedObjects> feedData = null;
ProjectManager projectManager= new ProjectManager();
feedData = projectManager.GetFeeds();
Gson gson = new Gson();
System.out.println(gson.toJson(feedData));
feeds = gson.toJson(feedData);
//System.out.println("Are we doing anything?");

}

catch (Exception e)
{
System.out.println("Exception Error:" + e.getMessage()); //Console
}
return feeds;
}

@GET
@Path("/GetFeedWithDates")
@Produces("application/json")
public String feed2(
@QueryParam("terrorParam1") String terrorParam1,
@QueryParam("terrorParam2") String terrorParam2)
{
String feeds = null;
try
{
ArrayList<FeedObjects> feedData = null;
ProjectManager projectManager= new ProjectManager();
feedData = projectManager.GetFeeds( terrorParam1, terrorParam2 );
Gson gson = new Gson();
System.out.println(gson.toJson(feedData));
feeds = gson.toJson(feedData);
//System.out.println("Are we doing anything?");

}

catch (Exception e)
{
System.out.println("Exception Error:" + e.getMessage()); //Console
}
return feeds;
}

@GET
@Path("/GetFeedWithAttacktype")
@Produces("application/json")
public String feed3(
@QueryParam("terrorParam3") String terrorParam3)

{
String feeds = null;
try
{
ArrayList<FeedObjects> feedData = null;
ProjectManager projectManager= new ProjectManager();
feedData = projectManager.GetFeeds( terrorParam3 );
Gson gson = new Gson();
System.out.println(gson.toJson(feedData));
feeds = gson.toJson(feedData);
//System.out.println("Are we doing anything?");

}

catch (Exception e)
{
System.out.println("Exception Error:" + e.getMessage()); //Console
}
return feeds;
}






@GET
@Path("/GetMethod")
@Produces(MediaType.TEXT_PLAIN)
public String newMethod(
@QueryParam("terrorParam1") String terrorParam1,
@QueryParam("terrorParam2") String terrorParam2)
{
return "These are your two params---->"
+ terrorParam1 + " and " + terrorParam2;
}


}
87 changes: 87 additions & 0 deletions Ira's branch .1/Project.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import dto.FeedObjects;

public class Project
{
public ArrayList<FeedObjects> GetFeeds(Connection connection) throws Exception
{
ArrayList<FeedObjects> feedData = new ArrayList<FeedObjects>();
try
{
PreparedStatement ps = connection.prepareStatement("SELECT gname, count(gname) AS number FROM `terrorism_data` GROUP BY gname ORDER BY number DESC");
ResultSet rs = ps.executeQuery();
while(rs.next())
{
FeedObjects feedObject = new FeedObjects();
feedObject.setGroup(rs.getString("gname"));
feedObject.setNumberOfAttacks(rs.getString("number"));
feedData.add(feedObject);
}
return feedData;
}
catch(Exception e)
{
System.out.println("Error Here");
throw e;
}
}

public ArrayList<FeedObjects> GetFeeds(Connection connection, String terrorParam1, String terrorParam2) throws Exception
{
ArrayList<FeedObjects> feedData = new ArrayList<FeedObjects>();
try
{
PreparedStatement ps = connection.prepareStatement("SELECT gname, count(gname) AS number FROM `terrorism_data`"
+ "WHERE iyear >= '" + terrorParam1 + "' AND iyear<='" + terrorParam2 + "' GROUP BY gname ORDER BY number DESC");
ResultSet rs = ps.executeQuery();
while(rs.next())
{
FeedObjects feedObject = new FeedObjects();
feedObject.setGroup(rs.getString("gname"));
feedObject.setNumberOfAttacks(rs.getString("number"));
feedData.add(feedObject);
}
return feedData;
}
catch(Exception e)
{
System.out.println("Error Here");
throw e;
}
}

public ArrayList<FeedObjects> GetFeeds1(Connection connection, String terrorParam3) throws Exception
{
ArrayList<FeedObjects> feedData = new ArrayList<FeedObjects>();
try
{
PreparedStatement ps = connection.prepareStatement("SELECT gname, count(gname) AS number FROM `terrorism_data`"
+ "WHERE attacktype1_txt = '" + terrorParam3 + "' GROUP BY gname ORDER BY number DESC");
ResultSet rs = ps.executeQuery();
while(rs.next())
{
FeedObjects feedObject = new FeedObjects();
feedObject.setGroup(rs.getString("gname"));
feedObject.setNumberOfAttacks(rs.getString("number"));
feedData.add(feedObject);
}
return feedData;
}
catch(Exception e)
{
System.out.println("Error Here");
throw e;
}
}





}
56 changes: 56 additions & 0 deletions Ira's branch .1/ProjectManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package model;

import java.sql.Connection;
import java.util.ArrayList;

import dao.Database;
import dao.Project;
import dto.FeedObjects;

public class ProjectManager {

public ArrayList<FeedObjects> GetFeeds()throws Exception {
ArrayList<FeedObjects> feeds = null;
try {
Database database= new Database();
Connection connection = database.Get_Connection();
Project project= new Project();
feeds=project.GetFeeds(connection);
}
catch (Exception e) {
throw e;
}
return feeds;
}

public ArrayList<FeedObjects> GetFeeds(String terrorParam1, String terrorParam2)throws Exception {
ArrayList<FeedObjects> feeds = null;
try {
Database database= new Database();
Connection connection = database.Get_Connection();
Project project= new Project();
feeds=project.GetFeeds(connection, terrorParam1, terrorParam2);
}
catch (Exception e) {
throw e;
}
return feeds;
}

public ArrayList<FeedObjects> GetFeeds(String terrorParam3)throws Exception {
ArrayList<FeedObjects> feeds = null;
try {
Database database= new Database();
Connection connection = database.Get_Connection();
Project project= new Project();
feeds=project.GetFeeds1(connection, terrorParam3);
}
catch (Exception e) {
throw e;
}
return feeds;
}



}