Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.iaito.atsws.controller; import com.iaito.atsws.bean.in.Entry; import com.iaito.atsws.bean.in.EntryData; import com.iaito.atsws.bean.in.TagMovement; import com.iaito.atsws.bean.out.ResponseStatus; import com.iaito.atsws.bean.out.TagListToTab; import com.iaito.atsws.entity.Reader; import com.iaito.atsws.entity.TagLog; import com.iaito.atsws.services.ClientService; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; /** * * @author habib */ @Controller public class TagEntryController { private ClientService clientService; @Autowired public void setClientService(ClientService clientService) { this.clientService = clientService; } @RequestMapping(value = "/getreaders", method = RequestMethod.GET) public @ResponseBody List<Reader> getReaders(HttpServletRequest request) { try { System.out.println("Ip address :" + request.getRemoteAddr()); List<Reader> readerList = clientService.getReaderList(); if (readerList == null) { readerList = new ArrayList(); } return readerList; } catch (Exception e) { System.out.println("Exception--in TagEntryController.java---getReaders()---" + e.getMessage()); return new ArrayList(); } } @RequestMapping(value = "/gettags/{reader}", method = RequestMethod.GET) public @ResponseBody List<TagLog> getTagLogs(@PathVariable String reader) { try { System.out.println("readerId-------------" + reader); List<TagLog> tagLogList = clientService.getTagLogs(reader); if (tagLogList == null) { tagLogList = new ArrayList(); } return tagLogList; } catch (Exception e) { System.out.println("Exception--in TagEntryController.java---getTagLogs()---" + e.getMessage()); return new ArrayList(); } } @RequestMapping(value = "/gettagsattab/{tab}", method = RequestMethod.GET) public @ResponseBody TagListToTab getTagsAtTab(@PathVariable String tab) { try { System.out.println("tab-------------" + tab); TagListToTab tagListToTab = clientService.getTagsAtTabNew(tab); if (tagListToTab == null) { tagListToTab = new TagListToTab(); } return tagListToTab; } catch (Exception e) { System.out.println("Exception--in TagEntryController.java---getTagsAtTab()---" + e.getMessage()); return new TagListToTab(); } } // @RequestMapping(value="/posttags", method = RequestMethod.POST) // public @ResponseBody ResponseStatus postTags(@RequestBody Entry[] entries) // { // try // { // for(Entry e : entries) // { // System.out.println("entrie-------------"+e.getTaglogId()); // } // String resp = clientService.postTags(entries); // return new ResponseStatus(resp); // } // catch(Exception e) // { // System.out.println("Exception--in TagEntryController.java---postTags()---"+e.getMessage()); // return new ResponseStatus("Entry Failed"); // } // } @RequestMapping(value = "/posttags", method = RequestMethod.POST) public @ResponseBody ResponseStatus postTags(@RequestBody EntryData entryData) { try { System.out.println("entryData.getEntry_by()-----------" + entryData.getEntry_by()); System.out.println("entryData.getTab()-----------" + entryData.getTab()); System.out.println("entryData.getEntry_type()-----------" + entryData.getEntry_type()); System.out.println("size--" + entryData.getEntries().length); for (Entry e : entryData.getEntries()) { System.out.println("entrie-------------" + e.getTaglogId()); } // for(int i=0; i<entryData.getEntries().length; i++) // { // System.out.println("entrie-------------"+entryData.getEntries()[i]); // } System.out.println("-------1"); String resp = clientService.postTags(entryData); System.out.println("-------2"); return new ResponseStatus(resp); } catch (Exception e) { System.out.println("Exception--in TagEntryController.java---postTags()---" + e.getMessage()); return new ResponseStatus("Entry Failed"); } } }