Fixed issues in Generic DAO Impl

feature/appm-store/pbac
lasantha 7 years ago
parent 8b4e3ec051
commit 2cbf78d464

@ -219,8 +219,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
+ " " + tenantId + ". While executing " + sql, e);
}
catch (DBConnectionException e) {
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while "
+ "getting application list for the tenant " + tenantId, e);
} catch (JSONException e) {
@ -325,9 +324,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try {
conn = this.getDBConnection();
String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY "
+ "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID FROM "
+ "AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? "
+ "AND AP_APP.TENANT_ID=?;";
+ "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS " +
"APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES " +
"WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql);
stmt.setString(1, appName);
@ -365,9 +364,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY \n"
+ "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID FROM \n"
+ "AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND AP_APP.TENANT_ID=?;";
String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " +
"AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " +
"AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=?" +
" AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, applicationId);
@ -425,8 +425,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app ID " + appId + " While executing query ", e);
}
catch (DBConnectionException e) {
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);

@ -1,208 +0,0 @@
/*
* 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.publisher.api.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.LifecycleManagementAPI;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import java.util.Arrays;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
/**
* Lifecycle Management related jax-rs APIs.
*/
@Path("/lifecycle")
public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
private static Log log = LogFactory.getLog(LifecycleManagementAPIImpl.class);
@GET
@Path("/{appId}/{uuid}")
public Response getLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid) {
LifecycleState lifecycleState;
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid);
} catch (LifecycleManagementException e) {
String msg = "Error occurred while getting lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity(lifecycleState).build();
}
@POST
@Path("/{appId}/{uuid}")
public Response addLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid,
LifecycleState state) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.addLifecycleState(applicationId, applicationUuid, state);
} catch (LifecycleManagementException e) {
String msg = "Error occurred while adding lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build();
}
//todo remove below part
@DELETE
@Path("/{identifier}")
public Response deleteLifecycleState(@PathParam("identifier") String identifier) {
return null;
// LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
// try {
// lifecycleStateManager.deleteLifecycleState(identifier);
// } catch (LifecycleManagementException e) {
// String msg = "Error occurred while deleting lifecycle state.";
// log.error(msg, e);
// return Response.status(Response.Status.BAD_REQUEST).build();
// }
// return Response.status(Response.Status.OK).entity("Lifecycle state deleted successfully.").build();
}
// @PUT
// @Consumes("application/json")
// @Path("/{uuid}/lifecycle")
// public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) {
// ApplicationManager applicationManager = APIUtil.getApplicationManager();
//
// if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
// log.warn("Provided lifecycle state " + state + " is not valid. Please select one from"
// + Arrays.toString(Constants.LIFE_CYCLES));
// return Response.status(Response.Status.BAD_REQUEST)
// .entity("Provided lifecycle state " + state + " is not valid. Please select one from "
// + Arrays.toString(Constants.LIFE_CYCLES)).build();
// }
// try {
// applicationManager.changeLifecycle(applicationUUID, state);
// return Response.status(Response.Status.OK)
// .entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build();
// } catch (org.wso2.carbon.device.application.mgt.core.exception.NotFoundException e) {
// return Response.status(Response.Status.NOT_FOUND).build();
// } catch (ApplicationManagementException e) {
// String msg = "Error occurred while changing the lifecycle of application: " + applicationUUID;
// log.error(msg, e);
// return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
// }
// }
//
// @GET
// @Path("/{uuid}/lifecycle")
// @Override
// public Response getNextLifeCycleStates(@PathParam("uuid") String applicationUUID) {
// ApplicationManager applicationManager = APIUtil.getApplicationManager();
// try {
// if (applicationManager.getApplication(applicationUUID) == null) {
// if (log.isDebugEnabled()) {
// log.debug("Application with the UUID '" + applicationUUID + "' is not found.");
// }
// return Response.status(Response.Status.NOT_FOUND).entity("Application with the UUID '" +
// applicationUUID + "' is not found.").build();
// }
//
// if (log.isDebugEnabled()) {
// log.debug("Application with UUID '" + applicationUUID + "' is found. Request received for getting "
// + "next life-cycle states for the particular application.");
// }
// return Response.status(Response.Status.OK).entity(applicationManager.getLifeCycleStates(applicationUUID))
// .build();
// } catch (NotFoundException e) {
// return Response.status(Response.Status.NOT_FOUND).build();
// } catch (ApplicationManagementException e) {
// log.error("Application Management Exception while trying to get next states for the applications with "
// + "the application ID", e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
// }
// ToDo
@PUT
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
log.warn("Provided lifecycle state " + state + " is not valid. Please select one from"
+ Arrays.toString(Constants.LIFE_CYCLES));
return Response.status(Response.Status.BAD_REQUEST)
.entity("Provided lifecycle state " + state + " is not valid. Please select one from "
+ Arrays.toString(Constants.LIFE_CYCLES)).build();
}
try {
applicationManager.changeLifecycle(applicationUUID, state);
return Response.status(Response.Status.OK)
.entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while changing the lifecycle of application: " + applicationUUID;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
}
}
@GET
@Path("/{uuid}/lifecycle")
@Override
public Response getNextLifeCycleStates(@PathParam("uuid") String applicationUUID) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
// if (applicationManager.getApplication(applicationUUID) == null) {
// if (log.isDebugEnabled()) {
// log.debug("Application with the UUID '" + applicationUUID + "' is not found.");
// }
// return Response.status(Response.Status.NOT_FOUND).entity("Application with the UUID '" +
// applicationUUID + "' is not found.").build();
// }
if (log.isDebugEnabled()) {
log.debug("Application with UUID '" + applicationUUID + "' is found. Request received for getting "
+ "next life-cycle states for the particular application.");
}
return Response.status(Response.Status.OK).entity(applicationManager.getLifeCycleStates(applicationUUID))
.build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
log.error("Application Management Exception while trying to get next states for the applications with "
+ "the application ID", e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}
Loading…
Cancel
Save