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

com.mx.path.model.mdx.web.controller.TransfersController Maven / Gradle / Ivy

The newest version!
package com.mx.path.model.mdx.web.controller;

import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.transfer.Transfer;
import com.mx.path.model.mdx.model.transfer.options.TransferListOptions;
import com.mx.path.model.mdx.web.model.transfer.TransferListQueryParameters;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA)
public class TransfersController extends BaseController {

  @RequestMapping(value = "/users/{userId}/transfers", method = RequestMethod.GET)
  public final ResponseEntity> list(TransferListQueryParameters queryParameters) {
    TransferListOptions options = new TransferListOptions();
    options.setTransferType(queryParameters.getTransfer_type());
    AccessorResponse> response = gateway().transfers().list(options);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/users/{user_id}/transfers/{id}", method = RequestMethod.GET)
  public final ResponseEntity getTransfer(@PathVariable("id") String transferId) {
    AccessorResponse response = gateway().transfers().get(transferId);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/users/{user_id}/transfers", method = RequestMethod.POST, consumes = MDX_MEDIA)
  public final ResponseEntity postTransfers(@RequestBody Transfer transferRequest) {
    AccessorResponse response = gateway().transfers().create(transferRequest);
    Transfer result = response.getResult();
    HttpStatus status = HttpStatus.OK;
    if (result.getChallenges() != null && result.getChallenges().size() > 0) {
      status = HttpStatus.ACCEPTED;
    }
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status);
  }

  @RequestMapping(value = "/users/{user_id}/transfers/{id}", method = RequestMethod.PUT, consumes = MDX_MEDIA)
  public final ResponseEntity updateTransfer(@PathVariable("id") String transferId, @RequestBody Transfer transfer) {
    transfer.setId(transferId);
    AccessorResponse response = gateway().transfers().update(transferId, transfer);
    Transfer result = response.getResult();
    HttpStatus status = HttpStatus.OK;
    if (result.getChallenges() != null && result.getChallenges().size() > 0) {
      status = HttpStatus.ACCEPTED;
    }
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status);
  }

  @RequestMapping(value = "/users/{user_id}/transfers/{id}/cancel", method = RequestMethod.PUT)
  public final ResponseEntity cancelTransfer(@PathVariable("id") String transferId) {
    AccessorResponse response = gateway().transfers().cancel(transferId);
    return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
  }

  @RequestMapping(value = "/users/{user_id}/transfers/start", method = RequestMethod.POST)
  public final ResponseEntity start(@RequestBody Transfer transfer) {
    AccessorResponse response = gateway().transfers().start(transfer);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/users/{user_id}/transfers/{id}/finish", method = RequestMethod.PUT)
  public final ResponseEntity finish(@PathVariable("id") String transferId) {
    AccessorResponse response = gateway().transfers().finish(transferId);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy