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


/** /**
* Returns a user with a specified identifier in async way. * 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 static org.kaaproject.kaa.server.admin.client.util.Utils.isNotBlank;


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


import java.util.Set;
import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid;
import org.kaaproject.kaa.common.dto.EndpointProfileDto; import org.kaaproject.kaa.common.dto.EndpointProfileDto;
import org.kaaproject.kaa.common.dto.EndpointProfilesPageDto; 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.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode; import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode;


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


public class EndpointProfileDataProvider extends AbstractDataProvider<EndpointProfileDto, String> { public class EndpointProfileDataProvider extends AbstractDataProvider<EndpointProfileDto, String> {


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


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

endpointProfilesList = new ArrayList<>();
@Override limit = String.valueOf(dataGrid.getPageSize() + 1);
protected void onRangeChanged(HasData<EndpointProfileDto> display) { }
if ((endpointKeyHash != null && !endpointKeyHash.isEmpty()) ||
(groupID != null && !groupID.isEmpty())) { @Override
int start = display.getVisibleRange().getStart(); protected void onRangeChanged(HasData<EndpointProfileDto> display) {
if (previousStart < start ) { if ((endpointKeyHash != null && !endpointKeyHash.isEmpty())
previousStart = start; || (groupId != null && !groupId.isEmpty())) {
setLoaded(false); int start = display.getVisibleRange().getStart();
} if (previousStart < start) {
super.onRangeChanged(display); previousStart = start;
} setLoaded(false);
}
super.onRangeChanged(display);
} }
}


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


@Override @Override
public void onSuccess(EndpointProfileDto endpointProfileDto) { public void onSuccess(EndpointProfileDto endpointProfileDto) {
List<EndpointProfileDto> result = new ArrayList<>(); List<EndpointProfileDto> result = new ArrayList<>();
if (endpointProfileDto.getApplicationId().equals(applicationId)) { if (endpointProfileDto.getApplicationId().equals(applicationId)) {
result.add(endpointProfileDto); result.add(endpointProfileDto);
} }
endpointProfilesList.clear(); endpointProfilesList.clear();
endpointProfilesList.addAll(result); endpointProfilesList.addAll(result);
callback.onSuccess(endpointProfilesList); 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 {
} else { callback.onFailure(caught);
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();
}
});
}
}


public void setNewGroup(String groupID) { @Override
this.groupID = groupID; public void onSuccess(EndpointProfilesPageDto result) {
this.endpointKeyHash = ""; Set<EndpointProfileDto> hs = new HashSet<>();
} hs.addAll(result.getEndpointProfiles());

hs.addAll(endpointProfilesList);
public void setEndpointKeyHash(String endpointKeyHash) { endpointProfilesList.clear();
this.endpointKeyHash = endpointKeyHash; endpointProfilesList.addAll(hs);
} callback.onSuccess(endpointProfilesList);

offset = result.getPageLinkDto().getOffset();
public void update() { }
reset(); });
dataGrid.getDataGrid().setVisibleRangeAndClearData(
new Range(0, dataGrid.getPageSize()), true);
} }
}


private void reset() { public void setNewGroup(String groupId) {
endpointProfilesList.clear(); this.groupId = groupId;
previousStart = -1; this.endpointKeyHash = "";
offset = DEFAULT_OFFSET; }
}
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()); return BaseEncoding.base64().encode(value.getEndpointKeyHash());
} }


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


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


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

0 comments on commit 545289d

Please sign in to comment.