blob: 4da6b4b539886fcfdd613b155e4199c6ce52df7c [file] [log] [blame]
/*
* Copyright 2017 The Mifos Initiative.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.individuallending.rest;
import io.mifos.anubis.annotation.AcceptedTokenType;
import io.mifos.anubis.annotation.Permittable;
import io.mifos.core.command.gateway.CommandGateway;
import io.mifos.portfolio.service.internal.command.CreateBeatPublishCommand;
import io.mifos.rhythm.spi.v1.client.BeatListener;
import io.mifos.rhythm.spi.v1.domain.BeatPublish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
/**
* @author Myrle Krantz
*/
@SuppressWarnings("unused")
@RestController
@RequestMapping(BeatListener.PUBLISH_BEAT_PATH) //
public class BeatPublishListenerRestController {
private final static String BEAT_PUBLISH = "portfolio__v1__khepri"; //PermittableGroupIds.forApplication("portfolio-v1");
private final CommandGateway commandGateway;
@Autowired
public BeatPublishListenerRestController(final CommandGateway commandGateway) {
this.commandGateway = commandGateway;
}
@Permittable(value = AcceptedTokenType.TENANT, groupId = BEAT_PUBLISH)
@RequestMapping(
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody
ResponseEntity<Void> publishBeat(@RequestBody @Valid final BeatPublish instance)
{
this.commandGateway.process(new CreateBeatPublishCommand(instance));
return new ResponseEntity<>(HttpStatus.ACCEPTED);
}
}