Fix MsSQL and Oracle syntax issues

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent 6ee1fa6eb1
commit 00526352da

@ -81,7 +81,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
+ "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
+ "INNER JOIN (SELECT ID FROM AP_APP OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID "
+ "INNER JOIN (SELECT ID FROM AP_APP ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID "
+ "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) {

@ -79,7 +79,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
+ "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
+ "INNER JOIN (SELECT ID FROM AP_APP OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID "
+ "INNER JOIN (SELECT ID FROM AP_APP ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID "
+ "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) {

@ -63,7 +63,7 @@ public class OracleReviewDAOImpl extends GenericReviewDAOImpl {
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
@ -114,7 +114,7 @@ public class OracleReviewDAOImpl extends GenericReviewDAOImpl {
") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
+ "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
@ -169,7 +169,7 @@ public class OracleReviewDAOImpl extends GenericReviewDAOImpl {
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
+ "AP_APP_REVIEW.USERNAME = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
+ "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {

@ -63,7 +63,7 @@ public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl {
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
@ -114,7 +114,7 @@ public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl {
") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
+ "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
@ -169,7 +169,7 @@ public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl {
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
+ "AP_APP_REVIEW.USERNAME = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
+ "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {

@ -971,8 +971,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
Connection conn = this.getDBConnection();
List<String> subscribedRoles = new ArrayList<>();
String sql = "SELECT "
+ "US.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION US "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {

@ -51,7 +51,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
+ "US.USER_NAME AS USER "
+ "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
@ -88,10 +88,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
Connection conn = this.getDBConnection();
List<String> subscribedRoles = new ArrayList<>();
String sql = "SELECT "
+ "US.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION US "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
@ -131,7 +131,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
+ "GS.GROUP_NAME AS GROUPS "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);

@ -51,7 +51,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
+ "US.USER_NAME AS USER "
+ "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
@ -88,10 +88,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
Connection conn = this.getDBConnection();
List<String> subscribedRoles = new ArrayList<>();
String sql = "SELECT "
+ "US.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION US "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
@ -131,7 +131,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
+ "GS.GROUP_NAME AS GROUPS "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);

@ -1276,7 +1276,7 @@ public interface ApplicationManagementPublisherAPI {
);
@PUT
@Path("/tags/{oldTagName}")
@Path("/tags/rename")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,

@ -230,12 +230,12 @@ public interface ApplicationManagementPublisherAdminAPI {
);
@PUT
@Path("/tags/{tagName}")
@Path("/categories/rename")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
httpMethod = "PUT",
value = "Update application category",
notes = "This will update application category.",
tags = "Application Management",

@ -48,7 +48,6 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import java.beans.Customizer;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@ -748,7 +747,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@DELETE
@Override
@Consumes("application/json")
@Consumes(MediaType.WILDCARD)
@Path("/{appId}/tags/{tagName}")
public Response deleteApplicationTag(
@PathParam("appId") int appId,
@ -775,7 +774,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@DELETE
@Override
@Consumes("application/json")
@Consumes(MediaType.WILDCARD)
@Path("/tags/{tagName}")
public Response deleteUnusedTag(
@PathParam("tagName") String tagName) {

@ -36,6 +36,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@ -49,6 +50,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class);
@DELETE
@Consumes(MediaType.WILDCARD)
@Path("/release/{uuid}")
public Response deleteApplicationRelease(
@PathParam("uuid") String releaseUuid) {
@ -76,6 +78,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
}
@DELETE
@Consumes(MediaType.WILDCARD)
@Path("/{appId}")
public Response deleteApplication(
@PathParam("appId") int applicationId) {
@ -102,7 +105,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
@DELETE
@Override
@Consumes("application/json")
@Consumes(MediaType.WILDCARD)
@Path("/tags/{tagName}")
public Response deleteTag(
@PathParam("tagName") String tagName) {
@ -168,7 +171,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
@DELETE
@Override
@Consumes("application/json")
@Consumes(MediaType.WILDCARD)
@Path("/categories/{categoryName}")
public Response deleteCategory(
@PathParam("categoryName") String categoryName) {

@ -70,10 +70,9 @@ import java.util.List;
public class InvokerHandler extends HttpServlet {
private static final Log log = LogFactory.getLog(InvokerHandler.class);
private static final long serialVersionUID = -6508020875358160165L;
private AuthData authData;
private String apiEndpoint;
private String serverUrl;
private String platform;
private static AuthData authData;
private static String serverUrl;
private static String platform;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
@ -229,7 +228,7 @@ public class InvokerHandler extends HttpServlet {
*/
private String generateBackendRequestURL(HttpServletRequest req) {
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.append(serverUrl).append(HandlerConstants.API_COMMON_CONTEXT).append(apiEndpoint);
urlBuilder.append(serverUrl).append(HandlerConstants.API_COMMON_CONTEXT).append(req.getPathInfo());
if (StringUtils.isNotEmpty(req.getQueryString())) {
urlBuilder.append("?").append(req.getQueryString());
}
@ -269,10 +268,9 @@ public class InvokerHandler extends HttpServlet {
* @return If request is a valid one, returns TRUE, otherwise return FALSE
* @throws IOException If and error occurs while witting error response to client side
*/
private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
serverUrl = req.getScheme() + "://" + req.getServerName() + ":" + System.getProperty("iot.gateway.https.port");
apiEndpoint = req.getPathInfo();
HttpSession session = req.getSession(false);
if (session == null) {
@ -289,8 +287,8 @@ public class InvokerHandler extends HttpServlet {
return false;
}
if (apiEndpoint == null || req.getMethod() == null) {
log.error("Bad Request, Either destination api-endpoint or method is empty");
if (req.getMethod() == null) {
log.error("Bad Request, Request method is empty");
handleError(req, resp, HttpStatus.SC_BAD_REQUEST);
return false;
}
@ -322,13 +320,14 @@ public class InvokerHandler extends HttpServlet {
}
/***
* This method is responsible to get the refresh token
*
* @param req {@link HttpServletRequest}
* @param resp {@link HttpServletResponse}
* @return If successfully renew tokens, returns TRUE otherwise return FALSE
* @throws IOException If an error occurs while witting error response to client side or invoke token renewal API
*/
private boolean refreshToken(HttpServletRequest req, HttpServletResponse resp)
private static boolean refreshToken(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if (log.isDebugEnabled()) {
log.debug("refreshing the token");
@ -391,7 +390,7 @@ public class InvokerHandler extends HttpServlet {
* @param errorCode HTTP error status code
* @throws IOException If error occurred when trying to send the error response.
*/
private void handleError(HttpServletRequest req, HttpServletResponse resp, int errorCode)
private static void handleError(HttpServletRequest req, HttpServletResponse resp, int errorCode)
throws IOException {
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setCode(errorCode);

@ -115,6 +115,7 @@ public class UserHandler extends HttpServlet {
/**
* Send UnAuthorized Response to the user
*
* @param req HttpServletRequest object
* @param resp HttpServletResponse object
* @param serverUrl Url of the server
@ -124,6 +125,8 @@ public class UserHandler extends HttpServlet {
throws IOException {
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
proxyResponse.setExecutorResponse(
HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_UNAUTHORIZED));
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
}
}

Loading…
Cancel
Save