All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unitedinternet.cosmo.ext.ContentConverter Maven / Gradle / Ivy

The newest version!
package org.unitedinternet.cosmo.ext;

import java.util.HashSet;
import java.util.Set;

import org.springframework.stereotype.Component;
import org.unitedinternet.cosmo.model.ICalendarItem;
import org.unitedinternet.cosmo.model.NoteItem;
import org.unitedinternet.cosmo.model.hibernate.EntityConverter;
import org.unitedinternet.cosmo.model.hibernate.HibNoteItem;

import net.fortuna.ical4j.model.Calendar;

/**
 * Helper class that allows translating Calendar objects to NoteItem-s.
 * 
 * @author daniel grigore
 *
 */
@Component
public class ContentConverter {

    private final EntityConverter entityConverter;

    public ContentConverter(EntityConverter entityConverter) {
        super();
        this.entityConverter = entityConverter;
    }

    public Set asItems(Calendar calendar) {
        Set items = new HashSet<>();
        if (calendar != null) {
            Set calendarItems = this.entityConverter.convertCalendar(calendar);

            for (ICalendarItem item : calendarItems) {
                /**
                 * Only VEVENT are supported currently. VTODO or VJOURNAL are not yet supported.
                 */
                if (item instanceof HibNoteItem) {
                    HibNoteItem noteItem = (HibNoteItem) item;
                    Long now = System.currentTimeMillis();
                    noteItem.setCreationDate(now);
                    noteItem.setModifiedDate(now);
                    items.add(noteItem);
                    noteItem.setName(noteItem.getIcalUid() + ".ics");
                }
            }
        }
        return items;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy