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

Added a staging area endpoint that accepts raw JSON for direct insertion #222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -679,6 +679,34 @@ public ResponseEntity<Object> updateImport(@RequestBody JsonNode updatedJson,
return new ResponseEntity<>(GsrsControllerUtil.enhanceWithView(itmd, queryParameters), HttpStatus.OK);
}

@hasAdminRole
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This makes sense.

@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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good point.
We have the same requirement for the /import endpoint and I copied it.
The other issue: how do we map from 'substances' to 'ix.ginas.models.v1.Substance?'

Objects.requireNonNull(entityType, "Must supply entityType (class of object to create)");
String adapterName = queryParameters.get("adapter");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.
But omitting a value in a POST worked fine.


String fileName = queryParameters.containsKey("fileName") ? queryParameters.get("fileName") : "POSTed JSON";
StagingAreaService stagingAreaService = getDefaultStagingAreaService();
ImportUtilities<T> importUtilities = new ImportUtilities<>(getEntityService().getContext(), getEntityService().getEntityClass(),
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ public JsonNode handleObjectCreationAsync(AbstractImportSupportingGsrsEntityCont
public String saveStagingAreaRecord(String json, AbstractImportSupportingGsrsEntityController.ImportTaskMetaData importTaskMetaData, Principal creatingUser) {
log.trace("in saveStagingAreaRecord,importTaskMetaData.getEntityType(): {}, file name: {}, adapter",
importTaskMetaData.getEntityType(), importTaskMetaData.getFilename(), importTaskMetaData.getAdapter());
if(creatingUser==null ){
creatingUser= (GsrsSecurityUtils.getCurrentUsername()!=null && GsrsSecurityUtils.getCurrentUsername().isPresent())
? principalRepository.findDistinctByUsernameIgnoreCase(GsrsSecurityUtils.getCurrentUsername().get())
: null;
}
ImportRecordParameters.ImportRecordParametersBuilder builder=
ImportRecordParameters.builder()
.jsonData(json)
Expand Down