Merge pull request #311 from madhawap/master

added 'updateNotificationStatus' endpoint and minor formattings to swagger annotations
4.x.x
Dilan U. Ariyaratne 9 years ago committed by GitHub
commit 951d68a92d

@ -91,7 +91,10 @@ public interface ActivityInfoProviderService {
message = "Internal Server Error. \n Server error occurred while fetching activity data.", message = "Internal Server Error. \n Server error occurred while fetching activity data.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"}) @Permission(
scope = "activity-view",
permissions = {"/permission/admin/device-mgt/admin/activities/view"}
)
Response getActivity( Response getActivity(
@ApiParam( @ApiParam(
name = "id", name = "id",
@ -150,7 +153,10 @@ public interface ActivityInfoProviderService {
message = "Internal Server Error. \n Server error occurred while fetching activity data.", message = "Internal Server Error. \n Server error occurred while fetching activity data.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"}) @Permission(
scope = "activity-view",
permissions = {"/permission/admin/device-mgt/admin/activities/view"}
)
Response getActivities( Response getActivities(
@ApiParam( @ApiParam(
name = "since", name = "since",

@ -47,7 +47,8 @@ public interface ConfigurationManagementService {
value = "Get the general platform configurations.", value = "Get the general platform configurations.",
notes = "Get the general platform level configuration details.", notes = "Get the general platform level configuration details.",
tags = "Configuration Management") tags = "Configuration Management")
@ApiResponses(value = { @ApiResponses(
value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched general platform configuration.", message = "OK. \n Successfully fetched general platform configuration.",
@ -65,7 +66,8 @@ public interface ConfigurationManagementService {
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }
),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " + message = "Not Modified. \n Empty body because the client has already the latest version of " +
@ -78,15 +80,19 @@ public interface ConfigurationManagementService {
message = "Internal Server Error. \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)
}) }
@Permission(scope = "configuration-view", )
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}) @Permission(
scope = "configuration-view",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}
)
Response getConfiguration( Response getConfiguration(
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified", value = "Validates if the requested variant has not been modified since the time specified",
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since")
String ifModifiedSince);
@PUT @PUT
@ApiOperation( @ApiOperation(
@ -96,7 +102,8 @@ public interface ConfigurationManagementService {
value = "Update General Platform Configurations.", value = "Update General Platform Configurations.",
notes = "This resource is used to update the general platform configuration.", notes = "This resource is used to update the general platform configuration.",
tags = "Configuration Management") tags = "Configuration Management")
@ApiResponses(value = { @ApiResponses(
value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n General platform configuration has been updated successfully", message = "OK. \n General platform configuration has been updated successfully",
@ -123,13 +130,17 @@ public interface ConfigurationManagementService {
message = "Internal Server Error. \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)
}) }
@Permission(scope = "configuration-modify", )
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"}) @Permission(
scope = "configuration-modify",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"}
)
Response updateConfiguration( Response updateConfiguration(
@ApiParam( @ApiParam(
name = "configuration", name = "configuration",
value = "The required properties to be updated in the platform configuration.", value = "The required properties to be updated in the platform configuration.",
required = true) PlatformConfiguration configuration); required = true)
PlatformConfiguration configuration);
} }

@ -89,13 +89,14 @@ public interface NotificationManagementService {
message = "Internal Server Error. " + message = "Internal Server Error. " +
"\n Server error occurred while fetching the notification list.", "\n Server error occurred while fetching the notification list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "device-notification-view", scope = "device-notification-view",
permissions = { permissions = {
"/permission/admin/device-mgt/admin/notifications/view", "/permission/admin/device-mgt/admin/notifications/view",
"/permission/admin/device-mgt/user/notifications/view" "/permission/admin/device-mgt/user/notifications/view" }
}) )
Response getNotifications( Response getNotifications(
@ApiParam( @ApiParam(
name = "status", name = "status",
@ -122,4 +123,15 @@ public interface NotificationManagementService {
required = false) required = false)
@QueryParam("limit") @QueryParam("limit")
int limit); int limit);
@PUT
@Path("{id}/{status}")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "",
notes = "",
tags = "Device Notification Management")
Response updateNotificationStatus(
@PathParam("id") int id);
} }

