Android Open Source - swazam Request Controller






From Project

Back to project page swazam.

License

The source code is released under:

MIT License

If you think the Android project swazam listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ac.tuwien.sa13.controller;
//from w w  w  . java  2s .c o m
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;





import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import ac.tuwien.sa13.entity.Request;
import ac.tuwien.sa13.entity.Transaction;
import ac.tuwien.sa13.entity.User;
import ac.tuwien.sa13.service.IRequestService;
import ac.tuwien.sa13.service.ITransactionService;
import ac.tuwien.sa13.service.IUserService;
import ac.tuwien.sa13.service.PeerManager;

/**
 * Handles requests for the application home page.
 */
@Controller
public class RequestController {

  private static final Logger logger = LoggerFactory
      .getLogger(RequestController.class);

  @Autowired
  private IUserService userService;

  @Autowired
  private IRequestService requestService;
  
  private PeerManager peerManager;
  
  @Autowired
  private ITransactionService transactionService;

  @RequestMapping(value = "/requests", method = RequestMethod.GET)
  @ResponseBody
  public List<Request> getRequests(Locale locale, Model model,
      @RequestParam(value = "token") String token)
      throws IOException {
    User user = userService.getUserWithToken(token);
    List<Request> requests = new ArrayList<Request>();
    if (user != null) {// In that case, token should be ok
      requests = requestService.getRequests(user);
    }

    return requests;
  }

  //Request call with token and fingerprint
  @RequestMapping(value = "/request", method = RequestMethod.POST)
  @ResponseBody
  public Request postRequest(
      Locale locale,
      Model model,
      @RequestParam(value = "token", defaultValue = "") String token,
      @RequestParam(value = "fingerprint", defaultValue = "") String fingerprint)
      throws IOException {

    peerManager = PeerManager.getInstance();
    User user = userService.getUserWithToken(token);
    Request request = new Request();

    if (user != null) {// In that case, token should be ok
      request.setUser(user);
      request.setFingerprint(fingerprint);
      request.setDate(new java.sql.Date((new Date().getTime())));

      Transaction transaction = transactionService.allowRequest(user, request);
      if (transaction != null) {
        requestService.add(request);
        transactionService.add(transaction);
        peerManager.issueRequest(request);
        return request;
      }
    }
    return new Request();
  }

  @RequestMapping(value = "/result", method = RequestMethod.POST)
  @ResponseBody
  public Request postResult(Locale locale, Model model,
      @RequestParam(value = "id", required=true) long id,
      @RequestParam(value = "result", required=true) String result,
      @RequestParam(value = "user", required=true) String user) throws IOException {
    
    Request r = requestService.find(id);
    r.setResult(result);
    requestService.update(r);
    
    User u = userService.getUser(user);
    
    Transaction t = transactionService.rewardUser(u, r);
    transactionService.add(t);
    
    return r;
  }
  
//  //Request call with real request entity object
//  @RequestMapping(value = "/request", method = RequestMethod.POST)
//  @ResponseBody
//  public Request postRequestWithEntity(
//      Locale locale,
//      Model model,
//      @RequestParam(value = "token", defaultValue = "") String token,
//      @RequestParam(value = "request") Request request)
//      throws IOException {
//
//    User user = userService.getUserWithToken(token);
//    Request requestGenerated = new Request();
//    
//    if (user != null) {// In that case, token should be ok
//      request.setUser(user);
//      requestService.add(request);
//      //TODO P2P: Here the request is generated, go with it and bring it into the P2P part
//    }
//
//    return request;
//  }
}




Java Source Code List

ac.tuwien.sa13.beans.HibernateAwareObjectMapper.java
ac.tuwien.sa13.controller.HomeController.java
ac.tuwien.sa13.controller.LoginController.java
ac.tuwien.sa13.controller.RequestController.java
ac.tuwien.sa13.controller.TransactionController.java
ac.tuwien.sa13.controller.api.UserRestController.java
ac.tuwien.sa13.dao.HibernateDAO.java
ac.tuwien.sa13.dao.IGenericDAO.java
ac.tuwien.sa13.dao.IRequestDAO.java
ac.tuwien.sa13.dao.ITransactionDAO.java
ac.tuwien.sa13.dao.IUserDAO.java
ac.tuwien.sa13.dao.RequestDAO.java
ac.tuwien.sa13.dao.TransactionDAO.java
ac.tuwien.sa13.dao.UserDAO.java
ac.tuwien.sa13.entity.Request.java
ac.tuwien.sa13.entity.Transaction.java
ac.tuwien.sa13.entity.User.java
ac.tuwien.sa13.service.IGenericService.java
ac.tuwien.sa13.service.IRequestService.java
ac.tuwien.sa13.service.ITransactionService.java
ac.tuwien.sa13.service.IUserService.java
ac.tuwien.sa13.service.PeerManager.java
ac.tuwien.sa13.service.RequestService.java
ac.tuwien.sa13.service.TransactionService.java
ac.tuwien.sa13.service.UserService.java
ac.tuwien.sa13.utilities.SessionIdentifierGenerator.java
ac.tuwien.sa13.utilities.Token.java
ac.tuwien.sa13.validator.LoginValidator.java
at.ac.tuwien.swa13.swazam.NetworkConnection.java
at.ac.tuwien.swa13.swazam.Peer.java
at.ac.tuwien.swa13.swazam.fingerprint.IFingerPrintCreator.java
at.ac.tuwien.swa13.swazam.fingerprint.impl.FingerPrintCreator.java
at.ac.tuwien.swa13.swazam.library.ILibraryManager.java
at.ac.tuwien.swa13.swazam.library.ISong.java
at.ac.tuwien.swa13.swazam.library.impl.LibraryManager.java
at.ac.tuwien.swa13.swazam.library.impl.Song.java
at.ac.tuwien.swa13.swazam.p2p.PeerConnector.java
at.saws2013.szazam.App.java
at.saws2013.szazam.BaseActivity.java
at.saws2013.szazam.HistoryActivity.java
at.saws2013.szazam.LoginActivity.java
at.saws2013.szazam.RecognitionActivity.java
at.saws2013.szazam.SettingsActivity.java
at.saws2013.szazam.entities.IListItem.java
at.saws2013.szazam.entities.ListItemTypes.java
at.saws2013.szazam.entities.Request.java
at.saws2013.szazam.entities.Transaction.java
at.saws2013.szazam.fingerprint.IFingerPrintSystem.java
at.saws2013.szazam.fingerprint.impl.FingerPrintCreator.java
at.saws2013.szazam.fragments.SettingsFragment.java
at.saws2013.szazam.media.IAudioFilePicker.java
at.saws2013.szazam.media.IAudioRecorder.java
at.saws2013.szazam.media.impl.AudioFilePicker.java
at.saws2013.szazam.media.impl.AudioRecorder.java
at.saws2013.szazam.store.IAuthStore.java
at.saws2013.szazam.store.IRequestStore.java
at.saws2013.szazam.store.ITransactionStore.java
at.saws2013.szazam.store.impl.AuthStore.java
at.saws2013.szazam.store.impl.RequestStore.java
at.saws2013.szazam.store.impl.TransactionStore.java
at.saws2013.szazam.ui.CustomListAdapter.java
at.saws2013.szazam.ui.ViewTools.java
at.saws2013.szazam.volley.CustomVolleyStringRequest.java
de.passsy.holocircularprogressbar.HoloCircularProgressBar.java