extend contact list with thumbnails

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

extend contact list with thumbnails

Florian Kessler-2
Hello all,

what would be the best way to show pictures/thumbnails from an active directory in an xwiki site?

So far, we are using groovy to contact an active directoy, extract user info, like name, mail, phone etc and return xwiki 2.0 syntax, see code below
Now we would love to extend that contact list with photos stored in the active directory.

Would that be possible? If so, how?

Thanks in advance,
Florian

---


// KE1019746, März 13, fke
// list contact data
// to be included via includeInContext-Marco
//
// CAUTION: has to saved by user with programming rights

// import lib for ldap access
import org.apache.directory.groovyldap.*

// ldap connection
ldap = LDAP.newInstance('ldap://ad-server/', 'ldapbind', 'secret')
ldapsearchParams = new Search()
ldapsearchParams.base = 'OU=People,DC=domain,DC=de'
ldapsearchParams.scope = SearchScope.SUB

// for each letter in the alphabet
//for ( letter in (('A'..'Z') + ('0'..'9')) ) {
for ( letter in [ 'F' ] ) {

    ldapsearchParams.filter = '(&(|(memberOf=CN=CN1-FIXME)(memberOf=CN=CN2-FIXME))(sn=' + letter.toLowerCase() + '*))'
    // do the query
    resultsUnsorted = ldap.search(ldapsearchParams)

    // ldap output isn't sorted
    // http://www.openldap.org/lists/openldap-software/200003/msg00058.html
    // 'A robust client should not rely on servers maintaining any
    // particular order over what are defined as unordered sequences.
    //
    // If your client wants to present the attributes and their values
    // in some order, it should order them itself.'
    //
    // results is an array of hashed maps:
    // groovy:000> println results.getClass()  
    // class java.util.ArrayList
    // groovy:000> println results[3].getClass()
    // class java.util.HashMap
    //
    // sort the array depending on the value of the field 'cn'
    results = resultsUnsorted.sort { it.sn }
    println results

    // if results contains at least one cn, i.e. ldap search result isn't emtpy
    if ( results.isEmpty() == false) {

        println '' // xwiki markup stunt - new line necessary to not merge different letters to one xwiki table
        println '==' + letter // xwiki markup - header
       
        println '|=Name|=Funktion|=Tel|=Mobile|=Privat|=Fax'

        for (entry in results) {
            if ( ! ( entry.dn.toUpperCase() =~ 'DEAKTIVIERT' ) ) {

                print '|'
                if ( entry.sn ) {
                    print entry.sn
                }
                if ( entry.givenname ) {
                    print " "
                    print entry.givenname
                }
                print '|'
                if ( entry.title ) {
                    print entry.title
                }

                print '|'
                if ( entry.telephonenumber ) {
                    print entry.telephonenumber
                }
                print '|'
                if ( entry.mobile ) {
                    print entry.mobile
                }
                print '|'
                if ( entry.homephone ) {
                    print entry.homephone
                }
                print '|'
                if ( entry.facsimiletelephonenumber ) {
                    print entry.facsimiletelephonenumber
                }
                print '|'
                if ( entry.thumbnailphoto ) {
                    byte [] picture = entry.thumbnailphoto
                    //print entry.thumbnailphoto
                    print picture
                }
                println '' // xwiki markup to 'close' table
                //} else {
                //    println 'No Match for ' + entry.dn.toUpperCase()
            }
        } // end for-token-loop
    } // end results-isnt-Empty

} // end for-letter-in-alphabet-loop

_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: extend contact list with thumbnails

jerem
Hello,

In ldap configuration, you can also have some fields synchronized with
xwiki users profiles [1].

It doesn't work for pictures (I think), in my case I have a script that
gets pictures bytes from ldap, save this as a picture attachment in wiki
user profile and associates the pic as user avatar (field with same name in
user profile). I do this in cron for users with ldap infos, and without
avatar already.

Br,
Jeremie

[1] -
http://platform.xwiki.org/xwiki/bin/view/AdminGuide/Authentication#HGenericLDAPconfiguration

Le mar. 23 déc. 2014 12:29, Florian Kessler <
[hidden email]> a écrit :

