Skip to content

Commit

Permalink
Merge fixes from release-0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Oct 7, 2016
1 parent 61cacc1 commit 545289d
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 199 deletions.
Expand Up @@ -604,19 +604,20 @@ protected void onResult(Void result) {

/**
* Edits a user.
*
* @param user new user
* @param callback callback which should be called with a result
*/
public void editUser(UserDto user, final AsyncCallback<UserDto> callback) {
userRpcService.editUser(user, true, new DataCallback<UserDto>(callback) {
@Override
protected void onResult(UserDto result) {
if (KaaAdmin.getAuthInfo().getAuthority() == KaaAuthorityDto.TENANT_ADMIN) {
refreshUsers();
}
}
});
}
public void editUser(UserDto user, final AsyncCallback<UserDto> callback) {
userRpcService.editUser(user, true, new DataCallback<UserDto>(callback) {
@Override
protected void onResult(UserDto result) {
if (KaaAdmin.getAuthInfo().getAuthority() == KaaAuthorityDto.TENANT_ADMIN) {
refreshUsers();
}
}
});
}

/**
* Returns a user with a specified identifier in async way.
Expand Down
Expand Up @@ -18,11 +18,10 @@

import static org.kaaproject.kaa.server.admin.client.util.Utils.isNotBlank;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.Range;

import java.util.Set;
import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid;
import org.kaaproject.kaa.common.dto.EndpointProfileDto;
import org.kaaproject.kaa.common.dto.EndpointProfilesPageDto;
Expand All @@ -32,117 +31,129 @@
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.Range;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class EndpointProfileDataProvider extends AbstractDataProvider<EndpointProfileDto, String> {

public static final String DEFAULT_OFFSET = "0";
private String limit = "11";
private String offset = DEFAULT_OFFSET;
private String applicationId;
private String groupID;
private String endpointKeyHash;
private List<EndpointProfileDto> endpointProfilesList;
private int previousStart = -1;
private AbstractGrid<EndpointProfileDto, String> dataGrid;

public EndpointProfileDataProvider(AbstractGrid<EndpointProfileDto, String> dataGrid,
HasErrorMessage hasErrorMessage, String applicationId) {
super(dataGrid, hasErrorMessage, true);
this.dataGrid = dataGrid;
this.applicationId = applicationId;
this.groupID = "";
endpointProfilesList = new ArrayList<>();
limit = String.valueOf(dataGrid.getPageSize() + 1);
}

@Override
protected void onRangeChanged(HasData<EndpointProfileDto> display) {
if ((endpointKeyHash != null && !endpointKeyHash.isEmpty()) ||
(groupID != null && !groupID.isEmpty())) {
int start = display.getVisibleRange().getStart();
if (previousStart < start ) {
previousStart = start;
setLoaded(false);
}
super.onRangeChanged(display);
}
public static final String DEFAULT_OFFSET = "0";
private String limit = "11";
private String offset = DEFAULT_OFFSET;
private String applicationId;
private String groupId;
private String endpointKeyHash;
private List<EndpointProfileDto> endpointProfilesList;
private int previousStart = -1;
private AbstractGrid<EndpointProfileDto, String> dataGrid;

/**
* All-args constructor.
*/
public EndpointProfileDataProvider(AbstractGrid<EndpointProfileDto, String> dataGrid,
HasErrorMessage hasErrorMessage, String applicationId) {
super(dataGrid, hasErrorMessage, true);
this.dataGrid = dataGrid;
this.applicationId = applicationId;
this.groupId = "";
endpointProfilesList = new ArrayList<>();
limit = String.valueOf(dataGrid.getPageSize() + 1);
}

@Override
protected void onRangeChanged(HasData<EndpointProfileDto> display) {
if ((endpointKeyHash != null && !endpointKeyHash.isEmpty())
|| (groupId != null && !groupId.isEmpty())) {
int start = display.getVisibleRange().getStart();
if (previousStart < start) {
previousStart = start;
setLoaded(false);
}
super.onRangeChanged(display);
}
}

@Override
protected void loadData(final LoadCallback callback) {
if (isNotBlank(endpointKeyHash)) {
KaaAdmin.getDataSource().getEndpointProfileByKeyHash(endpointKeyHash, new AsyncCallback<EndpointProfileDto>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof KaaAdminServiceException) {
if (((KaaAdminServiceException) caught).getErrorCode() == ServiceErrorCode.ITEM_NOT_FOUND) {
endpointProfilesList.clear();
callback.onSuccess(endpointProfilesList);
}
} else {
callback.onFailure(caught);
}
@Override
protected void loadData(final LoadCallback callback) {
if (isNotBlank(endpointKeyHash)) {
KaaAdmin.getDataSource()
.getEndpointProfileByKeyHash(endpointKeyHash, new AsyncCallback<EndpointProfileDto>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof KaaAdminServiceException) {
if (((KaaAdminServiceException) caught)
.getErrorCode() == ServiceErrorCode.ITEM_NOT_FOUND) {
endpointProfilesList.clear();
callback.onSuccess(endpointProfilesList);
}
} else {
callback.onFailure(caught);
}
}

@Override
public void onSuccess(EndpointProfileDto endpointProfileDto) {
List<EndpointProfileDto> result = new ArrayList<>();
if (endpointProfileDto.getApplicationId().equals(applicationId)) {
result.add(endpointProfileDto);
}
endpointProfilesList.clear();
endpointProfilesList.addAll(result);
callback.onSuccess(endpointProfilesList);
@Override
public void onSuccess(EndpointProfileDto endpointProfileDto) {
List<EndpointProfileDto> result = new ArrayList<>();
if (endpointProfileDto.getApplicationId().equals(applicationId)) {
result.add(endpointProfileDto);
}
endpointProfilesList.clear();
endpointProfilesList.addAll(result);
callback.onSuccess(endpointProfilesList);
}
});
} else {
KaaAdmin.getDataSource().getEndpointProfileByGroupId(groupId, limit, offset,
new AsyncCallback<EndpointProfilesPageDto>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof KaaAdminServiceException) {
if (((KaaAdminServiceException) caught)
.getErrorCode() == ServiceErrorCode.ITEM_NOT_FOUND) {
endpointProfilesList.clear();
callback.onSuccess(endpointProfilesList);
}
});
} else {
KaaAdmin.getDataSource().getEndpointProfileByGroupID(groupID, limit, offset,
new AsyncCallback<EndpointProfilesPageDto>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof KaaAdminServiceException) {
if (((KaaAdminServiceException) caught).getErrorCode() == ServiceErrorCode.ITEM_NOT_FOUND) {
endpointProfilesList.clear();
callback.onSuccess(endpointProfilesList);
}
} else callback.onFailure(caught);
}

@Override
public void onSuccess(EndpointProfilesPageDto result) {
Set<EndpointProfileDto> hs = new HashSet<>();
hs.addAll(result.getEndpointProfiles());
hs.addAll(endpointProfilesList);
endpointProfilesList.clear();
endpointProfilesList.addAll(hs);
callback.onSuccess(endpointProfilesList);
offset = result.getPageLinkDto().getOffset();
}
});
}
}
} else {
callback.onFailure(caught);
}
}

public void setNewGroup(String groupID) {
this.groupID = groupID;
this.endpointKeyHash = "";
}

public void setEndpointKeyHash(String endpointKeyHash) {
this.endpointKeyHash = endpointKeyHash;
}

public void update() {
reset();
dataGrid.getDataGrid().setVisibleRangeAndClearData(
new Range(0, dataGrid.getPageSize()), true);
@Override
public void onSuccess(EndpointProfilesPageDto result) {
Set<EndpointProfileDto> hs = new HashSet<>();
hs.addAll(result.getEndpointProfiles());
hs.addAll(endpointProfilesList);
endpointProfilesList.clear();
endpointProfilesList.addAll(hs);
callback.onSuccess(endpointProfilesList);
offset = result.getPageLinkDto().getOffset();
}
});
}
}

private void reset() {
endpointProfilesList.clear();
previousStart = -1;
offset = DEFAULT_OFFSET;
}
public void setNewGroup(String groupId) {
this.groupId = groupId;
this.endpointKeyHash = "";
}

public void setEndpointKeyHash(String endpointKeyHash) {
this.endpointKeyHash = endpointKeyHash;
}

/**
* Updates endpoint profile data.
*/
public void update() {
reset();
dataGrid.getDataGrid().setVisibleRangeAndClearData(
new Range(0, dataGrid.getPageSize()), true);
}

