Search in sources :

Example 1 with RelationshipSmsSubmission

use of org.hisp.dhis.smscompression.models.RelationshipSmsSubmission in project dhis2-core by dhis2.

the class RelationshipSMSListenerTest method createRelationshipSubmission.

private RelationshipSmsSubmission createRelationshipSubmission() {
    RelationshipSmsSubmission subm = new RelationshipSmsSubmission();
    subm.setUserId(user.getUid());
    subm.setRelationshipType(relationshipType.getUid());
    subm.setRelationship("uf3svrmpzOj");
    subm.setFrom(programInstance.getUid());
    subm.setTo(programInstance.getUid());
    subm.setSubmissionId(1);
    return subm;
}
Also used : RelationshipSmsSubmission(org.hisp.dhis.smscompression.models.RelationshipSmsSubmission)

Example 2 with RelationshipSmsSubmission

use of org.hisp.dhis.smscompression.models.RelationshipSmsSubmission in project dhis2-core by dhis2.

the class RelationshipSMSListener method postProcess.

@Override
protected SmsResponse postProcess(IncomingSms sms, SmsSubmission submission) throws SMSProcessingException {
    RelationshipSmsSubmission subm = (RelationshipSmsSubmission) submission;
    Uid fromid = subm.getFrom();
    Uid toid = subm.getTo();
    Uid typeid = subm.getRelationshipType();
    RelationshipType relType = relationshipTypeService.getRelationshipType(typeid.getUid());
    if (relType == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_RELTYPE.set(typeid));
    }
    RelationshipItem fromItem = createRelationshipItem(relType, RelationshipDir.FROM, fromid);
    RelationshipItem toItem = createRelationshipItem(relType, RelationshipDir.TO, toid);
    Relationship rel = new Relationship();
    // auto-generated
    if (subm.getRelationship() != null) {
        rel.setUid(subm.getRelationship().getUid());
    }
    rel.setRelationshipType(relType);
    rel.setFrom(fromItem);
    rel.setTo(toItem);
    rel.setCreated(new Date());
    rel.setLastUpdated(new Date());
    // TODO: Are there values we need to account for in relationships?
    relationshipService.addRelationship(rel);
    return SmsResponse.SUCCESS;
}
Also used : Uid(org.hisp.dhis.smscompression.models.Uid) RelationshipSmsSubmission(org.hisp.dhis.smscompression.models.RelationshipSmsSubmission) Relationship(org.hisp.dhis.relationship.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) Date(java.util.Date)

Aggregations

RelationshipSmsSubmission (org.hisp.dhis.smscompression.models.RelationshipSmsSubmission)2 Date (java.util.Date)1 Relationship (org.hisp.dhis.relationship.Relationship)1 RelationshipItem (org.hisp.dhis.relationship.RelationshipItem)1 RelationshipType (org.hisp.dhis.relationship.RelationshipType)1 Uid (org.hisp.dhis.smscompression.models.Uid)1