Search in sources :

Example 16 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class FileStore method loadCalendarData.

static CalendarData loadCalendarData(int mboxId, int folderId, int modSeq) throws ServiceException {
    File file = getCalFolderFile(mboxId, folderId);
    String encoded = loadFromFile(file);
    if (encoded == null)
        return null;
    Metadata meta = new Metadata(encoded);
    if (!meta.containsKey(FN_VERSION)) {
        ZimbraLog.calendar.warn("Cache file missing version field: path=" + file.getAbsolutePath());
        return null;
    }
    int ver = (int) meta.getLong(FN_VERSION);
    if (ver < CURRENT_VERSION) {
        if (ZimbraLog.calendar.isDebugEnabled())
            ZimbraLog.calendar.debug("Cached data's version is too old: cached=" + ver + ", expected=" + CURRENT_VERSION + ", path=" + file.getAbsolutePath());
        return null;
    }
    int modSeqSaved = (int) meta.getLong(FN_MODSEQ);
    if (modSeqSaved > modSeq) {
        ZimbraLog.calendar.warn("Ignoring cached data in the future: saved modseq=" + modSeqSaved + ", needed modseq=" + modSeq + ", path=" + file.getAbsolutePath());
        return null;
    }
    Metadata metaCalData = meta.getMap(FN_CALDATA, true);
    if (metaCalData == null) {
        ZimbraLog.calendar.warn("Cache file missing actual data: path=" + file.getAbsolutePath());
        return null;
    }
    return new CalendarData(metaCalData);
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) File(java.io.File)

Example 17 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class FullInstanceData method encodeMetadata.

Metadata encodeMetadata() {
    Metadata meta = super.encodeMetadata();
    meta.put(FN_IS_FULL_INSTANCE, true);
    meta.put(FN_INVID, mInvId);
    meta.put(FN_COMPNUM, mCompNum);
    meta.put(FN_RECURRENCE_ID, mRecurrenceId);
    meta.put(FN_SEQUENCE, mSequence);
    meta.put(FN_DTSTAMP, mDtStamp);
    if (mOrganizer != null)
        meta.put(FN_ORGANIZER, mOrganizer.encodeMetadata());
    if (mIsOrganizer != null)
        meta.put(FN_IS_ORGANIZER, mIsOrganizer.booleanValue());
    if (mAttendees != null) {
        meta.put(FN_NUM_ATTENDEES, mAttendees.size());
        int i = 0;
        for (ZAttendee at : mAttendees) {
            meta.put(FN_ATTENDEE + i, at.encodeAsMetadata());
            i++;
        }
    }
    if (mHasAlarm != null)
        meta.put(FN_HAS_ALARM, mHasAlarm.booleanValue());
    if (mHasAttachment != null)
        meta.put(FN_HAS_ATTACHMENT, mHasAttachment.booleanValue());
    if (mDraft != null)
        meta.put(FN_DRAFT, mDraft.booleanValue());
    if (mNeverSent != null)
        meta.put(FN_NEVER_SENT, mNeverSent.booleanValue());
    meta.put(FN_SUMMARY, mSummary);
    meta.put(FN_LOCATION, mLocation);
    meta.put(FN_FRAGMENT, mFragment);
    if (mDescInMeta != null)
        meta.put(FN_DESC_IN_META, mDescInMeta.booleanValue());
    meta.put(FN_DESC, mDesc);
    meta.put(FN_DESC_HTML, mDescHtml);
    if (mIsAllDay != null)
        meta.put(FN_IS_ALLDAY, mIsAllDay.booleanValue());
    meta.put(FN_STATUS, mStatus);
    meta.put(FN_PRIORITY, mPriority);
    meta.put(FN_CLASS, mClassProp);
    meta.put(FN_FREEBUSY, mFreeBusyIntended);
    meta.put(FN_TRANSPARENCY, mTransparency);
    if (mCategories != null) {
        int numCat = mCategories.size();
        if (numCat > 0) {
            meta.put(FN_NUM_CATEGORIES, numCat);
            int i = 0;
            for (String cat : mCategories) {
                meta.put(FN_CATEGORY + i, cat);
                i++;
            }
        }
    }
    if (mGeo != null) {
        meta.put(FN_GEO, com.zimbra.cs.mailbox.calendar.Util.encodeMetadata(mGeo));
    }
    return meta;
}
Also used : ZAttendee(com.zimbra.cs.mailbox.calendar.ZAttendee) Metadata(com.zimbra.cs.mailbox.Metadata)

Example 18 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class GalImport method importGal.

