Search in sources :

Example 1 with Contact

use of il.ac.technion.cs.smarthouse.system.user_information.Contact in project Smartcity-Smarthouse by TechnionYP5777.

the class AlertsManager method sendAlert.

/**
     * Report an abnormality in the expected schedule. The system will contact
     * the needed personal, according to the urgency level
     * 
     * @param message
     *            Specify the abnormality, will be presented to the contacted
     *            personal
     * @param eLevel
     *            The level of personnel needed in the situation
     */
public final void sendAlert(final String message, final EmergencyLevel eLevel) {
    final UserInformation user = systemCore.getUser();
    if (user == null) {
        log.debug("systemCore.getUser() returned a null");
        return;
    }
    final PhoneService ps = (PhoneService) getAnotherService(ServiceType.PHONE_SERVICE);
    final SmsService ss = (SmsService) getAnotherService(ServiceType.SMS_SERVICE);
    final EmailService es = (EmailService) getAnotherService(ServiceType.EMAIL_SERVICE);
    final List<Contact> $ = user.getContacts(eLevel);
    switch(eLevel) {
        case SMS_EMERGENCY_CONTACT:
            $.stream().forEach(c -> ss.sendMsg(c.getPhoneNumber(), message));
            break;
        case CALL_EMERGENCY_CONTACT:
        case CONTACT_HOSPITAL:
        case CONTACT_POLICE:
        case CONTACT_FIRE_FIGHTERS:
            $.stream().forEach(c -> ps.makeCall(c.getPhoneNumber()));
            break;
        case EMAIL_EMERGENCY_CONTACT:
            $.stream().forEach(c -> es.sendMsg(c.getEmailAddress(), message));
            break;
        default:
            log.warn(eLevel + " is not handled");
    }
}
Also used : UserInformation(il.ac.technion.cs.smarthouse.system.user_information.UserInformation) PhoneService(il.ac.technion.cs.smarthouse.system.services.communication_services.PhoneService) SmsService(il.ac.technion.cs.smarthouse.system.services.communication_services.SmsService) EmailService(il.ac.technion.cs.smarthouse.system.services.communication_services.EmailService) Contact(il.ac.technion.cs.smarthouse.system.user_information.Contact)

Example 2 with Contact

use of il.ac.technion.cs.smarthouse.system.user_information.Contact in project Smartcity-Smarthouse by TechnionYP5777.

the class UserInformationTest method contactsTest.

@Test
public void contactsTest() {
    userInfo.addContact(contactA, EmergencyLevel.CALL_EMERGENCY_CONTACT);
    userInfo.addContact(contactB, EmergencyLevel.SMS_EMERGENCY_CONTACT);
    List<Contact> temp = userInfo.getContacts(EmergencyLevel.CONTACT_FIRE_FIGHTERS);
    Assert.assertEquals(0, temp.size());
    temp = userInfo.getContacts(EmergencyLevel.SMS_EMERGENCY_CONTACT);
    Assert.assertEquals(1, temp.size());
    assert temp.contains(contactB);
    temp = userInfo.getContacts();
    assert temp.contains(contactA);
    assert temp.contains(contactB);
    Contact tempContact = userInfo.getContact("000");
    Assert.assertNull(tempContact);
    tempContact = userInfo.getContact("123");
    assert tempContact != null;
    userInfo.setContactEmergencyLevel("123", "CONTACT_HOSPITAL");
    temp = userInfo.getContacts(EmergencyLevel.CONTACT_HOSPITAL);
    Assert.assertEquals(1, temp.size());
    assert temp.contains(contactA);
    userInfo.removeContact(contactA.getId());
    userInfo.removeContact(contactB.getId());
}
Also used : Contact(il.ac.technion.cs.smarthouse.system.user_information.Contact) Test(org.junit.Test)

Example 3 with Contact

use of il.ac.technion.cs.smarthouse.system.user_information.Contact in project Smartcity-Smarthouse by TechnionYP5777.

the class UserInfoController method addContactToTable.

@FXML
private void addContactToTable(final ActionEvent __) {
    final Contact contact = new Contact(addIDField.getText(), addNameField.getText(), addPhoneField.getText(), addEmailField.getText());
    getModel().getUser().addContact(contact, addELevelField.getValue());
    final ContactGUI guiContact = new ContactGUI(contact, addELevelField.getValue());
    addNameField.clear();
    addIDField.clear();
    addPhoneField.clear();
    addEmailField.clear();
    addELevelField.setValue(null);
    contactsTable.getItems().add(guiContact);
}
Also used : Contact(il.ac.technion.cs.smarthouse.system.user_information.Contact) FXML(javafx.fxml.FXML)

Example 4 with Contact

use of il.ac.technion.cs.smarthouse.system.user_information.Contact in project Smartcity-Smarthouse by TechnionYP5777.

the class AlertsServiceTest method init.

@Before
public void init() {
    serviceManager_noUser = new ServiceManager(new SystemCore());
    SystemCore s = new SystemCore();
    serviceManager_withUser = new ServiceManager(s);
    s.initializeUser("Bob", "123", "050", "HERE");
    s.getUser().addContact(new Contact("111", "Alice", "999", "a@b.com"), EmergencyLevel.SMS_EMERGENCY_CONTACT);
    s.getUser().addContact(new Contact("111", "Alice", "999", "a@b.com"), EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
    s.getUser().addContact(new Contact("111", "Alice", "999", "a@b.com"), EmergencyLevel.CALL_EMERGENCY_CONTACT);
}
Also used : SystemCore(il.ac.technion.cs.smarthouse.system.SystemCore) ServiceManager(il.ac.technion.cs.smarthouse.system.services.ServiceManager) Contact(il.ac.technion.cs.smarthouse.system.user_information.Contact) Before(org.junit.Before)

Aggregations

Contact (il.ac.technion.cs.smarthouse.system.user_information.Contact)4 SystemCore (il.ac.technion.cs.smarthouse.system.SystemCore)1 ServiceManager (il.ac.technion.cs.smarthouse.system.services.ServiceManager)1 EmailService (il.ac.technion.cs.smarthouse.system.services.communication_services.EmailService)1 PhoneService (il.ac.technion.cs.smarthouse.system.services.communication_services.PhoneService)1 SmsService (il.ac.technion.cs.smarthouse.system.services.communication_services.SmsService)1 UserInformation (il.ac.technion.cs.smarthouse.system.user_information.UserInformation)1 FXML (javafx.fxml.FXML)1 Before (org.junit.Before)1 Test (org.junit.Test)1