TouK dla finansów

Już 7 lutego 2012 r. zapraszamy na konferencję Business Intelligence w instytucjach finansowych. Podczas imprezy Tomasz Wielga z TouK przedstawi temat: „Agile BI – decyzje, o których nie wiesz, że będziesz musiał je podjąć, na podstawie dużej ilości danych, o których nie wiesz, że masz je zbierać”.

Miejsce: Centrum Bankowo-Finansowe „Nowy Świat” S.A., Warszawa, ul. Nowy Świat 6/12.

Udział w konferencji  jest bezpłatny dla przedstawicieli sektora finansowego, wymaga jednak wcześniejszej rejestracji.


Developer Java poszukiwany

Szukamy developera Java do pracy w siedzibie naszego klienta z branży logistycznej w Piasecznie. Prowadzony projekt dotyczy integracji systemów przy użyciu szyny usług zrealizowanej w oparciu o Apache Servicemix 4. Do zadań zatrudnionej osoby będzie należeć wsparcie klienta w utrzymywaniu systemu oraz implementacja nowych usług. więcej…

How to get to TouK

This Tuesday, architect-wannabe group has it’s meeting at TouK at 18:00. Since TouK is not an easy company to find, here’s the video tutorial Piotr Przybylak asked for. It starts at Rondo Zesłańców Syberyjskich (driving from north). Hope it helps.

Thanks to Maciej Próchniak for participation :)

And here is a map:

Show larger map

Bash’ing your git deployment

Chuck Norris deploys after every commit. Smart men deploy after every successful build on their Continuous Integration server. Educated men, deploy code directly from their distributed version control systems. I, being neither, had to write my deployment script in bash.

We're using git and while doing so I wanted us to:
  • deploy from working copy, but...
  • make sure that you can deploy only if you committed everything
  • make sure that you can deploy only if you pushed everything upstream
  • tag the deployed hash
  • display changelog (all the commits between two last tags)

Here are some BASH procedures I wrote on the way, if you need them:

make sure that you can deploy only if you committed everything
verifyEverythingIsCommited() {
    gitCommitStatus=$(git status --porcelain)
    if [ "$gitCommitStatus" != "" ]; then
        echo "You have uncommited files."
        echo "Your git status:"
        echo $gitCommitStatus
        echo "Sorry. Rules are rules. Aborting!"
        exit 1
    fi
}

make sure that you can deploy only if you pushed everything upstream
verifyEverythingIsPushedToOrigin() {
    gitPushStatus=$(git cherry -v)
    if [ "$gitPushStatus" != "" ]; then
        echo "You have local commits that were NOT pushed."
        echo "Your 'git cherry -v' status:"
        echo $gitPushStatus
        echo "Sorry. Rules are rules. Aborting!"
        exit 1
    fi
}

tag the deployed hash

Notice: my script takes first parameter as the name of the server to deploy to (this is $1 passed to this procedure). Also notice, that 'git push' without the '--tags' does not push your tags.
tagLastCommit() {
    d=$(date '+%y-%m-%d_%H-%M-%S')
    git tag "$1_$d"
    git push --tags
}

This creates nice looking tags like these:
preprod_12-01-11_15-16-24
prod_12-01-12_10-51-33
test_12-01-11_15-11-10
test_12-01-11_15-53-42

display changelog (all the commits between two last tags)
printChangelog() {
    echo "This is changelog since last deploy. Send it to the client."
    twoLastHashesInOneLine=$(git show-ref --tags -s | tail -n 2 | tr "\\n" "-");
    twoLastHashesInOneLineWithThreeDots=${twoLastHashesInOneLine/-/...};
    twoLastHashesInOneLineWithThreeDotsNoMinusAtTheEnd=$(echo $twoLastHashesInOneLineWithThreeDots | sed 's/-$//');
    git log --pretty=oneline --no-merges --abbrev-commit  $twoLastHashesInOneLineWithThreeDotsNoMinusAtTheEnd
}

The last command gives you a nice log like this:
e755c63 deploy: fix for showing changelog from two first tags instead of two last ones
926eb02 pringing changelog between last two tags on deployment
34478b2 added git tagging to deploy


Komentarze są wyłączone more...

Atom Feeds with Spring MVC

How to add feeds (Atom) to your web application with just two classes?
How about Spring MVC?

Here are my assumptions:
  • you are using Spring framework
  • you have some entity, say “News”, that you want to publish in your feeds
  • your "News" entity has creationDate, title, and shortDescription
  • you have some repository/dao, say "NewsRepository", that will return the news from your database
  • you want to write as little as possible
  • you don't want to format Atom (xml) by hand
You actually do NOT need to use Spring MVC in your application already. If you do, skip to step 3.


Step 1: add Spring MVC dependency to your application
With maven that will be:
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.1.0.RELEASE</version>
</dependency>

Step 2: add Spring MVC DispatcherServlet
With web.xml that would be:
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/feed</url-pattern>
</servlet-mapping>
Notice, I set the url-pattern to “/feed” which means I don't want Spring MVC to handle any other urls in my app (I'm using a different web framework for the rest of the app). I also give it a brand new contextConfigLocation, where only the mvc configuration is kept.

Remember that, when you add a DispatcherServlet to an app that already has Spring (from ContextLoaderListener for example), your context is inherited from the global one, so you should not create beans that exist there again, or include xml that defines them. Watch out for Spring context getting up twice, and refer to spring or servlet documentation to understand what's happaning.

Step 3. add ROME – a library to handle Atom format
With maven that is:
<dependency>
    <groupId>net.java.dev.rome</groupId>
    <artifactId>rome</artifactId>
    <version>1.0.0</version>
</dependency>

Step 4. write your very simple controller
@Controller
public class FeedController {
    static final String LAST_UPDATE_VIEW_KEY = "lastUpdate";
    static final String NEWS_VIEW_KEY = "news";
    private NewsRepository newsRepository;
    private String viewName;

    protected FeedController() {} //required by cglib

    public FeedController(NewsRepository newsRepository, String viewName) {
        notNull(newsRepository); hasText(viewName);
        this.newsRepository = newsRepository;
        this.viewName = viewName;
    }

    @RequestMapping(value = "/feed", method = RequestMethod.GET)        
    @Transactional
    public ModelAndView feed() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(viewName);
        List<News> news = newsRepository.fetchPublished();
        modelAndView.addObject(NEWS_VIEW_KEY, news);
        modelAndView.addObject(LAST_UPDATE_VIEW_KEY, getCreationDateOfTheLast(news));
        return modelAndView;
    }

    private Date getCreationDateOfTheLast(List<News> news) {
        if(news.size() > 0) {
            return news.get(0).getCreationDate();
        }
        return new Date(0);
    }
}
And here's a test for it, in case you want to copy&paste (who doesn't?):
@RunWith(MockitoJUnitRunner.class)
public class FeedControllerShould {
    @Mock private NewsRepository newsRepository;
    private Date FORMER_ENTRY_CREATION_DATE = new Date(1);
    private Date LATTER_ENTRY_CREATION_DATE = new Date(2);
    private ArrayList<News> newsList;
    private FeedController feedController;

    @Before
    public void prepareNewsList() {
        News news1 = new News().title("title1").creationDate(FORMER_ENTRY_CREATION_DATE);
        News news2 = new News().title("title2").creationDate(LATTER_ENTRY_CREATION_DATE);
        newsList = newArrayList(news2, news1);
    }

    @Before
    public void prepareFeedController() {
        feedController = new FeedController(newsRepository, "viewName");
    }

    @Test
    public void returnViewWithNews() {
        //given
        given(newsRepository.fetchPublished()).willReturn(newsList);
        
        //when
        ModelAndView modelAndView = feedController.feed();
        
        //then
        assertThat(modelAndView.getModel())
                .includes(entry(FeedController.NEWS_VIEW_KEY, newsList));
    }

    @Test
    public void returnViewWithLastUpdateTime() {
        //given
        given(newsRepository.fetchPublished()).willReturn(newsList);

        //when
        ModelAndView modelAndView = feedController.feed();

        //then
        assertThat(modelAndView.getModel())
                .includes(entry(FeedController.LAST_UPDATE_VIEW_KEY, LATTER_ENTRY_CREATION_DATE));
    }

    @Test
    public void returnTheBeginningOfTimeAsLastUpdateInViewWhenListIsEmpty() {
        //given
        given(newsRepository.fetchPublished()).willReturn(new ArrayList<News>());

        //when
        ModelAndView modelAndView = feedController.feed();

        //then
        assertThat(modelAndView.getModel())
                .includes(entry(FeedController.LAST_UPDATE_VIEW_KEY, new Date(0)));
    }
}
Notice: here, I'm using fest-assert and mockito. The dependencies are:
<dependency>
 <groupId>org.easytesting</groupId>
 <artifactId>fest-assert</artifactId>
 <version>1.4</version>
 <scope>test</scope>
</dependency>
<dependency>
 <groupId>org.mockito</groupId>
 <artifactId>mockito-all</artifactId>
 <version>1.8.5</version>
 <scope>test</scope>
</dependency>

Step 5. write your very simple view
Here's where all the magic formatting happens. Be sure to take a look at all the methods of Entry class, as there is quite a lot you may want to use/fill.
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;
[...]

public class AtomFeedView extends AbstractAtomFeedView {
    private String feedId = "tag:yourFantastiSiteName";
    private String title = "yourFantastiSiteName: news";
    private String newsAbsoluteUrl = "http://yourfanstasticsiteUrl.com/news/"; 

    @Override
    protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
        feed.setId(feedId);
        feed.setTitle(title);
        setUpdatedIfNeeded(model, feed);
    }

    private void setUpdatedIfNeeded(Map<String, Object> model, Feed feed) {
        @SuppressWarnings("unchecked")
        Date lastUpdate = (Date)model.get(FeedController.LAST_UPDATE_VIEW_KEY);
        if (feed.getUpdated() == null || lastUpdate != null || lastUpdate.compareTo(feed.getUpdated()) > 0) {
            feed.setUpdated(lastUpdate);
        }
    }

    @Override
    protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        @SuppressWarnings("unchecked")
        List<News> newsList = (List<News>)model.get(FeedController.NEWS_VIEW_KEY);
        List<Entry> entries = new ArrayList<Entry>();
        for (News news : newsList) {
            addEntry(entries, news);
        }
        return entries;
    }

    private void addEntry(List<Entry> entries, News news) {
        Entry entry = new Entry();
        entry.setId(feedId + ", " + news.getId());
        entry.setTitle(news.getTitle());
        entry.setUpdated(news.getCreationDate());
        entry = setSummary(news, entry);
        entry = setLink(news, entry);
        entries.add(entry);
    }

    private Entry setSummary(News news, Entry entry) {
        Content summary = new Content();
        summary.setValue(news.getShortDescription());
        entry.setSummary(summary);
        return entry;
    }

    private Entry setLink(News news, Entry entry) {
        Link link = new Link();
        link.setType("text/html");
        link.setHref(newsAbsoluteUrl + news.getId()); //because I have a different controller to show news at http://yourfanstasticsiteUrl.com/news/ID
        entry.setAlternateLinks(newArrayList(link));
        return entry;
    }

}

Step 6. add your classes to your Spring context
I'm using xml approach. because I'm old and I love xml. No, seriously, I use xml because I may want to declare FeedController a few times with different views (RSS 1.0, RSS 2.0, etc.).

So this is the forementioned spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="atom" value="application/atom+xml"/>
                <entry key="html" value="text/html"/>
            </map>
        </property>
        <property name="viewResolvers">
            <list>
                <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
            </list>
        </property>
    </bean>

    <bean class="eu.margiel.pages.confitura.feed.FeedController">
        <constructor-arg index="0" ref="newsRepository"/>
        <constructor-arg index="1" value="atomFeedView"/>
    </bean>

    <bean id="atomFeedView" class="eu.margiel.pages.confitura.feed.AtomFeedView"/>
</beans>

And you are done.

I've been asked a few times before to put all the working code in some public repo, so this time it's the other way around. I've describe things that I had already published, and you can grab the commit from the bitbucket.

Hope that helps.
Komentarze są wyłączone more...

Tomcat: Problemy z requestami zawierającymi polskie znaki diakrytyczne


Jeśli jest problem z pobieraniem plików z polskimi znakami diakrytycznymi, to trzeba dopisać kodowanie do connectora w tomcat/conf/server.xml

URIEncoding="UTF-8"

Typowa konfiguracja connectora będzie wyglądała tak

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8" />
Komentarze są wyłączone more...

Może masz jakieś pytania do nas?- czyli co odpowiadamy na pytania kandydatów.

Ostatnio na jednej z rozmów rekrutacyjnych dowiedzieliśmy się, że na grupie dyskusyjnej warszawskiego juga pojawił się kiedyś wątek: “jakie pytania zadawać pracodawcom”. Postanowiliśmy odpowiedzieć na pytania jakie na początku zadał Witalij Olejnik.

1. O której zaczyna się i kończy praca?

Jesteśmy umówieni, że wszyscy są w biurze pomiędzy 10-16. Pracujemy osiem godzin dziennie. Od każdego indywidualnie i od umowy z resztą zespołu zależy czy zacznie pracę o 8 czy o 10:00. Staramy się nie zostawać po godzinach, w części projektów są dyżury z domu.

2. Którego dnia miesiąca pensja wpływa na konto?

Zwykle do ostatniego dnia miesiąca. Jeśli ktoś wystawia fakturę, w ciągu kilku dni od wystawienia.

3. Czy zespół spotyka się po pracy?

Raz w roku mamy imprezę ogólno firmową, w między czasie chodzimy na piwo (jak pojawi się taka inicjatywa), zdarza się, że gramy w piłkę lub squasha.

4. Jakie narzędzia poza IDE są wykorzystywane?

Nie narzucamy używania IDE, chociaż większość osób używa IDEI. :-) Pilnujemy zasady, żeby projekt budował się i testował z linii poleceń. Dzięki temu od razu działa ciągła integracja i statyczna analiza kodu. Jeśli potrzebne są inne narzędzia, to je kupujemy i używamy.

5. Czy odbywają się wewnętrzne szkolenia?

Tak, piątek jest naszym dniem nauki. Odbywają się wtedy warsztaty OCR (Open Code Review), wykłady technologiczne oraz nauka prezentacji. Jak masz dobry pomysł na zespołową naukę, chętnie pomożemy Ci w realizacji.

6. Czy piszecie testy jednostkowe, jeśli tak to czego do tego celu używacie?

Tak, kilku orędowników-ewangelistów nas tego nauczyło. Nowe projekty mają całkiem niezłe pokrycie testami. Narzędzia są różne w zależności od projektu, zespołu, technologii – junit, mockito, jmock, spock. Jakoś testujemy javascrypty – o szczegółach będzie na wykładzie w piątek. Może autor opisze to na blogu?

7. W jaki sposób jest gromadzona wiedza? Wiki?

Wiedza jest w samodokumentującym się kodzie. I na firmowym Confluence.

8. W jaki sposób tworzycie warstwę dostępu do danych?

Nie tworzymy, sama się robi. A jeśli to – z jakiś przyczyn – pobożne życzenie, to używamy narzędzi, które w danym kontekście są najlepsze.

9. Jakie frameworki wykorzystujecie w warstwie prezentacji?

Ja pamiętam: Strutsy, Wicketa, GWT, GXT, SmartClient, Spring MVC. Pewnie było ich więcej.

10. Czy istnieją wewnętrzne frameworki/biblioteki?

Najważniejsze są doświadczenia. Mamy mało powtarzalnej pracy, dlatego wolimy korzystać z otwartego oprogramowania, niż tworzyć własne frameworki. Z naszych większych kawałków softu na Apache-u są: xmlbeansxx – biblioteka do manipulacji XMLem w C++ oraz HISE – implementacja specyfikacji WS-HT.

11. Czy używacie serwera ciągłej integracji?

Aplikacji pilnuje u nas Jenkins.

12. Jakie metody prowadzenia projektów stosujecie?

Wewnątrz zespołów używamy zwinnych metodyk. Czasem metodyka ma inną fasadę dla klienta.

13. Czy prezes firmy programuje/programował?

Niestety cały zarząd ciągle programuje. :-)

14. Czy mój przełożony  programuje/programował?

Jest to niemal pewne. Tylko dwie osoby ze wszystkich 60, które zajmują się na co dzień projektami nie programuje obecnie, ale wszyscy kiedyś programowali.

15. Jakiego narzędzia do śledzenia błędów używacie?

Do wizualizacji błędów i zadań w ogóle – tablicy z postitami. Jeśli w grę wchodzi współpraca z klientem, to różnych systemów ticketowych u klientów.

16. Narzędzia do budowania projektów?

