use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class XTapiCall method toCall.
public ICall toCall() {
if (this.m_call == null) {
IRuntime r = PIMRuntime.getInstance();
IPhonenumber phone = PhonenumberAnalyzer.getInstance(r).toClirPhonenumber(this.m_number);
if (phone == null)
phone = PhonenumberAnalyzer.getInstance(r).toInternalPhonenumber(this.m_number, this.m_msn);
if (phone == null)
phone = PhonenumberAnalyzer.getInstance(r).toPhonenumber(this.m_number, this.m_msn);
ICaller c = r.getCallerFactory().createCaller(phone);
IMsn msn = null;
if (this.m_msn == null) {
msn = r.getCallFactory().createMsn(getFestnetzAlias(), "");
} else {
msn = r.getCallFactory().createMsn(this.m_msn, "");
}
msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
if (this.m_name != null && this.m_name.length() > 0) {
c.setName(r.getCallerFactory().createName("", this.m_name));
}
ICip cip = r.getCallFactory().createCip(getDefaultCip(), "");
cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
// create attributes
IAttributeMap am = r.getCallFactory().createAttributeMap();
am.add(r.getCallFactory().createAttribute("tapi.device", Integer.toString(this.m_device)));
am.add(r.getCallFactory().createAttribute("tapi.instance", Integer.toString(this.m_instance)));
am.add(r.getCallFactory().createAttribute("tapi.key", getKey(this.m_device, this.m_instance)));
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
this.m_call = r.getCallFactory().createCall(c, msn, cip, new Date());
this.m_call.setAttributes(am);
}
return this.m_call;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class FritzBoxMappingManager method mapJamCallerToFritzBox.
public IPhonebookEntry mapJamCallerToFritzBox(ICaller caller) throws IOException {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Processing JAM caller: " + caller.toString());
IPhonebookEntry pe = new FritzBoxPhonebookEntry();
IAttributeMap attributes = caller.getAttributes();
String name = "";
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME)) {
name += attributes.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue() + " ";
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, attributes.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME)) {
name += attributes.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue();
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_LASTNAME, attributes.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue());
}
pe.setName(name.trim());
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_STREET)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET, attributes.get(IJAMConst.ATTRIBUTE_NAME_STREET).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_STREET_NO)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET_NO, attributes.get(IJAMConst.ATTRIBUTE_NAME_STREET_NO).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_CITY)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_CITY, attributes.get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, attributes.get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_COUNTRY, attributes.get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_CATEGORY, attributes.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY).getValue());
}
if (// hack, since FB only supports integer values
caller.getUUID().length() < 10)
pe.setUniqueID(caller.getUUID());
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_EMAIL))
pe.setEmail(attributes.get(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
if (attributes.contains("fb_entryID"))
pe.setEntryID(attributes.get("fb_entryID").getValue());
if (attributes.contains("fb_mod_time"))
pe.setModTime(attributes.get("fb_mod_time").getValue());
if (attributes.contains("fb_category"))
pe.setCategory(attributes.get("fb_category").getValue());
if (attributes.contains("fb_imageURL")) {
// replace /download.lua?path=/var by f
String nurl = attributes.get("fb_imageURL").getValue();
nurl = StringUtils.replaceString(nurl, "/download.lua?path=/var", "file:///var");
pe.setImageURL(nurl);
}
List phones = new ArrayList();
if (caller instanceof IMultiPhoneCaller) {
phones = ((IMultiPhoneCaller) caller).getPhonenumbers();
} else {
phones.add(caller.getPhoneNumber());
}
for (int i = 0; i < phones.size(); i++) {
IPhonenumber pn = (IPhonenumber) phones.get(i);
String number = this.getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, pn);
if (attributes.contains("fb_number_type_" + pn.getTelephoneNumber())) {
pe.addNumber(number, attributes.get("fb_number_type_" + pn.getTelephoneNumber()).getValue());
pe.addNumberType(number, attributes.get("fb_number_type_" + pn.getTelephoneNumber()).getValue());
} else if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber())) {
if (attributes.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber()).getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
pe.addNumber(number, "mobile");
pe.addNumberType(number, "mobile");
} else if (attributes.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber()).getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
pe.addNumber(number, "fax_work");
pe.addNumberType(number, "fax_work");
} else {
pe.addNumber(number, "home");
pe.addNumberType(number, "home");
}
} else {
pe.addNumber(number, "home");
pe.addNumberType(number, "home");
}
if (attributes.contains("fb_number_id_" + pn.getTelephoneNumber())) {
pe.addNumberID(number, attributes.get("fb_number_id_" + pn.getTelephoneNumber()).getValue());
}
if (attributes.contains("fb_number_prio_" + pn.getTelephoneNumber())) {
pe.addNumberPrio(number, attributes.get("fb_number_prio_" + pn.getTelephoneNumber()).getValue());
}
if (attributes.contains("fb_number_quickdial_" + pn.getTelephoneNumber())) {
pe.addNumberQuickDial(number, attributes.get("fb_number_quickdial_" + pn.getTelephoneNumber()).getValue());
}
if (attributes.contains("fb_number_vanity_" + pn.getTelephoneNumber())) {
pe.addNumberVanity(number, attributes.get("fb_number_vanity_" + pn.getTelephoneNumber()).getValue());
}
}
return pe;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class FritzBoxMappingManager method mapFritzBoxCallerToJam.
public ICaller mapFritzBoxCallerToJam(IPhonebookEntry pe) throws IOException {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Processing FritzBox phonebook caller: " + pe.toString());
List phones = new ArrayList(3);
IAttributeMap attributes = getRuntime().getCallerFactory().createAttributeMap();
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, FritzBoxPhonebookManager.ID));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_LASTNAME) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_LASTNAME)));
} else {
try {
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, StringEscapeUtils.unescapeHtml(pe.getName())));
} catch (Exception ex) {
this.m_logger.log(Level.WARNING, ex.getMessage(), ex);
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, pe.getName()));
}
}
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME) != null)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME)));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET) != null)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET)));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET_NO) != null)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET_NO)));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE) != null)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE)));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_CITY) != null)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_CITY)));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_COUNTRY) != null)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_COUNTRY)));
if (pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_CATEGORY) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, pe.getJamInfo(IJAMConst.ATTRIBUTE_NAME_CATEGORY)));
}
if (!FirmwareManager.getInstance().isInstance(TR064FritzBoxFirmware.class)) {
if (pe.getAddressbook() != null && pe.getAddressbook().length() > 0)
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, pe.getAddressbook()));
}
if (pe.getEmail() != null && pe.getEmail().length() > 0) {
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, pe.getEmail()));
}
if (pe.getEntryID() != null && pe.getEntryID().length() > 0) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_entryID", pe.getEntryID()));
}
if (pe.getModTime() != null && pe.getModTime().length() > 0) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_mod_time", pe.getModTime()));
}
if (pe.getCatergory() != null && pe.getCatergory().length() > 0) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_category", pe.getCatergory()));
}
if (pe.getImageURL() != null && pe.getImageURL().length() > 0) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_imageURL", pe.getImageURL()));
}
Map phs = pe.getPhones();
Iterator entries = phs.keySet().iterator();
String key = null;
IPhonenumber phone = null;
while (entries.hasNext()) {
key = (String) entries.next();
// added 2016/01/19: remove internal FB AB numbers from contact list.
if (key != null && key.startsWith("**"))
continue;
if (key != null && !PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(key) && !PhonenumberAnalyzer.getInstance(getRuntime()).isClired(key)) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("FritzBox raw number: " + key);
}
phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(key);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("FritzBox identified number: " + phone);
}
if (phone != null) {
phones.add(phone);
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + phone.getTelephoneNumber(), (String) phs.get(key)));
if (pe.getNumberID(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_id_" + phone.getTelephoneNumber(), pe.getNumberID(key)));
}
if (pe.getNumberPrio(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_prio_" + phone.getTelephoneNumber(), pe.getNumberPrio(key)));
}
if (pe.getNumberQuickDial(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_quickdial_" + phone.getTelephoneNumber(), pe.getNumberQuickDial(key)));
}
if (pe.getNumberType(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_type_" + phone.getTelephoneNumber(), pe.getNumberType(key)));
}
if (pe.getNumberVanity(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_vanity_" + phone.getTelephoneNumber(), pe.getNumberVanity(key)));
}
}
}
if (PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).isInternal((key.trim()))) {
phone = PhonenumberAnalyzer.getInstance(getRuntime()).toInternalPhonenumber(key);
if (phone != null) {
phones.add(phone);
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + phone.getTelephoneNumber(), (String) phs.get(key)));
if (pe.getNumberID(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_id_" + phone.getTelephoneNumber(), pe.getNumberID(key)));
}
if (pe.getNumberPrio(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_prio_" + phone.getTelephoneNumber(), pe.getNumberPrio(key)));
}
if (pe.getNumberQuickDial(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_quickdial_" + phone.getTelephoneNumber(), pe.getNumberQuickDial(key)));
}
if (pe.getNumberType(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_type_" + phone.getTelephoneNumber(), pe.getNumberType(key)));
}
if (pe.getNumberVanity(key) != null) {
attributes.add(getRuntime().getCallerFactory().createAttribute("fb_number_vanity_" + phone.getTelephoneNumber(), pe.getNumberVanity(key)));
}
}
}
}
if (phones.size() == 0)
return null;
String img = pe.getImageBase64();
if (img == null && pe.getImageURL() != null) {
// get from FB directly
try {
img = pe.getImageURL();
img = StringUtils.replaceString(img, "file:///var", "/download.lua?path=/var");
img = FirmwareManager.getInstance().getCallerImage(img);
} catch (GetCallerImageException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
if (img != null) {
// 2015/11/06: added image support in FB phonebook
ByteArrayInputStream in = new ByteArrayInputStream(Base64Decoder.decode(img).getBytes("iso-8859-1"));
File photoDir = new File(PathResolver.getInstance().getPhotoDirectory());
if (!photoDir.exists())
photoDir.mkdirs();
FileOutputStream out = new FileOutputStream(new File(photoDir, ((IPhonenumber) phones.get(0)).getTelephoneNumber() + ".png"));
Stream.copy(in, out, true);
attributes.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, new File(PathResolver.getInstance().getPhotoDirectory(), ((IPhonenumber) phones.get(0)).getTelephoneNumber() + ".png").getAbsolutePath()));
}
if (pe.getUniqueID() != null && pe.getUniqueID().length() > 0) {
return getRuntime().getCallerFactory().createCaller(pe.getUniqueID(), null, phones, attributes);
}
return getRuntime().getCallerFactory().createCaller(null, phones, attributes);
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class FritzBoxUUIDManager method getUUID.
public String getUUID(String d, String n, String m) {
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy HH:mm");
try {
date = sdf.parse(d);
} catch (ParseException e) {
return null;
}
IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toIdentifiedPhonenumber(n, true);
IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(m, "");
return this.getUUID(date, pn, msn);
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class HsqldbCallDatabaseHandler method prepareStatement.
private String prepareStatement(IFilter[] filters, int count, int offset, boolean isCounter, ISearchTerm[] searchTerms) {
StringBuffer sql = new StringBuffer();
// build SQL statement
sql.append("SELECT");
if (filters.length == 1 && filters[0] == null)
filters = null;
// 2008/11/28: optimized attribute filter call
if (filters != null && filters.length > 0 && hasOnlyAttributeFilter(filters)) {
if (isCounter) {
sql.append(" COUNT(calls.uuid) ");
} else {
sql.append(" content ");
}
sql.append("FROM attributes LEFT JOIN calls ON calls.uuid=attributes.ref AND ");
IFilter f = null;
for (int i = 0; i < filters.length; i++) {
f = filters[i];
if (f.getType() == FilterType.ATTRIBUTE) {
IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
if (m != null && m.size() > 0) {
sql.append("(");
sql.append("(");
Iterator iter = m.iterator();
IAttribute a = null;
while (iter.hasNext()) {
a = (IAttribute) iter.next();
sql.append("attributes.name='");
sql.append(a.getName());
sql.append("'");
sql.append(" AND ");
sql.append("attributes.value='");
sql.append(a.getValue());
sql.append("'");
if (iter.hasNext())
sql.append(" OR ");
}
sql.append("))");
}
}
}
if (searchTerms != null && searchTerms.length > 0) {
sql.append(" AND");
sql.append(createSearchTerm(searchTerms));
}
} else if (filters != null && filters.length > 0) {
int limit = -1;
for (int i = 0; i < filters.length; i++) {
if (filters[i] != null && filters[i].getType() == FilterType.ITEMCOUNT) {
limit = ((ItemCountFilter) filters[i]).getLimit();
if (!isCounter) {
// 2008/05/19: to be done since offset was introduced !!
count = limit;
offset = 0;
}
}
}
if (isCounter) {
sql.append(" COUNT(calls.uuid) ");
} else {
sql.append(" content ");
}
sql.append("FROM calls");
if (hasAttributeFilter(filters))
sql.append(", attributes");
if (filters.length == 1 && filters[0] != null && filters[0].getType() == FilterType.ITEMCOUNT)
sql.append("");
else
sql.append(" WHERE ");
IFilter f = null;
boolean isCallerFilter = false;
boolean isMsnFilter = false;
for (int i = 0; i < filters.length; i++) {
if (filters[i] != null && filters[i].getType() == FilterType.ITEMCOUNT) {
// limit=((ItemCountFilter)filters[i]).getLimit();
continue;
}
f = filters[i];
if (f == null)
continue;
if (isCallerFilter && (f.getType() == FilterType.CALLER || f.getType() == FilterType.PHONENUMBER)) {
if (i > 0)
sql.append(" OR ");
} else if (isMsnFilter && f.getType() == FilterType.MSN) {
if (i > 0)
sql.append(" OR ");
} else {
if (i > 0 && filters[i - 1].getType() != FilterType.ITEMCOUNT)
sql.append(" AND ");
}
if (f.getType() == FilterType.DATE) {
DateFilter df = (DateFilter) f;
sql.append("(calls.cdate>");
sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
sql.append(" AND calls.cdate<");
sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
sql.append(")");
}
if (f.getType() == FilterType.YEAR) {
YearFilter df = (YearFilter) f;
sql.append("(calls.cdate>");
sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
sql.append(" AND calls.cdate<");
sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
sql.append(")");
}
if (f.getType() == FilterType.MONTH_YEAR) {
MonthYearFilter df = (MonthYearFilter) f;
sql.append("(calls.cdate>");
sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
sql.append(" AND calls.cdate<");
sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
sql.append(")");
}
if (f.getType() == FilterType.CALLER) {
if (!isCallerFilter)
sql.append("(");
isCallerFilter = true;
ICaller c = (ICaller) f.getFilterObject();
IPhonenumber pn = c.getPhoneNumber();
sql.append("(calls.country='");
sql.append(pn.getIntAreaCode());
sql.append("' AND calls.areacode='");
sql.append(pn.getAreaCode());
sql.append("' AND calls.number='");
sql.append(pn.getCallNumber());
sql.append("')");
if (isCallerFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.CALLER))))
sql.append(")");
}
if (f.getType() == FilterType.PHONENUMBER) {
if (!isCallerFilter)
sql.append("(");
isCallerFilter = true;
IPhonenumber pn = (IPhonenumber) f.getFilterObject();
sql.append("(calls.country='");
sql.append(pn.getIntAreaCode());
sql.append("' AND calls.areacode='");
sql.append(pn.getAreaCode());
sql.append("' AND calls.number='");
sql.append(pn.getCallNumber());
sql.append("')");
if (isCallerFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.PHONENUMBER))))
sql.append(")");
}
if (f.getType() == FilterType.CIP) {
ICip cip = (ICip) f.getFilterObject();
sql.append("calls.cip='");
sql.append(cip.getCIP());
sql.append("'");
}
if (f.getType() == FilterType.MSN) {
IMsn[] msn = (IMsn[]) f.getFilterObject();
if (msn != null && msn.length > 0) {
if (!isMsnFilter)
sql.append("(");
isMsnFilter = true;
sql.append("(");
for (int j = 0; j < msn.length; j++) {
if (j > 0)
sql.append(" OR ");
sql.append("calls.msn='");
sql.append(msn[j].getMSN());
sql.append("'");
}
sql.append(")");
if (isMsnFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.MSN))))
sql.append(")");
}
}
if (f.getType() == FilterType.UUID) {
String[] uuids = (String[]) f.getFilterObject();
if (uuids != null && uuids.length > 0) {
sql.append("(");
for (int j = 0; j < uuids.length; j++) {
if (j > 0)
sql.append(" OR ");
sql.append("calls.uuid='");
sql.append(uuids[i]);
sql.append("'");
}
sql.append(")");
}
}
if (f.getType() == FilterType.ATTRIBUTE) {
IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
if (m != null && m.size() > 0) {
sql.append("(");
sql.append("calls.uuid=attributes.ref AND (");
Iterator iter = m.iterator();
IAttribute a = null;
while (iter.hasNext()) {
a = (IAttribute) iter.next();
sql.append("attributes.name='");
sql.append(a.getName());
sql.append("'");
sql.append(" AND ");
sql.append("attributes.value='");
sql.append(a.getValue());
sql.append("'");
if (iter.hasNext())
sql.append(" OR ");
}
sql.append("))");
}
}
}
if (searchTerms != null && searchTerms.length > 0) {
if (filters.length == 1 && filters[0] != null && filters[0].getType() == FilterType.ITEMCOUNT)
sql.append(" WHERE");
else
sql.append(" AND");
sql.append(createSearchTerm(searchTerms));
}
if (limit > 0 && !isCounter) {
sql.append(" ORDER BY cdate DESC");
}
} else {
if (isCounter) {
sql.append(" COUNT(calls.uuid) ");
} else {
sql.append(" content ");
}
sql.append("FROM calls");
if (count > 0 && offset >= 0) {
sql.append(" AS rtable");
}
if (searchTerms != null && searchTerms.length > 0) {
sql.append(" WHERE");
sql.append(createSearchTerm(searchTerms));
}
}
if (count > 0 && offset >= 0) {
sql.append(" LIMIT ");
sql.append(count);
sql.append(" OFFSET ");
sql.append(offset);
}
sql.append(";");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info(sql.toString());
return sql.toString();
}
Aggregations