Search in sources :

Example 6 with IAttributeMap

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

the class LdapMappingManager method mapToJamCaller.

public ICaller mapToJamCaller(LDAPEntry entry) {
    IAttributeMap attributes = mapAttributes(entry);
    if (attributes == null || attributes.size() == 0) {
        m_logger.warning("The LDAP entry " + entry.getDN() + " has no matching attributes.");
        return null;
    }
    attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, LdapRepository.ID));
    List phones = mapPhones(entry, attributes);
    if (phones == null || phones.size() == 0) {
        m_logger.warning("The LDAP entry " + entry.getDN() + " has no matching phonenumbers.");
        return null;
    }
    return getRuntime().getCallerFactory().createCaller(entry.getDN(), null, phones, attributes);
}
Also used : IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with IAttributeMap

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

the class MacAddressBookManager method getCallers.

public ICallerList getCallers(IFilter filter) {
    try {
        if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
                return getProxy().getContacts(a.getValue());
            }
        }
        if (filter != null && filter.getType().equals(FilterType.PHONENUMBER)) {
            String intarea = ((PhonenumberFilter) filter).getPhonenumber().getIntAreaCode();
            String area = ((PhonenumberFilter) filter).getPhonenumber().getAreaCode();
            return getProxy().getContactsByAreaCode(intarea, area);
        }
        if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
            IAttribute charAtt = getRuntime().getCallerFactory().createAttribute(((CharacterFilter) filter).getAttributeName(), ((CharacterFilter) filter).getCharacter());
            return getProxy().getContactsByCharAttribute(charAtt);
        }
        return getProxy().getContacts(null);
    } catch (MacAddressBookProxyException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 8 with IAttributeMap

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

the class MacAddressBookMappingManager method mapToJamCaller.

@SuppressWarnings("unchecked")
public synchronized ICaller mapToJamCaller(Map<?, ?> oCaller, IMacAddressBookMapping om) {
    if (!oCaller.containsKey(IMacAddressBookConst.PHONE)) {
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Mac Address Book entry has no phone numbers: " + oCaller);
        }
        return null;
    }
    if (((List) oCaller.get(IMacAddressBookConst.PHONE)).size() == 0) {
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Mac Address Book entry phone numbers are empty: " + oCaller);
        }
        return null;
    }
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("Appliing mapping: " + om.toString());
    }
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    // processing the numbers
    List macNumberMappings = om.getSupportedNumbers();
    // added 2015/05/03: added generic etiketts
    if (macNumberMappings.contains("*")) {
        macNumberMappings.addAll(this.getGenericMappings(((List) oCaller.get(IMacAddressBookConst.PHONE))));
    }
    List phones = new ArrayList(macNumberMappings.size());
    String numbertype = null;
    String number = null;
    IPhonenumber phone = null;
    for (int i = 0, j = macNumberMappings.size(); i < j; i++) {
        numbertype = (String) macNumberMappings.get(i);
        while ((number = getRawNumber(((List) oCaller.get(IMacAddressBookConst.PHONE)), numbertype)) != null) {
            if (number != null && !PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number) && !PhonenumberAnalyzer.getInstance(getRuntime()).isClired(number)) {
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("MacAddressbook raw number: " + number);
                }
                phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("MacAddressbook identified number: " + phone);
                }
                if (phone != null && phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                    m.add(getNumberTypeAttribute(numbertype, phone, om));
                    m.add(om.createMacAddressBookNumberTypeAttribute(phone, numbertype));
                    phones.add(phone);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added phone " + phone.toString());
                    }
                }
            } else if (number != null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number)) {
                // found internal number
                phone = getRuntime().getCallerFactory().createInternalPhonenumber(number);
                if (phone != null && phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                    m.add(getNumberTypeAttribute(numbertype, phone, om));
                    m.add(om.createMacAddressBookNumberTypeAttribute(phone, numbertype));
                    phones.add(phone);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added internal phone " + phone.toString());
                    }
                }
            }
        }
    }
    if (phones.size() > 0) {
        if (phones.size() > 1)
            Collections.sort(phones, new PhonenumberTypeComparator(m, om));
        // process address data
        List macContacFieldMappings = om.getSupportedContactFields();
        String field = null;
        String jamField = null;
        IAttribute a = null;
        if (oCaller.containsKey(IMacAddressBookAddressMapping.ADDRESS)) {
            for (int i = 0, j = macContacFieldMappings.size(); i < j; i++) {
                field = (String) macContacFieldMappings.get(i);
                jamField = om.mapToJamField(field);
                if (jamField != null) {
                    a = createAttribute(jamField, this.getRawAddress((List) oCaller.get(IMacAddressBookAddressMapping.ADDRESS), om.getSupportedAddressType(), field));
                    if (a != null) {
                        m.add(a);
                        if (this.m_logger.isLoggable(Level.INFO)) {
                            this.m_logger.info("Added attribute " + a.toString());
                        }
                    }
                }
            }
        }
        if (oCaller.containsKey(IMacAddressBookAddressMapping.EMAIL)) {
            jamField = om.mapToJamField(IMacAddressBookAddressMapping.EMAIL);
            a = createAttribute(jamField, this.getRawEmail((List) oCaller.get(IMacAddressBookAddressMapping.EMAIL), om.getSupportedEmailType()));
            if (a != null) {
                m.add(a);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Added attribute " + a.toString());
                }
            }
        }
        for (int i = 0, j = macContacFieldMappings.size(); i < j; i++) {
            field = (String) macContacFieldMappings.get(i);
            jamField = om.mapToJamField(field);
            if (jamField != null) {
                a = createAttribute(jamField, (String) oCaller.get(field));
                if (a != null) {
                    m.add(a);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added attribute " + a.toString());
                    }
                }
            }
        }
        // date format 2010-07-22 15:34:45 +0200
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
        if (oCaller.containsKey(IMacAddressBookConst.CREATION)) {
            try {
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CREATION, Long.toString(sdf.parse((String) oCaller.get(IMacAddressBookConst.CREATION)).getTime()));
            } catch (ParseException e) {
                this.m_logger.warning("Could not parse creation date: " + oCaller.get(IMacAddressBookConst.CREATION));
            }
            if (a != null)
                m.add(a);
        }
        if (oCaller.containsKey(IMacAddressBookConst.MODIFICATION)) {
            try {
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_MODIFIED, Long.toString(sdf.parse((String) oCaller.get(IMacAddressBookConst.MODIFICATION)).getTime()));
            } catch (ParseException e) {
                this.m_logger.warning("Could not parse modification date: " + oCaller.get(IMacAddressBookConst.MODIFICATION));
            }
            if (a != null)
                m.add(a);
        }
        if (oCaller.containsKey(IMacAddressBookConst.PARENT_GROUPS)) {
            List categories = (List) oCaller.get(IMacAddressBookConst.PARENT_GROUPS);
            if (categories.size() > 0) {
                for (int i = 0; i < categories.size(); i++) {
                    a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, MacAddressBookProxy.getInstance().getCategory((String) categories.get(i)));
                    if (a != null) {
                        m.add(a);
                        break;
                    }
                }
            }
        }
        // TODO: 2008/08/13 - Hack - split up street and street no
        IAttribute street = m.get(IJAMConst.ATTRIBUTE_NAME_STREET);
        if (street != null && street.getValue().trim().length() > 0) {
            String[] streetSplit = street.getValue().trim().split(" ");
            if (streetSplit.length > 1) {
                street.setValue("");
                for (int i = 0; i < streetSplit.length - 1; i++) {
                    street.setValue(street.getValue() + " " + streetSplit[i]);
                }
                street.setValue(street.getValue().trim());
                m.add(street);
                IAttribute streetno = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO, streetSplit[streetSplit.length - 1]);
                m.add(streetno);
            }
        }
        String uuid = (String) oCaller.get(IMacAddressBookConst.UID);
        if (uuid == null || uuid.trim().length() == 0)
            uuid = new UUID().toString();
        try {
            MacAddressBookProxy.getInstance().getDataHandler().deleteAttributes(uuid);
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
        ICaller macCaller = getRuntime().getCallerFactory().createCaller(uuid, null, phones, m);
        this.setPictureAttribute(macCaller, oCaller);
        this.setGeoData(macCaller);
        IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
        macCaller.setAttribute(cm);
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Created Mac address book contact: " + macCaller.toString());
        }
        try {
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_LASTNAME, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue());
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_CITY, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY).getValue());
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_COUNTRY, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue());
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue());
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
        return macCaller;
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ICaller(de.janrufmonitor.framework.ICaller) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) UUID(de.janrufmonitor.util.uuid.UUID) SimpleDateFormat(java.text.SimpleDateFormat) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 9 with IAttributeMap

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

