use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class AbstractFilterSerializer method getFilterToString.
/**
* Transforms a IFilter object into a string representation
* @param f a valid IFilter object, should not be null
* @return a string representation of the filter.
*/
public String getFilterToString(IFilter f) {
StringBuffer sb = new StringBuffer();
if (f != null) {
FilterType ft = f.getType();
if (ft.equals(FilterType.DATE)) {
sb.append(ft.toString());
sb.append(",");
if (((DateFilter) f).getTimeframe() == -1) {
Date d = ((DateFilter) f).getDateFrom();
if (d == null)
sb.append(-1);
else
sb.append(d.getTime());
sb.append(",");
sb.append(((DateFilter) f).getDateTo().getTime());
} else {
sb.append("0");
sb.append(",");
sb.append("0");
sb.append(",");
sb.append(((DateFilter) f).getTimeframe());
}
}
if (ft.equals(FilterType.YEAR)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((YearFilter) f).getYear());
}
if (ft.equals(FilterType.MONTH_YEAR)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((MonthYearFilter) f).getYear());
sb.append(",");
sb.append(((MonthYearFilter) f).getMonth());
}
if (ft.equals(FilterType.CIP)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((CipFilter) f).getCip().getCIP());
}
if (ft.equals(FilterType.MSN)) {
sb.append(ft.toString());
sb.append(",");
IMsn[] msns = ((MsnFilter) f).getMsn();
if (msns.length == 1)
sb.append(((MsnFilter) f).getMsn()[0].getMSN());
else {
for (int i = 0, j = msns.length; i < j; i++) {
sb.append(((MsnFilter) f).getMsn()[i].getMSN());
if (i < j - 1)
sb.append(",");
}
}
}
if (ft.equals(FilterType.CALLER)) {
sb.append(ft.toString());
sb.append(",");
IPhonenumber pn = ((CallerFilter) f).getCaller().getPhoneNumber();
if (pn.isClired()) {
sb.append("clired");
} else {
sb.append(pn.getIntAreaCode());
sb.append(",");
sb.append(pn.getAreaCode());
sb.append(",");
sb.append(pn.getCallNumber());
}
}
if (ft.equals(FilterType.PHONENUMBER)) {
sb.append(ft.toString());
sb.append(",");
IPhonenumber pn = ((PhonenumberFilter) f).getPhonenumber();
sb.append(pn.getIntAreaCode());
sb.append(",");
sb.append((pn.getAreaCode().trim().length() > 0 ? pn.getAreaCode() : "+"));
sb.append(",");
sb.append((pn.getCallNumber().trim().length() > 0 ? pn.getCallNumber() : "+"));
}
if (ft.equals(FilterType.ITEMCOUNT)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((ItemCountFilter) f).getLimit());
}
if (ft.equals(FilterType.ATTRIBUTE)) {
sb.append(ft.toString());
sb.append(",");
IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
if (m != null && m.size() > 0) {
Iterator i = m.iterator();
IAttribute a = null;
while (i.hasNext()) {
a = (IAttribute) i.next();
sb.append(a.getName());
sb.append("=");
sb.append(a.getValue());
if (i.hasNext())
sb.append(",");
}
}
}
if (ft.equals(FilterType.CHARACTER)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((CharacterFilter) f).getAttributeName());
sb.append("=");
sb.append(((CharacterFilter) f).getCharacter());
}
if (ft.equals(FilterType.UUID)) {
sb.append(ft.toString());
sb.append(",");
String[] uuids = ((UUIDFilter) f).getUUID();
for (int i = uuids.length, j = 0; j < i; j++) {
sb.append(uuids[j]);
if (j < (i - 1))
sb.append(";");
}
}
// TODO: more filters to be added here
}
return sb.toString();
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class ThunderbirdTransformer method buildWorkContact.
private ICaller buildWorkContact(Map m) {
IAttributeMap attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
if (m.containsKey(FIRSTNAME))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, removeEscapedChars(((mork.Alias) m.get(FIRSTNAME)).getValue())));
if (m.containsKey(LASTNAME))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, removeEscapedChars(((mork.Alias) m.get(LASTNAME)).getValue())));
if (m.containsKey(COMPANY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, removeEscapedChars(((mork.Alias) m.get(COMPANY)).getValue())));
if (m.containsKey(WORK_STREET))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, removeEscapedChars(((mork.Alias) m.get(WORK_STREET)).getValue())));
if (m.containsKey(WORK_ZIP))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, ((mork.Alias) m.get(WORK_ZIP)).getValue()));
if (m.containsKey(WORK_CITY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, removeEscapedChars(((mork.Alias) m.get(WORK_CITY)).getValue())));
if (m.containsKey(WORK_COUNTRY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, removeEscapedChars(((mork.Alias) m.get(WORK_COUNTRY)).getValue())));
List phones = new ArrayList();
IPhonenumber pn = null;
if (m.containsKey(WORK_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(WORK_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE));
m.remove(WORK_PHONE);
}
}
if (m.containsKey(FAX_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(FAX_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE));
m.remove(FAX_PHONE);
}
}
if (m.containsKey(MOBILE_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(MOBILE_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE));
m.remove(MOBILE_PHONE);
}
}
if (phones.size() == 0)
return null;
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(null, phones, attributes);
c.setUUID(c.getName().getLastname() + "_" + c.getName().getFirstname() + "_" + c.getPhoneNumber().getTelephoneNumber());
IAttribute cm = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ThunderbirdCallerManager.ID);
c.setAttribute(cm);
return c;
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class ThunderbirdTransformer method buildHomeContact.
private ICaller buildHomeContact(Map m) {
IAttributeMap attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
if (m.containsKey(FIRSTNAME))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, removeEscapedChars(((mork.Alias) m.get(FIRSTNAME)).getValue())));
if (m.containsKey(LASTNAME))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, removeEscapedChars(((mork.Alias) m.get(LASTNAME)).getValue())));
else
return null;
if (m.containsKey(HOME_STREET))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, removeEscapedChars(((mork.Alias) m.get(HOME_STREET)).getValue())));
if (m.containsKey(HOME_ZIP))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, ((mork.Alias) m.get(HOME_ZIP)).getValue()));
if (m.containsKey(HOME_CITY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, removeEscapedChars(((mork.Alias) m.get(HOME_CITY)).getValue())));
if (m.containsKey(HOME_COUNTRY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, removeEscapedChars(((mork.Alias) m.get(HOME_COUNTRY)).getValue())));
List phones = new ArrayList();
IPhonenumber pn = null;
if (m.containsKey(HOME_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(HOME_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE));
}
}
if (m.containsKey(FAX_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(FAX_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE));
}
}
if (m.containsKey(MOBILE_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(MOBILE_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE));
}
}
if (phones.size() == 0)
return null;
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(null, phones, attributes);
c.setUUID(c.getName().getLastname() + "_" + c.getName().getFirstname() + "_" + c.getPhoneNumber().getTelephoneNumber());
IAttribute cm = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ThunderbirdCallerManager.ID);
c.setAttribute(cm);
return c;
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class TellowsProxy method getTellowsData.
public IAttributeMap getTellowsData(String number, String country) throws Exception {
IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
StringBuffer url_string = new StringBuffer();
url_string.append("https://www.tellows.de");
// if (country.equalsIgnoreCase("49")) {
// url_string.append("de");
// } else if (country.equalsIgnoreCase("43")) {
// url_string.append("at");
// } else if (country.equalsIgnoreCase("41")) {
// url_string.append("ch");
// } else {
// url_string.append("de");
// }
url_string.append("/basic/num/");
url_string.append("00");
url_string.append(country);
url_string.append((number.startsWith("0") ? number.substring(1) : number));
url_string.append("?xml=1&partner=");
url_string.append(TELLOWS_PARTNER);
url_string.append("&apikey=");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Tellows API Key: " + getTellowsApiKey());
url_string.append(getTellowsApiKey());
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Tellows.de URL: " + url_string.toString());
try {
URL url = new URL(url_string.toString());
// url.openConnection();
URLConnection c = null;
if (url.getProtocol().equalsIgnoreCase("http")) {
c = (HttpURLConnection) url.openConnection();
((HttpURLConnection) c).setRequestMethod("GET");
}
if (url.getProtocol().equalsIgnoreCase("https")) {
c = (HttpsURLConnection) url.openConnection();
((HttpsURLConnection) c).setRequestMethod("GET");
}
c.setDoInput(true);
c.setRequestProperty("User-Agent", "jAnrufmonitor " + IJAMConst.VERSION_DISPLAY);
c.connect();
StringBuffer content = new StringBuffer();
InputStream o = c.getInputStream();
if (o != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Content successfully retrieved from " + url.getHost() + "...");
InputStreamReader isr = new InputStreamReader(o, "iso-8859-1");
Thread.sleep(200);
BufferedReader br = new BufferedReader(isr);
while (br.ready()) {
content.append(br.readLine());
}
br.close();
isr.close();
}
if (content.toString().indexOf("ERROR") > 0) {
// check for ERROR
if (this.m_logger.isLoggable(Level.WARNING))
this.m_logger.warning("Invalid tellows API key detected. Service will be not processed.");
String msg = getRuntime().getI18nManagerFactory().getI18nManager().getString("service.Tellows", "invalid_api_key", "description", getLanguage());
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info(content.toString());
}
throw new Exception(msg);
}
if (content.length() > 10) {
XMLTellowsHandler handler = new XMLTellowsHandler();
SAXParser p = SAXParserFactory.newInstance().newSAXParser();
ByteArrayInputStream in = new ByteArrayInputStream(content.toString().getBytes("iso-8859-1"));
InputSource is = new InputSource(in);
is.setEncoding("iso-8859-1");
p.parse(is, handler);
m.addAll(handler.getAttributes());
}
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InterruptedException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (ParserConfigurationException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (SAXException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return m;
}
Aggregations