com.mntviews.base.controller.BaseController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mnt-base Show documentation
Show all versions of mnt-base Show documentation
Basis for mnt-bridge services
The newest version!
package com.mntviews.base.controller;
import com.mntviews.base.controller.exception.BaseControllerException;
import com.mntviews.base.service.BridgeBaseService;
import com.mntviews.bridge.model.ExtensionResponseData;
import com.mntviews.bridge.model.RawData;
import com.mntviews.bridge.service.BridgeExtension;
import com.mntviews.bridge.service.TypeOfGen;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/api/v1/")
public class BaseController {
private final static Logger log = LoggerFactory.getLogger(BaseController.class);
public BaseController(BridgeBaseService bridgeBaseService) {
this.bridgeBaseService = bridgeBaseService;
}
private final BridgeBaseService bridgeBaseService;
@PostMapping(value = "/{groupTag}/{metaTag}/send/")
public ResponseEntity send(@RequestBody String payload, @PathVariable String groupTag, @PathVariable String metaTag, @RequestParam(required = false) String dbTag, @RequestParam(required = false) String fId
, @RequestParam(value = "typeOfGen", required = false) String typeOfGenAsString) {
try {
TypeOfGen typeOfGen = TypeOfGen.valueOfString(typeOfGenAsString);
return new ResponseEntity<>(bridgeBaseService.getBridgeBase().findModule(groupTag, metaTag).getBridgeExtension().sendOne(dbTag, RawData.custom().withFId(fId).withFPayload(payload).withFGroupId(fId).build(), typeOfGen), HttpStatus.OK);
} catch (Exception e) {
throw new BaseControllerException(e);
}
}
@PostMapping(value = "/{groupTag}/{metaTag}/sendRaw/")
public ResponseEntity sendRaw(@RequestBody RawData payload, @PathVariable String groupTag, @PathVariable String metaTag, @RequestParam(required = false) String dbTag
, @RequestParam(value = "typeOfGen", required = false) String typeOfGenAsString) {
try {
TypeOfGen typeOfGen = TypeOfGen.valueOfString(typeOfGenAsString);
return new ResponseEntity<>(bridgeBaseService.getBridgeBase().findModule(groupTag, metaTag).getBridgeExtension().sendOne(dbTag, RawData.custom().withFId(payload.getFId()).withFPayload(payload.getFPayload()).withFMsg(payload.getFMsg()).build(), typeOfGen), HttpStatus.OK);
} catch (Exception e) {
throw new BaseControllerException(e);
}
}
@PostMapping(value = "/{groupTag}/{metaTag}/sendAndExecute/")
public ResponseEntity execute(@RequestBody String payload, @PathVariable String groupTag, @PathVariable String metaTag, @RequestParam(required = false) String dbTag) {
try {
ExtensionResponseData extensionResponseData = bridgeBaseService.getBridgeBase().findModule(groupTag, metaTag).getBridgeExtension().sendAndExecuteOne(dbTag, RawData.custom().withFPayload(payload).build(), BridgeExtension.DEFAULT_ATTEMPT_COUNT);
return new ResponseEntity<>(extensionResponseData, HttpStatus.OK);
} catch (Exception e) {
throw new BaseControllerException(e);
}
}
@PostMapping(value = "/{groupTag}/{metaTag}/executeOne/{rawId}/")
public ResponseEntity executeOne(@RequestBody(required=false) String fMsg,@PathVariable String groupTag, @PathVariable String metaTag, @PathVariable Long rawId, @RequestParam(required = false) String dbTag) {
try {
ExtensionResponseData extensionResponseData = bridgeBaseService.getBridgeBase().findModule(groupTag, metaTag).getBridgeExtension().executeOneAndReceive(dbTag, rawId, fMsg);
return new ResponseEntity<>(extensionResponseData, HttpStatus.OK);
} catch (Exception e) {
throw new BaseControllerException(e);
}
}
@PostMapping(value = {"/{groupTag}/{metaTag}/execute/", "/{groupTag}/{metaTag}/execute/{groupId}/"})
public ResponseEntity execute(@RequestBody(required=false) String fMsg,@PathVariable String groupTag, @PathVariable String metaTag, @PathVariable(required = false) Long groupId, @RequestParam(required = false) String dbTag) {
try {
return new ResponseEntity<>(bridgeBaseService.getBridgeBase().findModule(groupTag, metaTag).getBridgeExtension().execute(dbTag,fMsg), HttpStatus.OK);
} catch (Exception e) {
throw new BaseControllerException(e);
}
}
@GetMapping(value = "/{groupTag}/{metaTag}/receive/")
public ResponseEntity receive(@PathVariable String groupTag, @PathVariable String metaTag, @RequestParam(required = false) String dbTag, @RequestParam String fId, @RequestParam(required = false) Long rawId) {
try {
ExtensionResponseData extensionResponseData = bridgeBaseService.getBridgeBase().findModule(groupTag, metaTag).getBridgeExtension().receiveOne(dbTag, fId, rawId, BridgeExtension.DEFAULT_ATTEMPT_COUNT);
return new ResponseEntity<>(extensionResponseData, HttpStatus.OK);
} catch (Exception e) {
throw new BaseControllerException(e);
}
}
@ExceptionHandler(BaseControllerException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ResponseEntity handleInternalServerErrorException(BaseControllerException
mainControllerException) {
log.error(com.mntviews.Util.getStackTrace(mainControllerException));
return new ResponseEntity<>(mainControllerException.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}