forked from community/device-mgt-core
commit
de78869eea
@ -0,0 +1,416 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.application.mgt.api.services;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.Info;
|
||||||
|
import io.swagger.annotations.SwaggerDefinition;
|
||||||
|
import io.swagger.annotations.Extension;
|
||||||
|
import io.swagger.annotations.ExtensionProperty;
|
||||||
|
import io.swagger.annotations.Tag;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiResponse;
|
||||||
|
import io.swagger.annotations.ApiResponses;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||||
|
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Comment;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIs to handle comment management related tasks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SwaggerDefinition(
|
||||||
|
info = @Info(
|
||||||
|
version = "1.0.0",
|
||||||
|
title = "Store Management Service",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = "name", value = "CommentManagementService"),
|
||||||
|
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/comments"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
),
|
||||||
|
tags = {
|
||||||
|
@Tag(name = "store_management", description = "Comment Management related "
|
||||||
|
+ "APIs")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@Scopes(
|
||||||
|
scopes = {
|
||||||
|
@Scope(
|
||||||
|
name = "Get Comments Details",
|
||||||
|
description = "Get comments details",
|
||||||
|
key = "perm:comment:get",
|
||||||
|
permissions = {"/device-mgt/comment/get"}
|
||||||
|
),
|
||||||
|
@Scope(
|
||||||
|
name = "Add a Comment",
|
||||||
|
description = "Add a comment",
|
||||||
|
key = "perm:comment:add",
|
||||||
|
permissions = {"/device-mgt/comment/add"}
|
||||||
|
),
|
||||||
|
@Scope(
|
||||||
|
name = "Update a Comment",
|
||||||
|
description = "Update a Comment",
|
||||||
|
key = "perm:comment:update",
|
||||||
|
permissions = {"/device-mgt/comment/update"}
|
||||||
|
),
|
||||||
|
|
||||||
|
@Scope(
|
||||||
|
name = "Delete a Comment",
|
||||||
|
description = "Delete a comment",
|
||||||
|
key = "perm:comment:delete",
|
||||||
|
permissions = {"/device-mgt/comment/delete"}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@Path("/comments")
|
||||||
|
@Api(value = "Comments Management", description = "This API carries all comments management related operations " +
|
||||||
|
"such as get all the comments, add comment, etc.")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
|
||||||
|
public interface CommentManagementAPI {
|
||||||
|
String SCOPE = "scope";
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{uuid}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "GET",
|
||||||
|
value = "get comments",
|
||||||
|
notes = "Get all comments",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:store:get")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully retrieved comments.",
|
||||||
|
response = List.class,
|
||||||
|
responseContainer = "List"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found. \n No activity found with the given ID.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred while getting the comment list.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
Response getAllComments(
|
||||||
|
@ApiParam(
|
||||||
|
name="uuid",
|
||||||
|
value="uuid of the released version of application.",
|
||||||
|
required = true)
|
||||||
|
@PathParam("uuid")
|
||||||
|
String uuid,
|
||||||
|
@ApiParam(
|
||||||
|
name="offSet",
|
||||||
|
value="Starting comment number.",defaultValue = "1",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("offSet")
|
||||||
|
int offSet,
|
||||||
|
@ApiParam(
|
||||||
|
name="limit",
|
||||||
|
value = "Limit of paginated comments",defaultValue = "20",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("limit")
|
||||||
|
int limit);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/{uuid}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "POST",
|
||||||
|
value = "Add a comment",
|
||||||
|
notes = "This will add a new comment",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:store:add")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 201,
|
||||||
|
message = "OK. \n Successfully add a comment.",
|
||||||
|
response = Comment.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 400,
|
||||||
|
message =
|
||||||
|
"Bad Request. \n"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred adding a comment.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
Response addComments(
|
||||||
|
@ApiParam(
|
||||||
|
name = "comment",
|
||||||
|
value = "Comment details",
|
||||||
|
required = true)
|
||||||
|
Comment comment,
|
||||||
|
@ApiParam(
|
||||||
|
name="uuid",
|
||||||
|
value="uuid of the release version of the application",
|
||||||
|
required=true)
|
||||||
|
@PathParam("uuid")
|
||||||
|
String uuid);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/{CommentId}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "PUT",
|
||||||
|
value = "Edit a comment",
|
||||||
|
notes = "This will edit the comment",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:store:edit")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 201,
|
||||||
|
message = "OK. \n Successfully updated comment.",
|
||||||
|
response = Comment.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 400,
|
||||||
|
message = "Bad Request. \n Invalid request or validation error."),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found. \n No activity found with the given ID.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred while updating the new comment.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response updateComment(
|
||||||
|
@ApiParam(
|
||||||
|
name = "comment",
|
||||||
|
value = "The comment that need to be updated.",
|
||||||
|
required = true)
|
||||||
|
@Valid Comment comment,
|
||||||
|
@ApiParam(
|
||||||
|
name="commentId",
|
||||||
|
value = "comment id of the updating comment.",
|
||||||
|
required = true)
|
||||||
|
@QueryParam("commentId")
|
||||||
|
int commentId);
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/{CommentId}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "DELETE",
|
||||||
|
value = "Remove comment",
|
||||||
|
notes = "Remove comment",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:store:remove")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully deleted the comment"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found. \n No activity found with the given ID.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred while deleting the comment.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
Response deleteComment(
|
||||||
|
@ApiParam(
|
||||||
|
name="commentId",
|
||||||
|
value="Id of the comment.",
|
||||||
|
required = true)
|
||||||
|
@PathParam("commentId")
|
||||||
|
int commentId);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{uuid}/{stars}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "GET",
|
||||||
|
value = "get stars",
|
||||||
|
notes = "Get all stars",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:stars:get")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully retrieved stars.",
|
||||||
|
response = List.class,
|
||||||
|
responseContainer = "List"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred while getting the stars",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
Response getStars(
|
||||||
|
@ApiParam(
|
||||||
|
name = "uuid",
|
||||||
|
value = "uuid of the application release",
|
||||||
|
required = true)
|
||||||
|
@PathParam("uuid")
|
||||||
|
String uuid);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{uuid}/{stars}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "GET",
|
||||||
|
value = "get rated users",
|
||||||
|
notes = "Get all users",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:user:get")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully retrieved user.",
|
||||||
|
response = List.class,
|
||||||
|
responseContainer = "List"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred while getting the comment list.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
Response getRatedUser(
|
||||||
|
@ApiParam(
|
||||||
|
name = "uuid",
|
||||||
|
value = "uuid of the application release",
|
||||||
|
required = true)
|
||||||
|
@PathParam("uuid")
|
||||||
|
String uuid);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/uuid/{uuid}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "POST",
|
||||||
|
value = "Add a star value",
|
||||||
|
notes = "This will add star value",
|
||||||
|
tags = "Store Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = SCOPE, value = "perm:stars:add")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 201,
|
||||||
|
message = "OK. \n Successfully rated to the application.",
|
||||||
|
response = Comment.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 304,
|
||||||
|
message = "Not Modified. \n " +
|
||||||
|
"Empty body because the client already has the latest rating of the requested resource."),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Error occurred rating for the application.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
Response updateStars(
|
||||||
|
@ApiParam(
|
||||||
|
name = "stars",
|
||||||
|
value = "ratings for the application",
|
||||||
|
required = true)
|
||||||
|
int stars,
|
||||||
|
@ApiParam(
|
||||||
|
name="uuid",
|
||||||
|
value="uuid of the release version of the application",
|
||||||
|
required=true)
|
||||||
|
@PathParam("uuid")
|
||||||
|
String uuid);
|
||||||
|
}
|
@ -0,0 +1,228 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.application.mgt.api.services.impl;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.application.mgt.api.APIUtil;
|
||||||
|
import org.wso2.carbon.device.application.mgt.api.services.CommentManagementAPI;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Comment;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
|
||||||
|
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.NotFoundException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comment Management related jax-rs APIs.
|
||||||
|
*/
|
||||||
|
@Path("/comments")
|
||||||
|
public class CommentManagementAPIImpl implements CommentManagementAPI {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GET
|
||||||
|
@Path("/{uuid}")
|
||||||
|
public Response getAllComments(
|
||||||
|
@PathParam("uuid") String uuid,
|
||||||
|
@QueryParam("offset") int offSet, @
|
||||||
|
QueryParam("limit") int limit) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
List<Comment> comments = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PaginationRequest request = new PaginationRequest(offSet, limit);
|
||||||
|
if (request.validatePaginationRequest(offSet, limit)) {
|
||||||
|
commentsManager.getAllComments(request, uuid);
|
||||||
|
return Response.status(Response.Status.OK).entity(comments).build();
|
||||||
|
}
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
log.error("Not found exception occurs to uuid " + uuid + " .", e);
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity("Application with UUID " + uuid + " not found")
|
||||||
|
.build();
|
||||||
|
} catch (CommentManagementException e) {
|
||||||
|
String msg = "Error occurred while retrieving comments.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity(" Internal server error occurs").build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity(comments).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@POST
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Path("/{uuid}")
|
||||||
|
public Response addComments(
|
||||||
|
@ApiParam Comment comment,
|
||||||
|
@PathParam("uuid") String uuid) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
try {
|
||||||
|
Comment newComment = commentsManager.addComment(comment, uuid, tenantId);
|
||||||
|
if (comment != null) {
|
||||||
|
return Response.status(Response.Status.CREATED).entity(newComment).build();
|
||||||
|
} else {
|
||||||
|
String msg = "Given comment is not valid ";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
} catch (CommentManagementException e) {
|
||||||
|
String msg = "Error occurred while creating the comment";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity("Internal server error occurs").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PUT
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Path("/{commentId}")
|
||||||
|
public Response updateComment(
|
||||||
|
@ApiParam Comment comment,
|
||||||
|
@PathParam("commentId") int commentId) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
try {
|
||||||
|
if (commentId == 0) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
|
.entity("Comment not found").build();
|
||||||
|
} else if (comment == null) {
|
||||||
|
String msg = "Given comment is not valid ";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
} else {
|
||||||
|
comment = commentsManager.updateComment(comment, commentId);
|
||||||
|
return Response.status(Response.Status.OK).entity(comment).build();
|
||||||
|
}
|
||||||
|
} catch (CommentManagementException e) {
|
||||||
|
String msg = "Error occurred while retrieving comments.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity(" Internal server error occurs").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DELETE
|
||||||
|
@Path("/{commentId}")
|
||||||
|
public Response deleteComment(
|
||||||
|
@PathParam("commentId") int commentId) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
try {
|
||||||
|
commentsManager.deleteComment(commentId);
|
||||||
|
} catch (CommentManagementException e) {
|
||||||
|
String msg = "Error occurred while deleting the comment.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity("Internal server error occurs").build();
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
log.error("Not found exception occurs to comment id " + commentId + " .", e);
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity("Comment not found").build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GET
|
||||||
|
@Path("/{uuid}")
|
||||||
|
public Response getStars(
|
||||||
|
@PathParam("uuid") String uuid) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
int Stars = 0;
|
||||||
|
try {
|
||||||
|
Stars = commentsManager.getStars(uuid);
|
||||||
|
} catch (CommentManagementException e) {
|
||||||
|
log.error("Comment Management Exception occurs", e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
log.error("Application Management Exception occurs", e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity("Internal server error occurs").build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity(Stars).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GET
|
||||||
|
@Path("/{uuid}")
|
||||||
|
public Response getRatedUser(
|
||||||
|
@PathParam("uuid") String uuid) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
int ratedUsers = 0;
|
||||||
|
try {
|
||||||
|
ratedUsers = commentsManager.getRatedUser(uuid);
|
||||||
|
} catch (CommentManagementException e) {
|
||||||
|
log.error("Comment Management Exception occurs", e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity("Internal server error occurs").build();
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
log.error("Application Management Exception occurs", e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity(ratedUsers).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@POST
|
||||||
|
@Consumes("application/json")
|
||||||
|
public Response updateStars(
|
||||||
|
@ApiParam int stars,
|
||||||
|
@PathParam("uuid") String uuid) {
|
||||||
|
|
||||||
|
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||||
|
int newStars = 0;
|
||||||
|
try {
|
||||||
|
newStars = commentsManager.updateStars(stars, uuid);
|
||||||
|
|
||||||
|
if (stars != 0) {
|
||||||
|
return Response.status(Response.Status.CREATED).entity(newStars).build();
|
||||||
|
} else {
|
||||||
|
String msg = "Given star value is not valid ";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
log.error("Application Management Exception occurs", e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity(" Internal server error occurs").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds required parameters for a querying a paginated device response.
|
||||||
|
*/
|
||||||
|
public class PaginationRequest {
|
||||||
|
|
||||||
|
private int offSet;
|
||||||
|
private int limit;
|
||||||
|
|
||||||
|
public PaginationRequest(int start, int limit) {
|
||||||
|
this.offSet = start;
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOffSet() {
|
||||||
|
return offSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffSet(int offSet) {
|
||||||
|
this.offSet = offSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLimit(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validatePaginationRequest(int offSet, int limit) {
|
||||||
|
if (offSet < 0) {
|
||||||
|
throw new IllegalArgumentException("off set value can't be negative");
|
||||||
|
} else if (limit < 0) {
|
||||||
|
throw new IllegalArgumentException("limit value can't be negative");
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return "Off Set'" + this.offSet + "' row count '" + this.limit;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.common;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds necessary data to represent a paginated result.
|
||||||
|
*/
|
||||||
|
@ApiModel(value = "PaginationResult", description = "This class carries all information related Pagination Result")
|
||||||
|
public class PaginationResult implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1998101711L;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "recordsTotal", value = "The total number of records that are given before filtering", required = true)
|
||||||
|
private int recordsTotal;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "recordsFiltered", value = "The total number of records that are given after filtering", required = true)
|
||||||
|
private int recordsFiltered;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "draw", value = "The draw counter that this object is a response to, from the draw parameter sent as part of the data request", required = true)
|
||||||
|
private int draw;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "data", value = "This holds the database records that matches given criteria", required = true)
|
||||||
|
private List<?> data;
|
||||||
|
|
||||||
|
public int getRecordsTotal() {
|
||||||
|
return recordsTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRecordsFiltered() {
|
||||||
|
return recordsFiltered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecordsFiltered(int recordsFiltered) {
|
||||||
|
this.recordsFiltered = recordsFiltered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecordsTotal(int recordsTotal) {
|
||||||
|
this.recordsTotal = recordsTotal;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<?> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(List<?> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDraw() {
|
||||||
|
return draw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDraw(int draw) {
|
||||||
|
this.draw = draw;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||||
|
|
||||||
|
public class CommentManagementException extends Exception {
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public CommentManagementException(String message, Throwable throwable) {
|
||||||
|
super(message, throwable);
|
||||||
|
setMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommentManagementException(String message) {
|
||||||
|
super(message);
|
||||||
|
setMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommentManagementException() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.core.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the information related to Pagination configuration.
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "PaginationConfiguration") public class PaginationConfiguration {
|
||||||
|
|
||||||
|
private int commentListPageSize;
|
||||||
|
|
||||||
|
public int getCommentListPageSize() {
|
||||||
|
return commentListPageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "commentListPageSize", required = true) public void setCommentListPageSize(
|
||||||
|
int commentListPageSize) {
|
||||||
|
this.commentListPageSize = commentListPageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,255 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.application.mgt.core.dao.common;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.*;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.Comment.CommentDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
||||||
|
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil.resolveDataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class intends to act as the primary entity that hides all DAO instantiation related complexities and logic so
|
||||||
|
* that the business objection handling layer doesn't need to be aware of the same providing seamless plug-ability of
|
||||||
|
* different data sources, connection acquisition mechanisms as well as different forms of DAO implementations to the
|
||||||
|
* high-level implementations that require Application management related metadata persistence.
|
||||||
|
*/
|
||||||
|
public class ApplicationManagementDAOFactory {
|
||||||
|
|
||||||
|
private static String databaseEngine;
|
||||||
|
private static DataSource dataSource;
|
||||||
|
private static final Log log = LogFactory.getLog(ApplicationManagementDAOFactory.class);
|
||||||
|
|
||||||
|
public static void init(String datasourceName) {
|
||||||
|
ConnectionManagerUtil.resolveDataSource(datasourceName);
|
||||||
|
databaseEngine = ConnectionManagerUtil.getDatabaseType();
|
||||||
|
}
|
||||||
|
public static void init(DataSource dtSource){
|
||||||
|
dataSource=dtSource;
|
||||||
|
try {
|
||||||
|
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while retrieving config.datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void init(DataSourceConfig config) {
|
||||||
|
dataSource = resolveDataSource(config);
|
||||||
|
try {
|
||||||
|
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while retrieving config.datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ApplicationDAO getApplicationDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new GenericApplicationDAOImpl();
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
|
||||||
|
return new OracleApplicationDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LifecycleStateDAO getLifecycleStateDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
|
||||||
|
return new GenericLifecycleStateImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the instance of ApplicationReleaseDAOImplementation of the particular database engine.
|
||||||
|
*
|
||||||
|
* @return specific ApplicationReleaseDAOImplementation
|
||||||
|
*/
|
||||||
|
public static ApplicationReleaseDAO getApplicationReleaseDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
|
||||||
|
return new GenericApplicationReleaseDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the instance of VisibilityDAOImplementation of the particular database engine.
|
||||||
|
*
|
||||||
|
* @return specific VisibilityDAOImplementation
|
||||||
|
*/
|
||||||
|
public static VisibilityDAO getVisibilityDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
return new GenericVisibilityDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the instance of SubscriptionDAOImplementation of the particular database engine.
|
||||||
|
*
|
||||||
|
* @return GenericSubscriptionDAOImpl
|
||||||
|
*/
|
||||||
|
public static SubscriptionDAO getSubscriptionDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new GenericSubscriptionDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the instance of DeviceTypeDAOImpl of the particular database engine.
|
||||||
|
*
|
||||||
|
* @return DeviceTypeDAOImpl
|
||||||
|
*/
|
||||||
|
public static DeviceTypeDAO getDeviceTypeDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new DeviceTypeDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the instance of LifecycleDAOImplementation of the particular database engine.
|
||||||
|
*
|
||||||
|
* @return GenericLifecycleDAOImpl
|
||||||
|
*/
|
||||||
|
public static LifecycleStateDAO getLifecycleDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new GenericLifecycleStateImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method initializes the databases by creating the database.
|
||||||
|
*
|
||||||
|
* @throws ApplicationManagementDAOException Exceptions thrown during the creation of the tables
|
||||||
|
*/
|
||||||
|
public static void initDatabases() throws ApplicationManagementDAOException {
|
||||||
|
String dataSourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName();
|
||||||
|
String validationQuery = "SELECT * from APPM_PLATFORM";
|
||||||
|
try {
|
||||||
|
if (System.getProperty("setup") == null) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Application Management Database schema initialization check was skipped since "
|
||||||
|
+ "\'setup\' variable was not given during startup");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DatabaseCreator databaseCreator = new ApplicationMgtDatabaseCreator(dataSourceName);
|
||||||
|
if (!databaseCreator.isDatabaseStructureCreated(validationQuery)) {
|
||||||
|
databaseCreator.createRegistryDatabase();
|
||||||
|
log.info("Application Management tables are created in the database");
|
||||||
|
} else {
|
||||||
|
log.info("Application Management Database structure already exists. Not creating the database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ApplicationManagementDAOException(
|
||||||
|
"Error while creating application-mgt database during the " + "startup ", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ApplicationManagementDAOException(
|
||||||
|
"Error while creating application-mgt database in the " + "startup ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommentDAO getCommentDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new CommentDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue