adding application release creation functioanlity (NC)

feature/appm-store/pbac
lasantha 7 years ago
parent f8c5ff95b9
commit 486aac1cdc

@ -68,11 +68,13 @@ public class ApplicationRelease {
private ImageArtifact icon; private ImageArtifact icon;
private String iconLoc;
private ImageArtifact banner; private ImageArtifact banner;
private String currentState; private String currentState;
private String previouseState; private String previousState;
private String stateModifiedBy; private String stateModifiedBy;
@ -162,12 +164,12 @@ public class ApplicationRelease {
this.currentState = currentState; this.currentState = currentState;
} }
public String getPreviouseState() { public String getPreviousState() {
return previouseState; return previousState;
} }
public void setPreviouseState(String previouseState) { public void setPreviousState(String previousState) {
this.previouseState = previouseState; this.previousState = previousState;
} }
public String getStateModifiedBy() { public String getStateModifiedBy() {
@ -305,4 +307,12 @@ public class ApplicationRelease {
public void setModifiedAt(Timestamp modifiedAt) { public void setModifiedAt(Timestamp modifiedAt) {
this.modifiedAt = modifiedAt; this.modifiedAt = modifiedAt;
} }
public String getIconLoc() {
return iconLoc;
}
public void setIconLoc(String iconLoc) {
this.iconLoc = iconLoc;
}
} }

@ -96,4 +96,13 @@ public interface ApplicationManager {
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
Application getApplication(String appType, String appName) throws ApplicationManagementException; Application getApplication(String appType, String appName) throws ApplicationManagementException;
/**
* To get Application with the given UUID.
*
* @param appId ID of the Application
* @return the boolean value, whether application exist or not
* @throws ApplicationManagementException Application Management Exception.
*/
Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException;
} }

