package elezione.eco.server;
import elezione.eco.client.ECOService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import elezione.eco.shared.*;
import java.io.File;
import java.util.ArrayList;
import org.mapdb.DB;
import org.mapdb.DBMaker;
/**
* The server-side implementation of the RPC service.
*/
public class ECOServiceImpl extends RemoteServiceServlet implements ECOService {
private static final long serialVersionUID = 1L;
LoginServiceImpl loginService;
public ECOServiceImpl() {
DB db = DBMaker.newFileDB( new File( "ECO-DB.txt" ) ).closeOnJvmShutdown().make();
loginService = new LoginServiceImpl( db );
}
public void restartDb() {
loginService.clear();
loginService.addAdmin();
}
public void populate() {
try {
addUser( "Sergio" , "m" , "sergio@studio.it" , null , null , null , null , null , null );
} catch ( DuplicatedUserNameException e ) {
e.printStackTrace();
}
}
public User addUser( String username, String password, String email, String name, String surname, String sex,
String birthDate, String birthPlace, String address ) throws DuplicatedUserNameException {
return loginService.addUser( username , password , email , name , surname , sex , birthDate , birthPlace ,
address );
}
public User login( String userName, String password ) throws WrongPasswordException, UserNotFoundException {
return loginService.login( userName , password );
}
public ArrayList<User> getRegistered() {
return loginService.getRegistered();
}
public ArrayList<User> getAllUsers() {
return loginService.getAllUsers();
}
}