All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fivefaces.structureclient.controller.UtilsController Maven / Gradle / Ivy

There is a newer version: 1.0.62
Show newest version
package com.fivefaces.structureclient.controller;

import com.fivefaces.common.exception.ItemNotFoundException;
import com.fivefaces.structure.schema.StructureSchema;
import com.fivefaces.structure.service.StructureSchemaLoader;
import com.fivefaces.structureclient.domain.StructureSchemaWorkflowScaffold;
import com.fivefaces.structureclient.service.statemachine.ScaffoldStateMachineResult;
import com.fivefaces.structureclient.service.statemachine.ScaffoldStateMachineService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/utils")
@Slf4j
public class UtilsController extends AbstractStructureController {

    private final ScaffoldStateMachineService scaffoldStateMachineService;
    private final StructureSchemaLoader structureSchemaLoader;
    private final StructureSchemaWorkflowScaffold structureSchemaWorkflowScaffold;

    @PostMapping("/stateMachine/englishToAws")
    @ResponseBody
    public ResponseEntity englishToAws(@RequestBody Map input) throws Exception {
        return ResponseEntity.ok(scaffoldStateMachineService.scaffold(input.get("query")));
    }

    @PostMapping("/structures/scaffold")
    @ResponseBody
    public ResponseEntity> scaffoldStructure(@RequestBody String structureName) throws Exception {
        structureSchemaLoader.reloadStructureSchemas();
        StructureSchema structureSchema = structureSchemaLoader.getTargetSchemas().get(structureName);
        if (structureSchema == null) {
            throw new ItemNotFoundException(structureName + " is not defined");
        }
        return ResponseEntity.ok(structureSchemaWorkflowScaffold.scaffold(structureSchema));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy