From e368a519e912a96c35e172726ed7763f580f1572 Mon Sep 17 00:00:00 2001 From: Mitch Miller Date: Wed, 25 Oct 2023 23:33:43 -0400 Subject: [PATCH] Added a staging area endpoint that accepts raw JSON for direct insertion into the staging area. --- ...tImportSupportingGsrsEntityController.java | 27 +++++++++++++++++++ .../java/gsrs/imports/ImportUtilities.java | 5 ++++ 2 files changed, 32 insertions(+) diff --git a/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/controller/AbstractImportSupportingGsrsEntityController.java b/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/controller/AbstractImportSupportingGsrsEntityController.java index 1b0f28a8..95bd3036 100644 --- a/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/controller/AbstractImportSupportingGsrsEntityController.java +++ b/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/controller/AbstractImportSupportingGsrsEntityController.java @@ -679,6 +679,33 @@ public ResponseEntity updateImport(@RequestBody JsonNode updatedJson, return new ResponseEntity<>(GsrsControllerUtil.enhanceWithView(itmd, queryParameters), HttpStatus.OK); } + @hasAdminRole + @PostGsrsRestApiMapping(value = {"/stagingArea"}) + public ResponseEntity createEntity(@RequestBody String newEntity, + @RequestParam Map 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 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 diff --git a/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/imports/ImportUtilities.java b/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/imports/ImportUtilities.java index c7240f55..a1a20265 100644 --- a/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/imports/ImportUtilities.java +++ b/gsrs-spring-boot-autoconfigure/src/main/java/gsrs/imports/ImportUtilities.java @@ -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)