Code cleanup

revert-70aa11f8
prabathabey 8 years ago
parent f33ac36bfa
commit ed5d611c35

@ -87,7 +87,7 @@ public interface DeviceManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.",
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
response = ErrorResponse.class)
})
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
@ -180,7 +180,7 @@ public interface DeviceManagementService {
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while retrieving information requested device.",
response = ErrorResponse.class)
})
@ -259,7 +259,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while retrieving feature list of the device.",
response = ErrorResponse.class)
})
@ -331,7 +331,7 @@ public interface DeviceManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while enrolling the device.",
response = ErrorResponse.class)
})
@ -405,7 +405,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while retrieving installed application list of the device.",
response = ErrorResponse.class)
})
@ -494,7 +494,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while retrieving operation list scheduled for the device.",
response = ErrorResponse.class)
})
@ -582,7 +582,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while retrieving the effective policy calculated for the device.",
response = ErrorResponse.class)
})

@ -85,7 +85,8 @@ public interface NotificationManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the notification list.",
message = "Internal Server Error. " +
"\n Server error occurred while fetching the notification list.",
response = ErrorResponse.class)
})
@Permission(scope = "device-notification-view", permissions = {

@ -90,7 +90,7 @@ public interface PolicyManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while adding a new policy.",
response = ErrorResponse.class)
})
@ -142,7 +142,7 @@ public interface PolicyManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = ("Internal Server ErrorResponse. \n Server error occurred while fetching " +
message = ("Internal Server Error. \n Server error occurred while fetching " +
"policies."),
response = ErrorResponse.class)
})
@ -205,7 +205,7 @@ public interface PolicyManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the " +
message = "Internal Server Error. \n Server error occurred while fetching the " +
"policy.",
response = ErrorResponse.class)
})
@ -265,7 +265,7 @@ public interface PolicyManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while updating the policy.",
response = ErrorResponse.class)
})
@ -307,7 +307,7 @@ public interface PolicyManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while bulk removing policies.",
response = ErrorResponse.class)
})

@ -68,7 +68,7 @@ public interface ApplicationManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while bulk issuing application installation operations upon " +
"a given set of devices.",
response = ErrorResponse.class)
@ -106,7 +106,7 @@ public interface ApplicationManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while bulk issuing application un-installation operations upon " +
"a given set of devices.",
response = ErrorResponse.class)

@ -80,7 +80,7 @@ public interface DeviceManagementAdminService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.",
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
response = ErrorResponse.class)
})
Response getDevicesByName(

@ -60,7 +60,7 @@ public interface UserManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
message = "Internal Server Error. \n " +
"Server error occurred while updating credentials of the user.",
response = ErrorResponse.class)
})

@ -265,7 +265,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService();
result = dms.getOperations(new DeviceIdentifier(id, type),request);
result = dms.getOperations(new DeviceIdentifier(id, type), request);
operationsList.setList((List<? extends Operation>) result.getData());
operationsList.setCount(result.getRecordsTotal());

@ -22,11 +22,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.jaxrs.NotificationContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.NotificationList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.*;
@ -49,6 +48,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
String msg;
List<Notification> notifications;
NotificationList notificationList = new NotificationList();
try {
if (status != null) {
RequestValidationUtil.validateNotificationStatus(status);
@ -59,17 +59,14 @@ public class NotificationManagementServiceImpl implements NotificationManagement
notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
}
if (notifications == null || notifications.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No notification is " +
"available to be retrieved.").build());
}
return Response.status(Response.Status.OK).entity(notifications).build();
notificationList.setCount(notifications.size());
notificationList.setNotifications(notifications);
return Response.status(Response.Status.OK).entity(notificationList).build();
} catch (NotificationManagementException e) {
msg = "Error occurred while retrieving notification info";
msg = "Error occurred while retrieving notification list";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}

@ -298,7 +298,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
}
if (isPolicyDeActivated) {
return Response.status(Response.Status.OK).entity("Selected policies have been successfully " +
"deactivated").build();
"deactivated").build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " +

@ -209,7 +209,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
//TODO fix what's returned in the entity
return Response.created(new URI(API_BASE_PATH + "/" + roleInfo.getRoleName())).entity(
"Role '" + roleInfo.getRoleName() + "' has " +
"successfully been added").build();
"successfully been added").build();
} catch (UserStoreException e) {
String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'";
log.error(msg, e);

@ -110,7 +110,7 @@ public class UserManagementServiceImpl implements UserManagementService {
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"User doesn't exist.").build()).build();
"User doesn't exist.").build()).build();
}
BasicUserInfo user = this.getBasicUserInfo(username);

@ -29,9 +29,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.ApplicationManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAndroidOperationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.MDMIOSOperationUtil;
@ -82,21 +80,22 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
applicationWrapper.getDeviceIdentifiers().size() > 0) {
activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
} else {
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"No application installation criteria i.e. user/role/device is given").build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"No application installation criteria i.e. user/role/device is given").build()).build();
}
}
return Response.status(Response.Status.ACCEPTED).entity(activity).build();
} catch (ApplicationManagementException e) {
String msg = "ErrorResponse occurred while processing application installation request";
String msg = "Error occurred while processing application installation request";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (UnknownApplicationTypeException e) {
String msg = "The type of application requested to be installed is not supported";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
@ -130,22 +129,22 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
applicationWrapper.getDeviceIdentifiers().size() > 0) {
activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
} else {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"No application un-installation criteria i.e. user/role/device is given").build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"No application un-installation criteria i.e. user/role/device is given").build()).build();
}
}
return Response.status(Response.Status.ACCEPTED).entity(activity).build();
} catch (ApplicationManagementException e) {
String msg = "ErrorResponse occurred while processing application un-installation request";
String msg = "Error occurred while processing application un-installation request";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (UnknownApplicationTypeException e) {
String msg = "The type of application requested to be un-installed is not supported";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}

@ -28,8 +28,6 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.*;
@ -55,21 +53,16 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
try {
int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) {
throw new UnauthorizedAccessException(
new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage(
"Current logged in user is not authorized to perform this operation").build());
return Response.status(Response.Status.UNAUTHORIZED).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"Current logged in user is not authorized to perform this operation").build()).build();
}
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(DeviceMgtAPIUtils.getTenantId(tenantDomain));
List<Device> devices = DeviceMgtAPIUtils.getDeviceManagementService().
getDevicesByNameAndType(name, type, offset, limit);
if (devices == null || devices.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device, which carries" +
" the name '" + name + "', is currently enrolled in the system").build());
}
getDevicesByNameAndType(name, type, offset, limit);
// setting up paginated result
DeviceList deviceList = new DeviceList();
@ -80,8 +73,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
} catch (DeviceManagementException e) {
String msg = "Error occurred at server side while fetching device list.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}

@ -21,11 +21,9 @@ package org.wso2.carbon.device.mgt.jaxrs.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
@ -44,7 +42,8 @@ public class CredentialManagementResponseBuilder {
/**
* Builds the response to change the password of a user
* @param username - Username of the user.
*
* @param username - Username of the user.
* @param credentials - User credentials
* @return Response Object
*/
@ -52,38 +51,39 @@ public class CredentialManagementResponseBuilder {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("No user found with the username "
+ username).build());
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No user found with the username '"
+ username + "'").build()).build();
}
RequestValidationUtil.validateCredentials(credentials);
if (!validateCredential(credentials.getNewPassword())) {
String errorMsg = DeviceMgtAPIUtils.getRealmService().getBootstrapRealmConfiguration()
.getUserStoreProperty(PASSWORD_VALIDATION_ERROR_MSG_TAG);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMsg).build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMsg).build()).build();
}
userStoreManager.updateCredential(username, credentials.getNewPassword(),
credentials.getOldPassword());
credentials.getOldPassword());
return Response.status(Response.Status.OK).entity("UserImpl password by username: " +
username + " was successfully changed.").build();
} catch (UserStoreException e) {
log.error(e.getMessage(), e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(e.getMessage()).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
} catch (UnsupportedEncodingException e) {
String msg = "Could not change the password of the user: " + username +
". The Character Encoding is not supported.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
/**
* Builds the response to reset the password of a user
* @param username - Username of the user.
*
* @param username - Username of the user.
* @param credentials - User credentials
* @return Response Object
*/
@ -91,35 +91,35 @@ public class CredentialManagementResponseBuilder {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("No user found with the username "
+ username).build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No user found with the username "
+ username).build()).build();
}
if (credentials == null || credentials.getNewPassword() == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Password cannot be empty."
+ username).build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Password cannot be empty."
+ username).build()).build();
}
if (!validateCredential(credentials.getNewPassword())) {
String errorMsg = DeviceMgtAPIUtils.getRealmService().getBootstrapRealmConfiguration()
.getUserStoreProperty(PASSWORD_VALIDATION_ERROR_MSG_TAG);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMsg).build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMsg).build()).build();
}
userStoreManager.updateCredentialByAdmin(username, credentials.getNewPassword());
return Response.status(Response.Status.OK).entity("UserImpl password by username: " +
username + " was successfully changed.").build();
} catch (UserStoreException e) {
String msg = "ErrorResponse occurred while updating the credentials of user '" + username + "'";
String msg = "Error occurred while updating the credentials of user '" + username + "'";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (UnsupportedEncodingException e) {
String msg = "Could not change the password of the user: " + username +
". The Character Encoding is not supported.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}

Loading…
Cancel
Save