Skip to content

Commit

Permalink
move findAllTenantAdminsBuTenantId from TenantController to UserContr…
Browse files Browse the repository at this point in the history
…oller, added appropriate method to AdminClient.java
  • Loading branch information
Pyshankov committed Aug 8, 2016
1 parent 7651711 commit 979c0cb
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 19 deletions.
40 changes: 40 additions & 0 deletions doc/Programming-guide/Server-REST-APIs/swagger.json
Expand Up @@ -639,6 +639,46 @@
} }
} }
}, },
"/api/admins/{tenantId}" : {
"post" : {
"tags" : [ "User" ],
"summary" : "Select tenant admins by tenant id",
"description" : "",
"operationId" : "findAllTenantAdminsByTenantId",
"parameters" : [ {
"name" : "",
"in" : "path",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/UserDto"
}
}
},
"400" : {
"description" : "The specified tenantId is not valid"
},
"401" : {
"description" : "The user is not authenticated or invalid credentials were provided"
},
"403" : {
"description" : "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"
},
"404" : {
"description" : "The user with the specified tenantId does not exist"
},
"500" : {
"description" : "An unexpected error occurred on the server side"
}
}
}
},
"/api/application" : { "/api/application" : {
"post" : { "post" : {
"tags" : [ "Application" ], "tags" : [ "Application" ],
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Expand Up @@ -76,7 +76,6 @@ Copyright 2014-2016 CyberVision, Inc.
<httpcomponents.version>4.3.2</httpcomponents.version> <httpcomponents.version>4.3.2</httpcomponents.version>
<jackson.version>2.4.1</jackson.version> <jackson.version>2.4.1</jackson.version>
<javax.validation.version>1.1.0.Final</javax.validation.version> <javax.validation.version>1.1.0.Final</javax.validation.version>
<hibernate.validator.version>5.2.2.Final</hibernate.validator.version>
<joda-time.version>2.2</joda-time.version> <joda-time.version>2.2</joda-time.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<embed.mongo.version>1.42</embed.mongo.version> <embed.mongo.version>1.42</embed.mongo.version>
Expand Down Expand Up @@ -135,7 +134,7 @@ Copyright 2014-2016 CyberVision, Inc.
<swagger-maven-plugin.version>3.1.3</swagger-maven-plugin.version> <swagger-maven-plugin.version>3.1.3</swagger-maven-plugin.version>
<swagger-annotations.version>1.5.9</swagger-annotations.version> <swagger-annotations.version>1.5.9</swagger-annotations.version>
<javax.el>2.2.4</javax.el> <javax.el>2.2.4</javax.el>
<org.glassfish.web>2.2.4</org.glassfish.web> <org.glassfish.web>2.2.6</org.glassfish.web>
<hibernate-validator>5.2.4.Final</hibernate-validator> <hibernate-validator>5.2.4.Final</hibernate-validator>
</properties> </properties>


Expand Down
Expand Up @@ -180,6 +180,14 @@ public List<TenantDto> getTenants() throws Exception {
return entity.getBody(); return entity.getBody();
} }



public List<UserDto> getAllTenantAdminsBytenantId(String tenantId){
ParameterizedTypeReference<List<UserDto>> typeRef = new ParameterizedTypeReference<List<UserDto>>() {
};
ResponseEntity<List<UserDto>> entity = restTemplate.exchange(restTemplate.getUrl() + "admins/" + tenantId, HttpMethod.GET, null, typeRef);
return entity.getBody();
}

public TenantDto getTenant(String userId) throws Exception { public TenantDto getTenant(String userId) throws Exception {
return restTemplate.getForObject(restTemplate.getUrl() + "tenant/" + userId, TenantDto.class); return restTemplate.getForObject(restTemplate.getUrl() + "tenant/" + userId, TenantDto.class);
} }
Expand Down
Expand Up @@ -147,7 +147,7 @@ protected void onResult(UserDto result) {


public void loadAllTenantAdminsByTenantId(String tenantId, final AsyncCallback<List<UserDto>> callback) { public void loadAllTenantAdminsByTenantId(String tenantId, final AsyncCallback<List<UserDto>> callback) {


tenantRpcService.findAllTenantAdminsByTenantId(tenantId, new DataCallback<List<UserDto>>( userRpcService.findAllTenantAdminsByTenantId(tenantId, new DataCallback<List<UserDto>>(
callback) { callback) {
@Override @Override
protected void onResult(List<UserDto> result) { protected void onResult(List<UserDto> result) {
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.kaaproject.kaa.server.admin.shared.services.TenantService; import org.kaaproject.kaa.server.admin.shared.services.TenantService;
import org.kaaproject.kaa.server.admin.shared.services.UserService; import org.kaaproject.kaa.server.admin.shared.services.UserService;
import org.kaaproject.kaa.server.admin.shared.services.VerifierService; import org.kaaproject.kaa.server.admin.shared.services.VerifierService;
import org.kaaproject.kaa.server.control.service.ControlService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -156,6 +157,11 @@ public abstract class AbstractAdminController {
*/ */
@Autowired @Autowired
UserFacade userFacade; UserFacade userFacade;
/**
* The control service.
*/
@Autowired
ControlService controlService;


/** /**
* The password encoder. * The password encoder.
Expand Down
Expand Up @@ -271,4 +271,23 @@ public void deleteUser(
@RequestParam(value = "userId") String userId) throws KaaAdminServiceException { @RequestParam(value = "userId") String userId) throws KaaAdminServiceException {
userService.deleteUser(userId); userService.deleteUser(userId);
} }


@ApiOperation(value = "Select tenant admins by tenant id")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "The specified tenantId is not valid"),
@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 = 404, message = "The user with the specified tenantId does not exist"),
@ApiResponse(code = 500, message = "An unexpected error occurred on the server side")})
@RequestMapping(value = "admins/{tenantId}", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public List<UserDto> findAllTenantAdminsByTenantId(
@PathVariable String tenantId) throws KaaAdminServiceException {
return userService.findAllTenantAdminsByTenantId(tenantId);
}



} }
Expand Up @@ -83,20 +83,5 @@ public void deleteTenant(String tenantId) throws KaaAdminServiceException {
} }
} }


@Override
public List<org.kaaproject.kaa.common.dto.admin.UserDto> findAllTenantAdminsByTenantId(String tenantId) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.KAA_ADMIN);
List<org.kaaproject.kaa.common.dto.admin.UserDto> tenantAdminList=new ArrayList<>();
try {
List<UserDto> userDtoList=controlService.findAllTenantAdminsByTenantId(tenantId);
if(userDtoList!=null){
for(UserDto userDto:userDtoList)
tenantAdminList.add(toUser(userDto));
}
} catch (Exception e) {
throw Utils.handleException(e);
}
return tenantAdminList;
}


} }
Expand Up @@ -145,6 +145,23 @@ public void deleteUser(String userId) throws KaaAdminServiceException {
} }
} }


@Override
public List<org.kaaproject.kaa.common.dto.admin.UserDto> findAllTenantAdminsByTenantId(String tenantId) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.KAA_ADMIN);
List<org.kaaproject.kaa.common.dto.admin.UserDto> tenantAdminList=new ArrayList<>();
try {
List<UserDto> userDtoList=controlService.findAllTenantAdminsByTenantId(tenantId);
if(userDtoList!=null){
for(UserDto userDto:userDtoList)
tenantAdminList.add(toUser(userDto));
}
} catch (Exception e) {
throw Utils.handleException(e);
}
return tenantAdminList;
}


private void checkUserProfile(UserProfileUpdateDto userProfileUpdateDto) throws KaaAdminServiceException { private void checkUserProfile(UserProfileUpdateDto userProfileUpdateDto) throws KaaAdminServiceException {
if (isEmpty(userProfileUpdateDto.getFirstName())) { if (isEmpty(userProfileUpdateDto.getFirstName())) {
throw new IllegalArgumentException("First name is not valid."); throw new IllegalArgumentException("First name is not valid.");
Expand Down
Expand Up @@ -34,5 +34,4 @@ public interface TenantService extends RemoteService {


void deleteTenant(String tenantId) throws KaaAdminServiceException; void deleteTenant(String tenantId) throws KaaAdminServiceException;


List<UserDto> findAllTenantAdminsByTenantId(String id) throws KaaAdminServiceException;
} }
Expand Up @@ -37,4 +37,6 @@ public interface UserService extends RemoteService {
UserDto editUser(UserDto user) throws KaaAdminServiceException; UserDto editUser(UserDto user) throws KaaAdminServiceException;


void deleteUser(String userId) throws KaaAdminServiceException; void deleteUser(String userId) throws KaaAdminServiceException;

List<UserDto> findAllTenantAdminsByTenantId(String id) throws KaaAdminServiceException;
} }

0 comments on commit 979c0cb

Please sign in to comment.