To zależy od zespołu, technologii. Musi działać z linii poleceń, zwykle Maven, którego używamy też do zarządzania wydaniami, ale też ant i różne skrypty.

17. Dlaczego poprzedni pracownik zrezygnował?

Dostał lepszą finansowo ofertę, przeprowadził się (z żalem). Generalnie poświęcamy sporo czasu na rekrutację i mamy małą rotację.

18. OK, pokazałem wam swój kod, a teraz pokażcie mi swój.

https://github.com/TouK/

19. Jeżeli odpowiedź na niektóre z pytań (nie na wszystkie, inaczej tam nie idę;-) ). 4, 6, 7, 11, 12, 15, 16 będą negatywne: czy ja będę miał możliwość jego (narzędzia)  uruchomienia?

Jak sądzisz?

Magda (i Witek)


Table viewer using JQuery plugin and JEE

DataTables is a JQuery plugin, facilitating building Ajax table editors. In this example, I show how to connect it to JEE backend, which is a simple Servlet. Backend exposes a table, stored as a Java List within Servlet instance. Data is served back in JSON format using Jackson library.

Example is deployed on Google App Engine, datatablesjee.appspot.com. Code is available on GitHub github.com/rafalrusin/datatablesjee.

First, we need to instantiate DataTables plugin within a html page. This is extremely easy, by using code below:

AjaxSource parameter refers to Servlet URI, which handles requests for data.ServerSide argument is set to true, which means that backend will do sorting, filteringand pagination. This allows us to use large tables (>1000 rows) without performance problemson client side.

Now, we need to implement backend. Servlet requires a doGet method, which needs to retrieve parameters sent from clientas an Ajax request. Those parameters describe search keyword, starting row and page sizeof a table.

Then, we need to do filtering and sorting. I used a simple toString + contains methodson a single row in order to do filtering. Sorting is done via custom comparator, which sorts by given column number. Following code does the job:

Last, we need to send JSON response back to client. Here, we use Jackson, which is a very convenient library for manipulating JSON in Java.

iTotalRecords is total number of records, without filtering. iTotalDisplayRecords is number of records after applying filter. aaData is two dimensional array of strings, representing visible table data.

Summing up, I like the idea of Ajax in this form, because client side isnot rendered directly by backend (no jsp, etc.). This makes it a detached view, which could be served as static content, from Apache Web Server for example, which is very performant.
Komentarze są wyłączone more...

Szukamy developerów Java

Jeżeli jesteś pasjonatem programowania przyślij swoje CV z opisem projektów, w których pracowałaś/eś i którymi chciał(a)byś się pochwalić, komercyjnych lub/ i open source’owych lub własnych.

więcej informacji


Adding diff to Gitorious push notification emails

One thing we were really missing in Gitorious is lack of diff in email notifications.
We were using this feature in SVN for „quick code review”.
Before we moved to Gitorious, we were using Gitolite where it was possible to configure it with git .hooks.
However in Gitorious you do not have easy access to your repository directory ( it’s hashed ).
So I have started googling about the feature.
I have found in Gitorious a misterious feature called webhooks. But what it does is sending HTTP requests with JSON objects about commits, but without diff body.
After loosing few more hours on google, forums and different groups I decided to try to implement this feature on my own.
Few more hours to understand this mysterious ( for me ) Ruby on Rails code of Gitorious and I have localized few files that I should change to make it working.

After all I have to say it was quite simple.
The core are two lines that create commit diff in lib/event_rendering/text.rb:

repo = Repository.find_by_name_in_project!(event.target.name, event.project)
diff_content = repo.git.git.show({}, [start_sha, end_sha].join(".."))

(If you would like to modify content of the commit diff you just have to modify this git.git call ).
Rest of the code is just for putting diff_content value into email :).

You can review the whole patch here.

After applying the patch please remember to restart git-poller and subscribe in Gitorious to email notification.


  • About Us

    We create information and telecommunication technologies for large and medium-sized enterprises. They are based on recognized, primarily open standards and technologies, which are to guarantee our customers the highest quality and stability of information systems development. At the same time building our competencies, we are trying to shape such standards and support the development of open technologies.
    Copyright © 2002-2011 TouK sp. z o.o. s.k.a.
    iDream theme by Templates Next | Powered by WordPress