@ -19,6 +19,7 @@
package org.wso2.carbon.device.application.mgt.common.services; package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
@ -33,23 +34,24 @@ public interface ApplicationStorageManager {
/** /**
* To upload image artifacts related with an Application. * To upload image artifacts related with an Application.
* *
* @param applicationUUID UUID of the application * @param applicationId ID of the application
* @param applicationRelease ApplicationRelease Object
* @param iconFile Icon File input stream * @param iconFile Icon File input stream
* @param bannerFile Banner File input stream * @param bannerFile Banner File input stream
* @throws ResourceManagementException Resource Management Exception. * @throws ResourceManagementException Resource Management Exception.
*/ */
void uploadImageArtifacts(String applicationUUID, InputStream iconFile, InputStream bannerFile, ApplicationRelease uploadImageArtifacts(int applicationId, ApplicationRelease applicationRelease,
List<InputStream> screenshots) throws ResourceManagementException; InputStream iconFile, InputStream bannerFile, List<InputStream> screenshots) throws ResourceManagementException;
/** /**
* To upload release artifacts for an Application. * To upload release artifacts for an Application.
* *
* @param applicationUUID UUID of the application related with the release. * @param applicationId UUID of the application related with the release.
* @param versionName Name of version of the Applcation Release. * @param applicationRelease Application Release Object.
* @param binaryFile Binary File for the release. * @param binaryFile Binary File for the release.
* @throws ResourceManagementException Resource Management Exception. * @throws ResourceManagementException Resource Management Exception.
*/ */
void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile) ApplicationRelease uploadReleaseArtifacts(int applicationId, ApplicationRelease applicationRelease, InputStream binaryFile)
throws ResourceManagementException; throws ResourceManagementException;
/** /**

@ -85,14 +85,23 @@ 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 id of the application specified by the UUID * To get the application with the given uuid
* *
* @param appName name of the application. * @param appId ID of the application
* @param appType type of the application. * @return the boolean value
* @param tenantId ID of the tenant.
* @return ID of the Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementDAOException;
/**
* To get the application id of the application specified by the UUID
*
* @param appName name of the application.
* @param appType type of the application.
* @param tenantId ID of the tenant.
* @return ID of the Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
int getApplicationId(String appName, String appType, int tenantId) throws ApplicationManagementDAOException; int getApplicationId(String appName, String appType, int tenantId) throws ApplicationManagementDAOException;
/** /**

@ -343,6 +343,46 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
} }
@Override
public Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()){
log.debug("Getting application with the application ID(" + appId + " ) from the database");
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
Boolean isAppExist = false;
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.ID=?;";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId);
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application with the application ID " + appId);
}
if (rs.next()){
isAppExist = true;
}
return isAppExist;
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app ID " + appId + " While executing query ", e);
}
catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override @Override
public Application editApplication(Application application, int tenantId) throws ApplicationManagementException { public Application editApplication(Application application, int tenantId) throws ApplicationManagementException {
Connection conn; Connection conn;

@ -152,7 +152,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT")); applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStarts(resultSet.getInt("STARS")); applicationRelease.setStarts(resultSet.getInt("STARS"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE")); applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviouseState(resultSet.getString("PREVIOUSE_STATE")); applicationRelease.setPreviousState(resultSet.getString("PREVIOUSE_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY")); applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT")); applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
} }

@ -406,6 +406,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
public Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException{
try {
Boolean isAppExist;
ConnectionManagerUtil.openDBConnection();
isAppExist = ApplicationManagementDAOFactory.getApplicationDAO().verifyApplicationExistenceById(appId);
return isAppExist;
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
/** /**
* To check whether current user is application owner or admin. * To check whether current user is application owner or admin.
* *

@ -19,8 +19,11 @@
package org.wso2.carbon.device.application.mgt.core.impl; package org.wso2.carbon.device.application.mgt.core.impl;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
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.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
@ -28,7 +31,9 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil; import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
@ -62,109 +67,93 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
@Override @Override
public void uploadImageArtifacts(String applicationUUID, InputStream iconFileStream, InputStream bannerFileStream, public ApplicationRelease uploadImageArtifacts(int applicationId, ApplicationRelease applicationRelease,
List<InputStream> screenShotStreams) throws ResourceManagementException { InputStream iconFileStream, InputStream bannerFileStream, List<InputStream> screenShotStreams) throws ResourceManagementException {
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// Application application = validateApplication(applicationUUID); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// String artifactDirectoryPath = storagePath + application.getId(); String artifactDirectoryPath = null;
// if (log.isDebugEnabled()) { String iconStoredLocation;
// log.debug("Artifact Directory Path for saving the artifacts related with application " + applicationUUID String bannerStoredLocation;
// + " is " + artifactDirectoryPath); String scStoredLocation;
// }
// StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); try {
// if (iconFileStream != null) { if (validateApplication(applicationId)) {
// try { artifactDirectoryPath = storagePath + applicationRelease.getAppHashValue();
// saveFile(iconFileStream, artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0]); StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
// } catch (IOException e) { }
// throw new ApplicationStorageManagementException(
// "IO Exception while saving the icon file in the server for " + "the application " if (artifactDirectoryPath != null) {
// + applicationUUID, e);
// } iconStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0];
// } bannerStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1];
// if (bannerFileStream != null) { saveFile(iconFileStream, iconStoredLocation);
// try { saveFile(bannerFileStream, bannerStoredLocation);
// saveFile(bannerFileStream, artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1]); applicationRelease.setIconLoc(iconStoredLocation);
// } catch (IOException e) { applicationRelease.setBannerLoc(bannerStoredLocation);
// throw new ApplicationStorageManagementException(
// "IO Exception while saving the banner file in the server for" + " the application " if (screenShotStreams.size() > screenShotMaxCount) {
// + applicationUUID, e); throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
// } }
// }
// if (screenShotStreams != null) { int count = 1;
// int count = application.getScreenShotCount() + 1; for (InputStream screenshotStream : screenShotStreams) {
// boolean maxCountReached = false; scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count;
// if (count == 1) {
// if (count > screenShotMaxCount) { applicationRelease.setScreenshotLoc1(scStoredLocation);
// log.error("Maximum limit for the screen-shot is " + screenShotMaxCount }
// + " Cannot upload another screenshot for the application with the UUID " + applicationUUID); if (count == 2) {
// maxCountReached = true; applicationRelease.setScreenshotLoc2(scStoredLocation);
// } }
// String screenshotName; if (count == 3) {
// applicationRelease.setScreenshotLoc3(scStoredLocation);
// if (maxCountReached) { }
// return; saveFile(screenshotStream, scStoredLocation);
// } count++;
// for (InputStream screenshotStream : screenShotStreams) { }
// try { }
// screenshotName = Constants.IMAGE_ARTIFACTS[2] + count; return applicationRelease;
// saveFile(screenshotStream, artifactDirectoryPath + File.separator + screenshotName); } catch (IOException e) {
// count++; throw new ApplicationStorageManagementException(
// if (count > screenShotMaxCount) { "IO Exception while saving the screens hots for the " + "application " + applicationId, e);
// log.error("Maximum limit for the screen-shot is " + screenShotMaxCount } catch (ApplicationStorageManagementException e) {
// + " Cannot upload another screenshot for the application with the UUID " ConnectionManagerUtil.rollbackDBTransaction();
// + applicationUUID); throw new ApplicationStorageManagementException("Application Management DAO exception while trying to"
// break; + " update the screen-shot count for the application " + applicationId + " for the tenant "
// } + tenantId, e);
// } catch (IOException e) { }
// throw new ApplicationStorageManagementException(
// "IO Exception while saving the screens hots for the " + "application " + applicationUUID,
// e);
// }
// }
// try {
// ConnectionManagerUtil.beginDBTransaction();
// ApplicationManagementDAOFactory.getApplicationDAO().updateScreenShotCount(applicationUUID, tenantId, count - 1);
// ConnectionManagerUtil.commitDBTransaction();
// } catch (TransactionManagementException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw new ApplicationStorageManagementException("Transaction Management exception while trying to "
// + "update the screen-shot count of the application " + applicationUUID + " for the tenant "
// + tenantId, e);
// } catch (DBConnectionException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw new ApplicationStorageManagementException("Database connection management exception while "
// + "trying to update the screen-shot count for the application " + applicationUUID + " for the"
// + " tenant " + tenantId, e);
// } catch (ApplicationManagementDAOException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw new ApplicationStorageManagementException("Application Management DAO exception while trying to"
// + " update the screen-shot count for the application " + applicationUUID + " for the tenant "
// + tenantId, e);
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
} }
@Override @Override
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile) public ApplicationRelease uploadReleaseArtifacts(int applicationId, ApplicationRelease applicationRelease , InputStream binaryFile)
throws ResourceManagementException { throws ResourceManagementException {
Application application = validateApplication(applicationUUID);
String artifactDirectoryPath = storagePath + application.getId(); String artifactDirectoryPath;
if (log.isDebugEnabled()) { String md5OfApp;
log.debug("Artifact Directory Path for saving the application release related artifacts related with " md5OfApp = getMD5(binaryFile);
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
} if(validateApplication(applicationId) && md5OfApp != null){
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); artifactDirectoryPath = storagePath + md5OfApp;
if (binaryFile != null) { StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
if (log.isDebugEnabled()) {
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
+ "application ID " + applicationId + " is " + artifactDirectoryPath);
}
try { try {
saveFile(binaryFile, artifactDirectoryPath + File.separator + versionName); saveFile(binaryFile, artifactDirectoryPath);
applicationRelease.setAppStoredLoc(artifactDirectoryPath);
applicationRelease.setAppHashValue(md5OfApp);
} catch (IOException e) { } catch (IOException e) {
throw new ApplicationStorageManagementException( throw new ApplicationStorageManagementException(
"IO Exception while saving the release artifacts in the server for the application " "IO Exception while saving the release artifacts in the server for the application "
+ applicationUUID, e); + applicationId, e);
} }
}else{
log.error("Verify application existence and md5sum value retrieving process");
} }
return applicationRelease;
} }
@Override @Override
@ -278,24 +267,32 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
/** /**
* To validate the Application before storing and retrieving the artifacts of a particular application. * To validate the Application before storing and retrieving the artifacts of a particular application.
* *
* @param uuid UUID of the Application * @param appId ID of the Application
* @return {@link Application} if it is validated * @return {@link Application} if it is validated
* @throws ApplicationStorageManagementException Application Storage Management Exception will be thrown if a * @throws ApplicationStorageManagementException Application Storage Management Exception will be thrown if a
* valid application related with the specific UUID * valid application related with the specific UUID
* could not be found. * could not be found.
*/ */
private Application validateApplication(String uuid) throws ApplicationStorageManagementException { private Boolean validateApplication(int appId) throws ApplicationStorageManagementException {
Application application; Boolean isAppExist;
try { try {
application = DataHolder.getInstance().getApplicationManager().getApplication(uuid); isAppExist = DataHolder.getInstance().getApplicationManager().verifyApplicationExistenceById(appId);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
throw new ApplicationStorageManagementException( throw new ApplicationStorageManagementException(
"Exception while retrieving the application details for the application with UUID " "Exception while verifing the application existence for the application with ID "+ appId);
+ uuid);
} }
if (application == null) {
throw new ApplicationStorageManagementException("Application with UUID " + uuid + " does not exist."); return isAppExist;
}
private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException {
String md5;
try {
md5 = DigestUtils.md5Hex(IOUtils.toByteArray(binaryFile));
} catch (IOException e) {
throw new ApplicationStorageManagementException
("IO Exception while trying to get the md5sum value of application");
} }
return application; return md5;
} }
} }

