Search in sources :

Example 26 with IAttributeMap

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

the class GeoCoder method main.

public static void main(String[] args) {
    IAttributeMap m = new AttributeMap();
    m.add(new Attribute(IJAMConst.ATTRIBUTE_NAME_CITY, "Angelbachtal"));
    m.add(new Attribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, "74918"));
    m.add(new Attribute(IJAMConst.ATTRIBUTE_NAME_STREET, "Lindenweg"));
    m.add(new Attribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO, "12"));
    System.out.println(GeoCoder.getInstance().getCoordinates(m));
}
Also used : IAttributeMap(de.janrufmonitor.framework.IAttributeMap) AttributeMap(de.janrufmonitor.framework.objects.AttributeMap) Attribute(de.janrufmonitor.framework.objects.Attribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 27 with IAttributeMap

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

the class CsvCallerImporter method doImport.

public ICallerList doImport() {
    this.m_current = 0;
    this.m_total = 0;
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    this.m_logger.info("Start reading CSV file " + this.m_filename);
    File csv = new File(this.m_filename);
    if (csv == null || !csv.exists() || !csv.isFile())
        return cl;
    List contacts = new ArrayList();
    List attributes = new ArrayList();
    try {
        InputStreamReader inr = new InputStreamReader(new FileInputStream(csv));
        BufferedReader bufReader = new BufferedReader(inr);
        String line = null;
        String[] tokens = null;
        while (bufReader.ready()) {
            line = bufReader.readLine();
            // ignore comments
            if (line.trim().startsWith("#"))
                continue;
            tokens = line.split(";");
            if (attributes.size() == 0) {
                attributes.addAll(Arrays.asList(tokens));
                continue;
            }
            contacts.add(tokens);
        }
        bufReader.close();
        inr.close();
        this.m_total = contacts.size();
        for (int i = 0; i < this.m_total; i++) {
            this.m_current++;
            tokens = (String[]) contacts.get(i);
            if (tokens.length == attributes.size()) {
                List phones = new ArrayList();
                IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
                String attributename = null;
                for (int j = 0; j < tokens.length; j++) {
                    attributename = (String) attributes.get(j);
                    if (attributename.trim().toLowerCase().startsWith("pn:")) {
                        IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toIdentifiedPhonenumber(tokens[j]);
                        if (pn != null) {
                            phones.add(pn);
                            if (attributename.endsWith(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE))
                                m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE));
                            if (attributename.endsWith(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))
                                m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE));
                            if (attributename.endsWith(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE))
                                m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE));
                        }
                    } else {
                        if (tokens[j].trim().length() > 0) {
                            m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(attributename, tokens[j]));
                            if (attributename.equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_IMAGEURL)) {
                                String img = getImageFromURL(tokens[j]);
                                if (img != null) {
                                    m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, img));
                                }
                            }
                        }
                    }
                }
                if (phones.size() == 0) {
                    this.m_logger.warning("No phone numbers found. Can't parse CSV contact: " + Arrays.asList(tokens));
                    continue;
                }
                if (!m.contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME)) {
                    this.m_logger.warning("No LASTANME (ln) attribute found. Can't parse CSV contact: " + Arrays.asList(tokens));
                    continue;
                }
                cl.add(PIMRuntime.getInstance().getCallerFactory().createCaller(null, phones, m));
            } else {
                this.m_logger.warning("Invalid token length. Can't parse CSV contact data: " + Arrays.asList(tokens));
            }
        }
    } catch (FileNotFoundException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return cl;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ICallerList(de.janrufmonitor.framework.ICallerList) BufferedReader(java.io.BufferedReader) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 28 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap 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)

Example 29 with IAttributeMap

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

the class OutlookMappingManager method mapToOutlookCaller.

public void mapToOutlookCaller(Dispatch oCaller, ICaller jamCaller, IOutlookMapping om) {
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("Appliing mapping: " + om.toString());
    }
    // clear all supported fields in outlook
    List outlookContacFieldMappings = om.getSupportedContactFields();
    String field = null;
    for (int i = 0, j = outlookContacFieldMappings.size(); i < j; i++) {
        field = (String) outlookContacFieldMappings.get(i);
        Dispatch.put(oCaller, field, "");
    }
    // clear all supported numbers in outlook
    List outlookNumberMappings = om.getSupportedNumbers();
    String numbertype = null;
    for (int i = 0, j = outlookNumberMappings.size(); i < j; i++) {
        numbertype = (String) outlookNumberMappings.get(i);
        Dispatch.put(oCaller, numbertype, "");
    }
    // set address data
    Dispatch.put(oCaller, OutlookContactConst.User1, jamCaller.getUUID());
    Dispatch.put(oCaller, OutlookContactConst.User2, jamCaller.getPhoneNumber().getIntAreaCode() + jamCaller.getPhoneNumber().getAreaCode());
    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 = jamCaller.getAttribute(jamField);
            if (a != null) {
                // TODO: 2008/08/13 - Hack for street no
                if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_STREET)) {
                    if (jamCaller.getAttributes().contains((IJAMConst.ATTRIBUTE_NAME_STREET_NO))) {
                        Dispatch.put(oCaller, field, a.getValue() + " " + jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO).getValue());
                    } else {
                        Dispatch.put(oCaller, field, a.getValue());
                    }
                } else if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) || a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) || a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
                    StringBuffer geodata = new StringBuffer();
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC).getValue());
                    geodata.append(",");
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
                    geodata.append(",");
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
                    Dispatch.put(oCaller, field, geodata.toString());
                } else {
                    Dispatch.put(oCaller, field, a.getValue());
                }
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Setting attribute: " + a.toString());
                }
            }
        }
    }
    // set phone numbers
    if (jamCaller instanceof IMultiPhoneCaller) {
        List pns = ((IMultiPhoneCaller) jamCaller).getPhonenumbers();
        IPhonenumber pn = null;
        IAttributeMap m = jamCaller.getAttributes();
        for (int k = 0; k < pns.size(); k++) {
            pn = (IPhonenumber) pns.get(k);
            this.setContactPhone(oCaller, pn, m, om);
        }
    } else {
        this.setContactPhone(oCaller, jamCaller.getPhoneNumber(), jamCaller.getAttributes(), om);
    }
    Dispatch.call(oCaller, "RemovePicture");
    if (this.getAttribute(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)).length() > 0) {
        try {
            Dispatch.call(oCaller, "AddPicture", PathResolver.getInstance().resolve(this.getAttribute(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH))));
        } catch (ComFailException e) {
            this.m_logger.log(Level.WARNING, e.getMessage(), e);
        }
    }
    Dispatch.call(oCaller, "Save");
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ComFailException(com.jacob.com.ComFailException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 30 with IAttributeMap

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

the class OutlookTransformer method createBusinessAddressAttributes.

private IAttributeMap createBusinessAddressAttributes(Dispatch contact) throws ComFailException {
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, Dispatch.get(contact, "BusinessAddressCity").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, Dispatch.get(contact, "BusinessAddressPostalCode").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, Dispatch.get(contact, "BusinessAddressStreet").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO, Dispatch.get(contact, "BusinessAddressPostOfficeBox").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, Dispatch.get(contact, "BusinessAddressCountry").toString().trim());
    if (attribute != null)
        m.add(attribute);
    return m;
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

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