public void importGal(int fid, boolean fullSync, boolean force) throws ServiceException {
    mbox.beginTrackingSync();
    DataSource ds = getDataSource();
    DataSourceItem folderMapping = DbDataSource.getMapping(ds, fid);
    if (folderMapping.md == null) {
        folderMapping.itemId = fid;
        folderMapping.md = new Metadata();
        folderMapping.md.put(TYPE, FOLDER);
        DbDataSource.addMapping(ds, folderMapping);
    }
    String syncToken = fullSync ? "" : folderMapping.md.get(SYNCTOKEN, "");
    HashMap<String, DataSourceItem> allMappings = new HashMap<String, DataSourceItem>();
    if (fullSync || force)
        for (DataSourceItem dsItem : DbDataSource.getAllMappings(ds)) if (// non-folder items
        dsItem.md == null || dsItem.md.get(TYPE, null) == null)
            allMappings.put(dsItem.remoteId, dsItem);
    OperationContext octxt = new OperationContext(mbox);
    SearchGalResult result = SearchGalResult.newSearchGalResult(new GalSearchVisitor(mbox, allMappings, fid, force));
    try {
        searchGal(syncToken, result, true);
    } catch (Exception e) {
        setStatus(false);
        ZimbraLog.gal.error("Error executing gal search", e);
        return;
    }
    folderMapping.md.put(SYNCTOKEN, result.getToken());
    DbDataSource.updateMapping(ds, folderMapping);
    if (allMappings.size() == 0 || !fullSync) {
        setStatus(true);
        return;
    }
    ArrayList<Integer> deleted = new ArrayList<Integer>();
    int[] deletedIds = new int[allMappings.size()];
    int i = 0;
    for (DataSourceItem dsItem : allMappings.values()) {
        deleted.add(dsItem.itemId);
        deletedIds[i++] = dsItem.itemId;
    }
    try {
        mbox.delete(octxt, deletedIds, MailItem.Type.CONTACT, null);
    } catch (ServiceException e) {
        ZimbraLog.gal.warn("Ignoring error deleting gal contacts", e);
    }
    DbDataSource.deleteMappings(getDataSource(), deleted);
    mbox.index.optimize();
    setStatus(true);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) HashMap(java.util.HashMap) Metadata(com.zimbra.cs.mailbox.Metadata) ArrayList(java.util.ArrayList) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) ServiceException(com.zimbra.common.service.ServiceException) JSONException(org.json.JSONException) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource) ServiceException(com.zimbra.common.service.ServiceException) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem)

Example 19 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class Invite method encodeMetadata.

/**
     * This is only really public to support serializing RedoOps -- you
     * really don't want to call this API from anywhere else
     *
     * @param inv
     * @return
     */