@ -44,11 +44,9 @@ public class StorageManagementUtil {
public static void createArtifactDirectory(String artifactDirectoryPath) throws ResourceManagementException { public static void createArtifactDirectory(String artifactDirectoryPath) throws ResourceManagementException {
File artifactDirectory = new File(artifactDirectoryPath); File artifactDirectory = new File(artifactDirectoryPath);
if (!artifactDirectory.exists()) { if (!artifactDirectory.exists() && !artifactDirectory.mkdirs()) {
if (!artifactDirectory.mkdirs()) {
throw new ResourceManagementException( throw new ResourceManagementException(
"Cannot create directories in the path to save the application related artifacts"); "Cannot create directories in the path to save the application related artifacts");
}
} }
} }
@ -81,9 +79,9 @@ public class StorageManagementUtil {
outStream = new FileOutputStream(new File(path)); outStream = new FileOutputStream(new File(path));
outStream.write(buffer); outStream.write(buffer);
} finally { } finally {
if (inputStream != null) {
inputStream.close(); inputStream.close();
}
if (outStream != null) { if (outStream != null) {
outStream.close(); outStream.close();
} }

@ -23,12 +23,9 @@ 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.Application;
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.publisher.api.beans.ErrorResponse; import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import javax.validation.Valid;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -136,9 +133,7 @@ public interface ApplicationReleaseManagementAPI {
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.", message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }) Response createApplicationRelease(
Response createApplicationRelease(
@Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease, @Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease,
@ApiParam( @ApiParam(
name = "binaryFile", name = "binaryFile",

@ -26,25 +26,19 @@ import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
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.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; 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.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.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.FileStreamingOutput; import org.wso2.carbon.device.application.mgt.publisher.api.FileStreamingOutput;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationReleaseManagementAPI; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationReleaseManagementAPI;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import javax.validation.Valid;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -82,7 +76,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
throw new ApplicationManagementException( throw new ApplicationManagementException(
"Icon file is not uploaded for the application release of " + applicationId); } "Icon file is not uploaded for the application release of " + applicationId); }
if (bannerFile != null) { if (bannerFile == null) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
"Banner file is not uploaded for the application release of " + applicationId); } "Banner file is not uploaded for the application release of " + applicationId); }
@ -102,12 +96,16 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
attachments.add(screenshot.getDataHandler().getInputStream()); attachments.add(screenshot.getDataHandler().getInputStream());
} }
applicationStorageManager.uploadReleaseArtifacts(applicationUUID, applicationRelease.getVersion(), applicationRelease = applicationStorageManager.uploadReleaseArtifacts(applicationId, applicationRelease,
binaryFile.getDataHandler().getInputStream()); binaryFile.getDataHandler().getInputStream());
if(applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null){
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
applicationRelease = applicationStorageManager.uploadImageArtifacts(applicationId, applicationRelease,
iconFileStream, bannerFileStream, attachments);
// ToDo
applicationRelease.setUuid(UUID.randomUUID().toString()); applicationRelease.setUuid(UUID.randomUUID().toString());
applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease); applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease);
@ -131,42 +129,6 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
} }
} }
@Override
@POST
@Path("/release/{uuid}")
public Response createApplicationRelease(@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationRelease applicationRelease,
@Multipart("binaryFile") Attachment binaryFile) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease);
if (binaryFile != null) {
applicationStorageManager.uploadReleaseArtifacts(applicationUUID, applicationRelease.getVersion(),
binaryFile.getDataHandler().getInputStream());
}
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (ApplicationManagementException e) {
log.error("Error while creating an application release for the application with UUID " + applicationUUID,
e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (IOException e) {
String errorMessage =
"Error while uploading binary file for the application release of the application with UUID "
+ applicationUUID;
log.error(errorMessage, e);
return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
Response.Status.INTERNAL_SERVER_ERROR);
} catch (ResourceManagementException e) {
log.error("Error occurred while uploading the releases artifacts of the application with the uuid "
+ applicationUUID + " for the release " + applicationRelease.getVersion(), e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override @Override
@POST @POST
@Path("/upload-image-artifacts/{uuid}") @Path("/upload-image-artifacts/{uuid}")

Loading…
Cancel
Save