-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added a staging area endpoint that accepts raw JSON for direct insertion #222
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,34 @@ public ResponseEntity<Object> updateImport(@RequestBody JsonNode updatedJson, | |
return new ResponseEntity<>(GsrsControllerUtil.enhanceWithView(itmd, queryParameters), HttpStatus.OK); | ||
} | ||
|
||
@hasAdminRole | ||
@PostGsrsRestApiMapping(value = {"/stagingArea"}) | ||
public ResponseEntity<Object> createEntity(@RequestBody String newEntity, | ||
@RequestParam Map<String, String> queryParameters) throws Exception { | ||
log.trace("in createEntity"); | ||
String entityType = queryParameters.get("entityType");//type of domain object to create | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this be a POST at a level like "/api/v1/substances/stagingArea", does the client really need to tell you it's for substances again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. |
||
Objects.requireNonNull(entityType, "Must supply entityType (class of object to create)"); | ||
String adapterName = queryParameters.get("adapter"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this particular case I think we're expecting they're POSTing the JSON directly, so they shouldn't need an adapter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or if it is an adapter, it should be essentially a no-op one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the adapter parameter because it's used within the formalism of the ImportTaskMetaData. |
||
|
||
String fileName = queryParameters.containsKey("fileName") ? queryParameters.get("fileName") : "POSTed JSON"; | ||
StagingAreaService stagingAreaService = getDefaultStagingAreaService(); | ||
ImportUtilities<T> importUtilities = new ImportUtilities<>(getEntityService().getContext(), getEntityService().getEntityClass(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like it should already be in a registry, is it? |
||
stagingAreaService); | ||
AutowireHelper.getInstance().autowire(importUtilities); | ||
ImportTaskMetaData task = new ImportTaskMetaData(); | ||
task.setAdapter(adapterName); | ||
task.setEntityType(entityType); | ||
task.setFilename(fileName); | ||
task.setInternalUuid(UUID.randomUUID()); | ||
task.setSize((long) newEntity.length()); | ||
task.setAdapterSettings(JsonNodeFactory.instance.objectNode()); | ||
String result= importUtilities.saveStagingAreaRecord(newEntity, task, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could figure out the user here, no? And pass it? I think it's probably better to do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user is figured out by ImportUtilities. I avoided duplicating the process here. |
||
|
||
ObjectNode resultsNode = JsonNodeFactory.instance.objectNode(); | ||
resultsNode.put("results", result); | ||
return new ResponseEntity<>(GsrsControllerUtil.enhanceWithView(resultsNode, queryParameters), HttpStatus.OK); | ||
} | ||
|
||
//STEP 3.5: Preview import | ||
//May required additional work | ||
@hasAdminRole | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to adjust this for staging area and have some more configurable set of roles that can see the staging area. I currently think it may be best for super users or perhaps even users that are in a specific group ... maybe admins or "staging area registrars"? Can we make this configurable somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense.