Skip to content

Commit

Permalink
Merge pull request #691 from motech-implementations/feature
Browse files Browse the repository at this point in the history
NMS-330
  • Loading branch information
sripooja authored Jul 13, 2016
2 parents 2fb63a6 + 5bcec90 commit 315783b
Show file tree
Hide file tree
Showing 34 changed files with 537 additions and 55 deletions.
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.17</version>
<version>1.0.18</version>
<relativePath>../</relativePath>
</parent>

<artifactId>api</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
<packaging>bundle</packaging>
<name>API module</name>

Expand Down
27 changes: 25 additions & 2 deletions api/src/main/java/org/motechproject/nms/api/web/OpsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.motechproject.nms.api.web.converter.MobileAcademyConverter;
import org.motechproject.nms.imi.service.CdrFileService;
import org.motechproject.nms.kilkari.repository.SubscriptionDataService;
import org.motechproject.nms.kilkari.service.SubscriberService;
import org.motechproject.nms.kilkari.service.SubscriptionService;
import org.motechproject.nms.kilkari.utils.KilkariConstants;
import org.motechproject.nms.mcts.service.MctsWsImportService;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class OpsController extends BaseController {
@Autowired
private SubscriptionDataService subscriptionDataService;

@Autowired
private SubscriberService subscriberService;

@Autowired
private SubscriptionService subscriptionService;

Expand All @@ -62,6 +66,8 @@ public class OpsController extends BaseController {
@Autowired
private FrontLineWorkerService frontLineWorkerService;

private final String contactNumber = "contactNumber";

/**
* Provided for OPS as a crutch to be able to empty all MDS cache directly after modifying the database by hand
*/
Expand Down Expand Up @@ -119,8 +125,8 @@ public void createUpdateFlw(@RequestBody AddFlwRequest addFlwRequest) {
addFlwRequest.getDistrictId()));

StringBuilder failureReasons = new StringBuilder();
validateField10Digits(failureReasons, "contactNumber", addFlwRequest.getContactNumber());
validateFieldPositiveLong(failureReasons, "contactNumber", addFlwRequest.getContactNumber());
validateField10Digits(failureReasons, contactNumber, addFlwRequest.getContactNumber());
validateFieldPositiveLong(failureReasons, contactNumber, addFlwRequest.getContactNumber());
validateFieldPresent(failureReasons, "mctsFlwId", addFlwRequest.getMctsFlwId());
validateFieldPresent(failureReasons, "stateId", addFlwRequest.getStateId());
validateFieldPresent(failureReasons, "districtId", addFlwRequest.getDistrictId());
Expand Down Expand Up @@ -176,6 +182,23 @@ public GetBookmarkResponse getBookmarkWithScore(@RequestParam(required = false)
return ret;
}

@RequestMapping(value = "/deactivationRequest",
method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
@Transactional
public void deactivationRequest(@RequestParam(value = "msisdn") Long msisdn) {
log("REQUEST: /ops/deactivationRequest", String.format(
"callingNumber=%s",
LogHelper.obscure(msisdn)));
StringBuilder failureReasons = new StringBuilder();
validateField10Digits(failureReasons, contactNumber, msisdn);
validateFieldPositiveLong(failureReasons, contactNumber, msisdn);
if (failureReasons.length() > 0) {
throw new IllegalArgumentException(failureReasons.toString());
}
subscriberService.deactivateAllSubscriptionsForSubscriber(msisdn);
}

@RequestMapping("/getScores")
@ResponseBody
public String getScoresForNumber(@RequestParam(required = true) Long callingNumber) {
Expand Down
4 changes: 2 additions & 2 deletions csv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.17</version>
<version>1.0.18</version>
<relativePath>../</relativePath>
</parent>

<artifactId>csv</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
<packaging>bundle</packaging>
<name>CSV Module</name>

Expand Down
4 changes: 2 additions & 2 deletions flw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.17</version>
<version>1.0.18</version>
<relativePath>../</relativePath>
</parent>

<artifactId>flw</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
<packaging>bundle</packaging>
<name>FLW module</name>

Expand Down
4 changes: 2 additions & 2 deletions imi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.17</version>
<version>1.0.18</version>
<relativePath>../</relativePath>
</parent>

<artifactId>imi</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
<packaging>bundle</packaging>
<name>IMI module</name>

Expand Down
4 changes: 2 additions & 2 deletions kilkari/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.17</version>
<version>1.0.18</version>
<relativePath>../</relativePath>
</parent>

<artifactId>kilkari</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
<packaging>bundle</packaging>
<name>Kilkari module</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.motechproject.nms.kilkari.domain;

/**
* The Audit Status
*/
public enum AuditStatus {
SUCCESS,
FAILURE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.motechproject.nms.kilkari.domain;

import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;

import javax.jdo.annotations.Column;
import javax.jdo.annotations.Unique;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
* Record of Weekly Calls Not Answered Deactivated Numbers
*/
@Entity(tableName = "nms_blocked_msisdn")
public class BlockedMsisdnRecord {

@Field
@Unique
@Min(value = 1000000000L, message = "callingNumber must be 10 digits")
@Max(value = 9999999999L, message = "callingNumber must be 10 digits")
@Column(length = 10, allowsNull = "false")
private Long callingNumber;

@Field
@NotNull
private DeactivationReason deactivationReason;

public BlockedMsisdnRecord() {
}

public BlockedMsisdnRecord(Long callingNumber, DeactivationReason deactivationReason) {
this.callingNumber = callingNumber;
this.deactivationReason = deactivationReason;
}

public Long getCallingNumber() {
return callingNumber;
}

public void setCallingNumber(Long callingNumber) {
this.callingNumber = callingNumber;
}

public DeactivationReason getDeactivationReason() {
return deactivationReason;
}

public void setDeactivationReason(DeactivationReason deactivationReason) {
this.deactivationReason = deactivationReason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public enum DeactivationReason {
MATERNAL_DEATH,
INVALID_NUMBER, // See https://github.com/motech-implementations/mim/issues/169
DO_NOT_DISTURB,
MCTS_UPDATE
MCTS_UPDATE,
WEEKLY_CALLS_NOT_ANSWERED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.motechproject.nms.kilkari.domain;

import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;

import javax.jdo.annotations.Column;
import javax.validation.constraints.NotNull;

@Entity(tableName = "nms_deactivation_subscription_audit_records")
public class DeactivationSubscriptionAuditRecord {

public static final int MAX_OUTCOME_LENGTH = 1000; // Includes the "Failure: " string

@Field
@NotNull
private String subscriptionId;

@Field
@NotNull
private Long subscriberId;

@Field
@NotNull
private SubscriptionOrigin subscriptionOrigin;

@Field
@NotNull
private Long msisdn;

@Field
@NotNull
private SubscriptionStatus preStatus;

@Field
@NotNull
private AuditStatus auditStatus;

@Field
@Column(length = MAX_OUTCOME_LENGTH)
private String outcome;

public SubscriptionStatus getPreStatus() {
return preStatus;
}

public void setPreStatus(SubscriptionStatus preStatus) {
this.preStatus = preStatus;
}

public AuditStatus getAuditStatus() {
return auditStatus;
}

public void setAuditStatus(AuditStatus auditStatus) {
this.auditStatus = auditStatus;
}

public String getOutcome() {
return outcome;
}

public void setOutcome(String outcome) {
this.outcome = outcome;
}

public String getSubscriptionId() {
return subscriptionId;
}

public void setSubscriptionId(String subscriptionId) {
this.subscriptionId = subscriptionId;
}

public Long getSubscriberId() {
return subscriberId;
}

public void setSubscriberId(Long subscriberId) {
this.subscriberId = subscriberId;
}

public SubscriptionOrigin getSubscriptionOrigin() {
return subscriptionOrigin;
}

public void setSubscriptionOrigin(SubscriptionOrigin subscriptionOrigin) {
this.subscriptionOrigin = subscriptionOrigin;
}

public Long getMsisdn() {
return msisdn;
}

public void setMsisdn(Long msisdn) {
this.msisdn = msisdn;
}

public DeactivationSubscriptionAuditRecord(String subscriptionId, Long subscriberId, SubscriptionOrigin subscriptionOrigin, Long msisdn, SubscriptionStatus preStatus, AuditStatus auditStatus, String outcome) {
this.subscriptionId = subscriptionId;
this.subscriberId = subscriberId;
this.subscriptionOrigin = subscriptionOrigin;
this.msisdn = msisdn;
this.preStatus = preStatus;
this.auditStatus = auditStatus;
this.outcome = outcome;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Subscriber extends MdsEntity {
@Field
private Circle circle;

//TODO: making this a bi-directional relationship until MOTECH-1638 is fixed. See #31.
// TODO: making this a bi-directional relationship until MOTECH-1638 is fixed. See #31.
@Field
@Persistent(mappedBy = "subscriber", defaultFetchGroup = "false")
@JsonManagedReference
Expand Down Expand Up @@ -148,8 +148,7 @@ public Set<Subscription> getActiveAndPendingSubscriptions() {
@Ignore
@JsonIgnore
public Set<Subscription> getAllSubscriptions() {
// TODO: I have no idea why I need to do this, but returning just this.subscriptions always results in
// an empty set. Bi-directional relationship bug?
// TODO: I have no idea why I need to do this, but returning just this.subscriptions always results in an empty set. Bi-directional relationship bug?
Set<Subscription> allSubscriptions = new HashSet<>();

Iterator<Subscription> subscriptionIterator = subscriptions.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public enum SubscriptionRejectionReason {
MISSING_LMP,
INVALID_DOB,
INVALID_LMP,
MISSING_MSISDN;
MISSING_MSISDN,
WEEKLY_CALLS_NOT_ANSWERED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void initSubscriptionManager() {
LOGGER.debug("Scheduled cron job with subject {} and expression {}", KilkariConstants.SUBSCRIPTION_UPKEEP_SUBJECT, cronExpression);
}

@MotechListener(subjects = { KilkariConstants.SUBSCRIPTION_UPKEEP_SUBJECT})
@MotechListener(subjects = { KilkariConstants.SUBSCRIPTION_UPKEEP_SUBJECT })
public void upkeepSubscriptions(MotechEvent event) {
LOGGER.debug("Received event for subscription upkeep");
DateTime tomorrow = DateTime.now().plusDays(1).withTimeAtStartOfDay();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.motechproject.nms.kilkari.repository;

import org.motechproject.mds.annotations.Lookup;
import org.motechproject.mds.annotations.LookupField;
import org.motechproject.mds.service.MotechDataService;
import org.motechproject.nms.kilkari.domain.BlockedMsisdnRecord;

public interface BlockedMsisdnRecordDataService extends MotechDataService<BlockedMsisdnRecord> {

@Lookup
BlockedMsisdnRecord findByNumber(@LookupField(name = "callingNumber") Long callingNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.motechproject.nms.kilkari.repository;

import org.motechproject.mds.service.MotechDataService;
import org.motechproject.nms.kilkari.domain.DeactivationSubscriptionAuditRecord;

public interface DeactivationSubscriptionAuditRecordDataService extends MotechDataService<DeactivationSubscriptionAuditRecord> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@ public interface SubscriberService {
@InstanceLifecycleListener(InstanceLifecycleListenerType.PRE_DELETE)
void deleteAllowed(Subscriber subscriber);


/**
* Deactivate all Subscriptions of a given callingNumber on MOHFW request
* @param callingNumber
*/
void deactivateAllSubscriptionsForSubscriber(long callingNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,5 @@ Subscription createSubscription(long callingNumber, Language language, Circle ci
*
*/
List<Subscription> retrieveAll();

}
Loading

0 comments on commit 315783b

Please sign in to comment.