Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
8f8d25c
Merge pull request #6 from ZeeSaydullaev/master
jcraigh Oct 14, 2019
641d6ba
next merge request
Oct 14, 2019
2597a24
correct name
ZeeSaydullaev Oct 14, 2019
1f9a57b
Merge pull request #7 from ZeeSaydullaev/master
jcraigh Oct 14, 2019
3554a5b
submit working
Oct 14, 2019
cdf6cc5
Validating status code between 1 and 100
catlikecomet Oct 14, 2019
d67bd59
removal of an extra line
catlikecomet Oct 14, 2019
9684237
Merge pull request #8 from catlikecomet/statusCodeVal
jcraigh Oct 14, 2019
df69a19
Getting zee's commit
Oct 14, 2019
372e03e
pulling info from api
ZeeSaydullaev Oct 14, 2019
91b4012
submitters local time displayed
catlikecomet Oct 14, 2019
d4e7b8d
removing logs and extra lines
catlikecomet Oct 14, 2019
daee59a
formatting times
catlikecomet Oct 14, 2019
0381454
fixing more of the local time stuff
catlikecomet Oct 15, 2019
af11660
NavBar got Fourmoms on
zsolttek Oct 15, 2019
4dc9ba2
NavBar Done for fourm
zsolttek Oct 15, 2019
c63d50a
most wanted suspect images
ZeeSaydullaev Oct 15, 2019
abff799
Merge pull request #9 from catlikecomet/master
jcraigh Oct 15, 2019
c8896f4
Local Time on Report
Oct 15, 2019
b8ba898
error message works for incorrect timezone
catlikecomet Oct 15, 2019
20df722
Add json transformer to token check to prevent console warning
Oct 15, 2019
18e1a6b
error messages should now print correctly
catlikecomet Oct 15, 2019
a3397b5
Merge pull request #10 from JackMead/fix-token-check
jcraigh Oct 15, 2019
d0f784b
fixing a error message instead of how dare you
catlikecomet Oct 15, 2019
5e7f5fa
the errors should be sorted, the catch is seperate for rank
catlikecomet Oct 15, 2019
c6805c2
most wanted added to page with images and text
ZeeSaydullaev Oct 15, 2019
93078da
removing extra lines and removing comments
catlikecomet Oct 16, 2019
6c0ac0e
moving agentid check
catlikecomet Oct 16, 2019
6c9d666
fixing indentation stuffs
catlikecomet Oct 16, 2019
4b547de
Merge pull request #11 from catlikecomet/errorMssges
jcraigh Oct 16, 2019
eff08cf
Start of Forum
Oct 16, 2019
375a8ee
Up todate demo
Oct 16, 2019
f87ca83
page rough layout
ZeeSaydullaev Oct 16, 2019
221d83a
update to style of wanted
ZeeSaydullaev Oct 16, 2019
3be4ec1
photos link to location report
ZeeSaydullaev Oct 16, 2019
f5c7fc2
black text
ZeeSaydullaev Oct 16, 2019
ed0743d
agent can view their own reports but cannot yet update, there is an e…
catlikecomet Oct 16, 2019
7fc5248
Message Board - it's working, few things have to be done for better UI
zsolttek Oct 17, 2019
5822295
commit to push
zsolttek Oct 17, 2019
c84f9ba
Push retry
zsolttek Oct 17, 2019
f692cbc
tidy up
zsolttek Oct 17, 2019
515f256
Working wanted poage
ZeeSaydullaev Oct 17, 2019
440ce1a
Agents can edit their own reports through the myReports page
catlikecomet Oct 17, 2019
cd2dd4b
Merge pull request #12 from zsolttek/master
jcraigh Oct 17, 2019
f01ea56
Merge branch 'master' into agentReports
catlikecomet Oct 17, 2019
6c735ab
working wanted page with extra suspects
ZeeSaydullaev Oct 17, 2019
7c00475
fixed conflict
ZeeSaydullaev Oct 17, 2019
9406721
fixed errors
ZeeSaydullaev Oct 17, 2019
d24e47a
removin lines and comments
catlikecomet Oct 17, 2019
e6d86d7
Merge branch 'agentReports' of https://github.com/catlikecomet/AgentD…
catlikecomet Oct 17, 2019
b31e3bd
Merge pull request #13 from catlikecomet/agentReports
jcraigh Oct 17, 2019
acd09b4
Merge branch 'master' into master
jcraigh Oct 17, 2019
e8d51eb
Merge pull request #14 from ZeeSaydullaev/master
jcraigh Oct 17, 2019
12c7a7f
Delete .DS_Store
jcraigh Oct 17, 2019
d98a3a0
hope
Oct 17, 2019
aa5dd17
Delete .DS_Store
jcraigh Oct 17, 2019
c677fd3
Delete .DS_Store
jcraigh Oct 17, 2019
47beda6
dark mode dndndndndndndndndn
catlikecomet Oct 17, 2019
56b8b07
Merge branch 'master' into darkmode
catlikecomet Oct 17, 2019
f0acce6
removing extra lines, fixing nav items and sorting light mode
catlikecomet Oct 17, 2019
69c5066
trying to fix merge issues
catlikecomet Oct 17, 2019
22fb3da
working ready for demo
Oct 17, 2019
d6d314b
Merge branch 'master' into darkmode
jcraigh Oct 17, 2019
2754542
Merge pull request #15 from catlikecomet/darkmode
jcraigh Oct 17, 2019
273a1ca
Message Board - trying to get the username who wrote the message
zsolttek Oct 17, 2019
94aa2f2
Need work on home page
Oct 17, 2019
b648159
Simple demo of join across tables
Oct 17, 2019
c6c46c7
Merge pull request #1 from JackMead/join-tables
zsolttek Oct 17, 2019
554253f
fixing linting issues and the CSS file
catlikecomet Oct 18, 2019
818f68b
Merge branch 'master' into master
catlikecomet Oct 18, 2019
aedc0f4
Merge pull request #16 from catlikecomet/master
jcraigh Oct 18, 2019
41eaf5c
Forum - works (final, hopefully :P )
zsolttek Oct 18, 2019
8d890e0
to be pushed
zsolttek Oct 18, 2019
6955014
Remove images zsolt
Oct 18, 2019
757a369
Merge pull request #2 from JackMead/remove-images-zsolt
zsolttek Oct 21, 2019
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
16 changes: 15 additions & 1 deletion AgentDiscoveries-Backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,22 @@
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class AgentDiscoveriesApplication implements Runnable {
@Inject MessageProcessorRoutes messageProcessorRoutes;
@Inject ExternalReportRoutes externalReportRoutes;
@Inject PictureRoutes pictureRoutes;
@Inject ForumMessageRoutes forumMessageRoutes;

@Override
public void run() {
Expand All @@ -55,15 +56,15 @@ public void run() {

// Serve the static assets from the frontend project
staticFileLocation("/frontend");

// Setup of all the routes
path("/v1", () -> {
// Endpoint used to get an authorisation token
post("/token", tokenRoutes::createToken, responseTransformer);
path("/api", () -> {

before("/*", tokenRoutes::validateToken);
get("/checktoken", (req, res) -> "Token is valid");

get("/checktoken", (req, res) -> "Token is valid", responseTransformer);

path("/legacy", () -> {
before("/*", (request, response) -> response.type("text/plain"));
Expand All @@ -75,6 +76,7 @@ public void run() {
path("/reports/locationstatuses", () -> reportsRouteGroup(locationStatusReportsRoutes));
path("/reports/regionsummaries", () -> reportsRouteGroup(regionSummaryReportsRoutes));
path("/external", this::externalRouteGroup);
path("/forum", this::forumRouteGroup);

setupBasicEntityCrudRoutes("/locations", locationsRoutes);
get("/locations", locationsRoutes::readEntities, responseTransformer);
Expand All @@ -83,6 +85,8 @@ public void run() {
post("/decodemessage", messageProcessorRoutes::decodeMessage, responseTransformer);
post("/encodemessage", messageProcessorRoutes::encodeMessage, responseTransformer);

get("/mostwanted", (req, res) -> agentsRoutes.mostWanted(req, res), responseTransformer);

// API endpoint to initiate shutdown
put("/operations/shutdown", this::shutdown);
});
Expand All @@ -103,6 +107,12 @@ public void run() {
get("/healthcheck", (req, res) -> "Server started okay!");
}

private void forumRouteGroup() {
get("", (req, res) -> forumMessageRoutes.readForum(req, res), responseTransformer );
post("/add", (req, res) -> forumMessageRoutes.createForumMessage(req, res), responseTransformer);

}

private void executivesSummaryGroup() {
post("/generate", executiveSummaryRoutes::readExecutiveSummary);
}
Expand All @@ -118,6 +128,7 @@ private void agentsRouteGroup() {
get("/:id", (req, res) -> agentsRoutes.readAgent(req, res, idParamAsInt(req)), responseTransformer);
put("/:id", (req, res) -> agentsRoutes.updateAgent(req, res, idParamAsInt(req)), responseTransformer);
put("/editcallsign/:id", (req, res) -> agentsRoutes.editCallSign(req, res, idParamAsInt(req)), responseTransformer);
put("/mostwanted/:id", (req, res) -> agentsRoutes.editCallSign(req, res, idParamAsInt(req)), responseTransformer);
delete("/:id", (req, res) -> agentsRoutes.deleteAgent(req, res, idParamAsInt(req)), responseTransformer);
get("", (req, res) -> agentsRoutes.readAgents(req, res), responseTransformer);
}
Expand All @@ -133,6 +144,7 @@ private void regionsRouteGroup() {
private void reportsRouteGroup(ReportsRoutesBase<?, ?> reportsRoutes) {
post("", reportsRoutes::createReport, responseTransformer);
get("/:id", (req, res) -> reportsRoutes.readReport(req, res, idParamAsInt(req)), responseTransformer);
put("/:id", (req, res) -> reportsRoutes.updateReport(req, res, idParamAsInt(req)), responseTransformer);
delete("/:id", (req, res) -> reportsRoutes.deleteReport(req, res, idParamAsInt(req)), responseTransformer);
get("", reportsRoutes::searchReports, responseTransformer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.softwire.training.api.models.UserApiModel;
import java.io.IOException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.TimeZone;

public class CustomisedGsonBuilder {

Expand Down Expand Up @@ -73,6 +75,7 @@ private static class ZonedDateTimeAdapter extends TypeAdapter<ZonedDateTime> {

@Override
public void write(JsonWriter jsonWriter, ZonedDateTime localDateTime) throws IOException {

if (localDateTime == null) {
jsonWriter.nullValue();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ public void verifyIsAdminOrRelevantUser(Request req, int relevantUserId) {
}

public void verifyIsAdminOrRelevantAgent(Request req, int relevantAgentId) {

verifyUser(req, user -> user.isAdmin() || (user.getAgentId() != null && user.getAgentId() == relevantAgentId));
}

public void verifyisAgentorAdmin(Request req) {
verifyUser(req, user -> user.isAdmin() || (user.getAgentId() != null));
}

public void verifyIsAgent(Request req) {
verifyUser(req, user -> user.getAgentId() != null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public void setReportTitle(String reportTitle) {
this.reportTitle = reportTitle;
}


public int getLocationId() {
return locationId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.softwire.training.api.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MostWantedApiModel {
String title;
String description;
MostWantedSuspectImage[] images;

public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

public MostWantedSuspectImage[] getImages() {
return images;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.softwire.training.api.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MostWantedSuspectImage {
String original;

public String getOriginal() {
return original;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.softwire.training.api.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MostWantedWrapper {
public MostWantedApiModel[] items;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class ReportApiModelBase {

private int reportId;
private byte status;
private int status;
private ZonedDateTime reportTime;
private String reportBody;
private int agentId;
Expand All @@ -18,11 +18,11 @@ public void setReportId(int reportId) {
this.reportId = reportId;
}

public byte getStatus() {
public int getStatus() {
return status;
}

public void setStatus(byte status) {
public void setStatus(int status) {
this.status = status;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.softwire.training.api.routes.v1;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.softwire.training.api.core.JsonRequestUtils;
import org.softwire.training.api.core.PermissionsVerifier;
import org.softwire.training.api.models.ErrorCode;
import org.softwire.training.api.models.FailedRequestException;
import org.softwire.training.api.models.*;
import org.softwire.training.db.daos.AgentsDao;
import org.softwire.training.models.Agent;
import spark.Request;
import spark.Response;

import javax.inject.Inject;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.time.LocalDate;
import java.util.NoSuchElementException;
import java.util.Optional;

public class AgentsRoutes {

Expand Down Expand Up @@ -54,11 +54,27 @@ public List<Agent> readAgents(Request req, Response res) {
public Agent updateAgent(Request req, Response res, int id) {
permissionsVerifier.verifyIsAdminOrRelevantAgent(req, id);

try{
Agent agent = JsonRequestUtils.readBodyAsType(req, Agent.class);
} catch (Exception e){
throw new FailedRequestException(ErrorCode.INVALID_INPUT, "Rank is too high (max 11 digits).");
}

Agent agent = JsonRequestUtils.readBodyAsType(req, Agent.class);

if (agent.getFirstName().length() > 20){
throw new FailedRequestException(ErrorCode.INVALID_INPUT, "first name too long (max 20 characters)");
}

if (agent.getLastName().length() > 20){
throw new FailedRequestException(ErrorCode.INVALID_INPUT, "Last name too long (max 20 characters)");
}

agent.setAgentId(id);
agentsDao.updateAgent(agent);

return agent;

}

public Object deleteAgent(Request req, Response res, int id) {
Expand All @@ -82,4 +98,14 @@ public Agent editCallSign (Request req, Response res, int agentID) {
agentsDao.updateAgent(agent);
return agent;
}

public MostWantedApiModel[] mostWanted (Request req, Response res) {
Client client = ClientBuilder.newBuilder().register(JacksonFeature.class).hostnameVerifier((s1, s2) -> true).build();
MostWantedWrapper mostwanted = client
.target("https://api.fbi.gov/@wanted?pageSize=10&page=1&sort_on=modified&sort_order=desc&person_classification=main&status=na")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(MostWantedWrapper.class);

return mostwanted.items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.softwire.training.api.routes.v1;

import org.softwire.training.api.core.JsonRequestUtils;
import org.softwire.training.api.core.PermissionsVerifier;
import org.softwire.training.api.models.ErrorCode;
import org.softwire.training.api.models.FailedRequestException;
import org.softwire.training.db.daos.ForumMessageDao;
import org.softwire.training.models.ForumMessage;
import org.softwire.training.models.User;
import spark.Request;
import spark.Response;

import javax.inject.Inject;
import java.util.List;

public class ForumMessageRoutes {

private final ForumMessageDao forumMessageDao;
private final PermissionsVerifier permissionsVerifier;

@Inject
public ForumMessageRoutes(ForumMessageDao forumMessageDao, PermissionsVerifier permissionsVerifier) {
this.forumMessageDao = forumMessageDao;
this.permissionsVerifier = permissionsVerifier;
}

public List<ForumMessage> readForum(Request req, Response res) {
permissionsVerifier.verifyisAgentorAdmin(req);
return forumMessageDao.getForumMessages();
}

public ForumMessage createForumMessage(Request req, Response res) {
ForumMessage forumMessageModel = JsonRequestUtils.readBodyAsType(req, ForumMessage.class);
permissionsVerifier.verifyisAgentorAdmin(req);

User user = new User();
user.setUserId(req.attribute("user_id"));
forumMessageModel.setUser(user);

int MessageId = forumMessageDao.createForum(forumMessageModel);
forumMessageModel.setMessageId(MessageId);

// Create requests should return 201
res.status(201);

return forumMessageModel;
}

public ForumMessage readForum(Request req, Response res, int id) {
permissionsVerifier.verifyisAgentorAdmin(req);
return forumMessageDao.getForumMessage(id)
.orElseThrow(() -> new FailedRequestException(ErrorCode.NOT_FOUND, "Forum not found"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ protected LocationStatusReport validateThenMap(LocationStatusReportApiModel apiM
LocalDateTime reportTimeUtc = LocalDateTime.now(ZoneOffset.UTC);

LocationStatusReport model = new LocationStatusReport();
model.setStatus(apiModel.getStatus());

if (model.getStatus() > 100 || model.getStatus() <= 0){
throw new FailedRequestException(ErrorCode.UNKNOWN_ERROR, "Status code must be between 1 and 100.");
}

model.setAgentId(apiModel.getAgentId());
model.setLocationId(apiModel.getLocationId());
model.setStatus(apiModel.getStatus());
model.setReportTime(reportTimeUtc);
model.setReportBody(apiModel.getReportBody());
model.setReportTitle(apiModel.getReportTitle());
Expand Down Expand Up @@ -105,6 +110,9 @@ protected List<ReportSearchCriterion> parseSearchCriteria(Request req) {
searchCriteria.add(new ToTimeSearchCriterion(ZonedDateTime.parse(queryMap.get("toTime").value())));
}

if (!isNullOrEmpty(queryMap.get("agentId").value())) {
searchCriteria.add(new AgentIdSearchCriterion(queryMap.get("agentId").integerValue()));
}
return searchCriteria;
}
}
Loading