use of de.janrufmonitor.framework.IAttributeMap 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.IAttributeMap in project janrufmonitor by tbrandt77.
the class CommentCallerHandler method storeComments.
private void storeComments(List comments, String directory) {
// clean up old comments
File[] oldComments = new File(directory).listFiles(new FileFilter() {
public boolean accept(File pathname) {
if (pathname.getAbsolutePath().endsWith(getCommentFilenameExtension())) {
return true;
}
return false;
}
});
for (int i = 0; i < oldComments.length; i++) oldComments[i].delete();
for (int i = 0; i < comments.size(); i++) {
IComment comment = (IComment) comments.get(i);
File commentFile = new File(directory + comment.getID() + this.getCommentFilenameExtension());
try {
FileWriter commentWriter = new FileWriter(commentFile);
BufferedWriter bufWriter = new BufferedWriter(commentWriter);
bufWriter.write(comment.getText());
bufWriter.flush();
bufWriter.close();
commentWriter.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + directory + comment.getID());
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + directory + comment.getID());
}
commentFile.setLastModified(comment.getDate().getTime());
Properties commentAttributes = new Properties();
IAttributeMap m = comment.getAttributes();
Iterator it = m.iterator();
IAttribute a = null;
while (it.hasNext()) {
a = (IAttribute) it.next();
commentAttributes.setProperty(a.getName(), a.getValue());
}
File commentAttributesFile = new File(commentFile.getAbsolutePath() + ".attributes");
try {
FileOutputStream fos = new FileOutputStream(commentAttributesFile);
commentAttributes.store(fos, "");
fos.flush();
fos.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + directory + comment.getID());
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + directory + comment.getID());
}
commentAttributesFile.setLastModified(comment.getDate().getTime());
// TODO: removed due to performance reasons
// this.storeAttachments(comment.getAttachments(), directory + comment.getID());
}
}
use of de.janrufmonitor.framework.IAttributeMap 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();
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class HsqldbCallerDatabaseHandler method buildCallerList.
protected ICallerList buildCallerList(IFilter[] filters) throws SQLException {
ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
if (!isConnected())
return cl;
StringBuffer sql = new StringBuffer();
Statement stmt = m_con.createStatement();
// build SQL statement
sql.append("SELECT content FROM callers");
if (hasAttributeFilter(filters))
sql.append(", attributes");
if (filters != null && filters.length > 0 && filters[0] != null) {
IFilter f = null;
sql.append(" WHERE ");
for (int i = 0; i < filters.length; i++) {
f = filters[i];
if (i > 0)
sql.append(" AND ");
if (f.getType() == FilterType.PHONENUMBER) {
IPhonenumber pn = (IPhonenumber) f.getFilterObject();
sql.append("country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "'");
}
if (f.getType() == FilterType.ATTRIBUTE) {
IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
if (m != null && m.size() > 0) {
sql.append("(");
sql.append("callers.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 (f.getType() == FilterType.CHARACTER) {
sql.append("(");
sql.append("callers.uuid=attributes.ref AND (");
sql.append("attributes.name='");
sql.append(((CharacterFilter) f).getAttributeName());
sql.append("'");
sql.append(" AND ");
sql.append("(attributes.value like '");
sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
sql.append("%'");
sql.append(" OR attributes.value like '");
sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
sql.append("%'");
sql.append(")))");
}
}
}
sql.append(";");
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next()) {
try {
cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
return cl;
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class HsqldbMultiPhoneCallerDatabaseHandler method buildCallerList.
protected ICallerList buildCallerList(IFilter[] filters, ISearchTerm[] searchTerms) throws SQLException {
ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
if (!isConnected())
return cl;
StringBuffer sql = new StringBuffer();
Statement stmt = m_con.createStatement();
// build SQL statement
sql.append("SELECT content FROM callers");
if (hasAttributeFilter(filters))
sql.append(", attributes");
if (filters != null && filters.length > 0 && filters[0] != null) {
IFilter f = null;
sql.append(" WHERE ");
for (int i = 0; i < filters.length; i++) {
f = filters[i];
if (i > 0)
sql.append(" AND ");
if (f.getType() == FilterType.PHONENUMBER) {
IPhonenumber pn = (IPhonenumber) f.getFilterObject();
// sql.append("country='"+pn.getIntAreaCode()+"' AND areacode='"+pn.getAreaCode()+"'");
ResultSet rs = stmt.executeQuery("SELECT ref FROM phones WHERE country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "';");
if (rs.next()) {
sql.append("uuid='");
sql.append(rs.getString(1));
sql.append("'");
while (rs.next()) {
sql.append(" OR uuid='");
sql.append(rs.getString(1));
sql.append("'");
}
}
}
if (f.getType() == FilterType.ATTRIBUTE) {
IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
if (m != null && m.size() > 0) {
sql.append("(");
sql.append("callers.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 (f.getType() == FilterType.CHARACTER) {
sql.append("(");
sql.append("callers.uuid=attributes.ref AND (");
sql.append("attributes.name='");
sql.append(((CharacterFilter) f).getAttributeName());
sql.append("'");
sql.append(" AND ");
sql.append("(attributes.value like '");
sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
sql.append("%'");
sql.append(" OR attributes.value like '");
sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
sql.append("%'");
sql.append(")))");
}
}
if (searchTerms != null && searchTerms.length > 0) {
sql.append(" AND");
sql.append(createSearchTerm(searchTerms));
}
} else {
if (searchTerms != null && searchTerms.length > 0) {
sql.append(" WHERE");
sql.append(createSearchTerm(searchTerms));
}
}
sql.append(";");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info(sql.toString());
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next()) {
try {
cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
return cl;
}
Aggregations