Search in sources :

Example 1 with IWriteCallerRepository

use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.

the class IsdnMoniCallImporter method doImport.

public ICallList doImport() {
    this.m_callerList = null;
    boolean doNotShowmessage = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(this.getNamespace(), CFG_SHOW_ENTRY_WARNING).equalsIgnoreCase("true");
    if (!doNotShowmessage) {
        new SWTExecuter() {

            protected void execute() {
                String message = getI18nManager().getString(getNamespace(), "message", "description", getLanguage());
                MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "message", "label", getLanguage()), message, getI18nManager().getString(getNamespace(), "confirmmessage", "label", getLanguage()), false, null, null);
                if (d.getReturnCode() == 2) {
                    m_callerList = getRuntime().getCallerFactory().createCallerList();
                }
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), CFG_SHOW_ENTRY_WARNING, (d.getToggleState() ? "true" : "false"));
                getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
                isDialogFinished = true;
            }
        }.start();
    } else {
        isDialogFinished = true;
    }
    while (!isDialogFinished) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
    Date startDate = new Date();
    File db = new File(m_filename);
    int size = (int) db.length() / 64;
    size = Math.abs(size);
    ThreadGroup g = new ThreadGroup("JAM- HeuerMigrator-ThreadGroup");
    m_callList = getRuntime().getCallFactory().createCallList(size);
    m_pnList = new ArrayList(size);
    try {
        FileReader dbReader = new FileReader(db);
        BufferedReader bufReader = new BufferedReader(dbReader);
        int i = 0;
        while (bufReader.ready()) {
            String line = bufReader.readLine();
            if (line.indexOf("->") > 0) {
                try {
                    Thread t = new Thread(g, new MigratorThread(this.m_callList, (this.m_callerList != null ? this.m_callerList : null), line, this.m_pnList));
                    t.setName("JAM-HeuerMigrator#" + (i++) + "-Thread-(non-deamon)");
                    t.start();
                    if (g.activeCount() > 100) {
                        Thread.sleep(1000);
                    }
                } catch (Exception ex) {
                    this.m_logger.severe("Unexpected error during migration: " + ex);
                }
            }
        }
        bufReader.close();
        dbReader.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find call backup file " + m_filename);
        return this.m_callList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callList;
    }
    while (g.activeCount() > 0) {
        try {
            Thread.sleep(1000);
            this.m_logger.info("Waiting for " + g.activeCount() + " Migrator threads.");
        } catch (InterruptedException e) {
            this.m_logger.severe(e.getMessage());
        }
    }
    if (this.m_callerList != null) {
        this.m_logger.info("Commiting detected callers to default caller manager.");
        String cm = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "repository");
        ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getCallerManager(cm);
        if (cmg != null && cmg.isActive() && cmg.isSupported(IWriteCallerRepository.class)) {
            ((IWriteCallerRepository) cmg).setCaller(this.m_callerList);
        }
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported call file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callList.size()).toString() + " call items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return m_callList;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICallerManager(de.janrufmonitor.repository.ICallerManager) Shell(org.eclipse.swt.widgets.Shell) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) BufferedReader(java.io.BufferedReader) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) FileReader(java.io.FileReader) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) File(java.io.File)

Example 2 with IWriteCallerRepository

use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.

the class EditorController method deleteElements.

public synchronized void deleteElements(Object list) {
    if (list != null && list instanceof ICallerList) {
        Map cms = new HashMap();
        ICallerList tmplist = null;
        ICaller c = null;
        for (int i = 0; i < ((ICallerList) list).size(); i++) {
            c = ((ICallerList) list).get(i);
            IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
            String cname = (att == null ? "all" : att.getValue());
            if (cms.containsKey(cname)) {
                tmplist = (ICallerList) cms.get(cname);
                tmplist.add(c);
            } else {
                tmplist = this.getRuntime().getCallerFactory().createCallerList(1);
                tmplist.add(c);
                cms.put(cname, tmplist);
            }
        }
        List managers = this.getActiveCallerManagers();
        ICallerManager mgr = null;
        for (int i = 0; i < managers.size(); i++) {
            mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
            if (mgr != null) {
                if (mgr.isSupported(IWriteCallerRepository.class)) {
                    tmplist = (ICallerList) cms.get("all");
                    if (tmplist != null) {
                        this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
                        ((IWriteCallerRepository) mgr).removeCaller(tmplist);
                    }
                    tmplist = (ICallerList) cms.get(mgr.getManagerID());
                    if (tmplist != null) {
                        this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
                        ((IWriteCallerRepository) mgr).removeCaller(tmplist);
                    }
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) Map(java.util.Map) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 3 with IWriteCallerRepository

use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.

the class EditorController method updateElement.

public synchronized void updateElement(Object element) {
    if (element != null && element instanceof ICallerList) {
        ICallerManager mgr = this._getRepository();
        if (mgr != null) {
            if (mgr.isSupported(IWriteCallerRepository.class)) {
                for (int i = 0, j = ((ICallerList) element).size(); i < j; i++) {
                    ((IWriteCallerRepository) mgr).updateCaller(((ICallerList) element).get(i));
                }
            }
        }
    }
    if (element != null && element instanceof ICaller) {
        List managers = this.getActiveCallerManagers();
        ICallerManager mgr = null;
        IAttribute att = ((ICaller) element).getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
        for (int i = 0; i < managers.size(); i++) {
            mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
            if (mgr != null) {
                if (mgr.isSupported(IWriteCallerRepository.class)) {
                    if (att == null || att.getValue().equalsIgnoreCase(mgr.getManagerID()))
                        ((IWriteCallerRepository) mgr).updateCaller((ICaller) element);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 4 with IWriteCallerRepository

use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.

the class RemoveCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(RemoveCallerList.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l;
    try {
        l = XMLSerializer.toCallerList(this.getPostData(req));
        if (l != null) {
            this.m_logger.info("Removing caller list with " + l.size() + " entries.");
            ((IWriteCallerRepository) mgr).removeCaller(l);
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid caller list transfered from client.");
            throw new HandlerException("Invalid caller list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 5 with IWriteCallerRepository

use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.

the class SetCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(SetCallerList.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l;
    try {
        l = XMLSerializer.toCallerList(this.getPostData(req));
        if (l != null) {
            this.m_logger.info("Setting caller list with " + l.size() + " entries.");
            ((IWriteCallerRepository) mgr).setCaller(l);
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid caller list transfered from client.");
            throw new HandlerException("Invalid caller list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Aggregations

ICallerManager (de.janrufmonitor.repository.ICallerManager)7 IWriteCallerRepository (de.janrufmonitor.repository.types.IWriteCallerRepository)7 ICallerList (de.janrufmonitor.framework.ICallerList)5 ICaller (de.janrufmonitor.framework.ICaller)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IAttribute (de.janrufmonitor.framework.IAttribute)2 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)2 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)2 Shell (org.eclipse.swt.widgets.Shell)2 ICall (de.janrufmonitor.framework.ICall)1 ICallerImporter (de.janrufmonitor.repository.imexport.ICallerImporter)1 IImExporter (de.janrufmonitor.repository.imexport.IImExporter)1 IExtendedApplicationController (de.janrufmonitor.ui.jface.application.IExtendedApplicationController)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1