Merge branch 'application-mgt-new' into 'application-mgt-new'

app get by ID

See merge request entgra/carbon-device-mgt!11
feature/appm-store/pbac
Dharmakeerthi Lasantha 6 years ago
commit f6532e2e5f

@ -87,14 +87,13 @@ public interface ApplicationManager {
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 appName name of the Application
* @param id id of the Application
* @return the Application identified by the UUID
* @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.

@ -84,6 +84,17 @@ public interface ApplicationDAO {
*/
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
*

@ -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
public Application getApplicationById(int applicationId, int tenantId) throws
ApplicationManagementDAOException {
@ -420,7 +462,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
int paramIndex = 1;
Connection conn;
PreparedStatement stmt = null;
Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId);
Application existingApplication = this.getApplicationById(application.getId(), tenantId);
if (existingApplication == null) {
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)
throws UserStoreException {
String[] roleList;
@ -301,7 +341,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
return roleList;
}
@Override
public Application getApplication(String appType, String appName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -311,7 +350,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.openDBConnection();
application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplication(appType, appName, tenantId);
.getApplication(appName, appType, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId());
application.setApplicationReleases(applicationReleases);

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

@ -85,23 +85,23 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
}
@GET
@Consumes("application/json")
@Path("/{appType}")
@Path("/{appId}")
public Response getApplication(
@PathParam("appType") String appType,
@QueryParam("appName") String appName) {
@PathParam("appId") int appId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
Application application = applicationManager.getApplication(appType, appName);
Application application = applicationManager.getApplicationById(appId);
if (application == null) {
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();
} 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);
}
}

Loading…
Cancel
Save