1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
package org.syndic.client.web.home.controller;
import fr.upond.syndic.repo.model.common.Address;
import fr.upond.syndic.repo.model.common.Condo;
import fr.upond.syndic.repo.model.common.Lot;
import fr.upond.syndic.repo.model.common.Provider;
import fr.upond.syndic.repo.model.event.Event;
import fr.upond.syndic.service.IManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import fr.upond.syndic.repository.user.UserDaoImpl;
import org.springframework.web.servlet.view.RedirectView;
import org.syndic.client.web.command.CondoCommand;
import org.syndic.client.web.command.ProviderCommand;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.dropbox.core.*;
import java.io.*;
import java.util.Locale;
@Controller
@Transactional
public class Home {
private static final Log logger = LogFactory.getLog(Home.class);
@Autowired
private IManager<Object> manager;
@Autowired
private UserDaoImpl userDao;
public void setManager(IManager<Object> manager) {
this.manager = manager;
}
public void setUserDao(UserDaoImpl userDao) {
this.userDao = userDao;
}
@RequestMapping(value = "/getformaddcondo", method = RequestMethod.GET)
public String getFormAddCondo(Map<String,Object> model) {
logger.info("==== Get Form Condo =====");
model.put("condoCommand", new CondoCommand());
return "addCondoPage";
}
@RequestMapping(value = "/addcondo", method = RequestMethod.POST)
public String addCondo(@ModelAttribute("condoCommand") CondoCommand condoCommand) {
logger.info("== uri: /addcondo ==");
Address address = new Address(condoCommand.getNumAddressStart()+", "+condoCommand.getNumAddressEnd(),
condoCommand.getTypeAddress(), condoCommand.getStreet(),condoCommand.getCity(), condoCommand.getZipcode(),
condoCommand.getCountry(), condoCommand.getPlaceName());
Lot lot = new Lot(Integer.parseInt(condoCommand.getCodeLot()), condoCommand.getTypeLot(),
Integer.parseInt(condoCommand.getFloorLot()),
Double.parseDouble(condoCommand.getAreaLot()), Double.parseDouble(condoCommand.getPart()));
Set<Lot> setLot = new HashSet<Lot>(0);
setLot.add(lot);
Condo condo = new Condo(condoCommand.getName(), Double.parseDouble(condoCommand.getAreaCondo()), address);
condo.setLot(setLot);
this.manager.add(condo);
return "welcomeSyndicPage";
}
// + d'autres méthodes du même type
@RequestMapping(value = "/getformupload", method = RequestMethod.GET)
public String getFormUpload(Map<String,Object> model) {
logger.info("==== Get Form Upload =====");
return "uploadPage";
}
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public void uploadFile(@RequestParam("file") File file) throws IOException, DbxException{
final String APP_KEY = "64foz0ixb66kp79";
final String APP_SECRET = "kcqmxhagcs764jl";
DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
DbxRequestConfig config = new DbxRequestConfig(
"syndic/1.0", Locale.getDefault().toString());
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
String authorizeUrl = webAuth.start();
System.out.println("1. Go to: " + authorizeUrl);
System.out.println("2. Click \"Allow\" (you might have to log in first)");
System.out.println("3. Copy the authorization code.");
String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
// This will fail if the user enters an invalid authorization code.
DbxAuthFinish authFinish = webAuth.finish(code);
String accessToken = authFinish.accessToken;
DbxClient client = new DbxClient(config, accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
File inputFile = file;
FileInputStream inputStream = new FileInputStream(inputFile);
try {
DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
DbxWriteMode.add(), inputFile.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}
} |
Partager