> Hello all,
>
> what would be the best way to show pictures/thumbnails from an active
> directory in an xwiki site?
>
> So far, we are using groovy to contact an active directoy, extract user
> info, like name, mail, phone etc and return xwiki 2.0 syntax, see code below
> Now we would love to extend that contact list with photos stored in the
> active directory.
>
> Would that be possible? If so, how?
>
> Thanks in advance,
> Florian
>
> ---
>
>
> // KE1019746, März 13, fke
> // list contact data
> // to be included via includeInContext-Marco
> //
> // CAUTION: has to saved by user with programming rights
>
> // import lib for ldap access
> import org.apache.directory.groovyldap.*
>
> // ldap connection
> ldap = LDAP.newInstance('ldap://ad-server/', 'ldapbind', 'secret')
> ldapsearchParams = new Search()
> ldapsearchParams.base = 'OU=People,DC=domain,DC=de'
> ldapsearchParams.scope = SearchScope.SUB
>
> // for each letter in the alphabet
> //for ( letter in (('A'..'Z') + ('0'..'9')) ) {
> for ( letter in [ 'F' ] ) {
>
>     ldapsearchParams.filter = '(&(|(memberOf=CN=CN1-FIXME)(memberOf=CN=CN2-FIXME))(sn='
> + letter.toLowerCase() + '*))'
>     // do the query
>     resultsUnsorted = ldap.search(ldapsearchParams)
>
>     // ldap output isn't sorted
>     // http://www.openldap.org/lists/openldap-software/200003/
> msg00058.html
>     // 'A robust client should not rely on servers maintaining any
>     // particular order over what are defined as unordered sequences.
>     //
>     // If your client wants to present the attributes and their values
>     // in some order, it should order them itself.'
>     //
>     // results is an array of hashed maps:
>     // groovy:000> println results.getClass()
>     // class java.util.ArrayList
>     // groovy:000> println results[3].getClass()
>     // class java.util.HashMap
>     //
>     // sort the array depending on the value of the field 'cn'
>     results = resultsUnsorted.sort { it.sn }
>     println results
>
>     // if results contains at least one cn, i.e. ldap search result isn't
> emtpy
>     if ( results.isEmpty() == false) {
>
>         println '' // xwiki markup stunt - new line necessary to not merge
> different letters to one xwiki table
>         println '==' + letter // xwiki markup - header
>
>         println '|=Name|=Funktion|=Tel|=Mobile|=Privat|=Fax'
>
>         for (entry in results) {
>             if ( ! ( entry.dn.toUpperCase() =~ 'DEAKTIVIERT' ) ) {
>
>                 print '|'
>                 if ( entry.sn ) {
>                     print entry.sn
>                 }
>                 if ( entry.givenname ) {
>                     print " "
>                     print entry.givenname
>                 }
>                 print '|'
>                 if ( entry.title ) {
>                     print entry.title
>                 }
>
>                 print '|'
>                 if ( entry.telephonenumber ) {
>                     print entry.telephonenumber
>                 }
>                 print '|'
>                 if ( entry.mobile ) {
>                     print entry.mobile
>                 }
>                 print '|'
>                 if ( entry.homephone ) {
>                     print entry.homephone
>                 }
>                 print '|'
>                 if ( entry.facsimiletelephonenumber ) {
>                     print entry.facsimiletelephonenumber
>                 }
>                 print '|'
>                 if ( entry.thumbnailphoto ) {
>                     byte [] picture = entry.thumbnailphoto
>                     //print entry.thumbnailphoto
>                     print picture
>                 }
>                 println '' // xwiki markup to 'close' table
>                 //} else {
>                 //    println 'No Match for ' + entry.dn.toUpperCase()
>             }
>         } // end for-token-loop
>     } // end results-isnt-Empty
>
> } // end for-letter-in-alphabet-loop
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: extend contact list with thumbnails - SOLVED

Florian Kessler-2

> Il giorno 23/dic/2014, alle ore 12:55, Jeremie BOUSQUET <[hidden email]> ha scritto:
>
> Hello,
>
> In ldap configuration, you can also have some fields synchronized with
> xwiki users profiles [1].
>
> It doesn't work for pictures (I think), in my case I have a script that
> gets pictures bytes from ldap, save this as a picture attachment in wiki
> user profile and associates the pic as user avatar (field with same name in
> user profile). I do this in cron for users with ldap infos, and without
> avatar already.
>
> Br,
> Jeremie

Hi Jeremie,

thanks for your help, I solved it now:

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
...
            if ( ! ( entry.dn.toUpperCase() =~ 'DEAKTIVIERT' ) ) {
                print '|'
                if ( entry.sn ) {
                    print entry.sn
                }
                if ( entry.givenname ) {
                    print " "
                    print entry.givenname
                }
                if ( entry.thumbnailphoto ) {
                    print " "
                    byte[] picture = entry.thumbnailphoto
                    print '{{html}} '
                    print '<img height="45" src="data:image/jpeg;base64,'
                    print Base64.encode(picture);
                    print '">'
                    print '{{/html}}'
                }
                print '|'
                if ( entry.title ) {
                    print entry.title
                }
...


the missing links were

* {{html}} ... {{/html}} to insert plain html into an xwiki site
* the "inline" definition of the image, see http://aktuell.de.selfhtml.org/artikel/grafik/inline-images/ (sry, german only)

Again, thanks.
Florian
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users