Search in sources :

Example 21 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager 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)

Example 22 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.

the class OldDatFileCallImporter method parsePhone.

private IPhonenumber parsePhone(String caller) {
    if (caller.indexOf("(0") > -1) {
        IPhonenumber phone = null;
        String pn = caller.substring(caller.indexOf("(0") + 2, caller.lastIndexOf(")"));
        if (pn.length() > 0) {
            phone = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pn);
            ICallerManager cm = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
            if (cm != null && cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
                try {
                    ICaller parsedCaller = ((IIdentifyCallerRepository) cm).getCaller(phone);
                    return parsedCaller.getPhoneNumber();
                } catch (CallerNotFoundException e) {
                    this.m_logger.warning(e.getMessage());
                }
            }
        }
    }
    return PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 23 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.

the class OldDatFileCallerImporter method migrateCallerFromString.

private ICaller migrateCallerFromString(String scaller) {
    if (scaller != null && scaller.trim().length() == 0)
        return null;
    StringTokenizer st = new StringTokenizer(scaller, ";");
    String number = st.nextToken().trim();
    String caller = st.nextToken().trim();
    String reject = "0";
    if (st.hasMoreTokens())
        reject = st.nextToken().trim();
    IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(number.substring(1));
    try {
        ICaller migCaller = null;
        ICallerManager def = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
        if (def != null && def.isActive() && def.isSupported(IIdentifyCallerRepository.class)) {
            migCaller = ((IIdentifyCallerRepository) def).getCaller(pn);
        } else
            throw new CallerNotFoundException();
        StringTokenizer ctoken = new StringTokenizer(caller, " ");
        IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
        if (ctoken.hasMoreTokens()) {
            name.setFirstname(ctoken.nextToken());
        }
        if (ctoken.hasMoreTokens()) {
            name.setLastname(ctoken.nextToken());
        }
        if (ctoken.hasMoreTokens()) {
            name.setAdditional(ctoken.nextToken());
        }
        while (ctoken.hasMoreTokens()) {
            name.setAdditional(name.getAdditional() + " " + ctoken.nextToken());
        }
        migCaller.setName(name);
        if (reject.equalsIgnoreCase("1")) {
            IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_YES);
            migCaller.setAttribute(att);
        }
        if (reject.equalsIgnoreCase("0")) {
            IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_NO);
            migCaller.setAttribute(att);
        }
        LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).info(migCaller.toString());
        return migCaller;
    } catch (CallerNotFoundException e) {
        LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).warning(e.getMessage());
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttribute(de.janrufmonitor.framework.IAttribute) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) IName(de.janrufmonitor.framework.IName) ICallerManager(de.janrufmonitor.repository.ICallerManager) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 24 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.

the class ConsoleImport method execute.

public void execute() throws Exception {
    this.isExecuting = true;
    if (this.getExecuteParams().length != 1) {
        System.out.println("ERROR: Paramters are invalid. Please specify a valid module for installation.");
        this.isExecuting = false;
        return;
    }
    String filename = this.getExecuteParams()[0];
    IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallerImporter");
    if (imp != null && imp instanceof ICallerImporter) {
        ((ICallerImporter) imp).setFilename(filename);
        ICallerList cl = ((ICallerImporter) imp).doImport();
        ICallerManager mgr = this.getRuntime().getCallerManagerFactory().getCallerManager("CallerDirectory");
        if (mgr != null && mgr.isActive() && mgr.isSupported(IWriteCallerRepository.class)) {
            ((IWriteCallerRepository) mgr).setCaller(cl);
            System.out.println("INFO: Successfully imported " + cl.size() + " caller entries.");
        } else {
            System.out.println("ERROR: Caller manager is missing.");
        }
    } else {
        System.out.println("ERROR: import filter for DAT files is missing.");
    }
    this.isExecuting = false;
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) ICallerImporter(de.janrufmonitor.repository.imexport.ICallerImporter) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 25 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.