public static Metadata encodeMetadata(Invite inv) {
    Metadata meta = new Metadata();
    // looked before local-only flag was introduced.
    if (inv.isLocalOnly())
        meta.put(FN_LOCAL_ONLY, true);
    meta.put(FN_ITEMTYPE, inv.getItemType().toByte());
    meta.put(FN_UID, inv.getUid());
    meta.put(FN_INVMSGID, inv.getMailItemId());
    meta.put(FN_COMPNUM, inv.getComponentNum());
    meta.put(FN_SENTBYME, inv.mSentByMe);
    if (!inv.isPublic())
        meta.put(FN_CLASS, inv.getClassProp());
    meta.put(FN_CLASS_SETBYME, inv.classPropSetByMe());
    meta.put(FN_STATUS, inv.getStatus());
    if (inv.hasFreeBusy())
        meta.put(FN_APPT_FREEBUSY, inv.getFreeBusy());
    meta.put(FN_TRANSP, inv.getTransparency());
    meta.put(FN_START, inv.mStart);
    meta.put(FN_END, inv.mEnd);
    if (inv.mCompleted != 0)
        meta.put(FN_COMPLETED, inv.mCompleted);
    meta.put(FN_DURATION, inv.mDuration);
    meta.put(FN_METHOD, inv.mMethod.toString());
    meta.put(FN_FRAGMENT, inv.mFragment);
    // Put mDescription in metadata if it's short enough.
    if (inv.mDescInMeta) {
        meta.put(FN_DESC_IN_META, inv.mDescInMeta);
        if (inv.mDescription != null)
            meta.put(FN_DESC, inv.mDescription);
        if (inv.mDescHtml != null)
            meta.put(FN_DESC_HTML, inv.mDescHtml);
    }
    if (inv.mRecurrence != null) {
        meta.put(FN_RECURRENCE, inv.mRecurrence.encodeMetadata());
    }
    meta.put(FN_NAME, inv.getName());
    meta.put(FN_LOCATION, inv.mLocation);
    meta.put(FN_APPT_FLAGS, inv.getFlags());
    meta.put(FN_PARTSTAT, inv.getPartStat());
    meta.put(FN_RSVP, inv.getRsvp());
    meta.put(FN_TZMAP, Util.encodeAsMetadata(inv.mTzMap));
    if (inv.hasRecurId()) {
        meta.put(FN_RECUR_ID, inv.getRecurId().encodeMetadata());
    }
    meta.put(FN_DTSTAMP, inv.getDTStamp());
    if (inv.getLastModified() != 0)
        meta.put(FN_LAST_MODIFIED, inv.getLastModified());
    meta.put(FN_SEQ_NO, inv.getSeqNo());
    meta.put(FN_LAST_FULL_SEQ_NO, inv.getLastFullSeqNo());
    if (inv.hasOrganizer()) {
        meta.put(FN_ORGANIZER, inv.getOrganizer().encodeMetadata());
    }
    meta.put(FN_IS_ORGANIZER, inv.isOrganizer());
    List<ZAttendee> ats = inv.getAttendees();
    meta.put(FN_NUM_ATTENDEES, String.valueOf(ats.size()));
    int i = 0;
    for (Iterator<ZAttendee> iter = ats.iterator(); iter.hasNext(); i++) {
        ZAttendee at = iter.next();
        meta.put(FN_ATTENDEE + i, at.encodeAsMetadata());
    }
    meta.put(FN_PRIORITY, inv.getPriority());
    meta.put(FN_PCT_COMPLETE, inv.getPercentComplete());
    List<String> comments = inv.getComments();
    if (comments != null) {
        int numComm = comments.size();
        if (numComm > 0) {
            meta.put(FN_NUM_COMMENTS, numComm);
            int idx = 0;
            for (String comm : comments) {
                meta.put(FN_COMMENT + idx, comm);
                idx++;
            }
        }
    }
    List<String> contacts = inv.getContacts();
    if (contacts != null) {
        int numContacts = contacts.size();
        if (numContacts > 0) {
            meta.put(FN_NUM_CONTACTS, numContacts);
            int idx = 0;
            for (String contact : contacts) {
                meta.put(FN_CONTACT + idx, contact);
                idx++;
            }
        }
    }
    List<String> categories = inv.getCategories();
    if (categories != null) {
        int numCat = categories.size();
        if (numCat > 0) {
            meta.put(FN_NUM_CATEGORIES, numCat);
            int idx = 0;
            for (String cat : categories) {
                meta.put(FN_CATEGORY + idx, cat);
                idx++;
            }
        }
    }
    Geo geo = inv.getGeo();
    if (geo != null) {
        meta.put(FN_GEO, Util.encodeMetadata(geo));
    }
    String url = inv.getUrl();
    if (url != null && url.length() > 0)
        meta.put(FN_URL, url);
    if (!inv.mAlarms.isEmpty()) {
        meta.put(FN_NUM_ALARMS, inv.mAlarms.size());
        i = 0;
        for (Iterator<Alarm> iter = inv.mAlarms.iterator(); iter.hasNext(); i++) {
            Alarm alarm = iter.next();
            meta.put(FN_ALARM + i, alarm.encodeMetadata());
        }
    }
    if (inv.mXProps.size() > 0)
        Util.encodeXPropsAsMetadata(meta, inv.xpropsIterator());
    if (inv.mDontIndexMimeMessage)
        meta.put(FN_DONT_INDEX_MM, true);
    return meta;
}
Also used : Geo(com.zimbra.common.calendar.Geo) Metadata(com.zimbra.cs.mailbox.Metadata)

Example 20 with Metadata

use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.

the class Util method encodeAsMetadata.

public static Metadata encodeAsMetadata(TimeZoneMap tzmap) {
    Metadata meta = new Metadata();
    Map<String, Integer> /* index */
    tzIndex = new HashMap<String, Integer>();
    int nextIndex = 0;
    for (Iterator<Entry<String, ICalTimeZone>> iter = tzmap.getMap().entrySet().iterator(); iter.hasNext(); ) {
        Entry<String, ICalTimeZone> entry = iter.next();
        String tzid = entry.getKey();
        if (// ignore null/empty TZIDs (bug 25183)
        tzid == null || tzid.length() < 1)
            continue;
        ICalTimeZone zone = entry.getValue();
        String realTzid = zone.getID();
        if (!tzIndex.containsKey(realTzid)) {
            meta.put("#" + nextIndex, encodeAsMetadata(zone));
            tzIndex.put(realTzid, nextIndex);
            ++nextIndex;
        }
    }
    for (Iterator<Entry<String, String>> iter = tzmap.getAliasMap().entrySet().iterator(); iter.hasNext(); ) {
        Entry<String, String> entry = iter.next();
        String alias = entry.getKey();
        String realTzid = entry.getValue();
        if (tzIndex.containsKey(realTzid)) {
            int index = tzIndex.get(realTzid);
            meta.put(alias, index);
        }
    }
    return meta;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Metadata(com.zimbra.cs.mailbox.Metadata) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Aggregations

Metadata (com.zimbra.cs.mailbox.Metadata)60 Mailbox (com.zimbra.cs.mailbox.Mailbox)16 ArrayList (java.util.ArrayList)15 ServiceException (com.zimbra.common.service.ServiceException)13 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)9 SQLException (java.sql.SQLException)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 OperationContext (com.zimbra.cs.mailbox.OperationContext)7 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)6 MailItem (com.zimbra.cs.mailbox.MailItem)5 HashMap (java.util.HashMap)5 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)4 DataSource (com.zimbra.cs.account.DataSource)4 DbDataSource (com.zimbra.cs.db.DbDataSource)4 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)4 Map (java.util.Map)4 Entry (java.util.Map.Entry)4 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)3