use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class LdapContactsProxy method identify.
public synchronized ICaller identify(IPhonenumber pn) throws LdapContactsException {
ICaller c = Identifier.identifyDefault(getRuntime(), pn);
if (c == null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
c = getRuntime().getCallerFactory().createCaller(p);
}
if (c != null) {
pn = c.getPhoneNumber();
try {
List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("List of found UUIDs: " + uuids);
}
if (uuids.size() > 0) {
String uuid = null;
ICaller contact = null;
for (int k = 0; k < uuids.size(); k++) {
uuid = (String) uuids.get(k);
try {
contact = this.identifyByUUID(uuid);
if (contact != null) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("LDAP contact found for UUID: " + uuid);
}
contact.setUUID(new UUID().toString());
if (contact instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) contact).getPhonenumbers().clear();
}
contact.setPhoneNumber(pn);
contact.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber()));
return contact;
}
} catch (LdapContactsException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
} else {
Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(LdapRepository.NAMESPACE);
if (config.getProperty(CFG_LDAP_KEEPEXT, "false").equalsIgnoreCase("true")) {
// iterate down
String callnumber = pn.getCallNumber();
if (callnumber.length() > 1) {
pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
ICaller ca = this.identify(pn);
if (ca != null) {
pn.setCallNumber(callnumber);
if (ca instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) ca).getPhonenumbers().clear();
}
ca.setPhoneNumber(pn);
// set extension
if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
if (pn.getTelephoneNumber().length() > centralnumber.length()) {
IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
ca.setAttribute(att);
}
}
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Caller match by central number: " + ca.toString());
}
return ca;
}
}
}
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
}
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
return null;
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class MacAddressBookManager method getCallers.
public ICallerList getCallers(IFilter filter) {
try {
if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
return getProxy().getContacts(a.getValue());
}
}
if (filter != null && filter.getType().equals(FilterType.PHONENUMBER)) {
String intarea = ((PhonenumberFilter) filter).getPhonenumber().getIntAreaCode();
String area = ((PhonenumberFilter) filter).getPhonenumber().getAreaCode();
return getProxy().getContactsByAreaCode(intarea, area);
}
if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
IAttribute charAtt = getRuntime().getCallerFactory().createAttribute(((CharacterFilter) filter).getAttributeName(), ((CharacterFilter) filter).getCharacter());
return getProxy().getContactsByCharAttribute(charAtt);
}
return getProxy().getContacts(null);
} catch (MacAddressBookProxyException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return getRuntime().getCallerFactory().createCallerList();
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class MacAddressBookMappingManager method mapToJamCaller.
@SuppressWarnings("unchecked")
public synchronized ICaller mapToJamCaller(Map<?, ?> oCaller, IMacAddressBookMapping om) {
if (!oCaller.containsKey(IMacAddressBookConst.PHONE)) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Mac Address Book entry has no phone numbers: " + oCaller);
}
return null;
}
if (((List) oCaller.get(IMacAddressBookConst.PHONE)).size() == 0) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Mac Address Book entry phone numbers are empty: " + oCaller);
}
return null;
}
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Appliing mapping: " + om.toString());
}
IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
// processing the numbers
List macNumberMappings = om.getSupportedNumbers();
// added 2015/05/03: added generic etiketts
if (macNumberMappings.contains("*")) {
macNumberMappings.addAll(this.getGenericMappings(((List) oCaller.get(IMacAddressBookConst.PHONE))));
}
List phones = new ArrayList(macNumberMappings.size());
String numbertype = null;
String number = null;
IPhonenumber phone = null;
for (int i = 0, j = macNumberMappings.size(); i < j; i++) {
numbertype = (String) macNumberMappings.get(i);
while ((number = getRawNumber(((List) oCaller.get(IMacAddressBookConst.PHONE)), numbertype)) != null) {
if (number != null && !PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number) && !PhonenumberAnalyzer.getInstance(getRuntime()).isClired(number)) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("MacAddressbook raw number: " + number);
}
phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("MacAddressbook identified number: " + phone);
}
if (phone != null && phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
m.add(getNumberTypeAttribute(numbertype, phone, om));
m.add(om.createMacAddressBookNumberTypeAttribute(phone, numbertype));
phones.add(phone);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Added phone " + phone.toString());
}
}
} else if (number != null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number)) {
// found internal number
phone = getRuntime().getCallerFactory().createInternalPhonenumber(number);
if (phone != null && phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
m.add(getNumberTypeAttribute(numbertype, phone, om));
m.add(om.createMacAddressBookNumberTypeAttribute(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 macContacFieldMappings = om.getSupportedContactFields();
String field = null;
String jamField = null;
IAttribute a = null;
if (oCaller.containsKey(IMacAddressBookAddressMapping.ADDRESS)) {
for (int i = 0, j = macContacFieldMappings.size(); i < j; i++) {
field = (String) macContacFieldMappings.get(i);
jamField = om.mapToJamField(field);
if (jamField != null) {
a = createAttribute(jamField, this.getRawAddress((List) oCaller.get(IMacAddressBookAddressMapping.ADDRESS), om.getSupportedAddressType(), field));
if (a != null) {
m.add(a);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Added attribute " + a.toString());
}
}
}
}
}
if (oCaller.containsKey(IMacAddressBookAddressMapping.EMAIL)) {
jamField = om.mapToJamField(IMacAddressBookAddressMapping.EMAIL);
a = createAttribute(jamField, this.getRawEmail((List) oCaller.get(IMacAddressBookAddressMapping.EMAIL), om.getSupportedEmailType()));
if (a != null) {
m.add(a);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Added attribute " + a.toString());
}
}
}
for (int i = 0, j = macContacFieldMappings.size(); i < j; i++) {
field = (String) macContacFieldMappings.get(i);
jamField = om.mapToJamField(field);
if (jamField != null) {
a = createAttribute(jamField, (String) oCaller.get(field));
if (a != null) {
m.add(a);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Added attribute " + a.toString());
}
}
}
}
// date format 2010-07-22 15:34:45 +0200
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
if (oCaller.containsKey(IMacAddressBookConst.CREATION)) {
try {
a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CREATION, Long.toString(sdf.parse((String) oCaller.get(IMacAddressBookConst.CREATION)).getTime()));
} catch (ParseException e) {
this.m_logger.warning("Could not parse creation date: " + oCaller.get(IMacAddressBookConst.CREATION));
}
if (a != null)
m.add(a);
}
if (oCaller.containsKey(IMacAddressBookConst.MODIFICATION)) {
try {
a = createAttribute(IJAMConst.ATTRIBUTE_NAME_MODIFIED, Long.toString(sdf.parse((String) oCaller.get(IMacAddressBookConst.MODIFICATION)).getTime()));
} catch (ParseException e) {
this.m_logger.warning("Could not parse modification date: " + oCaller.get(IMacAddressBookConst.MODIFICATION));
}
if (a != null)
m.add(a);
}
if (oCaller.containsKey(IMacAddressBookConst.PARENT_GROUPS)) {
List categories = (List) oCaller.get(IMacAddressBookConst.PARENT_GROUPS);
if (categories.size() > 0) {
for (int i = 0; i < categories.size(); i++) {
a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, MacAddressBookProxy.getInstance().getCategory((String) categories.get(i)));
if (a != null) {
m.add(a);
break;
}
}
}
}
// 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);
}
}
String uuid = (String) oCaller.get(IMacAddressBookConst.UID);
if (uuid == null || uuid.trim().length() == 0)
uuid = new UUID().toString();
try {
MacAddressBookProxy.getInstance().getDataHandler().deleteAttributes(uuid);
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
ICaller macCaller = getRuntime().getCallerFactory().createCaller(uuid, null, phones, m);
this.setPictureAttribute(macCaller, oCaller);
this.setGeoData(macCaller);
IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
macCaller.setAttribute(cm);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Created Mac address book contact: " + macCaller.toString());
}
try {
if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME))
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_LASTNAME, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue());
if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY))
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_CITY, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY).getValue());
if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY))
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_COUNTRY, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue());
if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE))
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue());
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return macCaller;
}
return null;
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class MacAddressBookMappingManager method setGeoData.
private void setGeoData(ICaller macCaller) {
// check cache
try {
String LNG = MacAddressBookProxy.getInstance().getDataHandler().selectAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
String LAT = MacAddressBookProxy.getInstance().getDataHandler().selectAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
String ACC = MacAddressBookProxy.getInstance().getDataHandler().selectAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_GEO_ACC);
IAttribute a = null;
if (LNG != null && LNG.length() > 0 && LAT != null && LAT.length() > 0) {
a = createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, LNG);
if (a != null)
macCaller.getAttributes().add(a);
a = createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, LAT);
if (a != null)
macCaller.getAttributes().add(a);
if (ACC != null && ACC.length() > 0) {
a = createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, ACC);
if (a != null)
macCaller.getAttributes().add(a);
}
return;
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
List msvc = getRuntime().getServiceFactory().getModifierServices();
IModifierService s = null;
for (int k = 0, l = msvc.size(); k < l; k++) {
s = (IModifierService) msvc.get(k);
if (s != null && s.getServiceID().equalsIgnoreCase("GeoCoding") && s.isEnabled()) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Processing modifier service <" + s.getServiceID() + ">");
s.modifyObject(macCaller);
if (macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) != null && macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) != null && macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) != null) {
try {
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_GEO_LNG, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_GEO_LAT, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_GEO_ACC, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC).getValue());
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}
}
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class ImageHandler method getImageStream.
public InputStream getImageStream(ICaller caller) {
Object provider = null;
IAttribute cm_att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
if (cm_att != null && cm_att.getValue().length() > 0) {
provider = (IImageProvider) this.m_providers.get(cm_att.getValue());
if (provider == null)
provider = (IImageProvider) this.m_providers.get("default");
if (provider instanceof IImageStreamProvider) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Using IImageProvider <" + ((IImageProvider) provider).getID() + "> for getting image stream.");
InputStream in = ((IImageStreamProvider) provider).getImageInputStream(caller);
boolean isForceImage = Boolean.parseBoolean(System.getProperty(IJAMConst.SYSTEM_UI_FORCEIMAGE, "false"));
if (isForceImage) {
if (in != null)
return in;
} else {
return (in != null ? in : null);
}
}
}
return this.getImageStreamFromDefault(caller);
}
Aggregations