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.",
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(
@ApiParam(
name = "id",
@ -150,7 +153,10 @@ public interface ActivityInfoProviderService {
message = "Internal Server Error. \n Server error occurred while fetching activity data.",
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(
@ApiParam(
name = "since",

@ -47,7 +47,8 @@ public interface ConfigurationManagementService {
value = "Get the general platform configurations.",
notes = "Get the general platform level configuration details.",
tags = "Configuration Management")
@ApiResponses(value = {
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched general platform configuration.",
@ -65,7 +66,8 @@ public interface ConfigurationManagementService {
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
}
),
@ApiResponse(
code = 304,
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 " +
"platform configuration.",
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(
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@HeaderParam("If-Modified-Since")
String ifModifiedSince);
@PUT
@ApiOperation(
@ -96,7 +102,8 @@ public interface ConfigurationManagementService {
value = "Update General Platform Configurations.",
notes = "This resource is used to update the general platform configuration.",
tags = "Configuration Management")
@ApiResponses(value = {
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n General platform configuration has been updated successfully",
@ -123,13 +130,17 @@ public interface ConfigurationManagementService {
message = "Internal Server Error. \n " +
"Server error occurred while modifying general platform configuration.",
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(
@ApiParam(
name = "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. " +
"\n Server error occurred while fetching the notification list.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "device-notification-view",
permissions = {
"/permission/admin/device-mgt/admin/notifications/view",
"/permission/admin/device-mgt/user/notifications/view"
})
"/permission/admin/device-mgt/user/notifications/view" }
)
Response getNotifications(
@ApiParam(
name = "status",
@ -122,4 +123,15 @@ public interface NotificationManagementService {
required = false)
@QueryParam("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",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")
}),
}
),
@ApiResponse(
code = 303,
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 " +
"Server error occurred while adding a new policy.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/add"})
permissions = {"/permission/admin/device-mgt/admin/policies/add"}
)
Response addPolicy(
@ApiParam(
name = "policy",
@ -132,7 +135,8 @@ public interface PolicyManagementService {
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
}
),
@ApiResponse(
code = 304,
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 " +
"policies."),
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "policy-view",
permissions = {"/permission/admin/device-mgt/admin/policies/list"})
permissions = {"/permission/admin/device-mgt/admin/policies/list"}
)
Response getPolicies(
@ApiParam(
name = "If-Modified-Since",
@ -199,15 +205,15 @@ public interface PolicyManagementService {
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
}
),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n No policy is found with the given id.",
response = ErrorResponse.class
),
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ -219,7 +225,8 @@ public interface PolicyManagementService {
})
@Permission(
scope = "policy-view",
permissions = {"/permission/admin/device-mgt/admin/policies/list"})
permissions = {"/permission/admin/device-mgt/admin/policies/list"}
)
Response getPolicy(
@ApiParam(
name = "id",
@ -263,7 +270,9 @@ public interface PolicyManagementService {
@ResponseHeader(
name = "Last-Modified",
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(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
@ -280,10 +289,12 @@ public interface PolicyManagementService {
message = "Internal Server Error. \n " +
"Server error occurred while updating the policy.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/update"})
permissions = {"/permission/admin/device-mgt/admin/policies/update"}
)
Response updatePolicy(
@ApiParam(
name = "id",
@ -321,16 +332,19 @@ public interface PolicyManagementService {
response = ErrorResponse.class),
@ApiResponse(
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(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while bulk removing policies.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "policy-modify",
permissions = {"/permission/admin/device-mgt/admin/policies/remove"})
permissions = {"/permission/admin/device-mgt/admin/policies/remove"}
)
Response removePolicies(
@ApiParam(
name = "policyIds",
@ -365,11 +379,13 @@ public interface PolicyManagementService {
code = 500,
message = "ErrorResponse in activating policies.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update",
"/permission/admin/device-mgt/admin/policies/add"})
"/permission/admin/device-mgt/admin/policies/add"}
)
Response activatePolicies(
@ApiParam(
name = "policyIds",
@ -384,8 +400,8 @@ public interface PolicyManagementService {
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Deactivating policies.",
notes = "Using the REST API command you are able to unpublish a policy in order to bring a policy that " +
"is in the active state to the inactive state.",
notes = "Using the REST API command you are able to unpublish a policy in order to bring a "
+ "policy that is in the active state to the inactive state.",
tags = "Device Policy Management")
@ApiResponses(
value = {
@ -404,12 +420,14 @@ public interface PolicyManagementService {
code = 500,
message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "policy-modify",
permissions = {
"/permission/admin/device-mgt/admin/policies/update",
"/permission/admin/device-mgt/admin/policies/add"})
"/permission/admin/device-mgt/admin/policies/add"}
)
Response deactivatePolicies(
@ApiParam(
name = "policyIds",
@ -441,8 +459,12 @@ public interface PolicyManagementService {
code = 500,
message = "ErrorResponse in deactivating policies.",
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();
@ -470,7 +492,8 @@ public interface PolicyManagementService {
code = 500,
message = "Exception in updating policy priorities.",
response = ErrorResponse.class)
})
}
)
@Permission(
scope = "",
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.service.api.NotificationManagementService;
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 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;
Notification getNotification(int notificationId) 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
public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException {
PaginationResult paginationResult = new PaginationResult();

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

@ -70,6 +70,35 @@ public class NotificationDAOImpl implements NotificationDAO {
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
public int updateNotification(Notification notification)
throws NotificationManagementException {

Loading…
Cancel
Save