Zianne 0 Newbie Poster

Recently in an interview I was asked to design a "send invitation for an appointment to multiple contacts in a company". (Something similar to creating an Appointment in Outlook)

Here is what I came up with, I would really appreciate some feedback, suggestions, questions.

So, after asking few questions, the interviewer wanted me to figure out how would I save the Calendar data of everyone from different timezones in my company. The invitation would have just 2 things, time and contacts…

example:

From: me@myCompany.com To: brad@myCompany.com; star@myCompany.com, angel@myCompany.com Time: 3:30 to 4:30 (CST) Date: 08/20/2015

I recommended that we save all employees data in different locations. So the DB servers will be at a location near you, which would make your calendar loading faster. There will be a centralized server which will store the machine ID against your employee id.

Ex:

Table Name: Machine_Mapping

| Employee_ID | Machine_ID |

| 101 | 1

| 102 | 2

| 103 | 2

| 104 | 1

| 105 | 3

Data on a particular machine: Table Name: Calendar_Data

| Employee_ID | Email_ID | From | TO | Date

| 101 | brad@myCompany.com | 14:00 | 14:30 | 01/01/2014

| 101 | brad@myCompany.com | 14:00 | 14:30 | 01/01/2015

| 101 | brad@myCompany.com | 15:00 | 16:00 | 08/20/2015
( This should be a conflict as the requested timing overlaps with this )

| 102 | star@myCompany.com | 17:00 | 17:30 | 08/20/2015

| 103 | angel@myCompany.com | 15:00 | 16:00 | 08/24/2015

| 104 | me@myCompany.com | 15:00 | 16:00 | 08/24/2015

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/01/2015 .... ( This is something like a daily Scrum

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/02/2015 .... meeting invite. Will this be repeated?

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/03/2015 .... or there should be some way to store

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/04/2015 .... it efficiently ? Please suggest. )

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/05/2015

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/06/2015

| 104 | me@myCompany.com | 11:00 | 11:30 | 07/07/2015

….

I was also asked to implement sendInvite method… Here is my implementation:
`

public Result sendInvite(List<Contact> contacts, Date date, Timestamp from,
        Timestamp to) {

    List<Contact> contactsHavingConflict = new ArrayList<Contact>();
    Result result = new Result();
    try {
        for (Contact c : contacts) {
            if (!checkAvailability(c, from, to)) {    // This method will first compare the date of invitation with the dates of each contact in database. 
                contactsHavingConflict.add(c);
            }

            if (contactsHavingConflict.size() == 0) {
                sendInvite(contacts);
                result.setInvitationSent(true);
            } else {
                result.setContactsHavingConflict(contactsHavingConflict);
                result.setInvitationSent(false);
            }
        }
    } catch (Exception e) {
        // log.error(e.getMessage());
        result.setError(e.getMessage());
        result.setInvitationSent(false);
    }
    return result;
}

private boolean checkAvailability(Contact c, Timestamp from, Timestamp to) {
    int count = 0;
    // count = select count(*) from Calendar_Data where c.getEmail =
    // Email_ID and (from >= From or to <=TO);

    if (count > 0)
        return false;
    else
        return true;
}Inline Code Example Here

`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.