the class Serializer method toString.

private static String toString(ICaller caller, boolean includeImage) throws SerializerException {
    if (caller instanceof IMultiPhoneCaller) {
        return toString((IMultiPhoneCaller) caller, includeImage);
    }
    StringBuffer serialized = new StringBuffer(128);
    try {
        // add int area code
        serialized.append(encode((caller.getPhoneNumber().getIntAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getIntAreaCode())));
        serialized.append(m_token);
        // add area code
        serialized.append(encode((caller.getPhoneNumber().getAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getAreaCode())));
        serialized.append(m_token);
        // add call number
        serialized.append(encode((caller.getPhoneNumber().getCallNumber().length() == 0 ? BLANK : caller.getPhoneNumber().getCallNumber())));
        serialized.append(m_token);
        // add firstname
        serialized.append(encode((caller.getName().getFirstname().length() == 0 ? BLANK : caller.getName().getFirstname())));
        serialized.append(m_token);
        // add lastname
        serialized.append(encode((caller.getName().getLastname().length() == 0 ? BLANK : caller.getName().getLastname())));
        serialized.append(m_token);
        // add additional
        serialized.append(encode((caller.getName().getAdditional().length() == 0 ? BLANK : caller.getName().getAdditional())));
        serialized.append(m_token);
        // add caller UUID
        serialized.append(encode((caller.getUUID().length() == 0 ? BLANK : caller.getUUID())));
        serialized.append(m_token);
        // add attributes
        IAttributeMap al = caller.getAttributes();
        if (al.size() == 0)
            serialized.append(BLANK);
        Iterator i = al.iterator();
        IAttribute att = null;
        while (i.hasNext()) {
            att = (IAttribute) i.next();
            serialized.append(encode(att.getName()));
            serialized.append(EQUAL);
            serialized.append(encodeAttributeValue(att.getValue()));
            serialized.append(m_atoken);
        }
    } catch (Throwable t) {
        throw new SerializerException(t.getMessage());
    }
    return serialized.toString();
}
Also used : Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller)

Example 10 with IAttributeMap

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

the class Serializer method toCall.

/**
 * Deserializes a byte array stream into an call object.
 *
 * @param call call as a byte array representation.
 * @param runtime runtime to used
 * @return call object
 * @throws SerializerException
 */
public static ICall toCall(byte[] call, IRuntime runtime) throws SerializerException {
    if (runtime == null)
        throw new SerializerException("Runtime object is not set but required.");
    String callString = new String(call);
    if (callString.indexOf(m_ctoken) < 0)
        throw new SerializerException("Call format is invalid. Call is set <" + callString + ">");
    // tokenize the whole input
    StringTokenizer st = new StringTokenizer(callString, m_ctoken);
    if (st.countTokens() != 2)
        throw new SerializerException("Call format is invalid. Found " + st.countTokens() + " tokens, but required are exactly 2.");
    ICaller caller = toCaller(st.nextToken().getBytes(), runtime);
    if (!st.hasMoreTokens())
        throw new SerializerException("Call format is invalid. Second token is empty.");
    // tokenize to call data
    callString = st.nextToken();
    st = new StringTokenizer(callString, m_token);
    if (st.countTokens() < 7)
        throw new SerializerException("Call format is invalid. Token count < 7.");
    // build MSN
    IMsn msn = runtime.getCallFactory().createMsn(// token 1
    decode(st.nextToken().trim()), // token 2
    decode(st.nextToken().trim()));
    if (msn.getMSN().equalsIgnoreCase("*")) {
        msn.setMSN("0");
    }
    // build CIP
    ICip cip = runtime.getCallFactory().createCip(// token 3
    decode(st.nextToken().trim()), // token 4
    decode(st.nextToken().trim()));
    // token 5
    String uuid = decode(st.nextToken().trim());
    // token 6
    Date date = new Date(Long.parseLong(decode(st.nextToken().trim())));
    // build attributes
    String attString = decode(st.nextToken().trim());
    IAttributeMap attList = runtime.getCallFactory().createAttributeMap();
    if (attString.length() > 0) {
        StringTokenizer ast = new StringTokenizer(attString, m_atoken);
        String attrib = null;
        while (ast.hasMoreTokens()) {
            attrib = ast.nextToken().trim();
            if (attrib.indexOf(EQUAL) > -1) {
                IAttribute att = runtime.getCallFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
                attList.add(att);
            }
        }
    }
    return runtime.getCallFactory().createCall(uuid, caller, msn, cip, date, attList);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICip(de.janrufmonitor.framework.ICip) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date)

Aggregations

IAttributeMap (de.janrufmonitor.framework.IAttributeMap)64 IAttribute (de.janrufmonitor.framework.IAttribute)37 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)36 ICaller (de.janrufmonitor.framework.ICaller)31 List (java.util.List)24 ICallerList (de.janrufmonitor.framework.ICallerList)23 ArrayList (java.util.ArrayList)21 Iterator (java.util.Iterator)17 IOException (java.io.IOException)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)13 Date (java.util.Date)12 IMsn (de.janrufmonitor.framework.IMsn)11 File (java.io.File)10 ICip (de.janrufmonitor.framework.ICip)8 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)8 Message (de.janrufmonitor.exception.Message)6 ICall (de.janrufmonitor.framework.ICall)6 SimpleDateFormat (java.text.SimpleDateFormat)6 StringTokenizer (java.util.StringTokenizer)6 IFilter (de.janrufmonitor.repository.filter.IFilter)5