Search in sources :

Example 11 with ICip

use of de.janrufmonitor.framework.ICip in project janrufmonitor by tbrandt77.

the class OutgoingCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    IPhonenumber pn = null;
    try {
        String phone = req.getParameter(OutgoingCall.PARAMETER_NUMBER);
        if (phone == null || phone.length() == 0)
            pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
        else
            pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
        IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
        ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
        ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(OutgoingCall.PARAMETER_CIP), "");
        IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(OutgoingCall.PARAMETER_MSN), "");
        Date date = new Date(Long.parseLong(req.getParameter(OutgoingCall.PARAMETER_DATE)));
        ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
        ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
        Thread sender = new Thread(new HandlerThread(call, this));
        sender.start();
        resp.getContentStreamForWrite().close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 12 with ICip

use of de.janrufmonitor.framework.ICip in project janrufmonitor by tbrandt77.

the class NcidCallRaw method toCall.

public ICall toCall() {
    if (this.m_line == null || this.m_line.length() == 0)
        return null;
    if (this.m_call == null) {
        IRuntime r = PIMRuntime.getInstance();
        String[] call = this.m_line.split("\\*");
        if (call.length >= 8 && (call[0].trim().equalsIgnoreCase("CID:") || call[0].trim().equalsIgnoreCase("CIDLOG:"))) {
            // create MSN
            IMsn msn = r.getCallFactory().createMsn(getFestnetzAlias(call[6]), "");
            msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
            IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[8].trim());
            // if no CLIR call, check internal
            if (pn == null)
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[8].trim(), msn.getMSN());
            // if no internal call, check regular
            if (pn == null) {
                // if incoming call does not start with 0, the Provider number seems to have the wrong format
                // assume it is an international format 4971657110
                boolean onlyNumbers = call[8].matches("[+-]?[0-9]+");
                if (!call[8].startsWith("0") && onlyNumbers) {
                    call[8] = "00" + call[8];
                }
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[8].trim(), msn.getMSN());
            }
            ICaller caller = r.getCallerFactory().createCaller(pn);
            // create call data
            // added 2009/05/01
            String dateformat = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(NcidMonitor.NAMESPACE, "dateformat");
            if (dateformat == null || dateformat.trim().length() == 0)
                dateformat = "ddMMyyyyHHmm";
            if (Logger.getLogger(IJAMConst.DEFAULT_LOGGER).isLoggable(Level.INFO))
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Setting date format to #" + dateformat + "#");
            SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
            Date date = new Date(0);
            try {
                date = sdf.parse(call[2] + call[4]);
            } catch (ParseException e) {
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected. " + call[2] + call[4] + " does not match #" + dateformat + "#");
            }
            ICip cip = r.getCallFactory().createCip(getCip("sip"), "");
            cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
            // create attributes
            IAttributeMap am = r.getCallFactory().createAttributeMap();
            am.add(r.getCallFactory().createAttribute("ncid.key", call[6]));
            if (call.length >= 12) {
                am.add(r.getCallFactory().createAttribute("ncid.msg", call[10]));
                am.add(r.getCallFactory().createAttribute("ncid.callername", call[12]));
            }
            am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
            // create UUID
            StringBuffer uuid = new StringBuffer();
            uuid.append(date.getTime());
            uuid.append("-");
            uuid.append(pn.getTelephoneNumber());
            uuid.append("-");
            uuid.append(msn.getMSN());
            // limit uuid to 32 chars
            if (uuid.length() > 31) {
                // reduce byte length to append -1 for redundant calls max -1-1 --> 3 calls
                uuid = new StringBuffer(uuid.substring(0, 31));
            }
            this.m_call = r.getCallFactory().createCall(uuid.toString(), caller, msn, cip, date);
            this.m_call.setAttributes(am);
        }
        if (call.length >= 8 && call[0].trim().equalsIgnoreCase("OUT:")) {
            // create msn
            IMsn msn = r.getCallFactory().createMsn(getFestnetzAlias(call[6]), "");
            msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
            // create caller data
            String callByCall = null;
            IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[8].trim());
            // if no CLIR call, check internal
            if (pn == null)
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[8].trim(), msn.getMSN());
            // if no internal call, check regular
            if (pn == null) {
                // added 2006/08/10: trim call-by-call information
                // only can occure on state CALL (out-going calls)
                callByCall = getCallByCall(call[8]);
                if (callByCall != null) {
                    call[8] = call[8].substring(callByCall.length());
                }
                // requires addition of areacode
                if (!call[8].startsWith("0")) {
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Assuming number " + call[8] + " has missing areacode.");
                    call[8] = this.getGeneralAreaCode() + call[8];
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Added areacode to number " + call[8]);
                }
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[8].trim(), msn.getMSN());
            }
            ICaller caller = r.getCallerFactory().createCaller(pn);
            // create call data
            // added 2009/05/27
            String dateformat = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(NcidMonitor.NAMESPACE, "dateformat");
            if (dateformat == null || dateformat.trim().length() == 0)
                dateformat = "ddMMyyyyHHmm";
            if (Logger.getLogger(IJAMConst.DEFAULT_LOGGER).isLoggable(Level.INFO))
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Setting date format to #" + dateformat + "#");
            SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
            Date date = new Date(0);
            try {
                date = sdf.parse(call[2] + call[4]);
            } catch (ParseException e) {
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected. " + call[2] + call[4] + " does not match #" + dateformat + "#");
            }
            ICip cip = r.getCallFactory().createCip(getCip("sip"), "");
            cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
            // create attributes
            IAttributeMap am = r.getCallFactory().createAttributeMap();
            am.add(r.getCallFactory().createAttribute("ncid.key", call[6]));
            if (call.length >= 12) {
                am.add(r.getCallFactory().createAttribute("ncid.msg", call[10]));
                am.add(r.getCallFactory().createAttribute("ncid.callername", call[12]));
            }
            am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
            if (callByCall != null)
                am.add(r.getCallFactory().createAttribute("ncid.callbycall", callByCall));
            // create UUID
            StringBuffer uuid = new StringBuffer();
            uuid.append(date.getTime());
            uuid.append("-");
            uuid.append(pn.getTelephoneNumber());
            uuid.append("-");
            uuid.append(msn.getMSN());
            // limit uuid to 32 chars
            if (uuid.length() > 31) {
                // reduce byte length to append -1 for redundant calls max -1-1 --> 3 calls
                uuid = new StringBuffer(uuid.substring(0, 31));
            }
            this.m_call = r.getCallFactory().createCall(uuid.toString(), caller, msn, cip, date);
            this.m_call.setAttributes(am);
        }
    }
    return this.m_call;
}
Also used : ICip(de.janrufmonitor.framework.ICip) Date(java.util.Date) IRuntime(de.janrufmonitor.runtime.IRuntime) ICaller(de.janrufmonitor.framework.ICaller) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ParseException(java.text.ParseException) IMsn(de.janrufmonitor.framework.IMsn) SimpleDateFormat(java.text.SimpleDateFormat) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 13 with ICip

