2013-09-30

[Android] Intent i wybór wynikowego activity

Problem

Uruchomienie odpowiedniego activity w zależności od tego czy powiadomienie (notification) jest odpalone przy aktywnym obecnie activity czy też nie.

Rozwiązanie

  • do nowego obiektu typu Intent przypisujemy odpowiednią klasę na podstawie metody sprawdzającej czy activity jest obecnie aktywne. Jeśli klasa ListOfOrdersActivity maw tej chwili aktywną reprezentację w postaci activity to Intent odwoła się właśnie do tej klasy. Jeśli nie to powołana do życia  zostanie  nowa activity klasy MainActivity.
  • metoda sprawdzająca czy dane activity jest w tej chwili aktywne:

2013-09-27

[Spring] Simple tutorial

How to start with java spring framework

prerequisites
  1. Maven (v 3)
    1. configured connection to Nexus;
2.     configured connection via proxy;
Maven settings.xml
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    c:\REPO\MVN\main\
    
            
            
              optional
               true
                     http
                     10.0.5.232
                     8080
                     10.*|112.*
            
    
    
    
            
                     nexus
                     *
                     Nordea Nexus repo
                     http://10.0.52.97:9001/nexus/content/groups/nordea-repos/
            
            
                     nexus-plug
                     *
                     Nordea Nexus repo
                     http://10.0.52.97:9001/nexus/content/groups/nordea-repos/
            
    
    
    1. optionally you can set Environment/User variable parameter for M2_REPO (used by eclipse):
    2. and also MAVEN_HOME param:
  1. Eclipse environment with Maven plugin (m2e - Maven Integration for Eclipse) or VMware Spring Tool Suite (based on Eclipse);
  2. Configured  Local repository (don't know why Remote repo doesn't work (smile) ) for Maven Archetype:
    1. go to url: http://repo1.maven.org/maven2/archetype-catalog.xml
    2. store xml on local disk
    3. configure the Archetypes on Maven menu under project Preferences:
      1. Catalog file: /archetype-catalog.xml
      2. Description:

creating project
  1. Create new Maven project structure



  2. find Archetype with spring-mvc pattern. Choose co.ntier (GroupId) with artifactId: spring-mvc-archetype


  3. Provide Archetype parameters


  4. After confirming Finish button, you'll get the new project created:

Runing project
§  in the controller code you can see that main, root path of project request is set to test() method:
@RequestMapping(value="/") 
HomeController.java
package com.nordea.spring.controller;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HomeController {
  @RequestMapping(value="/")
  public ModelAndView test(HttpServletResponse response) throws IOException{
           return new ModelAndView("home");
  }
}

  • method test() returns the "home" as a view and model which should be refilled (in this case model is empty);
§  going to the MvcConfiguration class, where there is configured the views prefix and suffix, you can see that "home" value of the HomeController.test method result will give the "/WEB-INF/views/home.jsp" path;
MvcConfiguration.java
package com.nordea.spring.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@ComponentScan(basePackages="com.nordea.spring")
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
  @Bean
  public ViewResolver getViewResolver(){
           InternalResourceViewResolver resolver = new InternalResourceViewResolver();
           resolver.setPrefix("/WEB-INF/views/");
           resolver.setSuffix(".jsp");
           return resolver;
  }
  
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
           registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
  }
}
the same configuration can be done with use of xml config file.

2013-09-25

Maven, eclipse i spring framework. Problemy z odpaleniem podstawowego projektu maven.

Po załadowaniu przykładowego projektu wykorzystującego Spring Framework (przy użyciu maven archetype), eclipse zgłasza szereg wyjątków. Między innymi widzimy coś takiego:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (execution: default, phase: process-classes)

Replikacja błędu

  • W eclipse wybieramy nowy projekt maven tworzony na podstawie archetypu :
    • groupId: co.ntier
    • artifactId: spring-mvc-archetype
  • Po ściągnięciu i utworzeniu projektu możemy zauważyć powyższe wyjątki związane z sekcją build pliku pom:

  • po dodaniu węzła pluginManagement przed plugins wszystko jest ok:


  • co dziwne po wyczyszczeniu projektu, wykonaniu maven update i wyrzuceniu dodanego węzła wszystko jest ok - brak błędu?!