Skip to content

Commit

Permalink
Added a staging area endpoint that accepts raw JSON for direct insertion
Browse files Browse the repository at this point in the history
into the staging area.
  • Loading branch information
ChemMitch committed Oct 26, 2023
1 parent 09e71c6 commit e368a51
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,33 @@ 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
Objects.requireNonNull(entityType, "Must supply entityType (class of object to create)");
String adapterName = queryParameters.get("adapter");

StagingAreaService stagingAreaService = getDefaultStagingAreaService();
ImportUtilities<T> importUtilities = new ImportUtilities<>(getEntityService().getContext(), getEntityService().getEntityClass(),
stagingAreaService);
AutowireHelper.getInstance().autowire(importUtilities);
ImportTaskMetaData task = new ImportTaskMetaData();
task.setAdapter(adapterName);
task.setEntityType(entityType);
task.setFilename("POSTed JSON");
task.setInternalUuid(UUID.randomUUID());
task.setSize((long) newEntity.length());
task.setAdapterSettings(JsonNodeFactory.instance.objectNode());
String result= importUtilities.saveStagingAreaRecord(newEntity, task, null);

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

0 comments on commit e368a51

Please sign in to comment.