Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void setUser(
- @ApiParam(value = "строка текст, логин пользователя для определения наличия пользователя в базе", required = true) @RequestParam(value = "sLogin", required = true) String sLogin,
- //@ApiParam(value = "строка текст, пароль для пользователя", required = true) @RequestParam(value = "sPassword", required = true) String sPassword,
- //@ApiParam(value = "строка текст, имя пользователя", required = true) @RequestParam(value = "sName", required = true) String sName,
- //@ApiParam(value = "строка текст, фамилия пользователя", required = true) @RequestParam(value = "sDescription", required = true) String sDescription,
- //@ApiParam(value = "строка текст, имейл пользователя, опциональный параметр", required = false) @RequestParam(value = "sEmail", required = false) String sEmail,
- @ApiParam(value = "JSON-объект с параметрами: " +
- "sPassword - (обязательный при создании нового пользователя) строка текст, логин пользователя для определения наличия пользователя в базе; " +
- "sName - (обязательный) строка текст, имя пользователя; " +
- "sDescription - (обязательный) строка текст, фамилия пользователя; " +
- "sEmail - строка текст, имейл пользователя, опциональный параметр", required = true) @RequestBody String body)
- throws Exception {
- log.info("Method setUser startred");
- String sPassword = null;
- String sName = null;
- String sDescription = null;
- String sEmail = null;
- if(body != null){
- Map<String, Object> mBody;
- try {
- mBody = (Map<String, Object>) JSONValue.parse(body);
- } catch (Exception e){
- throw new IllegalArgumentException("Error parse JSON body: " + e.getMessage());
- }
- if(mBody != null){
- if (mBody.containsKey("sPassword")) {
- sPassword = (String) mBody.get("sPassword");
- }
- if (mBody.containsKey("sName")) {
- sName = (String) mBody.get("sName");
- } else {
- throw new Exception("The sName in RequestBody is not defined");
- }
- if (mBody.containsKey("sDescription")) {
- sDescription = (String) mBody.get("sDescription");
- } else {
- throw new Exception("The sDescription in RequestBody is not defined");
- }
- if (mBody.containsKey("sEmail")) {
- sEmail = (String) mBody.get("sEmail");
- }
- }
- }
- User oUser = identityService.createUserQuery().userId(sLogin).singleResult();
- if (oUser == null) {
- log.info("Creating new user");
- oUser = identityService.newUser(sLogin);
- if(sPassword == null || sPassword.equals("")){
- throw new Exception("The password for new User is not defined");
- } else {
- oUser.setPassword(sPassword);
- }
- }
- oUser.setFirstName(sName);
- oUser.setLastName(sDescription);
- if (sEmail != null) {
- oUser.setEmail(sEmail);
- }
- log.info("Saving user to database");
- identityService.saveUser(oUser);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement