Improving HTTP status code handling and the resource implementations

revert-70aa11f8
prabathabey 8 years ago
parent a23f44e682
commit 624e7df688

@ -68,13 +68,14 @@ public interface ConfigurationManagementService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the general " + message = "Internal Server Error. \n Server error occurred while fetching the general " +
"platform configuration.", "platform configuration.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@ -100,9 +101,6 @@ public interface ConfigurationManagementService {
code = 200, code = 200,
message = "OK. \n General platform configuration has been updated successfully", message = "OK. \n General platform configuration has been updated successfully",
responseHeaders = { responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated general platform configuration."),
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), description = "The content type of the body"),
@ -122,7 +120,7 @@ public interface ConfigurationManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server Error. \n " +
"Server error occurred while modifying general platform configuration.", "Server error occurred while modifying general platform configuration.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })

@ -308,9 +308,6 @@ public interface RoleManagementService {
code = 200, code = 200,
message = "OK. \n Role has been updated successfully", message = "OK. \n Role has been updated successfully",
responseHeaders = { responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated role."),
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "Content type of the body"), description = "Content type of the body"),
@ -404,9 +401,6 @@ public interface RoleManagementService {
code = 200, code = 200,
message = "OK. \n User list of the role has been updated successfully", message = "OK. \n User list of the role has been updated successfully",
responseHeaders = { responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated user list."),
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "Content type of the body"), description = "Content type of the body"),

@ -162,9 +162,6 @@ public interface UserManagementService {
code = 200, code = 200,
message = "OK. \n User has been updated successfully", message = "OK. \n User has been updated successfully",
responseHeaders = { responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated user."),
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "Content type of the body"), description = "Content type of the body"),
@ -190,7 +187,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server Error. \n " +
"Server error occurred while updating the user.", "Server error occurred while updating the user.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@ -224,7 +221,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server Error. \n " +
"Server error occurred while removing the user.", "Server error occurred while removing the user.",
response = ErrorResponse.class response = ErrorResponse.class
) )
@ -274,7 +271,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the role list" + message = "Internal Server Error. \n Server error occurred while fetching the role list" +
" assigned to the user.", " assigned to the user.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@ -318,7 +315,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the user list.", message = "Internal Server Error. \n Server error occurred while fetching the user list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
@ -384,7 +381,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the username " + message = "Internal Server Error. \n Server error occurred while fetching the username " +
"list that matches the given filter.", "list that matches the given filter.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@ -438,7 +435,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server Error. \n " +
"Server error occurred while updating credentials of the user.", "Server error occurred while updating credentials of the user.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })

@ -55,19 +55,19 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
ConfigurationEntry configurationEntry = new ConfigurationEntry(); ConfigurationEntry configurationEntry = new ConfigurationEntry();
configurationEntry.setContentType("text"); configurationEntry.setContentType("text");
configurationEntry.setName("notifierFrequency"); configurationEntry.setName("notifierFrequency");
configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency()); configurationEntry.setValue(PolicyManagerUtil.getMonitoringFrequency());
List<ConfigurationEntry> configList = config.getConfiguration(); List<ConfigurationEntry> configList = config.getConfiguration();
if (configList == null) { if (configList == null) {
configList = new ArrayList<>(); configList = new ArrayList<>();
configList.add(configurationEntry); configList.add(configurationEntry);
} }
config.setConfiguration(configList); config.setConfiguration(configList);
return Response.status(Response.Status.OK).entity(config).build(); return Response.ok().entity(config).build();
} catch (ConfigurationManagementException | PolicyManagementException e) { } catch (ConfigurationManagementException | PolicyManagementException e) {
msg = "ErrorResponse occurred while retrieving the configurations."; msg = "Error occurred while retrieving the general platform configuration";
log.error(msg, e); log.error(msg, e);
throw new UnexpectedServerErrorException( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} }
} }
@ -80,13 +80,15 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH); MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
//Schedule the task service //Schedule the task service
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config)); DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config));
return Response.status(Response.Status.CREATED)
.entity("Configuration has successfully been updated").build(); PlatformConfiguration updatedConfig = DeviceMgtAPIUtils.getPlatformConfigurationManagementService().
getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
return Response.ok().entity(updatedConfig).build();
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
String msg = "ErrorResponse occurred while updating the configuration."; String msg = "Error occurred while updating the general platform configuration";
log.error(msg, e); log.error(msg, e);
throw new UnexpectedServerErrorException( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} }
} }

@ -91,7 +91,7 @@ public class PolicyManagementServiceComponent {
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration(); DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration();
if(policyConfiguration.getMonitoringEnable()) { if(policyConfiguration.getMonitoringEnable()) {
TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl(); TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl();
taskScheduleService.startTask(PolicyManagerUtil.getMonitoringFequency()); taskScheduleService.startTask(PolicyManagerUtil.getMonitoringFrequency());
} }
} catch (Throwable t) { } catch (Throwable t) {

@ -196,7 +196,7 @@ public class PolicyManagerUtil {
} }
public static int getMonitoringFequency() throws PolicyManagementException { public static int getMonitoringFrequency() throws PolicyManagementException {
PlatformConfigurationManagementService configMgtService = new PlatformConfigurationManagementServiceImpl(); PlatformConfigurationManagementService configMgtService = new PlatformConfigurationManagementServiceImpl();
PlatformConfiguration tenantConfiguration; PlatformConfiguration tenantConfiguration;

Loading…
Cancel
Save