Changeset 667 for ether_statistics/web/src/com
- Timestamp:
- 11/15/12 11:01:02 (12 years ago)
- Location:
- ether_statistics/web/src/com/ether
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_statistics/web/src/com/ether/ControllerEponge.java
r574 r667 1 1 package com.ether; 2 2 3 import com.ether.account.Account; 3 4 import com.ether.annotation.ControllerMethod; 4 5 import com.ether.annotation.ParamName; 5 import com.ether.user.User;6 6 import net.sf.json.JSONObject; 7 7 import org.apache.commons.logging.Log; 8 8 import org.apache.commons.logging.LogFactory; 9 9 import org.jetbrains.annotations.NotNull; 10 import org.springframework.mail.javamail.JavaMailSenderImpl;11 import org.springframework.mail.javamail.MimeMessageHelper;12 10 13 import javax.mail.MessagingException;14 import javax.mail.internet.MimeMessage;15 11 import javax.servlet.http.HttpServletRequest; 12 import java.security.DigestException; 13 import java.security.NoSuchAlgorithmException; 16 14 import java.util.HashMap; 17 15 import java.util.Map; … … 56 54 @ParamName(ParameterConstants.PARAMETER_PWD) final String password, 57 55 @NotNull final HttpServletRequest request ) 58 throws ServiceException56 throws WebException 59 57 { 60 58 final JSONObject jSONUser = new JSONObject(); … … 65 63 try 66 64 { 67 // final User user = getTapasService().getUserByEmail( login ); 68 // final String encryptedPassword = EtherHelper.encryptPassword( password ); 69 // if( user == null ) 70 // result.put( "errors", "login.error.notFound" ); 71 // else if( !encryptedPassword.equals( user.getPassword() ) ) 72 // result.put( "errors", "login.error.wrongPassword" ); 73 // else 74 // { 75 // request.getSession().setAttribute( "SES_USER", user ); 76 // jSONUser.put( "name", user.getLastName() ); 77 // jSONUser.put( "firstName", user.getFirstName() ); 78 // jSONUser.put( "role", user.getRole().name() ); 79 // } 65 final Account account = getEtherService().getAccountByLogin( login ); 66 final String encryptedPassword = EtherHelper.encryptPassword( password ); 67 if( account == null ) 68 throw new WebException( WebException.WebCode.ERROR_LOGIN_NOT_FOUND, "No login found", WebException.getExceptionThrowable() ); 69 else if( !encryptedPassword.equals( account.getPassword() ) ) 70 throw new WebException( WebException.WebCode.ERROR_PASSWORD, "Wrong password", WebException.getExceptionThrowable() ); 71 else 72 { 73 request.getSession().setAttribute( "SES_ACCOUNT", account ); 74 jSONUser.put( "name", account.getName() ); 75 jSONUser.put( "role", account.getRole() ); 76 } 80 77 } 81 catch( Exception e )78 catch( DigestException e ) 82 79 { 83 result.put( "errors", "login.error.failed" ); 80 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "Error to encrypt password", WebException.getExceptionThrowable() ); 81 } 82 catch( NoSuchAlgorithmException e ) 83 { 84 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "Error to encrypt password", WebException.getExceptionThrowable() ); 85 } 86 catch( ServiceException e ) 87 { 88 throw new WebException( WebException.WebCode.ERROR_LOGIN_NOT_FOUND, "Error no login found", WebException.getExceptionThrowable() ); 84 89 } 85 90 } … … 92 97 @ControllerMethod(requestMandatory = true, jsonResult = true) 93 98 public JSONObject logout( @NotNull final HttpServletRequest request ) 94 throws ServiceException99 throws WebException 95 100 { 96 request.getSession().setAttribute( "SES_ USER", null );101 request.getSession().setAttribute( "SES_ACCOUNT", null ); 97 102 request.getSession().invalidate(); 98 103 … … 100 105 } 101 106 102 103 // @ControllerMethod(jsonResult = true)104 // public JSONObject createAccount( @NotNull @ParamName(ParameterConstants.PARAMETER_NAME) final String lastName,105 // @Nullable @ParamName(ParameterConstants.PARAMETER_FIRST_NAME) final String firstName,106 // @NotNull @ParamName(ParameterConstants.PARAMETER_EMAIL) final String email,107 // @NotNull @ParamName(ParameterConstants.PARAMETER_PWD) final String password,108 // @Nullable @ParamName(ParameterConstants.PARAMETER_LABORATORY) final String laboratory,109 // @Nullable @ParamName(ParameterConstants.PARAMETER_COUNTRY) final String country )110 // throws ServiceException, WebException111 // {112 // try113 // {114 // final User existingUser = getTapasService().getUserByEmail( email );115 // if( null == existingUser )116 // {117 // final Date creationDate = new Date();118 //119 // final String encryptedPassword = EtherHelper.encryptPassword( password );120 // final User user = new User( lastName, firstName, email, encryptedPassword, UserRole.USER, false, laboratory, country, creationDate );121 //122 // getTapasService().createUser( user );123 //124 // // Send email to administrator to inform there is a new account125 // sendEmailToAdministratorAndUser( user );126 // }127 // else128 // throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() );129 // }130 // catch( DigestException e )131 // {132 // throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" );133 // }134 // catch( NoSuchAlgorithmException e )135 // {136 // throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" );137 // }138 //139 // return new JSONObject();140 // }141 142 /**143 * This method create and send an email to :144 * - the administrator to inform there is a new created account145 * - the user to inform his account is created146 *147 * @param user148 * @throws WebException149 */150 private void sendEmailToAdministratorAndUser( @NotNull final User user )151 throws WebException152 {153 try154 {155 final String host = getProperty( "mail.host" );156 final String webMaster = getProperty( "mail.webmaster" );157 final JavaMailSenderImpl sender = new JavaMailSenderImpl();158 sender.setHost( host );159 160 final MimeMessage message = sender.createMimeMessage();161 final MimeMessageHelper helper = new MimeMessageHelper( message );162 163 // Mail Admin164 final String subjectAdmin = "[TAPAS] Nouveau compte utilisateur";165 final String contentAdmin = "Nouvelle création de compte : \n\n" +166 " - Nom : " + user.getLastName() + '\n' +167 " - Prénom : " + user.getFirstName() + '\n' +168 " - Email : " + user.getEmail() + "\n\n" +169 "Le serveur de mail masqué";170 171 helper.setFrom( webMaster );172 helper.setTo( webMaster );173 helper.setSubject( subjectAdmin );174 helper.setText( contentAdmin );175 sender.send( message );176 177 // Mail User178 final String subjectUser = "[TAPAS] New account";179 final String contentUser = "Dear " + user.getLastName() + "\n\n" +180 "Your account on TAPAS is now created. You can access to the website with your email as login and your password.\n\n" +181 "The TAPAS Administrator";182 183 helper.setFrom( webMaster );184 helper.setTo( user.getEmail() );185 helper.setSubject( subjectUser );186 helper.setText( contentUser );187 sender.send( message );188 }189 catch( MessagingException e )190 {191 throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the TAPAS administrator or USER" );192 }193 }194 195 // @ControllerMethod(downloadFile = DOWNLOAD_DATA_PROTOCOL_EN)196 // public void downloadFileDataProtocolEn()197 // {198 // }199 //200 // @ControllerMethod(downloadFile = DOWNLOAD_DATA_PROTOCOL_FR)201 // public void downloadFileDataProtocolFr()202 // {203 // }204 //205 107 private static final Log LOGGER = LogFactory.getLog( ControllerEponge.class ); 206 207 108 private static final String VIEW_INIT = "init"; 208 private static final String VIEW_DATA_PROTOCOL_EN = "project/home_dataProtocol_en";209 // TODO : mettre les bons fichiers de Dataprotocol210 private static final String DOWNLOAD_DATA_PROTOCOL_EN = "bib.txt";211 private static final String DOWNLOAD_DATA_PROTOCOL_FR = "bib.txt";212 109 } -
ether_statistics/web/src/com/ether/ControllerEther.java
r574 r667 1 1 package com.ether; 2 2 3 import com.ether.account.Account; 3 4 import com.ether.annotation.ControllerMethod; 4 5 import com.ether.annotation.Mandatory; 5 6 import com.ether.annotation.ParamName; 6 7 import com.ether.annotation.UseJSON; 7 import com.ether.user.User;8 8 import net.sf.json.JSON; 9 9 import net.sf.json.JSONArray; … … 113 113 // Parse parameters 114 114 final Object[] params = buildParams( methodDescription, request ); 115 final String defaultView = ( null != methodDescription.getDefaultView() && !"".equals( methodDescription.getDefaultView() ) ) ? methodDescription.getDefaultView() : methodDescription.getView();116 117 115 118 116 if( methodDescription.isRequestMandatory() ) 119 117 params[params.length - 1] = request; //params = parametre de la methode du Controller 120 118 121 122 119 if( methodDescription.isLoginMandatory() ) 123 120 { 124 final User user = (User) request.getSession().getAttribute( "SES_USER" ); 125 if( null == user ) 126 return new ModelAndView( defaultView, "errors", "login.error.unknown" ); 121 final Account account = (Account) request.getSession().getAttribute( "SES_ACCOUNT" ); 122 if( null == account ) 123 { 124 sendSerializedException( response, new WebException( WebException.WebCode.ERROR_LOGIN_NOT_FOUND, "No login found", WebException.getExceptionThrowable() ) ); 125 return null; 126 } 127 127 } 128 128 … … 135 135 // params[params.length - 1] = user; 136 136 // } 137 //138 if( methodDescription.isBackofficeMethod() )139 {140 final User user = (User) request.getSession().getAttribute( "SES_USER" );141 if( null == user )142 {143 return new ModelAndView( defaultView, "errors", "login.error.unknown" );144 }145 else if( null != user && !user.isAccessToBO() )146 {147 return new ModelAndView( defaultView, "errors", "login.error.bo.notAccepted" );148 }149 }150 137 151 138 final Object result; … … 177 164 return null; 178 165 } 179 // else if( null != methodDescription.getDownloadFile() && !"".equals( methodDescription.getDownloadFile() ) )180 // {181 // final String fileName = methodDescription.getDownloadFile();182 // final String downloadPath = getProperty( "downloadPath" );183 // WebHelper.downloadFileToResponse( fileName, downloadPath, response );184 // return null;185 // }186 166 else 187 167 { … … 190 170 } 191 171 } 192 catch( Throwablee )193 { 194 throw new WebException( e );172 catch( IOException e ) 173 { 174 throw new WebException( WebException.WebCode.IO_EXCEPTION_ERROR, e ); 195 175 } 196 176 } -
ether_statistics/web/src/com/ether/ControllerStatistics.java
r657 r667 30 30 throws ServiceException 31 31 { 32 return new ModelAndView( VIEW_ ERRORS);32 return new ModelAndView( VIEW_INIT ); 33 33 } 34 34 … … 37 37 throws ServiceException 38 38 { 39 // final Calendar cal = Calendar.getInstance();40 // final Date today = cal.getTime();41 // cal.set( 1900, Calendar.JANUARY, 1 );42 // final Date begin = cal.getTime();43 // cal.set( Calendar.DST_OFFSET, 40001 );44 // final Date bob = cal.getTime();45 39 return new HashMap<String, Object>(); 46 40 } … … 56 50 * @throws ServiceException 57 51 */ 58 @ControllerMethod(jsonResult = true )52 @ControllerMethod(jsonResult = true, loginMandatory = true) 59 53 public JSONObject searchMainStatisticsByProject( @Mandatory @ParamName(ParameterConstants.PARAMETER_NAME) final String projectName ) 60 54 throws ServiceException … … 70 64 private static final Log LOGGER = LogFactory.getLog( ControllerStatistics.class ); 71 65 66 private static final String VIEW_INIT = "init"; 72 67 private static final String VIEW_STATISTICS = "project/statistics"; 73 private static final String VIEW_VISUALIZATION_PARAMETER_BY_PLATEFORM = "visualization/visu_parameter_by_pf";74 private static final String VIEW_DOWNLOAD_OK = "data/access/extract3";75 private static final String VIEW_WORK = "project/inWork";76 public static final String VIEW_ERRORS = "project/errors";77 78 private static final String FORMAT_DEFAULT = "NASA-AMES";79 private static final String COMPRESSION_DEFAULT = "None";80 68 } -
ether_statistics/web/src/com/ether/WebException.java
r574 r667 41 41 ERROR_NO_REQUEST_HANDLING_METHOD, 42 42 ERROR_NUMBER_OF_PARAM_TYPES_NOT_EQUAL_TO_PARAM_ANNOTATIONS, 43 USER_ALREADY_EXISTS,44 43 ERROR_ENCRYPT_PASSWORD, 45 ERROR_EMAIL_CANNOT_BE_SEND, 46 ERROR_XML_CREATION, 47 ERROR_NO_OBSERVATORY_FOUND, 48 ERROR_NO_USER_FOUND, 44 ERROR_PASSWORD, 45 ERROR_LOGIN_NOT_FOUND, 49 46 ERROR_TO_READ_FILE_PROPERTIES, 50 ERROR_TO_REMOVE_USER, 51 ERROR_USERS_CREATION 47 IO_EXCEPTION_ERROR 52 48 } 53 49 -
ether_statistics/web/src/com/ether/WebHelper.java
r587 r667 2 2 3 3 import com.ether.WebException.WebCode; 4 import com.ether. user.User;4 import com.ether.account.Account; 5 5 import net.sf.json.JSONObject; 6 6 import org.apache.commons.logging.Log; … … 86 86 final JSONObject jSONPeople = new JSONObject(); 87 87 88 final User user = (User) request.getSession().getAttribute( "SES_USER" );89 if( null == user)88 final Account account = (Account) request.getSession().getAttribute( "SES_ACCOUNT" ); 89 if( null == account ) 90 90 return null; 91 91 92 jSONPeople.put( "name", user.getLastName() ); 93 jSONPeople.put( "firstName", user.getFirstName() ); 94 jSONPeople.put( "role", user.getRole() ); 92 jSONPeople.put( "name", account.getName() ); 93 jSONPeople.put( "role", account.getRole() ); 95 94 return jSONPeople; 96 95 }
Note: See TracChangeset
for help on using the changeset viewer.