@ -69,7 +69,8 @@ public interface PolicyManagementService {
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.") "Used by caches, or in conditional requests.")
}), }
),
@ApiResponse( @ApiResponse(
code = 303, code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
@ -93,10 +94,12 @@ public interface PolicyManagementService {
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while adding a new policy.", "Server error occurred while adding a new policy.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "policy-modify", scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/add"}) permissions = {"/permission/admin/device-mgt/admin/policies/add"}
)
Response addPolicy( Response addPolicy(
@ApiParam( @ApiParam(
name = "policy", name = "policy",
@ -132,7 +135,8 @@ public interface PolicyManagementService {
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }
),
@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."),
@ -148,10 +152,12 @@ public interface PolicyManagementService {
message = ("Internal Server Error. \n Server error occurred while fetching " + message = ("Internal Server Error. \n Server error occurred while fetching " +
"policies."), "policies."),
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "policy-view", scope = "policy-view",
permissions = {"/permission/admin/device-mgt/admin/policies/list"}) permissions = {"/permission/admin/device-mgt/admin/policies/list"}
)
Response getPolicies( Response getPolicies(
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
@ -199,15 +205,15 @@ public interface PolicyManagementService {
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }
),
@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 = 404, code = 404,
message = "Not Found. \n No policy is found with the given id.", message = "Not Found. \n No policy is found with the given id.",
response = ErrorResponse.class response = ErrorResponse.class),
),
@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"),
@ -219,7 +225,8 @@ public interface PolicyManagementService {
}) })
@Permission( @Permission(
scope = "policy-view", scope = "policy-view",
permissions = {"/permission/admin/device-mgt/admin/policies/list"}) permissions = {"/permission/admin/device-mgt/admin/policies/list"}
)
Response getPolicy( Response getPolicy(
@ApiParam( @ApiParam(
name = "id", name = "id",
@ -263,7 +270,9 @@ public interface PolicyManagementService {
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}), "Used by caches, or in conditional requests.")
}
),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -280,10 +289,12 @@ public interface PolicyManagementService {
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while updating the policy.", "Server error occurred while updating the policy.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "policy-modify", scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/update"}) permissions = {"/permission/admin/device-mgt/admin/policies/update"}
)
Response updatePolicy( Response updatePolicy(
@ApiParam( @ApiParam(
name = "id", name = "id",
@ -321,16 +332,19 @@ public interface PolicyManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 415, code = 415,
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 Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while bulk removing policies.", "Server error occurred while bulk removing policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "policy-modify", scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/remove"}) permissions = {"/permission/admin/device-mgt/admin/policies/remove"}
)
Response removePolicies( Response removePolicies(
@ApiParam( @ApiParam(
name = "policyIds", name = "policyIds",
@ -365,11 +379,13 @@ public interface PolicyManagementService {
code = 500, code = 500,
message = "ErrorResponse in activating policies.", message = "ErrorResponse in activating policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "policy-modify", permissions = { scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update", "/permission/admin/device-mgt/admin/policies/update",
"/permission/admin/device-mgt/admin/policies/add"}) "/permission/admin/device-mgt/admin/policies/add"}
)
Response activatePolicies( Response activatePolicies(
@ApiParam( @ApiParam(
name = "policyIds", name = "policyIds",
@ -384,8 +400,8 @@ public interface PolicyManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Deactivating policies.", value = "Deactivating policies.",
notes = "Using the REST API command you are able to unpublish a policy in order to bring a policy that " + notes = "Using the REST API command you are able to unpublish a policy in order to bring a "
"is in the active state to the inactive state.", + "policy that is in the active state to the inactive state.",
tags = "Device Policy Management") tags = "Device Policy Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -404,12 +420,14 @@ public interface PolicyManagementService {
code = 500, code = 500,
message = "ErrorResponse in deactivating policies.", message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "policy-modify", scope = "policy-modify",
permissions = { permissions = {
"/permission/admin/device-mgt/admin/policies/update", "/permission/admin/device-mgt/admin/policies/update",
"/permission/admin/device-mgt/admin/policies/add"}) "/permission/admin/device-mgt/admin/policies/add"}
)
Response deactivatePolicies( Response deactivatePolicies(
@ApiParam( @ApiParam(
name = "policyIds", name = "policyIds",
@ -441,8 +459,12 @@ public interface PolicyManagementService {
code = 500, code = 500,
message = "ErrorResponse in deactivating policies.", message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"}) )
@Permission(
scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/update"}
)
Response applyChanges(); Response applyChanges();
@ -470,7 +492,8 @@ public interface PolicyManagementService {
code = 500, code = 500,
message = "Exception in updating policy priorities.", message = "Exception in updating policy priorities.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }
)
@Permission( @Permission(
scope = "", scope = "",
permissions = {}) permissions = {})

@ -28,6 +28,7 @@ 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.beans.NotificationList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; 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.DeviceMgtAPIUtils;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -74,4 +75,29 @@ public class NotificationManagementServiceImpl implements NotificationManagement
} }
} }
@PUT
@Path("{id}/mark-checked")
public Response updateNotificationStatus(
@PathParam("id") int id) {
String msg;
Notification.Status status = Notification.Status.CHECKED;
Notification notification;
try {
DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
} catch (NotificationManagementException e) {
msg = "Error occurred while updating notification status.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
try {
notification = DeviceMgtAPIUtils.getNotificationManagementService().getNotification(id);
return Response.status(Response.Status.OK).entity(notification).build();
} catch (NotificationManagementException e) {
msg = "Notification updated successfully. But the retrial of the updated notification failed";
log.error(msg, e);
return Response.status(Response.Status.OK).build();
}
}
} }

@ -71,6 +71,8 @@ public interface NotificationManagementService {
*/ */
List<Notification> getAllNotifications() throws NotificationManagementException; List<Notification> getAllNotifications() throws NotificationManagementException;
Notification getNotification(int notificationId) throws NotificationManagementException;
PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException; PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException;
/** /**

@ -160,6 +160,19 @@ public class NotificationManagementServiceImpl implements NotificationManagement
} }
} }
@Override
public Notification getNotification(int notificationId) throws NotificationManagementException {
try {
NotificationManagementDAOFactory.openConnection();
return notificationDAO.getNotification(NotificationDAOUtil.getTenantId(), notificationId);
} catch (SQLException e) {
throw new NotificationManagementException("Error occurred while opening a connection to" +
" the data source", e);
} finally {
NotificationManagementDAOFactory.closeConnection();
}
}
@Override @Override
public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException { public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();

@ -71,6 +71,8 @@ public interface NotificationDAO {
*/ */
List<Notification> getAllNotifications(int tenantId) throws NotificationManagementException; List<Notification> getAllNotifications(int tenantId) throws NotificationManagementException;
Notification getNotification(int tenantId, int notificationId) throws NotificationManagementException;
List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException; List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException;
int getNotificationCount(int tenantId) throws NotificationManagementException; int getNotificationCount(int tenantId) throws NotificationManagementException;

@ -70,6 +70,35 @@ public class NotificationDAOImpl implements NotificationDAO {
return notificationId; return notificationId;
} }
@Override
public Notification getNotification(int tenantId, int notificationId) throws NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
Notification notification = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT NOTIFICATION_ID, OPERATION_ID, DESCRIPTION, STATUS FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND NOTIFICATION_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, notificationId);
rs = stmt.executeQuery();
while (rs.next()) {
notification = this.getNotification(rs);
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notification;
}
@Override @Override
public int updateNotification(Notification notification) public int updateNotification(Notification notification)
throws NotificationManagementException { throws NotificationManagementException {

Loading…
Cancel
Save