Fixed application getting issues and improved the application getting functionality

Improved application functionalities. Modified service layer, DAO layer and API layer
feature/appm-store/pbac
lasantha 7 years ago
parent ef0e7ee738
commit 6e3cc085ff

@ -132,13 +132,17 @@ public class ApplicationRelease {
this.appHashValue = appHashValue; this.appHashValue = appHashValue;
} }
public void setIsSharedWithAllTenants(int isSharedWithAllTenants) { this.isSharedWithAllTenants = isSharedWithAllTenants; } public void setIsSharedWithAllTenants(int isSharedWithAllTenants) {
this.isSharedWithAllTenants = isSharedWithAllTenants;
}
public void setMetaData(String metaData) { public void setMetaData(String metaData) {
this.metaData = metaData; this.metaData = metaData;
} }
public int getId() { return id; } public int getId() {
return id;
}
public String getVersion() { public String getVersion() {
return version; return version;

@ -23,26 +23,17 @@ package org.wso2.carbon.device.application.mgt.common;
*/ */
public class Filter { public class Filter {
/** private String appName;
* Order which the search results should be shown. Ascending or Descending.
*/
public enum SortingOrder {
ASC, DESC
}
private int limit;
private int offset; private String appType;
private String searchQuery;
private boolean isFullMatch; private boolean isFullMatch;
private SortingOrder sortingOrder; private int limit;
private String sortBy; private int offset;
private String userName; private String sortBy;
public int getLimit() { public int getLimit() {
return limit; return limit;
@ -60,20 +51,12 @@ public class Filter {
this.offset = offset; this.offset = offset;
} }
public String getSearchQuery() { public String getAppName() {
return searchQuery; return appName;
}
public void setSearchQuery(String searchQuery) {
this.searchQuery = searchQuery;
}
public SortingOrder getSortingOrder() {
return sortingOrder;
} }
public void setSortingOrder(SortingOrder sortingOrder) { public void setAppName(String appName) {
this.sortingOrder = sortingOrder; this.appName = appName;
} }
public String getSortBy() { public String getSortBy() {
@ -84,14 +67,6 @@ public class Filter {
this.sortBy = sortBy; this.sortBy = sortBy;
} }
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean isFullMatch() { public boolean isFullMatch() {
return isFullMatch; return isFullMatch;
} }
@ -100,8 +75,11 @@ public class Filter {
isFullMatch = fullMatch; isFullMatch = fullMatch;
} }
public boolean hasCondition() { public String getAppType() {
return searchQuery != null; return appType;
} }
public void setAppType(String appType) {
this.appType = appType;
}
} }

@ -181,7 +181,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Filter need to be instantiated"); throw new ApplicationManagementDAOException("Filter need to be instantiated");
} }
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { if (filter.getAppType() != null) {
sql += " AND AP_APP.TYPE ";
sql += "= ?";
}
if (filter.getAppName() != null) {
sql += " AND LOWER (AP_APP.NAME) "; sql += " AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
sql += "= ?"; sql += "= ?";
@ -200,11 +204,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(++index, tenantId); stmt.setInt(++index, tenantId);
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { if (filter.getAppType() != null) {
stmt.setString(++index, filter.getAppType());
}
if (filter.getAppName() != null) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(++index, filter.getSearchQuery().toLowerCase()); stmt.setString(++index, filter.getAppName().toLowerCase());
} else { } else {
stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%"); stmt.setString(++index, "%" + filter.getAppName().toLowerCase() + "%");
} }
} }
@ -212,9 +219,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setInt(++index, filter.getOffset()); stmt.setInt(++index, filter.getOffset());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
applicationList.setApplications(Util.loadApplications(rs)); applicationList.setApplications(Util.loadApplications(rs));
pagination.setSize(filter.getOffset());
pagination.setCount(this.getApplicationCount(filter));
applicationList.setPagination(pagination); applicationList.setPagination(pagination);
applicationList.getPagination().setSize(filter.getOffset());
applicationList.getPagination().setCount(applicationList.getApplications().size());
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
@ -287,15 +294,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT count(APP.ID) AS APP_COUNT FROM AP_APP AS APP WHERE TENANT_ID = ?"; sql += "SELECT count(APP.ID) AS APP_COUNT FROM AP_APP AS APP WHERE TENANT_ID = ?";
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { if (filter.getAppName() != null) {
sql += " AND LOWER (APP.NAME) LIKE ? "; sql += " AND LOWER (APP.NAME) LIKE ? ";
} }
sql += ";"; sql += ";";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
int index = 0; int index = 0;
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { if (filter.getAppName() != null) {
stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%"); stmt.setString(++index, "%" + filter.getAppName().toLowerCase() + "%");
} }
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {

@ -27,9 +27,11 @@ import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.SortingOrder;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole; import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.User; import org.wso2.carbon.device.application.mgt.common.User;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
@ -53,10 +55,11 @@ import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.sql.Timestamp;
import java.util.Date;
/** /**
* Default Concrete implementation of Application Management related implementations. * Default Concrete implementation of Application Management related implementations.
@ -64,6 +67,8 @@ import java.util.List;
public class ApplicationManagerImpl implements ApplicationManager { public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private static final int DEFAULT_LIMIT = 20;
private static final int DEFAULT_OFFSET = 10;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private VisibilityDAO visibilityDAO; private VisibilityDAO visibilityDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
@ -90,7 +95,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
validateAppCreatingRequest(application); validateAppCreatingRequest(application);
validateReleaseCreateRequest(application.getApplicationReleases()); validateReleaseCreatingRequest(application.getApplicationReleases());
DeviceType deviceType; DeviceType deviceType;
ApplicationRelease applicationRelease; ApplicationRelease applicationRelease;
try { try {
@ -149,8 +154,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationList applicationList; ApplicationList applicationList;
List<ApplicationRelease> applicationReleases; List<ApplicationRelease> applicationReleases;
filter = validateFilter(filter);
if (filter == null) {
throw new ApplicationManagementException("Filter validation failed, Please verify the request payload");
}
try { try {
filter.setUserName(userName);
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
applicationList = applicationDAO.getApplications(filter, tenantId); applicationList = applicationDAO.getApplications(filter, tenantId);
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
@ -427,17 +436,26 @@ public class ApplicationManagerImpl implements ApplicationManager {
*/ */
private void validateAppCreatingRequest(Application application) throws ValidationException { private void validateAppCreatingRequest(Application application) throws ValidationException {
Boolean isValidApplicationType;
try {
if (application.getName() == null) { if (application.getName() == null) {
throw new ValidationException("Application name cannot be empty"); throw new ValidationException("Application name cannot be empty");
} }
if (application.getUser() == null || application.getUser().getUserName() == null if (application.getUser() == null || application.getUser().getUserName() == null
|| application.getUser().getTenantId() == 0) { || application.getUser().getTenantId() == -1) {
throw new ValidationException("Username and tenant Id cannot be empty"); throw new ValidationException("Username and tenant Id cannot be empty");
} }
if (application.getAppCategory() == null) { if (application.getAppCategory() == null) {
throw new ValidationException("Username and tenant Id cannot be empty"); throw new ValidationException("Username and tenant Id cannot be empty");
} }
try {
isValidApplicationType = isValidAppType(application);
if (!isValidApplicationType) {
throw new ValidationException("App Type contains in the application creating payload doesn't match with " +
"supported app types");
}
validateApplicationExistence(application); validateApplicationExistence(application);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
throw new ValidationException("Error occured while validating whether there is already an application " throw new ValidationException("Error occured while validating whether there is already an application "
@ -445,6 +463,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private Boolean isValidAppType(Application application) {
for (ApplicationType applicationType : ApplicationType.values()) {
if (applicationType.toString().equals(application.getType())) {
return true;
}
}
return false;
}
/** /**
* To validate the application existence * To validate the application existence
* *
@ -454,7 +481,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
private void validateApplicationExistence(Application application) throws ApplicationManagementException { private void validateApplicationExistence(Application application) throws ApplicationManagementException {
Filter filter = new Filter(); Filter filter = new Filter();
filter.setFullMatch(true); filter.setFullMatch(true);
filter.setSearchQuery(application.getName().trim()); filter.setAppName(application.getName().trim());
filter.setOffset(0); filter.setOffset(0);
filter.setLimit(1); filter.setLimit(1);
@ -544,7 +571,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param applicationReleases ApplicationRelease that need to be created. * @param applicationReleases ApplicationRelease that need to be created.
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
private void validateReleaseCreateRequest(List<ApplicationRelease> applicationReleases) private void validateReleaseCreatingRequest(List<ApplicationRelease> applicationReleases)
throws ApplicationManagementException { throws ApplicationManagementException {
if (applicationReleases.isEmpty() || applicationReleases.size() > 1) { if (applicationReleases.isEmpty() || applicationReleases.size() > 1) {
@ -747,4 +774,34 @@ public class ApplicationManagerImpl implements ApplicationManager {
//todo update application //todo update application
return application; return application;
} }
private Filter validateFilter(Filter filter) {
if (filter != null) {
if (filter.getLimit() == 0) {
filter.setLimit(DEFAULT_LIMIT);
}
if (filter.getOffset() == 0) {
filter.setOffset(DEFAULT_OFFSET);
}
if (!SortingOrder.ASC.toString().equals(filter.getSortBy()) &&
!SortingOrder.DESC.toString().equals(filter.getSortBy())) {
return null;
}
if (filter.getAppType() != null) {
Boolean isValidRequest = false;
for (ApplicationType applicationType: ApplicationType.values()){
if(applicationType.toString().equals(filter.getAppType())){
isValidRequest = true;
break;
}
}
if (!isValidRequest){
return null;
}
}
}
return filter;
}
} }

@ -32,11 +32,8 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
@ -146,17 +143,10 @@ public interface ApplicationManagementAPI {
}) })
Response getApplications( Response getApplications(
@ApiParam( @ApiParam(
name = "offset", name = "filter",
value = "Provide from which position apps should return", defaultValue = "20") value = "Filter to get application list",
@QueryParam("offset") int offset, required = true)
@ApiParam( @Valid Filter filter
name = "limit",
value = "Provide how many apps it should return", defaultValue = "0")
@QueryParam("limit") int limit,
@ApiParam(
name = "searchQuery",
value = "Relevant search query to search on", defaultValue = "*")
@QueryParam("searchQuery") String searchQuery
); );
@GET @GET
@ -395,8 +385,12 @@ public interface ApplicationManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateApplicationArtifact( Response updateApplicationArtifact(
@ApiParam(name = "id", value = "Id of the application", required = true) @PathParam("uuid") int applicationId, @ApiParam(name = "appType", value = "Type of the application i.e Android, iOS etc", required = true)
@ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID, @PathParam("appType") String appType,
@ApiParam(name = "id", value = "Id of the application", required = true)
@PathParam("uuid") int applicationId,
@ApiParam(name = "uuid", value = "UUID of the application", required = true)
@PathParam("uuid") String applicationUUID,
@Multipart("binaryFile") Attachment binaryFile); @Multipart("binaryFile") Attachment binaryFile);
@PUT @PUT

@ -56,7 +56,6 @@ import javax.ws.rs.core.Response;
@Path("/publisher/applications") @Path("/publisher/applications")
public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static final int DEFAULT_LIMIT = 20;
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
@ -64,28 +63,22 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Override @Override
@Consumes("application/json") @Consumes("application/json")
public Response getApplications( public Response getApplications(
@QueryParam("offset") int offset, @Valid Filter filter) {
@QueryParam("limit") int limit,
@QueryParam("query") String searchQuery) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
if (limit == 0) {
limit = DEFAULT_LIMIT;
}
Filter filter = new Filter();
filter.setOffset(offset);
filter.setLimit(limit);
filter.setSearchQuery(searchQuery);
ApplicationList applications = applicationManager.getApplications(filter); ApplicationList applications = applicationManager.getApplications(filter);
if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity
("Couldn't find any application for requested query.").build();
}
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application list for publisher "; String msg = "Error occurred while getting the application list for publisher ";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
} }
@ -100,7 +93,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
Application application = applicationManager.getApplication(appType, appName); Application application = applicationManager.getApplication(appType, appName);
if (application == null) { if (application == null) {
return Response.status(Response.Status.NOT_FOUND).entity return Response.status(Response.Status.NOT_FOUND).entity
("Application with UUID " + appType + " not found").build(); ("Application with application type: " + appType + " not found").build();
} }
return Response.status(Response.Status.OK).entity(application).build(); return Response.status(Response.Status.OK).entity(application).build();
@ -126,32 +119,32 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
InputStream iconFileStream; InputStream iconFileStream;
InputStream bannerFileStream; InputStream bannerFileStream;
List<InputStream> attachments = new ArrayList<>(); List<InputStream> attachments = new ArrayList<>();
List<ApplicationRelease> applicationReleases = new ArrayList<>();
try { try {
if (iconFile == null) { if (iconFile == null) {
throw new ApplicationManagementException( log.error("Icon file is not uploaded for the application release of " + application.getName() +
"Icon file is not uploaded for the application release of " + application.getName() +
" of application type " + application.getType()); " of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build();
} }
if (bannerFile == null) { if (bannerFile == null) {
throw new ApplicationManagementException( log.error("Banner file is not uploaded for the application release of " + application.getName() +
"Banner file is not uploaded for the application release of " + application.getName() +
" of application type " + application.getType()); " of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build();
} }
if (attachmentList == null || attachmentList.isEmpty()) { if (attachmentList == null || attachmentList.isEmpty()) {
throw new ApplicationManagementException( log.error("Screenshots are not uploaded for the application release of " + application.getName() +
"Screenshots are not uploaded for the application release of " + application.getName() +
" of application type " + application.getType()); " of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build();
} }
if (binaryFile == null) { if (binaryFile == null) {
throw new ApplicationManagementException( log.error("Binary file is not uploaded for the application release of " + application.getName() +
"Binary file is not uploaded for the application release of " + application.getName() +
" of application type " + application.getType()); " of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build();
} }
iconFileStream = iconFile.getDataHandler().getInputStream(); iconFileStream = iconFile.getDataHandler().getInputStream();
bannerFileStream = bannerFile.getDataHandler().getInputStream(); bannerFileStream = bannerFile.getDataHandler().getInputStream();
@ -159,7 +152,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
attachments.add(screenshot.getDataHandler().getInputStream()); attachments.add(screenshot.getDataHandler().getInputStream());
} }
applicationRelease = applicationStorageManager.uploadReleaseArtifacts(applicationRelease, applicationRelease = applicationStorageManager.uploadReleaseArtifact(applicationRelease, application.getType(),
binaryFile.getDataHandler().getInputStream()); binaryFile.getDataHandler().getInputStream());
if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) {
@ -169,18 +162,19 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
bannerFileStream, attachments); bannerFileStream, attachments);
applicationRelease.setUuid(UUID.randomUUID().toString()); applicationRelease.setUuid(UUID.randomUUID().toString());
applicationReleases.add(applicationRelease);
application.setApplicationReleases(applicationReleases);
Application createdApplication = applicationManager.createApplication(application); Application createdApplication = applicationManager.createApplication(application);
if (createdApplication != null) {
if (application != null) {
return Response.status(Response.Status.CREATED).entity(createdApplication).build(); return Response.status(Response.Status.CREATED).entity(createdApplication).build();
} else { } else {
log.error("Given device type is not matched with existing device types"); log.error("Application Creation Failed");
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application"; String msg = "Error occurred while creating the application";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
log.error("Error occurred while uploading the releases artifacts of the application " log.error("Error occurred while uploading the releases artifacts of the application "
+ application.getName(), e); + application.getName(), e);
@ -232,16 +226,18 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationUuid).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build(); String msg = "Couldn't found application release details and storage details";
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application"; String msg = "Error occurred while updating the application";
log.error(msg, e); log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (IOException e) { } catch (IOException e) {
log.error("Exception while trying to read icon, banner files for the application " + applicationUuid); log.error("Exception while trying to read icon, banner files for the application " + applicationUuid);
return APIUtil.getResponse(new ApplicationManagementException( return APIUtil.getResponse(new ApplicationManagementException(
"Exception while trying to read icon, " + "banner files for the application " + applicationUuid, e), "Exception while trying to read icon, " + "banner files for the application " + applicationUuid, e),
Response.Status.BAD_REQUEST); Response.Status.INTERNAL_SERVER_ERROR);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid " log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUuid, e); + applicationUuid, e);
@ -251,29 +247,28 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Override @Override
@PUT @PUT
@Path("/app-artifacts/{appId}/{uuid}") @Path("/app-artifacts/{appType}/{appId}/{uuid}")
public Response updateApplicationArtifact( public Response updateApplicationArtifact(
@PathParam("appType") String appType,
@PathParam("appId") int applicationId, @PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuuid, @PathParam("uuid") String applicationUuuid,
@Multipart("binaryFile") Attachment binaryFile) { @Multipart("binaryFile") Attachment binaryFile) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationRelease applicationRelease; ApplicationRelease applicationRelease;
try { try {
if (binaryFile != null) { if (binaryFile == null) {
return Response.status(Response.Status.BAD_REQUEST)
.entity("Uploading artifacts for the application is failed " + applicationUuuid).build();
}
applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid); applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid);
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, appType,
binaryFile.getDataHandler().getInputStream()); binaryFile.getDataHandler().getInputStream());
applicationManager.updateRelease(applicationId, applicationRelease); applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationUuuid).build();
}
return Response.status(Response.Status.BAD_REQUEST)
.entity("Uploading artifacts for the application is failed " + applicationUuuid).build();
} catch (IOException e) { } catch (IOException e) {
log.error("Exception while trying to read icon, banner files for the application " + applicationUuuid); log.error("Exception while trying to read icon, banner files for the application " + applicationUuuid);
return APIUtil.getResponse(new ApplicationManagementException( return APIUtil.getResponse(new ApplicationManagementException(
@ -325,21 +320,18 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
List<InputStream> attachments = new ArrayList<>(); List<InputStream> attachments = new ArrayList<>();
try { try {
Application application = applicationManager.validateApplication(applicationId);
applicationRelease = applicationManager.validateApplicationRelease(applicationUUID);
if (binaryFile != null) { if (binaryFile != null) {
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, binaryFile.getDataHandler().getInputStream()); applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease,
application.getType(), binaryFile.getDataHandler().getInputStream());
} }
if (iconFile != null) { if (iconFile != null) {
iconFileStream = iconFile.getDataHandler().getInputStream(); iconFileStream = iconFile.getDataHandler().getInputStream();
} }
if (bannerFile != null) { if (bannerFile != null) {
bannerFileStream = bannerFile.getDataHandler().getInputStream(); bannerFileStream = bannerFile.getDataHandler().getInputStream();
} }
if (!attachmentList.isEmpty()) { if (!attachmentList.isEmpty()) {
for (Attachment screenshot : attachmentList) { for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream()); attachments.add(screenshot.getDataHandler().getInputStream());
@ -423,7 +415,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while getting lifecycle state."; String msg = "Error occurred while getting lifecycle state.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.status(Response.Status.OK).entity(lifecycleState).build(); return Response.status(Response.Status.OK).entity(lifecycleState).build();
} }
@ -440,7 +432,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while adding lifecycle state."; String msg = "Error occurred while adding lifecycle state.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build(); return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build();
} }

@ -75,7 +75,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
Filter filter = new Filter(); Filter filter = new Filter();
filter.setOffset(offset); filter.setOffset(offset);
filter.setLimit(limit); filter.setLimit(limit);
filter.setSearchQuery(searchQuery); filter.setAppName(searchQuery);
ApplicationList applications = applicationManager.getApplications(filter); ApplicationList applications = applicationManager.getApplications(filter);

Loading…
Cancel
Save