the class AbstractCallerDatabaseHandler method getCaller.

public ICaller getCaller(IPhonenumber pn) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    PreparedStatement ps = this.getStatement("SELECT_CALLER_PHONE");
    String p = pn.getTelephoneNumber();
    ResultSet rs = null;
    // check for internal telephone system numbers
    if (this.isInternalNumber(pn)) {
        ps.setString(1, p);
        rs = ps.executeQuery();
        while (rs.next()) {
            this.m_logger.info("Found exact match of call number: " + p);
            try {
                return Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    int maxLength = this.maxInternalNumberLength();
    // p must be an internal number but has no entry in this caller manager
    if (p.length() < maxLength)
        return null;
    // check for international call
    if (p.startsWith(this.getPrefix())) {
        this.m_logger.info("Found international call number: " + p);
        ICaller internationaCaller = null;
        ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
        if (cmg != null && cmg.isActive() && cmg.isSupported(IIdentifyCallerRepository.class)) {
            try {
                internationaCaller = ((IIdentifyCallerRepository) cmg).getCaller(pn);
            } catch (CallerNotFoundException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (internationaCaller != null)
            pn = internationaCaller.getPhoneNumber();
        ps.setString(1, pn.getTelephoneNumber());
        rs = ps.executeQuery();
        while (rs.next()) {
            try {
                ICaller c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                if (pn.getTelephoneNumber().equalsIgnoreCase(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
                    // found international number
                    return c;
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    // check for extension
    if (pn.getIntAreaCode() == null || pn.getIntAreaCode().length() == 0) {
        pn.setIntAreaCode(this.getDefaultIntAreaCode());
    }
    for (int i = 0; i < p.length() - maxLength; i++) {
        ps.setString(1, p.substring(0, p.length() - i) + "%");
        rs = ps.executeQuery();
        while (rs.next()) {
            try {
                ICaller c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                if (p.startsWith(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
                    // found extension phone
                    String extension = p.substring(c.getPhoneNumber().getTelephoneNumber().length(), p.length());
                    this.m_logger.info("Found call extension -" + extension + " for call number: " + p);
                    c.setUUID(new UUID().toString());
                    c.getPhoneNumber().setTelephoneNumber(p);
                    c.getPhoneNumber().setCallNumber(c.getPhoneNumber().getCallNumber() + extension);
                    // add attributes
                    IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, extension);
                    c.setAttribute(att);
                    att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, p.substring(0, p.length() - extension.length()));
                    c.setAttribute(att);
                    return c;
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) PreparedStatement(java.sql.PreparedStatement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerManager(de.janrufmonitor.repository.ICallerManager) ICaller(de.janrufmonitor.framework.ICaller) ResultSet(java.sql.ResultSet) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttribute(de.janrufmonitor.framework.IAttribute) UUID(de.janrufmonitor.util.uuid.UUID)

Aggregations

ICallerManager (de.janrufmonitor.repository.ICallerManager)31 List (java.util.List)15 ArrayList (java.util.ArrayList)14 ICallerList (de.janrufmonitor.framework.ICallerList)13 ICaller (de.janrufmonitor.framework.ICaller)12 IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)11 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)9 IWriteCallerRepository (de.janrufmonitor.repository.types.IWriteCallerRepository)7 IAttribute (de.janrufmonitor.framework.IAttribute)6 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)6 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)5 IFilter (de.janrufmonitor.repository.filter.IFilter)4 RepositoryManagerComparator (de.janrufmonitor.repository.RepositoryManagerComparator)3 ILocalRepository (de.janrufmonitor.repository.types.ILocalRepository)3 IReadCallerRepository (de.janrufmonitor.repository.types.IReadCallerRepository)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 StringTokenizer (java.util.StringTokenizer)3 Shell (org.eclipse.swt.widgets.Shell)3 IConfigurable (de.janrufmonitor.framework.configuration.IConfigurable)2