app get by ID

feature/appm-store/pbac
Inosh Perara 6 years ago committed by Dharmakeerthi Lasantha
parent be6f72889b
commit df65b68597

@ -87,14 +87,13 @@ public interface ApplicationManager {
String getUuidOfLatestRelease(int appId) throws ApplicationManagementException; String getUuidOfLatestRelease(int appId) throws ApplicationManagementException;
/** /**
* To get Application with the given UUID. * To get Application with the given Id.
* *
* @param appType type of the Application * @param id id of the Application
* @param appName name of the Application
* @return the Application identified by the UUID * @return the Application identified by the UUID
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
Application getApplication(String appType, String appName) throws ApplicationManagementException; Application getApplicationById(int id) throws ApplicationManagementException;
/** /**
* To get an application associated with the release. * To get an application associated with the release.

@ -84,6 +84,17 @@ public interface ApplicationDAO {
*/ */
Application getApplication(String appName, String appType, int tenantId) throws ApplicationManagementDAOException; Application getApplication(String appName, String appType, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the application with the given id
*
* @param id ID of the application.
* @param tenantId ID of the tenant.
* @return the application
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Application getApplicationById(String id, int tenantId) throws
ApplicationManagementDAOException;
/** /**
* To get the application with the given uuid * To get the application with the given uuid
* *

@ -337,6 +337,48 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
} }
@Override
public Application getApplicationById(String id, int tenantId) throws
ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting application with the id:" + id);
}
Connection conn;
PreparedStatement stmt = null;
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 "
+ "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY,"
+ " AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE "
+ "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.NAME=? AND "
+ "AP_APP.APP_ID= ? AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql);
stmt.setString(1, id);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application with the id:" + id);
}
return Util.loadApplication(rs);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app id " + id +
" While executing query ", e);
} catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override @Override
public Application getApplicationById(int applicationId, int tenantId) throws public Application getApplicationById(int applicationId, int tenantId) throws
ApplicationManagementDAOException { ApplicationManagementDAOException {
@ -420,7 +462,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
int paramIndex = 1; int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId); Application existingApplication = this.getApplicationById(application.getId(), tenantId);
if (existingApplication == null) { if (existingApplication == null) {
throw new ApplicationManagementException("There doesn't have an application for updating"); throw new ApplicationManagementException("There doesn't have an application for updating");

@ -276,6 +276,46 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override
public Application getApplicationById(int id) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Application application;
boolean isAppAllowed = false;
List<ApplicationRelease> applicationReleases;
try {
ConnectionManagerUtil.openDBConnection();
application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplicationById(id, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId());
application.setApplicationReleases(applicationReleases);
return application;
}
if (!application.getUnrestrictedRoles().isEmpty()) {
if (isRoleExists(application.getUnrestrictedRoles(), userName)) {
isAppAllowed = true;
}
} else {
isAppAllowed = true;
}
if (!isAppAllowed) {
return null;
}
applicationReleases = getReleases(application.getId());
application.setApplicationReleases(applicationReleases);
return application;
} catch (UserStoreException e) {
throw new ApplicationManagementException(
"User-store exception while getting application with the application id " + id);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
private boolean isRoleExists(Collection<UnrestrictedRole> unrestrictedRoleList, String userName) private boolean isRoleExists(Collection<UnrestrictedRole> unrestrictedRoleList, String userName)
throws UserStoreException { throws UserStoreException {
String[] roleList; String[] roleList;
@ -301,7 +341,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
return roleList; return roleList;
} }
@Override
public Application getApplication(String appType, String appName) throws ApplicationManagementException { public Application getApplication(String appType, String appName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -311,7 +350,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
application = ApplicationManagementDAOFactory.getApplicationDAO() application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplication(appType, appName, tenantId); .getApplication(appName, appType, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId()); applicationReleases = getReleases(application.getId());
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);

@ -174,15 +174,10 @@ public interface ApplicationManagementAPI {
}) })
Response getApplication( Response getApplication(
@ApiParam( @ApiParam(
name = "appType", name = "appId",
value = "Type of the application", value = "application Id",
required = true) required = true)
@PathParam("appType") String appType, @PathParam("appId") int appId
@ApiParam(
name = "appName",
value = "Application name",
required = true)
@QueryParam("isWithImages") String appName
); );
@PUT @PUT

@ -85,23 +85,23 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
@GET @GET
@Consumes("application/json") @Consumes("application/json")
@Path("/{appType}") @Path("/{appId}")
public Response getApplication( public Response getApplication(
@PathParam("appType") String appType, @PathParam("appId") int appId) {
@QueryParam("appName") String appName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
Application application = applicationManager.getApplication(appType, appName); Application application = applicationManager.getApplicationById(appId);
if (application == null) { if (application == null) {
return Response.status(Response.Status.NOT_FOUND).entity return Response.status(Response.Status.NOT_FOUND).entity
("Application with application type: " + appType + " not found").build(); ("Application with application id: " + appId + " not found").build();
} }
return Response.status(Response.Status.OK).entity(application).build(); return Response.status(Response.Status.OK).entity(application).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Error occurred while getting application with the uuid " + appType, e); log.error("Error occurred while getting application with the id " + appId, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} }
} }

Loading…
Cancel
Save