Skip to content

Commit

Permalink
KAA-1250: method 'editUserProfile' fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchizhevsky committed Jul 20, 2016
1 parent d1a6e5a commit d1588db
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 58 deletions.
Expand Up @@ -55,14 +55,7 @@
import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto;
import org.kaaproject.kaa.common.dto.TopicDto;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.AuthResultDto;
import org.kaaproject.kaa.common.dto.admin.RecordKey;
import org.kaaproject.kaa.common.dto.admin.ResultCode;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.admin.SdkPlatform;
import org.kaaproject.kaa.common.dto.admin.SdkProfileDto;
import org.kaaproject.kaa.common.dto.admin.TenantUserDto;
import org.kaaproject.kaa.common.dto.admin.UserDto;
import org.kaaproject.kaa.common.dto.admin.*;
import org.kaaproject.kaa.common.dto.credentials.CredentialsDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod;
Expand Down Expand Up @@ -1054,8 +1047,8 @@ public UserDto getUserProfile() throws Exception {
return restTemplate.getForObject(restTemplate.getUrl() + "userProfile", UserDto.class);
}

public UserDto editUserProfile(UserDto userDto) {
return restTemplate.postForObject(restTemplate.getUrl() + "userProfile", userDto, UserDto.class);
public void editUserProfile(UserProfileUpdateDto userProfileUpdateDto) {
restTemplate.postForObject(restTemplate.getUrl() + "userProfile", userProfileUpdateDto, Void.class);
}

public List<EndpointProfileDto> getEndpointProfilesByUserExternalId(String endpointUserExternalId) {
Expand Down
@@ -0,0 +1,125 @@
/*
* Copyright 2014-2016 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kaaproject.kaa.common.dto.admin;

import org.kaaproject.kaa.common.dto.KaaAuthorityDto;

import java.io.Serializable;

public class UserProfileUpdateDto implements Serializable {

private static final long serialVersionUID = 8016870008519720555L;

private String username;
private String firstName;
private String lastName;
private String mail;
private KaaAuthorityDto authority;

public UserProfileUpdateDto(String username, String firstName, String lastName, String mail, KaaAuthorityDto authority) {
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
this.mail = mail;
this.authority = authority;
}

public UserProfileUpdateDto(UserDto userDto) {
this.username = userDto.getUsername();
this.firstName = userDto.getFirstName();
this.lastName = userDto.getLastName();
this.mail = userDto.getMail();
this.authority = userDto.getAuthority();
}

public UserProfileUpdateDto() {
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getMail() {
return mail;
}

public void setMail(String mail) {
this.mail = mail;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public KaaAuthorityDto getAuthority() {
return authority;
}

public void setAuthority(KaaAuthorityDto authority) {
this.authority = authority;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

UserProfileUpdateDto that = (UserProfileUpdateDto) o;

if (!username.equals(that.username)) return false;
if (!firstName.equals(that.firstName)) return false;
if (!lastName.equals(that.lastName)) return false;
return mail.equals(that.mail);

}

@Override
public int hashCode() {
int result = username.hashCode();
result = 31 * result + firstName.hashCode();
result = 31 * result + lastName.hashCode();
result = 31 * result + mail.hashCode();
return result;
}

@Override
public String toString() {
return "UserProfileUpdateDto{" +
"username='" + username + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", mail='" + mail + '\'' +
", authority=" + authority +
'}';
}
}
Expand Up @@ -19,6 +19,7 @@
import org.kaaproject.avro.ui.gwt.client.util.BusyAsyncCallback;
import org.kaaproject.kaa.common.dto.admin.ResultCode;
import org.kaaproject.kaa.common.dto.admin.UserDto;
import org.kaaproject.kaa.common.dto.admin.UserProfileUpdateDto;
import org.kaaproject.kaa.server.admin.client.KaaAdmin;
import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory;
import org.kaaproject.kaa.server.admin.client.mvp.place.UserProfilePlace;
Expand Down Expand Up @@ -132,9 +133,18 @@ protected void getEntity(String id, AsyncCallback<UserDto> callback) {
}

@Override
protected void editEntity(UserDto entity,
AsyncCallback<UserDto> callback) {
KaaAdmin.getDataSource().editUserProfile(entity, callback);
protected void editEntity(UserDto entity, AsyncCallback<UserDto> callback) {
KaaAdmin.getDataSource().editUserProfile(new UserProfileUpdateDto(entity), new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
Utils.handleException(caught, detailsView);
}

@Override
public void onSuccess(Void aVoid) {
reload();
}
});
}

private void showChangePasswordDialog() {
Expand Down
Expand Up @@ -38,13 +38,8 @@
import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto;
import org.kaaproject.kaa.common.dto.TopicDto;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.*;
import org.kaaproject.kaa.common.dto.admin.RecordKey.RecordFiles;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.admin.SdkPlatform;
import org.kaaproject.kaa.common.dto.admin.SdkProfileDto;
import org.kaaproject.kaa.common.dto.admin.SdkProfileViewDto;
import org.kaaproject.kaa.common.dto.admin.TenantUserDto;
import org.kaaproject.kaa.common.dto.admin.UserDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto;
import org.kaaproject.kaa.common.dto.event.AefMapInfoDto;
Expand Down Expand Up @@ -102,12 +97,12 @@ protected void onResult(UserDto result) {
});
}

public void editUserProfile(UserDto user,
final AsyncCallback<UserDto> callback) {
rpcService.editUserProfile(user,
new DataCallback<UserDto>(callback) {
public void editUserProfile(UserProfileUpdateDto userProfileUpdateDto,
final AsyncCallback<Void> callback) {
rpcService.editUserProfile(userProfileUpdateDto,
new DataCallback<Void>(callback) {
@Override
protected void onResult(UserDto result) {
protected void onResult(Void result) {
}
});
}
Expand Down
Expand Up @@ -49,14 +49,7 @@
import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto;
import org.kaaproject.kaa.common.dto.TopicDto;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.AuthResultDto;
import org.kaaproject.kaa.common.dto.admin.RecordKey;
import org.kaaproject.kaa.common.dto.admin.ResultCode;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.admin.SdkPlatform;
import org.kaaproject.kaa.common.dto.admin.SdkProfileDto;
import org.kaaproject.kaa.common.dto.admin.TenantUserDto;
import org.kaaproject.kaa.common.dto.admin.UserDto;
import org.kaaproject.kaa.common.dto.admin.*;
import org.kaaproject.kaa.common.dto.credentials.CredentialsDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod;
Expand Down Expand Up @@ -529,16 +522,15 @@ public UserDto getUserProfile() throws KaaAdminServiceException {
/**
* Edits user profile to all user profiles.
*
* @param userDto
* @param userProfileUpdateDto
* the user dto
* @return the user dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "userProfile", method = RequestMethod.POST)
@ResponseBody
public UserDto editUserProfile(@RequestBody UserDto userDto) throws KaaAdminServiceException {
return kaaAdminService.editUserProfile(userDto);
public void editUserProfile(@RequestBody UserProfileUpdateDto userProfileUpdateDto) throws KaaAdminServiceException {
kaaAdminService.editUserProfile(userProfileUpdateDto);
}

/**
Expand Down
Expand Up @@ -82,12 +82,7 @@
import org.kaaproject.kaa.common.dto.TopicDto;
import org.kaaproject.kaa.common.dto.UserDto;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.RecordKey;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.admin.SdkPlatform;
import org.kaaproject.kaa.common.dto.admin.SdkProfileDto;
import org.kaaproject.kaa.common.dto.admin.SdkProfileViewDto;
import org.kaaproject.kaa.common.dto.admin.TenantUserDto;
import org.kaaproject.kaa.common.dto.admin.*;
import org.kaaproject.kaa.common.dto.credentials.CredentialsDto;
import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;
Expand Down Expand Up @@ -575,17 +570,25 @@ private void checkUserProfile(org.kaaproject.kaa.common.dto.admin.UserDto userDt
}

@Override
public org.kaaproject.kaa.common.dto.admin.UserDto editUserProfile(org.kaaproject.kaa.common.dto.admin.UserDto userDto)
public void editUserProfile(UserProfileUpdateDto userProfileUpdateDto)
throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_USER, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.KAA_ADMIN, KaaAuthorityDto.TENANT_ADMIN);
try {
checkUserProfile(userDto);
if(!userProfileUpdateDto.getUsername().equals(getCurrentUser().getUsername())){
throw new IllegalArgumentException("Username is not valid.");
}
if(!userProfileUpdateDto.getAuthority().equals(getCurrentUser().getAuthority())){
throw new IllegalArgumentException("Authority is not valid.");
}
org.kaaproject.kaa.common.dto.admin.UserDto userDto = new org.kaaproject.kaa.common.dto.admin.UserDto();
userDto.setUsername(userProfileUpdateDto.getUsername());
userDto.setFirstName(userProfileUpdateDto.getFirstName());
userDto.setLastName(userProfileUpdateDto.getLastName());
userDto.setMail(userProfileUpdateDto.getMail());
userDto.setAuthority(userProfileUpdateDto.getAuthority());
userDto.setExternalUid(getCurrentUser().getExternalUid());
Long userId = saveUser(userDto);
User user = userFacade.findById(userId);
org.kaaproject.kaa.common.dto.admin.UserDto result = new org.kaaproject.kaa.common.dto.admin.UserDto(user.getId().toString(),
user.getUsername(), user.getFirstName(), user.getLastName(), user.getMail(), KaaAuthorityDto.valueOf(user
.getAuthorities().iterator().next().getAuthority()));
return result;
checkUserProfile(userDto);
saveUser(userDto);
} catch (Exception e) {
throw Utils.handleException(e);
}
Expand Down
Expand Up @@ -39,13 +39,7 @@
import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto;
import org.kaaproject.kaa.common.dto.TopicDto;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.RecordKey;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.admin.SdkPlatform;
import org.kaaproject.kaa.common.dto.admin.SdkProfileDto;
import org.kaaproject.kaa.common.dto.admin.SdkProfileViewDto;
import org.kaaproject.kaa.common.dto.admin.TenantUserDto;
import org.kaaproject.kaa.common.dto.admin.UserDto;
import org.kaaproject.kaa.common.dto.admin.*;
import org.kaaproject.kaa.common.dto.credentials.CredentialsDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod;
Expand Down Expand Up @@ -111,7 +105,7 @@ public interface KaaAdminService extends RemoteService {

UserDto getUserProfile() throws KaaAdminServiceException;

UserDto editUserProfile(UserDto userDto) throws KaaAdminServiceException;
void editUserProfile(UserProfileUpdateDto userProfileUpdateDto) throws KaaAdminServiceException;

PropertiesDto getMailProperties() throws KaaAdminServiceException;

Expand Down

0 comments on commit d1588db

Please sign in to comment.