Search in sources :

Example 1 with OutlookDate

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

the class OutlookMappingManager method mapToJamCaller.

public ICaller mapToJamCaller(Dispatch oCaller, IOutlookMapping om) {
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("Applying mapping: " + om.toString());
    }
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    // processing the numbers
    List outlookNumberMappings = om.getSupportedNumbers();
    List phones = new ArrayList(outlookNumberMappings.size());
    String numbertype = null;
    String number = null;
    IPhonenumber phone = null;
    for (int i = 0, j = outlookNumberMappings.size(); i < j; i++) {
        numbertype = (String) outlookNumberMappings.get(i);
        number = Dispatch.get(oCaller, numbertype).toString().trim();
        if (number != null && !PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number) && !PhonenumberAnalyzer.getInstance(getRuntime()).isClired(number)) {
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("OutlookCallerManager raw number: " + number);
            }
            phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("OutlookCallerManager identified number: " + phone);
            }
            if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                m.add(getNumberTypeAttribute(numbertype, phone, om));
                m.add(om.createOutlookNumberTypeAttribute(phone, numbertype));
                phones.add(phone);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Added phone " + phone.toString());
                }
            }
        } else if (number != null && (number.length() > 0 && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number))) {
            // found internal number
            phone = getRuntime().getCallerFactory().createInternalPhonenumber(number);
            if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                m.add(getNumberTypeAttribute(numbertype, phone, om));
                m.add(om.createOutlookNumberTypeAttribute(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 outlookContacFieldMappings = om.getSupportedContactFields();
        String field = null;
        String jamField = null;
        IAttribute a = null;
        for (int i = 0, j = outlookContacFieldMappings.size(); i < j; i++) {
            field = (String) outlookContacFieldMappings.get(i);
            jamField = om.mapToJamField(field);
            if (jamField != null) {
                a = createAttribute(jamField, Dispatch.get(oCaller, field).toString().trim());
                if (a != null) {
                    m.add(a);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added attribute " + a.toString());
                    }
                    a = om.createOutlookContactFieldAttribute(field);
                    if (a != null)
                        m.add(a);
                }
            }
        }
        a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CREATION, Long.toString(new OutlookDate(Dispatch.get(oCaller, "CreationTime").getDate()).getTime()));
        if (a != null)
            m.add(a);
        a = createAttribute(IJAMConst.ATTRIBUTE_NAME_MODIFIED, Long.toString(new OutlookDate(Dispatch.get(oCaller, "LastModificationTime").getDate()).getTime()));
        if (a != null)
            m.add(a);
        a = createAttribute("outlook.uuid", Dispatch.get(oCaller, OutlookContactConst.User1).toString());
        if (a != null)
            m.add(a);
        String geodata = null;
        if (om.getSupportedContactFields().contains(OutlookContactConst.User3)) {
            geodata = Dispatch.get(oCaller, OutlookContactConst.User3).toString();
        }
        if (om.getSupportedContactFields().contains(OutlookContactConst.User4)) {
            geodata = Dispatch.get(oCaller, OutlookContactConst.User4).toString();
        }
        if (geodata != null && geodata.trim().length() > 0) {
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("Found geodata: " + geodata);
            }
            String[] values = geodata.split(",");
            if (values.length == 3) {
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, values[0]);
                if (a != null)
                    m.add(a);
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, values[1]);
                if (a != null)
                    m.add(a);
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, values[2]);
                if (a != null)
                    m.add(a);
            }
        }
        IAttributeMap additionalMap = om.getSpecialAttributes();
        if (additionalMap != null) {
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("Adding special attributes: " + additionalMap.toString());
            }
            m.addAll(additionalMap);
        }
        // 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);
            }
        }
        ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
        String uuid = Dispatch.get(oCaller, OutlookContactConst.User1).toString().trim();
        if (uuid != null && uuid.length() > 0)
            outlookCaller.setUUID(uuid);
        else
            // outlookCaller.setUUID(outlookCaller.getName().getLastname()+"_"+outlookCaller.getName().getFirstname()+"_"+outlookCaller.getPhoneNumber().getTelephoneNumber());
            outlookCaller.setUUID(new UUID().toString());
        this.setPictureAttribute(outlookCaller, oCaller);
        IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
        outlookCaller.setAttribute(cm);
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Created Outlook contact: " + outlookCaller.toString());
        }
        return outlookCaller;
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ArrayList(java.util.ArrayList) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) UUID(de.janrufmonitor.util.uuid.UUID) OutlookDate(de.janrufmonitor.repository.OutlookDate) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IAttribute (de.janrufmonitor.framework.IAttribute)1 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 ICaller (de.janrufmonitor.framework.ICaller)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 OutlookDate (de.janrufmonitor.repository.OutlookDate)1 UUID (de.janrufmonitor.util.uuid.UUID)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1