use of de.janrufmonitor.framework.ICip in project janrufmonitor by tbrandt77.

the class XMLCallHandler method startElement.

public void startElement(String uri, String name, String qname, Attributes attributes) throws SAXException {
    if (this.m_multi && qname.equalsIgnoreCase(TAG_CALLLIST)) {
        this.m_calllist = this.getRuntime().getCallFactory().createCallList();
    }
    if (qname.equalsIgnoreCase(TAG_CALL)) {
        this.m_call = this.getRuntime().getCallFactory().createCall(null, this.getRuntime().getCallFactory().createMsn("", ""), this.getRuntime().getCallFactory().createCip("", ""));
    }
    if (qname.equalsIgnoreCase(TAG_CALLER)) {
        this.m_iscaller = true;
    }
    if (this.m_iscaller) {
        super.startElement(uri, name, qname, attributes);
        return;
    }
    if (qname.equalsIgnoreCase(TAG_UUID)) {
        this.m_call.setUUID(attributes.getValue(ATTRIBUTE_VALUE));
    }
    if (qname.equalsIgnoreCase(TAG_DATE)) {
        this.m_call.setDate(new Date(Long.parseLong(attributes.getValue(ATTRIBUTE_VALUE))));
    }
    if (qname.equalsIgnoreCase(TAG_CIP)) {
        ICip cip = this.m_call.getCIP();
        cip.setCIP(attributes.getValue(ATTRIBUTE_VALUE));
        cip.setAdditional(this.getRuntime().getCipManager().getCipLabel(cip, this.getLanguage()));
        this.m_call.setCIP(cip);
    }
    if (qname.equalsIgnoreCase(TAG_MSN)) {
        IMsn msn = this.m_call.getMSN();
        msn.setMSN(attributes.getValue(ATTRIBUTE_VALUE));
        msn.setAdditional(decode(attributes.getValue(ATTRIBUTE_ADDITIONAL)));
        this.m_call.setMSN(msn);
    }
    if (qname.equalsIgnoreCase(TAG_ATTRIBUTE)) {
        IAttribute att = this.getRuntime().getCallerFactory().createAttribute(attributes.getValue(ATTRIBUTE_NAME), decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_call.setAttribute(att);
    }
}
Also used : ICip(de.janrufmonitor.framework.ICip) IAttribute(de.janrufmonitor.framework.IAttribute) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date)

Example 14 with ICip

use of de.janrufmonitor.framework.ICip in project janrufmonitor by tbrandt77.

the class OldDatFileCallImporter method migrateCallFromString.

