Search in sources :

Example 31 with DataSource

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

the class ProvTestUtil method createDataSourceRaw.

public DataSource createDataSourceRaw(Account acct, String dataSourceName) throws Exception {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
    attrs.put(Provisioning.A_zimbraDataSourceFolderId, "123");
    attrs.put(Provisioning.A_zimbraDataSourceConnectionType, "ssl");
    attrs.put(Provisioning.A_zimbraDataSourceHost, "zimbra.com");
    attrs.put(Provisioning.A_zimbraDataSourcePort, "9999");
    DataSource ds = prov.createDataSource(acct, DataSourceType.pop3, dataSourceName, attrs);
    createdAccountSubordinates.add(ds);
    return ds;
}
Also used : HashMap(java.util.HashMap) DataSource(com.zimbra.cs.account.DataSource)

Example 32 with DataSource

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

the class TestPop3ImportServer method testUidPersistence.

/*
     * Tests the UID persistence methods in {@link DbPop3Message}.
     */
@Test
public void testUidPersistence() throws Exception {
    mIsServerSideTest = true;
    DataSource ds = getDataSource();
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    // Create set of id's.  Id's are the same characters in different
    // case, to test case-sensitivity (bug 15090)
    String uid1 = "myUID";
    String uid2 = "myUid";
    Set<String> uids = new HashSet<String>();
    uids.add(uid1);
    uids.add(uid2);
    // Make sure no id's match
    Set<String> matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
    assertEquals("Test 1: set size", 0, matchingUids.size());
    // Store uid1 and make sure it matches
    DbPop3Message.storeUid(mbox, ds.getId(), uid1, Mailbox.ID_FOLDER_INBOX);
    matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
    assertEquals("Test 2: set size", 1, matchingUids.size());
    assertTrue("Test 2: did not find uid1", matchingUids.contains(uid1));
    assertFalse("Test 2: found uid2", matchingUids.contains(uid2));
    // Store uid2 and make sure it matches
    DbPop3Message.storeUid(mbox, ds.getId(), uid2, Mailbox.ID_FOLDER_TRASH);
    matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
    assertEquals("Test 3: set size", 2, matchingUids.size());
    assertTrue("Test 3: did not find uid1", matchingUids.contains(uid1));
    assertTrue("Test 3: did not find uid2", matchingUids.contains(uid2));
    // Test delete
    DbPop3Message.deleteUids(mbox, ds.getId());
    matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
    assertEquals("Test 3: set size", 0, matchingUids.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZDataSource(com.zimbra.client.ZDataSource) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) DataSource(com.zimbra.cs.account.DataSource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with DataSource

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

the class CreateGalSyncAccount method addDataSource.

static void addDataSource(Element request, ZimbraSoapContext zsc, Account account, Domain domain, String folder, String name, GalMode type) throws ServiceException {
    String acctName = account.getName();
    String acctId = account.getId();
    HashSet<String> galAcctIds = new HashSet<String>();
    galAcctIds.addAll(Arrays.asList(domain.getGalAccountId()));
    if (!galAcctIds.contains(acctId)) {
        galAcctIds.add(acctId);
        domain.setGalAccountId(galAcctIds.toArray(new String[0]));
    }
    // create folder if not already exists.
    if (folder == null) {
        folder = "/Contacts";
    } else if (folder.length() > 0 && folder.charAt(0) != '/') {
        folder = "/" + folder;
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    Folder contactFolder = null;
    try {
        contactFolder = mbox.getFolderByPath(null, folder);
    } catch (MailServiceException.NoSuchItemException e) {
        contactFolder = mbox.createFolder(null, folder, new Folder.FolderOptions().setDefaultView(MailItem.Type.CONTACT));
    }
    int folderId = contactFolder.getId();
    // check if there is another datasource already that maps to the same contact folder.
    for (DataSource ds : account.getAllDataSources()) {
        if (ds.getFolderId() == folderId) {
            throw MailServiceException.ALREADY_EXISTS("data source " + ds.getName() + " already contains folder " + folder);
        }
    }
    mbox.grantAccess(null, folderId, domain.getId(), ACL.GRANTEE_DOMAIN, ACL.stringToRights("r"), null);
    // create datasource
    Map<String, Object> attrs = AdminService.getAttrs(request, true);
    try {
        attrs.put(Provisioning.A_zimbraGalType, type.name());
        attrs.put(Provisioning.A_zimbraDataSourceFolderId, "" + folderId);
        if (!attrs.containsKey(Provisioning.A_zimbraDataSourceEnabled)) {
            attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
        }
        if (!attrs.containsKey(Provisioning.A_zimbraGalStatus)) {
            attrs.put(Provisioning.A_zimbraGalStatus, "enabled");
        }
        Provisioning.getInstance().createDataSource(account, DataSourceType.gal, name, attrs);
    } catch (ServiceException e) {
        ZimbraLog.gal.error("error creating datasource for GalSyncAccount", e);
        throw e;
    }
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateGalSyncAccount", "name", acctName }));
}
Also used : Folder(com.zimbra.cs.mailbox.Folder) DataSource(com.zimbra.cs.account.DataSource) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashSet(java.util.HashSet)

Example 34 with DataSource

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

the class GetDataSources method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetDataSourcesRequest req = zsc.elementToJaxb(request);
    String id = req.getId();
    Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    defendAgainstAccountOrCalendarResourceHarvesting(account, AccountBy.id, id, zsc, Admin.R_adminLoginAs, Admin.R_adminLoginCalendarResourceAs);
    Element response = zsc.createElement(AdminConstants.GET_DATA_SOURCES_RESPONSE);
    List<DataSource> sources = Provisioning.getInstance().getAllDataSources(account);
    for (DataSource ds : sources) {
        com.zimbra.cs.service.account.ToXML.encodeDataSource(response, ds);
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) GetDataSourcesRequest(com.zimbra.soap.admin.message.GetDataSourcesRequest) DataSource(com.zimbra.cs.account.DataSource)

Example 35 with DataSource

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

the class SyncGalAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    ZimbraLog.addToContext(ZimbraLog.C_ANAME, getAuthenticatedAccount(zsc).getName());
    for (Element accountEl : request.listElements(AdminConstants.E_ACCOUNT)) {
        String accountId = accountEl.getAttribute(AdminConstants.A_ID);
        Account account = prov.getAccountById(accountId);
        if (account == null) {
            throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
        }
        ZimbraLog.addToContext(ZimbraLog.C_NAME, account.getName());
        for (Element dsEl : accountEl.listElements(AdminConstants.E_DATASOURCE)) {
            String by = dsEl.getAttribute(AdminConstants.A_BY);
            String name = dsEl.getText();
            DataSource ds = by.equals("id") ? account.getDataSourceById(name) : account.getDataSourceByName(name);
            if (ds == null) {
                throw AccountServiceException.NO_SUCH_DATA_SOURCE(name);
            }
            if (!ds.getType().equals(DataSourceType.gal)) {
                continue;
            }
            boolean fullSync = dsEl.getAttributeBool(AdminConstants.A_FULLSYNC, false);
            boolean reset = dsEl.getAttributeBool(AdminConstants.A_RESET, false);
            int fid = ds.getFolderId();
            DataImport dataImport = DataSourceManager.getInstance().getDataImport(ds);
            if (dataImport instanceof GalImport) {
                ((GalImport) dataImport).importGal(fid, (reset ? reset : fullSync), reset);
            }
            // flush domain gal group cache
            Domain domain = prov.getDomain(account);
            GalGroup.flushCache(domain);
        }
    }
    return zsc.createElement(AdminConstants.SYNC_GAL_ACCOUNT_RESPONSE);
}
Also used : Account(com.zimbra.cs.account.Account) GalImport(com.zimbra.cs.gal.GalImport) DataImport(com.zimbra.cs.account.DataSource.DataImport) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataSource (com.zimbra.cs.account.DataSource)71 Account (com.zimbra.cs.account.Account)29 HashMap (java.util.HashMap)21 Provisioning (com.zimbra.cs.account.Provisioning)18 DbDataSource (com.zimbra.cs.db.DbDataSource)18 ServiceException (com.zimbra.common.service.ServiceException)15 Element (com.zimbra.common.soap.Element)14 Mailbox (com.zimbra.cs.mailbox.Mailbox)11 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)11 ArrayList (java.util.ArrayList)11 ZDataSource (com.zimbra.client.ZDataSource)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Folder (com.zimbra.cs.mailbox.Folder)7 DataSourceType (com.zimbra.soap.admin.type.DataSourceType)7 HashSet (java.util.HashSet)7 Test (org.junit.Test)7 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)6 ZMailbox (com.zimbra.client.ZMailbox)5 LdapDataSource (com.zimbra.cs.account.ldap.entry.LdapDataSource)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5