Commit 5e81c389 authored by Sridhar Pothanaveni's avatar Sridhar Pothanaveni

BPN Service added

parent c8ecd85f
package com.nisum.task.controller;
import com.nisum.task.entity.ActionEnum;
import com.nisum.task.entity.BPN;
import com.nisum.task.service.BPNService;
import lombok.extern.slf4j.Slf4j;
......@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@CrossOrigin(origins = "*")
@Slf4j
@RestController
@RequestMapping("/bpn")
......@@ -36,9 +38,11 @@ public class BPNController {
@PostMapping("/processBPN")
public Flux<BPN> processBPN(@RequestBody BPN bpn) {
public Mono<BPN> processBPN(@RequestBody BPN bpn) {
log.info("processBPN {}",bpn);
return bPNService.processBPN(bpn);
}
}
package com.nisum.task.entity;
public enum ActionEnum {
FORCE("Force"),
BLOCK("Block"),
RECALL("Recall");
private String name;
ActionEnum(String name) {
this.name = name;
}
}
......@@ -24,6 +24,6 @@ public class BPN {
private Date firstEffectiveDate;
private Date lasttEffectiveDate;
private String bpnStatus;
private String bpnProcessMessage;
}
package com.nisum.task.entity;
public enum BPNStatusEnum {
ACTIVE("Active"),
BLOCKED("Blocked"),
IN_ACTIVE("In Active"),
DELETED("Deleted");
private String name;
BPNStatusEnum(String name) {
this.name = name;
}
}
......@@ -3,7 +3,9 @@ package com.nisum.task.repository;
import com.nisum.task.entity.BPN;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;
@Repository
public interface BPNRepository extends ReactiveMongoRepository<BPN,Long> {
Mono<BPN> findByBpn(String bpn);
}
package com.nisum.task.service;
import com.nisum.task.entity.ActionEnum;
import com.nisum.task.entity.BPN;
import com.nisum.task.entity.BPNStatusEnum;
import com.nisum.task.repository.BPNRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -19,7 +21,7 @@ public class BPNService {
bpn.setBpnStatus("Active");
bpn.setFirstEffectiveDate(new Date());
bpn.setLasttEffectiveDate(new Date());
return bpnRepository.save(bpn);
return processBPN(bpn).then(bpnRepository.save(bpn));
}
public Mono<BPN> findById(Long bpnId) {
......@@ -30,8 +32,34 @@ public class BPNService {
return bpnRepository.findAll();
}
public Flux<BPN> processBPN(BPN bpn) {
return bpnRepository.findAll();
public Mono<BPN> processBPN(BPN bpnObject) {
return Mono.just(bpnObject).flatMap(bpn2 -> {
if (bpn2.getForceOptCd().equalsIgnoreCase(ActionEnum.BLOCK.name())) {
return bpnRepository.findByBpn(bpn2.getBpn())
.flatMap(bpn1 -> {
if (bpn2.getForceOptCd().equalsIgnoreCase(BPNStatusEnum.DELETED.name())) {
bpn1.setBpnProcessMessage("BPN is Deleted already, Can't block it");
return Mono.just(bpn1);
} else {
bpn1.setBpnProcessMessage("Blocked Successfully");
return Mono.just(bpn1);
}
});
} else if (bpn2.getForceOptCd().equalsIgnoreCase(ActionEnum.FORCE.name())) {
return bpnRepository.findByBpn(bpn2.getBpn())
.flatMap(bpn1 -> {
if (bpn2.getForceOptCd().equalsIgnoreCase(BPNStatusEnum.DELETED.name())) {
bpn1.setBpnProcessMessage("BPN is Deleted already, Can't block it");
return Mono.just(bpn1);
} else {
bpn1.setBpnProcessMessage("BPN Forced successfully");
return Mono.just(bpn1);
}
});
} else {
return Mono.just(bpn2);
}
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment