@Override public synchronized List<SchemaField> getOrCreateCollectionFields(String project, String collection, Set<SchemaField> fields) throws NotExistsException { ValidationUtil.checkCollectionValid(collection); Map<String, List<SchemaField>> list = collections.get(project); if (list == null) { throw new NotExistsException("Project"); } List<SchemaField> schemaFields = list.computeIfAbsent(collection, (key) -> new ArrayList<>()); fields.stream() .filter(field -> !schemaFields.stream().anyMatch(f -> f.getName().equals(field.getName()))) .forEach(schemaFields::add); return schemaFields; }
@Override public void alter(String project, MaterializedView view) { Set<MaterializedView> materializedViews = this.materializedViews.computeIfAbsent(project, (key) -> new HashSet<>()); if (!materializedViews.contains(view)) { throw new NotExistsException("Materialized view"); } materializedViews.add(view); } }
@Override public synchronized void changeMaterializedView(String project, String tableName, boolean realTime) { Set<MaterializedView> materializedViews = this.materializedViews.get(project); MaterializedView materializedView = materializedViews.stream().filter(e -> e.tableName.equals(tableName)) .findAny().orElseThrow(() -> new NotExistsException("Materialized view")); materializedViews.remove(materializedView); materializedViews.add(new MaterializedView(materializedView.tableName, materializedView.name, materializedView.query, materializedView.updateInterval, materializedView.incremental, realTime, materializedView.options)); }
if (currentFields.isEmpty()) { if (!getProjects().contains(project)) { throw new NotExistsException("Project");
if (currentFields.isEmpty()) { if (!getProjects().contains(ValidationUtil.checkProject(project))) { throw new NotExistsException("Project");
public void delete(String project, String tableName) { try (Handle handle = dbi.open()) { int execute = handle.createStatement("DELETE FROM realtime_reports WHERE project = :project AND table_name = :table_name") .bind("project", project) .bind("table_name", tableName).execute(); if (execute == 0) { throw new NotExistsException("Report"); } } }
throw new NotExistsException("Project");
public QueryExecution executeQuery(RequestContext context, String sqlQuery, Optional<QuerySampling> sample, String defaultSchema, ZoneId zoneId, int limit) { if (!projectExists(context.project)) { throw new NotExistsException("Project");
public void delete(Integer userId, int project, String slug) { try (Handle handle = dbi.open()) { int execute = handle.createStatement("DELETE FROM reports WHERE project_id = :project AND slug = :slug" + " AND (:user is null or user_id = :user or (SELECT user_id = :user FROM web_user_project WHERE id = :project))") .bind("project", project) .bind("slug", slug) .bind("user", userId).execute(); if (execute == 0) { throw new NotExistsException("Report"); } } }
@Override public MaterializedView getMaterializedView(String project, String tableName) { Map<String, AttributeValue> item = dynamoDBClient.getItem(new GetItemRequest().withTableName(tableConfig.getTableName()) .withAttributesToGet("value") .withKey(of( "project", new AttributeValue(project), "type_table_name", new AttributeValue("materialized_" + tableName)))).getItem(); if (item == null) { throw new NotExistsException("Materialized view"); } return JsonHelper.read(item.get("value").getS(), MaterializedView.class); }
@JsonRequest @ApiOperation(value = "Delete dashboard item") @Path("/delete") @ProtectEndpoint(writeOperation = true) public SuccessMessage delete(@Named("user_id") Project project, @ApiParam("id") int dashboard) { try (Handle handle = dbi.open()) { int execute = handle.createStatement("DELETE FROM dashboard WHERE id = :id and project_id = :project") .bind("id", dashboard).bind("project", project.project).execute(); if (execute == 0) { throw new NotExistsException("Dashboard"); } } return SuccessMessage.success(); }
@Override public void changeMaterializedView(String project, String tableName, boolean realTime) { try (Handle handle = dbi.open()) { int execute = handle.createStatement("UPDATE materialized_views SET real_time = :real_time " + "WHERE project = :project AND table_name = :table_name") .bind("project", project) .bind("table_name", tableName) .bind("real_time", realTime) .execute(); if (execute == 0) { throw new NotExistsException("Materialized view"); } } }
@Override public MaterializedView load(ProjectCollection key) throws Exception { try (Handle handle = dbi.open()) { MaterializedView first = handle.createQuery("SELECT project, name, query, table_name, update_interval, last_updated, incremental, real_time, options " + "from materialized_views WHERE project = :project AND table_name = :name") .bind("project", key.project) .bind("name", key.collection) .map(materializedViewMapper).first(); if (first == null) { throw new NotExistsException("Materialized view"); } return first; } } });
public Report get(Integer requestedUserId, int project, String slug) { try (Handle handle = dbi.open()) { Report report = handle.createQuery("SELECT r.project_id, r.slug, r.category, r.name, query, r.options, r.query_options, r.shared, r.user_id, web_user.email FROM reports r " + " LEFT JOIN web_user_api_key permission ON (permission.project_id = r.project_id)" + " JOIN web_user ON (web_user.id = r.user_id)" + " WHERE r.project_id = :project AND r.slug = :slug AND (" + "((permission.master_key IS NOT NULL OR r.shared OR r.user_id = :requestedUser)))") .bind("project", project) .bind("requestedUser", requestedUserId) .bind("slug", slug).map(mapper).first(); if (report == null) { throw new NotExistsException("Report"); } return report; } }
@Override public void alter(String project, MaterializedView view) { try (Handle handle = dbi.open()) { int execute = handle.createStatement("UPDATE materialized_views SET query = :query, table_name = :table_name, update_interval = :update_interval, incremental = :incremental, real_time = :real_time, options = :options " + "WHERE project = :project AND table_name = :table_name") .bind("project", project) .bind("name", view.name) .bind("table_name", view.tableName) .bind("query", view.query) .bind("update_interval", view.updateInterval != null ? view.updateInterval.toMillis() : null) .bind("incremental", view.incremental) .bind("real_time", view.realTime) .bind("options", JsonHelper.encode(view.options)) .execute(); if (execute == 0) { throw new NotExistsException("Materialized view"); } } }
throw new NotExistsException("Dashboard");
throw new NotExistsException("Project");