private void reset() {
endpointProfilesList.clear();
previousStart = -1;
offset = DEFAULT_OFFSET;
}
}
Expand Up @@ -122,15 +122,15 @@ protected String getObjectId(EndpointProfileDto value) {
return BaseEncoding.base64().encode(value.getEndpointKeyHash());
}

@Override
protected SimplePager getPager() {
return new SimplePager(SimplePager.TextLocation.CENTER, pagerResources, false, 0, false){
@Override
protected String createText() {
Range range = getDisplay().getVisibleRange();
int currentPage = range.getStart() / (range.getLength() != 0 ? range.getLength() : 1) + 1;
return Utils.messages.pagerText(currentPage + "");
}
@Override
protected SimplePager getPager() {
return new SimplePager(SimplePager.TextLocation.CENTER, pagerResources, false, 0, false) {
@Override
protected String createText() {
Range range = getDisplay().getVisibleRange();
int currentPage = range.getStart() / (range.getLength() != 0 ? range.getLength() : 1) + 1;
return Utils.messages.pagerText(currentPage + "");
}

@Override
public void setPageStart(int index) {
Expand Down
Expand Up @@ -244,37 +244,45 @@ public UserDto getUser(
return userService.getUser(userId);
}

/**
* Edits user to the list of all users.
*
* @param user the user
* @return the user dto
* @throws KaaAdminServiceException the kaa admin service exception
*/
@ApiOperation(value = "Create/Edit user",
notes = "Creates or edits a user. To create a user you do not need to specify the user ID, its Tenant ID will be set to the Tenant ID of the " +
"request submitter. A random password will be generated and presented in the success response in the tempPassword field. To edit user " +
"specify the user ID. If a user with the specified ID exists, it will be updated. Only users with the TENANT_ADMIN role can perform " +
"this operation.")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Some of the mandatory fields are not correct or are empty"),
@ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"),
@ApiResponse(code = 403, message = "The authenticated user does not have the required TENANT_ADMIN role or the Tenant ID of the editing user " +
"does not match the Tenant ID of the authenticated user"),
@ApiResponse(code = 500, message = "An unexpected error occurred on the server side")})
@RequestMapping(value = "user", method = RequestMethod.POST)
@ResponseBody
public UserDto editUser(
@ApiParam(name = "user", value = "UserDto body. Mandatory fields: username, firstName, lastName, mail, authority", required = true)
@Valid @RequestBody UserDto user,
@RequestParam(value="doSendTempPassword", required = false, defaultValue = "false")
boolean doSendTempPassword) throws KaaAdminServiceException {
try {
return userService.editUser(user, doSendTempPassword);
} catch (Exception e) {
throw Utils.handleException(e);
}
/**
* Edits user to the list of all users.
*
* @param user the user
* @return the user dto
* @throws KaaAdminServiceException the kaa admin service exception
*/
@ApiOperation(value = "Create/Edit user",
notes = "Creates or edits a user. To create a user you do not need to specify the user ID,"
+ " its Tenant ID will be set to the Tenant ID of the request submitter. "
+ "A random password will be generated and presented in the success response in "
+ "the tempPassword field. To edit user specify the user ID. If a user with "
+ "the specified ID exists, it will be updated. Only users with the "
+ "TENANT_ADMIN role can perform this operation.")
@ApiResponses(value = {
@ApiResponse(code = 400,
message = "Some of the mandatory fields are not correct or are empty"),
@ApiResponse(code = 401,
message = "The user is not authenticated or invalid credentials were provided"),
@ApiResponse(code = 403,
message = "The authenticated user does not have the required "
+ "TENANT_ADMIN role or the Tenant ID of the editing user "
+ "does not match the Tenant ID of the authenticated user"),
@ApiResponse(code = 500, message = "An unexpected error occurred on the server side")})
@RequestMapping(value = "user", method = RequestMethod.POST)
@ResponseBody
public UserDto editUser(
@ApiParam(name = "user",
value = "UserDto body. Mandatory fields: username, firstName, lastName, mail, authority",
required = true)
@Valid @RequestBody UserDto user,
@RequestParam(value = "doSendTempPassword", required = false, defaultValue = "false")
boolean doSendTempPassword) throws KaaAdminServiceException {
try {
return userService.editUser(user, doSendTempPassword);
} catch (Exception ex) {
throw Utils.handleException(ex);
}
}

/**
* Delete user by user id.
Expand Down

0 comments on commit 545289d

Please sign in to comment.