private ICall migrateCallFromString(String scall, String datePattern) {
    if (scall != null && scall.trim().length() == 0)
        return null;
    try {
        StringTokenizer st = new StringTokenizer(scall, "%$");
        if (st.countTokens() < 5) {
            this.m_logger.warning("Invalid entry found: entry was dropped for migration.");
            return null;
        }
        String state = st.nextToken().trim();
        String msn = st.nextToken().trim();
        String caller = st.nextToken().trim();
        String cip = st.nextToken().trim();
        String date = st.nextToken().trim();
        // parse MSN
        IMsn parsedMSN = this.parseMsn(msn);
        ICip parsedCIP = this.parseCip(cip);
        IAttribute att = this.parseState(state);
        IPhonenumber phone = this.parsePhone(caller);
        IName name = this.parseName(caller);
        ICaller parsedCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
        Date parsedDate = this.parseDate(date, datePattern);
        ICall aCall = PIMRuntime.getInstance().getCallFactory().createCall(parsedCaller, parsedMSN, parsedCIP, parsedDate);
        if (!att.getName().equalsIgnoreCase("")) {
            aCall.setAttribute(att);
        }
        this.m_logger.info(aCall.toString());
        return aCall;
    } catch (NoSuchElementException ex) {
        this.m_logger.warning("FormatException: migration failed due to incompatible format information.");
    } catch (NullPointerException ex) {
        this.m_logger.warning("Invalid entry found: entry was dropped for migration.");
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) IMsn(de.janrufmonitor.framework.IMsn) IName(de.janrufmonitor.framework.IName) Date(java.util.Date) NoSuchElementException(java.util.NoSuchElementException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 15 with ICip

use of de.janrufmonitor.framework.ICip in project janrufmonitor by tbrandt77.

the class ConsoleSimulate method execute.

public void execute() {
    this.isExecuting = true;
    String number = "";
    String cip = "";
    String msn = "";
    if (this.getExecuteParams().length < 2 || this.getExecuteParams().length > 3) {
        System.out.println("ERROR: Invalid SIMULATE command.");
        System.out.println("USAGE for regular call simulation: SIMULATE <number> <msn> <cip>");
        System.out.println("USAGE for CLIR call simulation: SIMULATE <msn> <cip>");
        this.isExecuting = false;
        return;
    }
    if (this.getExecuteParams().length == 2) {
        msn = this.getExecuteParams()[0];
        cip = this.getExecuteParams()[1];
    }
    if (this.getExecuteParams().length == 3) {
        number = this.getExecuteParams()[0];
        msn = this.getExecuteParams()[1];
        cip = this.getExecuteParams()[2];
    }
    IEventBroker evtBroker = PIMRuntime.getInstance().getEventBroker();
    IPhonenumber phone = PhonenumberAnalyzer.getInstance(getRuntime()).toClirPhonenumber(number);
    if (phone != null)
        System.out.println("Call detected as CLIR: " + phone.isClired());
    if (phone == null) {
        phone = PhonenumberAnalyzer.getInstance(getRuntime()).toInternalPhonenumber(number, msn);
        if (phone != null)
            System.out.println("Call detected as internal: " + number.trim());
    }
    if (phone == null) {
        phone = PhonenumberAnalyzer.getInstance(getRuntime()).toPhonenumber(number, msn);
        if (phone != null)
            System.out.println("Call detected as external: " + number.trim());
    }
    IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
    ICaller aCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
    ICip ocip = PIMRuntime.getInstance().getCallFactory().createCip(cip, "");
    IMsn omsn = PIMRuntime.getInstance().getCallFactory().createMsn(msn, "");
    ICall newCall = PIMRuntime.getInstance().getCallFactory().createCall(aCaller, omsn, ocip);
    evtBroker.register(this);
    IEvent ev = evtBroker.createEvent(IEventConst.EVENT_TYPE_INCOMINGCALL, newCall);
    evtBroker.send(this, ev);
    evtBroker.unregister(this);
    this.isExecuting = false;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IEvent(de.janrufmonitor.framework.event.IEvent) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

ICip (de.janrufmonitor.framework.ICip)20 IMsn (de.janrufmonitor.framework.IMsn)17 ICaller (de.janrufmonitor.framework.ICaller)14 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)13 Date (java.util.Date)13 ICall (de.janrufmonitor.framework.ICall)10 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)8 IAttribute (de.janrufmonitor.framework.IAttribute)6 IName (de.janrufmonitor.framework.IName)6 IRuntime (de.janrufmonitor.runtime.IRuntime)4 ICallList (de.janrufmonitor.framework.ICallList)3 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)3 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)3 DateFilter (de.janrufmonitor.repository.filter.DateFilter)3 ItemCountFilter (de.janrufmonitor.repository.filter.ItemCountFilter)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IEvent (de.janrufmonitor.framework.event.IEvent)2