Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
*/
@SuppressWarnings({"unused", "ThrowableNotThrown"})
public class ProjectController {

// TODO We can probably replace this with something from Mongo so we use one JSON serializer / deserializer throughout
private static JsonManager<Project> json = new JsonManager<>(Project.class, JsonViews.UserInterface.class);
private static final Logger LOG = LoggerFactory.getLogger(ProjectController.class);

/**
Expand Down Expand Up @@ -316,20 +313,28 @@ private static Project thirdPartySync(Request req, Response res) {
* A bit too static/global for an OO language, but that's how Spark works.
*/
public static void register (String apiPrefix) {
get(apiPrefix + "secure/project/:id", ProjectController::getProject, json::write);
get(apiPrefix + "secure/project", ProjectController::getAllProjects, json::write);
post(apiPrefix + "secure/project", ProjectController::createProject, json::write);
put(apiPrefix + "secure/project/:id", ProjectController::updateProject, json::write);
delete(apiPrefix + "secure/project/:id", ProjectController::deleteProject, json::write);
get(apiPrefix + "secure/project/:id/thirdPartySync/:type", ProjectController::thirdPartySync, json::write);
post(apiPrefix + "secure/project/:id/fetch", ProjectController::fetch, json::write);
post(apiPrefix + "secure/project/:id/deployPublic", ProjectController::publishPublicFeeds, json::write);
// Construct JSON managers which help serialize the response. Slim JSON is the generic JSON view. Full JSON
// contains additional fields (at the moment just #otpServers) and should only be used when the controller
// returns a single project (slimJson is better suited for a collection). If fullJson is attempted for use
// with a collection, massive performance issues will ensure (mainly due to multiple calls to AWS EC2).
JsonManager<Project> slimJson = new JsonManager<>(Project.class, JsonViews.UserInterface.class);
JsonManager<Project> fullJson = new JsonManager<>(Project.class, JsonViews.UserInterface.class);
fullJson.addMixin(Project.class, Project.ProjectWithOtpServers.class);

get(apiPrefix + "secure/project/:id", ProjectController::getProject, fullJson::write);
get(apiPrefix + "secure/project", ProjectController::getAllProjects, slimJson::write);
post(apiPrefix + "secure/project", ProjectController::createProject, fullJson::write);
put(apiPrefix + "secure/project/:id", ProjectController::updateProject, fullJson::write);
delete(apiPrefix + "secure/project/:id", ProjectController::deleteProject, fullJson::write);
get(apiPrefix + "secure/project/:id/thirdPartySync/:type", ProjectController::thirdPartySync, fullJson::write);
post(apiPrefix + "secure/project/:id/fetch", ProjectController::fetch, fullJson::write);
post(apiPrefix + "secure/project/:id/deployPublic", ProjectController::publishPublicFeeds, fullJson::write);

get(apiPrefix + "secure/project/:id/download", ProjectController::mergeProjectFeeds);
get(apiPrefix + "secure/project/:id/downloadtoken", ProjectController::getFeedDownloadCredentials, json::write);
get(apiPrefix + "secure/project/:id/downloadtoken", ProjectController::getFeedDownloadCredentials, fullJson::write);

get(apiPrefix + "public/project/:id", ProjectController::getProject, json::write);
get(apiPrefix + "public/project", ProjectController::getAllProjects, json::write);
get(apiPrefix + "public/project/:id", ProjectController::getProject, fullJson::write);
get(apiPrefix + "public/project", ProjectController::getAllProjects, slimJson::write);
get(apiPrefix + "downloadprojectfeed/:token", ProjectController::downloadMergedFeedWithToken);
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/conveyal/datatools/manager/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class Project extends Model {
* project as well as those that belong to no project.
* @return
*/
@JsonProperty("otpServers")
public List<OtpServer> availableOtpServers() {
return Persistence.servers.getFiltered(or(
eq("projectId", this.id),
Expand Down Expand Up @@ -111,4 +110,17 @@ public void delete() {
// Finally, delete the project.
Persistence.projects.removeById(this.id);
}

/**
* A MixIn to be applied to this project, for returning a single project, so that the list of otpServers is
* included in the JSON response.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: javadoc copy pasta

*
* Usually a mixin would be used on an external class, but since we are changing one thing about a single class, it
* seemed unnecessary to define a new view.
*/
public abstract static class ProjectWithOtpServers {

@JsonProperty("otpServers")
public abstract Collection<OtpServer> availableOtpServers ();
}
}