Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed Source Summary #529

Merged
merged 15 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -9,9 +9,11 @@
import com.conveyal.datatools.manager.extensions.ExternalFeedResource;
import com.conveyal.datatools.manager.jobs.FetchSingleFeedJob;
import com.conveyal.datatools.manager.jobs.NotifyUsersForSubscriptionJob;
import com.conveyal.datatools.manager.models.DeploymentSummary;
import com.conveyal.datatools.manager.models.ExternalFeedSourceProperty;
import com.conveyal.datatools.manager.models.FeedRetrievalMethod;
import com.conveyal.datatools.manager.models.FeedSource;
import com.conveyal.datatools.manager.models.FeedSourceSummary;
import com.conveyal.datatools.manager.models.JsonViews;
import com.conveyal.datatools.manager.models.Project;
import com.conveyal.datatools.manager.models.transform.NormalizeFieldTransformation;
Expand Down Expand Up @@ -395,6 +397,20 @@ protected static FeedSource cleanFeedSourceForNonAdmins(FeedSource feedSource, b
return feedSource;
}

private static Collection<FeedSourceSummary> getAllFeedSourceSummaries(Request req, Response res) {
Auth0UserProfile userProfile = req.attribute("user");
String projectId = req.queryParams("projectId");
Project project = Persistence.projects.getById(projectId);
if (project == null) {
logMessageAndHalt(req, 400, "Must provide valid projectId value.");
}
if (!userProfile.canAdministerProject(project)) {
logMessageAndHalt(req, 401, "User not authorized to view project feed sources.");
}
return project.retrieveFeedSourceSummaries();
}


// FIXME: use generic API controller and return JSON documents via BSON/Mongo
public static void register (String apiPrefix) {
get(apiPrefix + "secure/feedsource/:id", FeedSourceController::getFeedSource, json::write);
Expand All @@ -404,5 +420,6 @@ public static void register (String apiPrefix) {
put(apiPrefix + "secure/feedsource/:id/updateExternal", FeedSourceController::updateExternalFeedResource, json::write);
delete(apiPrefix + "secure/feedsource/:id", FeedSourceController::deleteFeedSource, json::write);
post(apiPrefix + "secure/feedsource/:id/fetch", FeedSourceController::fetch, json::write);
get(apiPrefix + "secure/feedsourceSummaries", FeedSourceController::getAllFeedSourceSummaries, json::write);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -459,71 +458,6 @@ public String latestVersionId() {
return latest != null ? latest.id : null;
}

/**
* The deployed feed version.
* This cannot be returned because of a circular reference between feed source and feed version. Instead, individual
* parameters (version id, start date and end date) are returned.
*/
@JsonIgnore
@BsonIgnore
private FeedVersionDeployed deployedFeedVersion;

/**
* This value is set to true once an attempt has been made to get the deployed feed version. This prevents subsequent
* attempts by Json annotated properties to get a deployed feed version that is not available.
*/
@JsonIgnore
@BsonIgnore
private boolean deployedFeedVersionDefined;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonView(JsonViews.UserInterface.class)
@JsonProperty("deployedFeedVersionId")
@BsonIgnore
public String getDeployedFeedVersionId() {
deployedFeedVersion = retrieveDeployedFeedVersion();
return deployedFeedVersion != null ? deployedFeedVersion.id : null;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonView(JsonViews.UserInterface.class)
@JsonProperty("deployedFeedVersionStartDate")
@BsonIgnore
public LocalDate getDeployedFeedVersionStartDate() {
deployedFeedVersion = retrieveDeployedFeedVersion();
return deployedFeedVersion != null ? deployedFeedVersion.startDate : null;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonView(JsonViews.UserInterface.class)
@JsonProperty("deployedFeedVersionEndDate")
@BsonIgnore
public LocalDate getDeployedFeedVersionEndDate() {
deployedFeedVersion = retrieveDeployedFeedVersion();
return deployedFeedVersion != null ? deployedFeedVersion.endDate : null;
}

/**
* Get deployed feed version for this feed source.
*
* If a project has a "pinned" deployment, return the feed version from this pinned deployment. If it is not
* available return null and don't attempt to get the feed version from the latest deployment.
*
* If a project does not have a "pinned" deployment, return the latest deployment's feed versions for this feed
* source, if available.
*/
public FeedVersionDeployed retrieveDeployedFeedVersion() {
if (deployedFeedVersionDefined) {
return deployedFeedVersion;
}
Project project = Persistence.projects.getById(projectId);
deployedFeedVersion = (project.pinnedDeploymentId != null && !project.pinnedDeploymentId.isEmpty())
? FeedVersionDeployed.getFeedVersionFromPinnedDeployment(projectId, id)
: FeedVersionDeployed.getFeedVersionFromLatestDeployment(projectId, id);
deployedFeedVersionDefined = true;
return deployedFeedVersion;
}

/**
* Number of {@link FeedVersion}s that exist for the feed source.
*/
Expand Down
Loading
Loading