Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #96 from multinet-app/csv_validation
Browse files Browse the repository at this point in the history
Specify which keys are duplicate and fix front-end bug
  • Loading branch information
jjnesbitt committed Jul 25, 2019
2 parents ec34b29 + 4d94f0f commit 24fbc9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
8 changes: 4 additions & 4 deletions client/src/views/WorkspaceDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<v-card-text>
<v-layout row wrap>
<v-flex>
<v-text-field v-model="newTable" placeholder="name your table" solo :error-messages="tableCreationErrors"/>
<v-text-field v-model="newTable" placeholder="name your table" solo :error-messages="tableCreationError"/>
</v-flex>
</v-layout>
<v-layout row wrap>
Expand Down Expand Up @@ -205,7 +205,7 @@ export default {
selectedType: null,
graphNodeTables: [],
graphEdgeTable: null,
tableCreationErrors: [],
tableCreationError: null,
}
},
computed: {
Expand Down Expand Up @@ -268,10 +268,10 @@ export default {
},
}
);
this.tableCreationErrors = [];
this.tableCreationError = null;
this.update()
} catch(err) {
this.tableCreationErrors.push(err.response.data.message);
this.tableCreationError = err.response.data.message;
}
},
Expand Down
25 changes: 19 additions & 6 deletions multinet/multinet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ def graphql_query(query, variables=None):
return dict(data=result.data, errors=errors, query=query)


def validate_csv(rows):
"""Perform any necessary CSV validation, and raise appropriate exceptions."""
# Check for key uniqueness
if ('_key' in rows.fieldnames):
keys = [row['_key'] for row in rows]
uniqueKeys = set()
duplicates = set()
for key in keys:
if key in uniqueKeys:
duplicates.add(key)
else:
uniqueKeys.add(key)

if (len(duplicates) > 0):
raise RestException(f'CSV Validation Failed: Duplicate Keys {", ".join(duplicates)}.')


class MultiNet(Resource):
"""Define the MultiNet API within Girder."""

Expand Down Expand Up @@ -95,12 +112,8 @@ def bulk(self, params, workspace=None, table=None):
rows = csv.DictReader(StringIO(cherrypy.request.body.read().decode('utf8')))
workspace = db.db(workspace)

# Check for key uniqueness
if ('_key' in rows.fieldnames):
keys = [row['_key'] for row in rows]
uniqueKeys = set(keys)
if len(keys) != len(uniqueKeys):
raise RestException('CSV Validation Failed: Non-unique key detected.')
# Do any CSV validation necessary, and raise appropriate exceptions
validate_csv(rows)

# Set the collection, paying attention to whether the data contains
# _from/_to fields.
Expand Down

0 comments on commit 24fbc9c

Please sign in to comment.