mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding some more validations fot the application management.
This commit is contained in:
parent
9656b9b747
commit
692ed6aa59
@ -34,6 +34,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorag
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -81,10 +82,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
|
||||
ApplicationList applications = applicationManager.getApplications(filter);
|
||||
return Response.status(Response.Status.OK).entity(applications).build();
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while getting the application list";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,6 +103,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
.entity("Application with UUID " + uuid + " not found").build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(application).build();
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
log.error("Error occurred while getting application with the uuid " + uuid, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
@ -110,7 +115,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@Consumes("application/json")
|
||||
@Path("/{uuid}/lifecycle")
|
||||
public Response changeLifecycleState(@PathParam("uuid") String applicationUUID,
|
||||
@QueryParam("state") String state) {
|
||||
@QueryParam("state") String state) {
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
|
||||
if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
|
||||
@ -122,13 +127,15 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
}
|
||||
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);
|
||||
}
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -151,6 +158,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
}
|
||||
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);
|
||||
@ -176,8 +185,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@POST
|
||||
@Path("upload-image-artifacts/{uuid}")
|
||||
public Response uploadApplicationArtifacts(@PathParam("uuid") String applicationUUID,
|
||||
@Multipart("icon")Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart
|
||||
("screenshot") List<Attachment> attachmentList) {
|
||||
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart
|
||||
("screenshot") List<Attachment> attachmentList) {
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
try {
|
||||
InputStream iconFileStream;
|
||||
@ -208,6 +217,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
.uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Successfully uploaded artifacts for the application " + applicationUUID).build();
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating the application";
|
||||
log.error(msg, e);
|
||||
@ -215,8 +226,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
} catch (IOException e) {
|
||||
log.error("Exception while trying to read icon, banner files for the application " + applicationUUID);
|
||||
return APIUtil.getResponse(new ApplicationManagementException(
|
||||
"Exception while trying to read icon, " + "banner files for the application " +
|
||||
applicationUUID, e), Response.Status.BAD_REQUEST);
|
||||
"Exception while trying to read icon, " + "banner files for the application " +
|
||||
applicationUUID, e), Response.Status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,8 +235,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@PUT
|
||||
@Path("upload-image-artifacts/{uuid}")
|
||||
public Response updateApplicationArtifacts(@PathParam("uuid") String applicationUUID,
|
||||
@Multipart("icon")Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart
|
||||
("screenshot") List<Attachment> attachmentList) {
|
||||
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart
|
||||
("screenshot") List<Attachment> attachmentList) {
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
try {
|
||||
InputStream iconFileStream = null;
|
||||
@ -262,11 +273,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@PUT
|
||||
@Consumes("application/json")
|
||||
public Response editApplication(@Valid Application application) {
|
||||
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
try {
|
||||
application = applicationManager.editApplication(application);
|
||||
|
||||
} catch (NotFoundException e) {
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating the application";
|
||||
log.error(msg, e);
|
||||
@ -287,6 +298,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
applicationManager.deleteApplication(uuid);
|
||||
String responseMsg = "Successfully deleted the application: " + uuid;
|
||||
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
||||
} catch (NotFoundException e) {
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while deleting the application: " + uuid;
|
||||
log.error(msg, e);
|
||||
@ -298,8 +311,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@POST
|
||||
@Path("/release/{uuid}")
|
||||
public Response createApplicationRelease(@PathParam("uuid") String applicationUUID,
|
||||
@Multipart("applicationRelease") ApplicationRelease applicationRelease,
|
||||
@Multipart("binaryFile") Attachment binaryFile) {
|
||||
@Multipart("applicationRelease") ApplicationRelease applicationRelease,
|
||||
@Multipart("binaryFile") Attachment binaryFile) {
|
||||
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
try {
|
||||
@ -329,7 +342,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@Path("/release/{uuid}")
|
||||
public Response updateApplicationRelease(@PathParam("uuid") String applicationUUID, @Multipart
|
||||
("applicationRelease") ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment
|
||||
binaryFile) {
|
||||
binaryFile) {
|
||||
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
try {
|
||||
@ -347,14 +360,16 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
.uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream());
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(applicationRelease).build();
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
log.error("Error while updating the application release of the application with UUID " + applicationUUID);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (IOException e) {
|
||||
log.error("Error while updating the release artifacts of the application with UUID " + applicationUUID);
|
||||
return APIUtil.getResponse(new ApplicationManagementException(
|
||||
"Error while updating the release artifacts of the application with UUID "
|
||||
+ applicationUUID), Response.Status.INTERNAL_SERVER_ERROR);
|
||||
"Error while updating the release artifacts of the application with UUID "
|
||||
+ applicationUUID), Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,7 +378,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
@Path("/release-artifacts/{uuid}/{version}")
|
||||
public Response getApplicationReleaseArtifacts(@PathParam("uuid") String applicationUUID,
|
||||
@PathParam("version") String version) {
|
||||
@PathParam("version") String version) {
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
try {
|
||||
InputStream binaryFile = applicationStorageManager.getReleasedArtifacts(applicationUUID, version);
|
||||
@ -386,7 +401,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@Path("/release/{uuid}")
|
||||
@GET
|
||||
public Response getApplicationReleases(@PathParam("uuid") String applicationUUID,
|
||||
@QueryParam("version") String version) {
|
||||
@QueryParam("version") String version) {
|
||||
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
||||
try {
|
||||
if (version == null || version.isEmpty()) {
|
||||
@ -396,6 +411,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version);
|
||||
return Response.status(Response.Status.OK).entity(applicationRelease).build();
|
||||
}
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
log.error("Error while getting all the application releases for the application with the UUID "
|
||||
+ applicationUUID, e);
|
||||
@ -407,7 +424,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@DELETE
|
||||
@Path("/release/{uuid}")
|
||||
public Response deleteApplicationRelease(@PathParam("uuid") String applicationUUID,
|
||||
@QueryParam("version") String version) {
|
||||
@QueryParam("version") String version) {
|
||||
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
||||
try {
|
||||
@ -424,6 +441,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
.entity("Successfully deleted Application releases for the " + "application with UUID "
|
||||
+ applicationUUID).build();
|
||||
}
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
log.error("Error while deleting application release with the application UUID " + applicationUUID, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
@ -435,7 +454,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@Path("/image-artifacts/{uuid}")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response getApplicationImageArtifacts(@PathParam("uuid") String applicationUUID,
|
||||
@QueryParam("name") String name, @QueryParam("count") int count) {
|
||||
@QueryParam("name") String name, @QueryParam("count") int count) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("Name should not be null. Name is mandatory to"
|
||||
+ " retrieve the particular image artifact of the release").build();
|
||||
@ -466,6 +485,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Successfully changed the default version for the " + "release channel " + channel
|
||||
+ " for the application UUID " + applicationUUID).build();
|
||||
} catch (NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
log.error("Application Release Management Exception while changing the default release for the release "
|
||||
+ "channel " + channel + " for the application with UUID " + applicationUUID + " for the version "
|
||||
|
||||
@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Filter represents a criteria that can be used for searching applications.
|
||||
*/
|
||||
@ -36,12 +34,10 @@ public class Filter {
|
||||
|
||||
private int offset;
|
||||
|
||||
private String filter;
|
||||
|
||||
private List<FilterProperty> filterProperties;
|
||||
|
||||
private String searchQuery;
|
||||
|
||||
private boolean isFullMatch;
|
||||
|
||||
private SortingOrder sortingOrder;
|
||||
|
||||
private String sortBy;
|
||||
@ -64,22 +60,6 @@ public class Filter {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(String filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public List<FilterProperty> getFilterProperties() {
|
||||
return filterProperties;
|
||||
}
|
||||
|
||||
public void setFilterProperties(List<FilterProperty> filterProperties) {
|
||||
this.filterProperties = filterProperties;
|
||||
}
|
||||
|
||||
public String getSearchQuery() {
|
||||
return searchQuery;
|
||||
}
|
||||
@ -112,11 +92,16 @@ public class Filter {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public boolean isFullMatch() {
|
||||
return isFullMatch;
|
||||
}
|
||||
|
||||
public void setFullMatch(boolean fullMatch) {
|
||||
isFullMatch = fullMatch;
|
||||
}
|
||||
|
||||
public boolean hasCondition() {
|
||||
if (filterProperties != null || searchQuery != null || filter != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return searchQuery != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -34,7 +34,9 @@ public interface SubscriptionManager {
|
||||
* @return DeviceList which the application has been installed
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
List<DeviceIdentifier> installApplicationForDevices(String applicationUUID, List<DeviceIdentifier> deviceList) throws ApplicationManagementException;
|
||||
List<DeviceIdentifier> installApplicationForDevices(String applicationUUID,
|
||||
List<DeviceIdentifier> deviceList)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To install an application to given list of users.
|
||||
@ -43,7 +45,9 @@ public interface SubscriptionManager {
|
||||
* @return User list which the application has been installed
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
List<String> installApplicationForUsers(String applicationUUID, List<String> userList) throws ApplicationManagementException;
|
||||
List<String> installApplicationForUsers(String applicationUUID,
|
||||
List<String> userList)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To install an application to given list of users.
|
||||
@ -52,7 +56,9 @@ public interface SubscriptionManager {
|
||||
* @return Role list which the application has been installed
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
List<String> installApplicationForRoles(String applicationUUID, List<String> roleList) throws ApplicationManagementException;
|
||||
List<String> installApplicationForRoles(String applicationUUID,
|
||||
List<String> roleList)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* To uninstall an application from a given list of devices.
|
||||
@ -61,6 +67,8 @@ public interface SubscriptionManager {
|
||||
* @return DeviceList which the application has been uninstalled
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
List<DeviceIdentifier> uninstallApplication(String applicationUUID, List<DeviceIdentifier> deviceList) throws ApplicationManagementException;
|
||||
List<DeviceIdentifier> uninstallApplication(String applicationUUID,
|
||||
List<DeviceIdentifier> deviceList)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -21,8 +21,6 @@ package org.wso2.carbon.device.application.mgt.common.services;
|
||||
import org.wso2.carbon.device.application.mgt.common.Visibility;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* This interface manages all the operations related with Application Visibility.
|
||||
* This will be invoking the necessary backend calls for the data bases layer
|
||||
|
||||
@ -62,7 +62,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "";
|
||||
String generatedColumns[] = { "ID" };
|
||||
String generatedColumns[] = {"ID"};
|
||||
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
|
||||
int index = 0;
|
||||
try {
|
||||
@ -121,7 +121,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
ApplicationList applicationList = new ApplicationList();
|
||||
List<Application> applications = new ArrayList<>();
|
||||
Pagination pagination = new Pagination();
|
||||
int index = 0;
|
||||
|
||||
if (filter == null) {
|
||||
throw new ApplicationManagementDAOException("Filter need to be instantiated");
|
||||
@ -185,13 +184,13 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
* @throws SQLException SQL Exception
|
||||
*/
|
||||
protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn,
|
||||
int tenantId) throws SQLException {
|
||||
int tenantId) throws SQLException {
|
||||
int index = 0;
|
||||
String sql = "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER, CAT.ID AS CAT_ID, "
|
||||
+ "CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, "
|
||||
+ "LS.DESCRIPTION AS LS_DESCRIPTION " + "FROM APPM_APPLICATION APP " + "INNER JOIN APPM_PLATFORM APL "
|
||||
+ "ON APP.PLATFORM_ID = APL.ID " + "INNER JOIN APPM_APPLICATION_CATEGORY CAT "
|
||||
+ "ON APP.APPLICATION_CATEGORY_ID = CAT.ID " + "INNER JOIN APPM_LIFECYCLE_STATE LS "
|
||||
+ "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION APP INNER JOIN APPM_PLATFORM APL "
|
||||
+ "ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY CAT "
|
||||
+ "ON APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE LS "
|
||||
+ "ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? ";
|
||||
|
||||
String userName = filter.getUserName();
|
||||
@ -199,7 +198,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
sql += " AND APP.CREATED_BY = ? ";
|
||||
}
|
||||
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
|
||||
sql += "AND APP.NAME LIKE ? ";
|
||||
sql += "AND LOWER (APP.NAME) ";
|
||||
if (filter.isFullMatch()) {
|
||||
sql += "= ?";
|
||||
} else {
|
||||
sql += "LIKE ?";
|
||||
}
|
||||
}
|
||||
|
||||
sql += "LIMIT ? OFFSET ?";
|
||||
@ -211,7 +215,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
stmt.setString(++index, userName);
|
||||
}
|
||||
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
|
||||
stmt.setString(++index, "%" + filter.getSearchQuery() + "%");
|
||||
if (filter.isFullMatch()) {
|
||||
stmt.setString(++index, filter.getSearchQuery().toLowerCase());
|
||||
} else {
|
||||
stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%");
|
||||
}
|
||||
}
|
||||
|
||||
stmt.setInt(++index, filter.getLimit());
|
||||
@ -245,14 +253,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
sql += "INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON APP.APPLICATION_CATEGORY_ID = CAT.ID ";
|
||||
|
||||
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
|
||||
sql += "WHERE APP.NAME LIKE ? ";
|
||||
sql += "WHERE LOWER (APP.NAME) LIKE ? ";
|
||||
}
|
||||
sql += ";";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
int index = 0;
|
||||
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
|
||||
stmt.setString(++index, "%" + filter.getSearchQuery() + "%");
|
||||
stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%");
|
||||
}
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
@ -287,11 +295,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
+ "LS.DESCRIPTION AS LS_DESCRIPTION "
|
||||
+ "FROM APPM_APPLICATION APP "
|
||||
+ "INNER JOIN APPM_PLATFORM APL "
|
||||
+ "ON APP.PLATFORM_ID = APL.ID "
|
||||
+ "ON APP.PLATFORM_ID = APL.ID "
|
||||
+ "INNER JOIN APPM_APPLICATION_CATEGORY CAT "
|
||||
+ "ON APP.APPLICATION_CATEGORY_ID = CAT.ID "
|
||||
+ "ON APP.APPLICATION_CATEGORY_ID = CAT.ID "
|
||||
+ "INNER JOIN APPM_LIFECYCLE_STATE LS "
|
||||
+ " ON APP.LIFECYCLE_STATE_ID = LS.ID "
|
||||
+ " ON APP.LIFECYCLE_STATE_ID = LS.ID "
|
||||
+ "WHERE UUID = ? AND APP.TENANT_ID = ? ";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
@ -521,7 +529,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
*
|
||||
* @param application Application in which the properties and tags need to be inserted
|
||||
*/
|
||||
private void insertApplicationTagsAndProperties (Application application, PreparedStatement stmt, Connection
|
||||
private void insertApplicationTagsAndProperties(Application application, PreparedStatement stmt, Connection
|
||||
conn, boolean isBatchExecutionSupported) throws SQLException {
|
||||
String sql;
|
||||
if (application.getTags() != null && application.getTags().size() > 0) {
|
||||
@ -632,7 +640,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql;
|
||||
int id = 0;
|
||||
int id = -1;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT ID FROM APPM_APPLICATION WHERE UUID = ? AND TENANT_ID = ?";
|
||||
|
||||
@ -33,7 +33,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
|
||||
|
||||
@Override
|
||||
protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn,
|
||||
int tenantId) throws SQLException {
|
||||
int tenantId) throws SQLException {
|
||||
int index = 0;
|
||||
String sql = "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER, CAT.ID AS CAT_ID, "
|
||||
+ "CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, "
|
||||
@ -47,11 +47,14 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
|
||||
sql += " AND APP.CREATED_BY = ? ";
|
||||
}
|
||||
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
|
||||
sql += "AND APP.NAME LIKE ? ";
|
||||
sql += "AND LOWER (APP.NAME) ";
|
||||
if (filter.isFullMatch()) {
|
||||
sql += "= ?";
|
||||
} else {
|
||||
sql += "LIKE ?";
|
||||
}
|
||||
}
|
||||
|
||||
sql += " ORDER BY APP.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(++index, tenantId);
|
||||
|
||||
@ -59,7 +62,11 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
|
||||
stmt.setString(++index, userName);
|
||||
}
|
||||
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
|
||||
stmt.setString(++index, "%" + filter.getSearchQuery() + "%");
|
||||
if (filter.isFullMatch()) {
|
||||
stmt.setString(++index, filter.getSearchQuery().toLowerCase());
|
||||
} else {
|
||||
stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%");
|
||||
}
|
||||
}
|
||||
stmt.setInt(++index, filter.getOffset());
|
||||
stmt.setInt(++index, filter.getLimit());
|
||||
|
||||
@ -121,33 +121,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
throw new ApplicationManagementException("User " + userName + " does not have permissions to edit the "
|
||||
+ "application with the UUID " + application.getUuid());
|
||||
}
|
||||
try {
|
||||
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
|
||||
Platform platform = DataHolder.getInstance().getPlatformManager()
|
||||
.getPlatform(tenantId, application.getPlatform().getIdentifier());
|
||||
if (platform == null) {
|
||||
throw new NotFoundException(
|
||||
"Platform specified by identifier " + application.getPlatform().getIdentifier()
|
||||
+ " is not found. Please give a valid platform identifier.");
|
||||
if (this.getApplication(application.getUuid()) != null) {
|
||||
try {
|
||||
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
|
||||
Platform platform = DataHolder.getInstance().getPlatformManager()
|
||||
.getPlatform(tenantId, application.getPlatform().getIdentifier());
|
||||
if (platform == null) {
|
||||
throw new NotFoundException(
|
||||
"Platform specified by identifier " + application.getPlatform().getIdentifier()
|
||||
+ " is not found. Please give a valid platform identifier.");
|
||||
}
|
||||
application.setPlatform(platform);
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
||||
application.setModifiedAt(new Date());
|
||||
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
|
||||
Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(),
|
||||
application.getVisibility());
|
||||
modifiedApplication.setVisibility(visibility);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return modifiedApplication;
|
||||
} else {
|
||||
throw new NotFoundException("Platform information not available with the application!");
|
||||
}
|
||||
application.setPlatform(platform);
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
||||
application.setModifiedAt(new Date());
|
||||
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
|
||||
Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(),
|
||||
application.getVisibility());
|
||||
modifiedApplication.setVisibility(visibility);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return modifiedApplication;
|
||||
} else {
|
||||
throw new NotFoundException("Platform information not available with the application!");
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
} else {
|
||||
throw new NotFoundException("No applications found with application UUID - " + application.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,10 +167,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
int appId = applicationDAO.getApplicationId(uuid, tenantId);
|
||||
applicationDAO.deleteTags(appId);
|
||||
applicationDAO.deleteProperties(appId);
|
||||
DataHolder.getInstance().getVisibilityManager().remove(appId);
|
||||
applicationDAO.deleteApplication(uuid, tenantId);
|
||||
if (appId != -1) {
|
||||
applicationDAO.deleteTags(appId);
|
||||
applicationDAO.deleteProperties(appId);
|
||||
DataHolder.getInstance().getVisibilityManager().remove(appId);
|
||||
applicationDAO.deleteApplication(uuid, tenantId);
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
@ -389,5 +395,26 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {
|
||||
throw new ValidationException("Platform identifier cannot be empty");
|
||||
}
|
||||
try {
|
||||
validateApplicationExistence(application);
|
||||
} catch (ApplicationManagementException e) {
|
||||
throw new ValidationException("Error occured while validating whether there is already an application " +
|
||||
"registered with same name.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateApplicationExistence(Application application) throws ApplicationManagementException {
|
||||
Filter filter = new Filter();
|
||||
filter.setFullMatch(true);
|
||||
filter.setSearchQuery(application.getName().trim());
|
||||
filter.setOffset(0);
|
||||
filter.setLimit(1);
|
||||
|
||||
ApplicationList applicationList = getApplications(filter);
|
||||
if (applicationList != null && applicationList.getApplications() != null &&
|
||||
!applicationList.getApplications().isEmpty()) {
|
||||
throw new ValidationException("Already an application registered with same name - "
|
||||
+ applicationList.getApplications().get(0).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||
|
||||
@ -195,7 +196,7 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
||||
}
|
||||
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUuid);
|
||||
if (application == null) {
|
||||
throw new ApplicationManagementException(
|
||||
throw new NotFoundException(
|
||||
"Application with UUID " + applicationUuid + " does not exist.");
|
||||
}
|
||||
return application;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user