adding appliction release functionalites and fixed build failure

feature/appm-store/pbac
lasantha 7 years ago
parent f17c36d13f
commit 669881eae7

@ -36,7 +36,7 @@ public interface ApplicationManager {
* @throws ApplicationManagementException Application Management Exception
*/
Application createApplication(Application application)
throws ApplicationManagementException, DeviceManagementDAOException;
throws ApplicationManagementException;
/**
* Updates an already existing application.

@ -84,12 +84,12 @@ public interface ApplicationReleaseManager {
/**
* To update with a new release for an Application.
*
* @param applicationUuid UUID of the Application
* @param appId ID of the Application
* @param applicationRelease ApplicationRelease
* @return Updated Application Release.
* @throws ApplicationManagementException Application Management Exception.
*/
ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease)
ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease)
throws ApplicationManagementException;
/**

@ -21,6 +21,7 @@ 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.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
@ -43,6 +44,20 @@ public interface ApplicationStorageManager {
ApplicationRelease uploadImageArtifacts(int applicationId, ApplicationRelease applicationRelease,
InputStream iconFile, InputStream bannerFile, List<InputStream> screenshots) throws ResourceManagementException;
/**
* To upload image artifacts related with an Application.
*
* @param applicationId ID of the application
* @param uuid Unique Identifier of the application
* @param iconFile Icon File input stream
* @param bannerFile Banner File input stream
* @param screenshots Input Streams of screenshots
* @throws ResourceManagementException Resource Management Exception.
*/
ApplicationRelease updateImageArtifacts(int applicationId, String uuid, InputStream iconFile,
InputStream bannerFile, List<InputStream> screenshots)
throws ResourceManagementException, ApplicationManagementException;
/**
* To upload release artifacts for an Application.
*
@ -54,6 +69,17 @@ public interface ApplicationStorageManager {
ApplicationRelease uploadReleaseArtifacts(int applicationId, ApplicationRelease applicationRelease, InputStream binaryFile)
throws ResourceManagementException;
/**
* To upload release artifacts for an Application.
*
* @param applicationId Id of the application.
* @param applicationUuid UUID of the application related with the release.
* @param binaryFile Binary File for the release.
* @throws ResourceManagementException Resource Management Exception.
*/
ApplicationRelease updateReleaseArtifacts(int applicationId, String applicationUuid, InputStream binaryFile)
throws ResourceManagementException;
/**
* To get released artifacts for the particular version of the application.
*

@ -28,9 +28,9 @@ import java.util.List;
*/
public interface LifecycleStateManager {
List<LifecycleState> getLifecycleStates() throws LifecycleManagementException;
List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifecycleManagementException;
void addLifecycleState(LifecycleState state) throws LifecycleManagementException;
void deleteLifecycleState(String identifier) throws LifecycleManagementException;
void deleteLifecycleState(int identifier) throws LifecycleManagementException;
}

@ -78,7 +78,10 @@
org.wso2.carbon,
org.apache.commons.io,
org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}",
org.wso2.carbon.base
org.apache.commons.codec.digest;version="${commons-codec.wso2.osgi.version.range}",
org.wso2.carbon.base,
org.wso2.carbon.device.mgt.core.dto.*;version="${carbon.device.mgt.version}",
org.wso2.carbon.device.mgt.core.dao.*;version="${carbon.device.mgt.version}"
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.application.mgt.core.internal.*,

@ -22,6 +22,7 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
@ -104,7 +105,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override
public ApplicationRelease getRelease(String applicationName,String applicationType, String versionName,
public ApplicationRelease getRelease(String applicationName, String applicationType, String versionName,
String releaseType, int tenantId) throws ApplicationManagementDAOException {
Connection connection;
@ -133,7 +134,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (resultSet.next()) {
applicationRelease = new ApplicationRelease();
applicationRelease.setId(resultSet.getInt("RELESE_ID"));
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
@ -221,7 +222,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStarts(resultSet.getInt("STARS"));
applicationReleases.add(applicationRelease);
if ("REMOVED".equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())){
applicationReleases.add(applicationRelease);
}
}
return applicationReleases;
} catch (DBConnectionException e) {

@ -31,46 +31,46 @@ import java.sql.SQLException;
*/
public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
@Override
protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn,
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 "
+ "ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? ";
String userName = filter.getUserName();
if (!userName.equals("ALL")) {
sql += " AND APP.CREATED_BY = ? ";
}
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
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);
if (!userName.equals("ALL")) {
stmt.setString(++index, userName);
}
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
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());
return stmt;
}
// @Override
// protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn,
// 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 "
// + "ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? ";
//
// String userName = filter.getUserName();
// if (!userName.equals("ALL")) {
// sql += " AND APP.CREATED_BY = ? ";
// }
// if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
// 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);
//
// if (!userName.equals("ALL")) {
// stmt.setString(++index, userName);
// }
// if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
// 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());
// return stmt;
// }
}

@ -66,8 +66,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public Application createApplication(Application application)
throws ApplicationManagementException, DeviceManagementDAOException {
public Application createApplication(Application application) throws ApplicationManagementException {
User loggedInUser = new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(),
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
@ -112,7 +111,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
String msg = "Error occurred while getting device type id of " + application.getType();
log.error(msg, e);
ConnectionManagerUtil.rollbackDBTransaction();
throw new DeviceManagementDAOException(msg, e);
throw new ApplicationManagementException(msg, e);
} catch(ApplicationManagementException e){
String msg = "Error occurred while adding application";
log.error(msg, e);

@ -45,7 +45,7 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) throws
ApplicationManagementException {
Application application = validateApplication(applicationId);
validateReleaseCreateRequest(applicationRelease.getUuid(), applicationRelease);
validateReleaseCreateRequest(applicationRelease);
if (log.isDebugEnabled()) {
log.debug("Application release request is received for the application " + application.toString());
}
@ -64,24 +64,27 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
}
}
//todo
@Override
public ApplicationRelease getRelease(String applicationUuid, String version, String releaseType) throws
ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplicationRelease(applicationUuid);
if (log.isDebugEnabled()) {
log.debug("Application release retrieval request is received for the application " +
application.toString() + " and version " + version);
}
try {
ConnectionManagerUtil.openDBConnection();
return ApplicationManagementDAOFactory.getApplicationReleaseDAO()
.getRelease(application.getName(), application.getType(), version, releaseType, tenantId );
} finally {
ConnectionManagerUtil.closeDBConnection();
}
return null;
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// Application application = validateApplicationRelease(applicationUuid);
// if (log.isDebugEnabled()) {
// log.debug("Application release retrieval request is received for the application " +
// application.toString() + " and version " + version);
// }
// try {
// ConnectionManagerUtil.openDBConnection();
// return ApplicationManagementDAOFactory.getApplicationReleaseDAO()
// .getRelease(application.getName(), application.getType(), version, releaseType, tenantId );
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
}
//todo
@Override public ApplicationRelease getReleaseByUuid(String applicationUuid) throws ApplicationManagementException {
return null;
}
@ -130,7 +133,7 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
// ToDo
@Override
public ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease)
public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease)
throws ApplicationManagementException {
// Application application = validateApplicationRelease(applicationUuid);
// ApplicationRelease oldApplicationRelease = null;
@ -162,36 +165,38 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
return null;
}
//todo
@Override
public void deleteApplicationRelease(String applicationUuid, String version, String releaseType)
throws ApplicationManagementException {
Application application = validateApplicationRelease(applicationUuid);
ApplicationRelease applicationRelease = getRelease(applicationUuid, version, releaseType);
if (applicationRelease == null) {
throw new ApplicationManagementException(
"Cannot delete a non-existing application release for the " + "application with UUID "
+ applicationUuid);
}
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteRelease(application.getId(), version);
// ToDO remove storage details as well
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw e;
} finally {
ConnectionManagerUtil.closeDBConnection();
}
// Application application = validateApplicationRelease(applicationUuid);
// ApplicationRelease applicationRelease = getRelease(applicationUuid, version, releaseType);
// if (applicationRelease == null) {
// throw new ApplicationManagementException(
// "Cannot delete a non-existing application release for the " + "application with UUID "
// + applicationUuid);
// }
// try {
// ConnectionManagerUtil.beginDBTransaction();
// ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteRelease(application.getId(), version);
//// ToDO remove storage details as well
// ConnectionManagerUtil.commitDBTransaction();
// } catch (ApplicationManagementDAOException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw e;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
}
//todo
@Override
public void deleteApplicationReleases(String applicationUuid) throws ApplicationManagementException {
List<ApplicationRelease> applicationReleases = getReleases(applicationUuid);
for (ApplicationRelease applicationRelease : applicationReleases) {
deleteApplicationRelease(applicationUuid, applicationRelease.getVersion());
}
// List<ApplicationRelease> applicationReleases = getReleases(applicationUuid);
//
// for (ApplicationRelease applicationRelease : applicationReleases) {
// deleteApplicationRelease(applicationUuid, applicationRelease.getVersion());
// }
}
/**
@ -224,7 +229,8 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
}
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease();
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager()
.getReleaseByUuid(applicationUuid);
if (applicationRelease == null) {
throw new NotFoundException(
"Application with UUID " + applicationUuid + " does not exist.");
@ -235,21 +241,20 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
/**
* To validate a create release request to make sure all the pre-conditions satisfied.
*
* @param applicationUuid UUID of the Application.
* @param applicationRelease ApplicationRelease that need to be created.
* @throws ApplicationManagementException Application Management Exception.
*/
private void validateReleaseCreateRequest(String applicationUuid, ApplicationRelease applicationRelease)
private void validateReleaseCreateRequest(ApplicationRelease applicationRelease)
throws ApplicationManagementException {
if (applicationRelease == null || applicationRelease.getVersion() == null) {
throw new ApplicationManagementException("ApplicationRelease version name is a mandatory parameter for "
+ "creating release. It cannot be found.");
}
if (getRelease(applicationUuid, applicationRelease.getVersion()) != null) {
throw new ApplicationManagementException(
"Application Release for the Application UUID " + applicationUuid + " " + "with the version "
+ applicationRelease.getVersion() + " already exists. Cannot create an "
+ "application release with the same version.");
if (getRelease(applicationRelease.getUuid(), applicationRelease.getVersion(),
applicationRelease.getReleaseType()) != null) {
throw new ApplicationManagementException( "Application Release for the Application UUID " +
applicationRelease.getUuid() + " " + "with the version " + applicationRelease.getVersion() +
" already exists. Cannot create an " + "application release with the same version.");
}
}

@ -117,8 +117,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
count++;
}
}
}
return applicationRelease;
} catch (IOException e) {
@ -126,7 +124,32 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
"IO Exception while saving the screens hots for the " + "application " + applicationId, e);
} catch (ApplicationStorageManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationStorageManagementException("Application Management DAO exception while trying to"
throw new ApplicationStorageManagementException("Application Management DAO exception while trying to "
+ "update the screen-shot count for the application " + applicationId + " for the tenant id "
+ tenantId, e);
}
}
@Override
public ApplicationRelease updateImageArtifacts(int applicationId, String uuid, InputStream iconFileStream,
InputStream bannerFileStream, List<InputStream> screenShotStreams)
throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ApplicationRelease applicationRelease = validateApplicationRelease(uuid);
applicationRelease = uploadImageArtifacts(applicationId, applicationRelease, iconFileStream, bannerFileStream, screenShotStreams);
return applicationRelease;
} catch (ApplicationStorageManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationStorageManagementException("Application Storage exception while trying to"
+ " update the screen-shot count for the application " + applicationId + " for the tenant "
+ tenantId, e);
} catch (ApplicationManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException("Application Management DAO exception while trying to"
+ " update the screen-shot count for the application " + applicationId + " for the tenant "
+ tenantId, e);
}
@ -167,100 +190,125 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
}
@Override
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
throws ApplicationStorageManagementException {
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
String artifactPath = storagePath + application.getId() + File.separator + versionName;
if (log.isDebugEnabled()) {
log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
}
public ApplicationRelease updateReleaseArtifacts(int applicationId, String applicationUuid, InputStream binaryFile)
throws ResourceManagementException {
File binaryFile = new File(artifactPath);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (!binaryFile.exists()) {
throw new ApplicationStorageManagementException("Binary file does not exist for this release");
} else {
try {
return new FileInputStream(artifactPath);
} catch (FileNotFoundException e) {
throw new ApplicationStorageManagementException(
"Binary file does not exist for the version " + versionName + " for the application ", e);
}
ApplicationRelease applicationRelease = null;
try {
applicationRelease = validateApplicationRelease(applicationUuid);
applicationRelease = uploadReleaseArtifacts(applicationId, applicationRelease,binaryFile);
return applicationRelease;
} catch (ApplicationManagementException e) {
throw new ApplicationStorageManagementException("Application Management exception while trying to"
+ " update the Application artifact for the application " + applicationId + " for the tenant "
+ tenantId, e);
}
}
//todo
@Override
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
throws ApplicationStorageManagementException {
return null;
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
String artifactDirectoryPath = storagePath + application.getId();
File artifactDirectory = new File(artifactDirectoryPath);
// Application application = validateApplication(applicationUUID);
// String artifactPath = storagePath + application.getId() + File.separator + versionName;
//
// if (log.isDebugEnabled()) {
// log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
// }
//
// File binaryFile = new File(artifactPath);
//
// if (!binaryFile.exists()) {
// throw new ApplicationStorageManagementException("Binary file does not exist for this release");
// } else {
// try {
// return new FileInputStream(artifactPath);
// } catch (FileNotFoundException e) {
// throw new ApplicationStorageManagementException(
// "Binary file does not exist for the version " + versionName + " for the application ", e);
// }
// }
}
if (artifactDirectory.exists()) {
StorageManagementUtil.deleteDir(artifactDirectory);
}
//todo
@Override
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
// todo this should be validate application release
// Application application = validateApplication(applicationUUID);
// String artifactDirectoryPath = storagePath + application.getId();
// File artifactDirectory = new File(artifactDirectoryPath);
//
// if (artifactDirectory.exists()) {
// StorageManagementUtil.deleteDir(artifactDirectory);
// }
}
//todo
@Override
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
throws ApplicationStorageManagementException {
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
String artifactPath = storagePath + application.getId() + File.separator + version;
File artifact = new File(artifactPath);
if (artifact.exists()) {
StorageManagementUtil.deleteDir(artifact);
}
// Application application = validateApplication(applicationUUID);
// String artifactPath = storagePath + application.getId() + File.separator + version;
// File artifact = new File(artifactPath);
//
// if (artifact.exists()) {
// StorageManagementUtil.deleteDir(artifact);
// }
}
//todo
@Override
public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws
ApplicationStorageManagementException {
// todo this should be validate application release
validateApplication(applicationUUID);
try {
List<ApplicationRelease> applicationReleases = DataHolder.getInstance().getApplicationReleaseManager()
.getReleases(applicationUUID);
for (ApplicationRelease applicationRelease : applicationReleases) {
deleteApplicationReleaseArtifacts(applicationUUID, applicationRelease.getVersion());
}
} catch (ApplicationManagementException e) {
throw new ApplicationStorageManagementException(
"Application Management Exception while getting releases " + "for the application "
+ applicationUUID, e);
}
// validateApplication(applicationUUID);
// try {
// List<ApplicationRelease> applicationReleases = DataHolder.getInstance().getApplicationReleaseManager()
// .getReleases(applicationUUID);
// for (ApplicationRelease applicationRelease : applicationReleases) {
// deleteApplicationReleaseArtifacts(applicationUUID, applicationRelease.getVersion());
// }
// } catch (ApplicationManagementException e) {
// throw new ApplicationStorageManagementException(
// "Application Management Exception while getting releases " + "for the application "
// + applicationUUID, e);
// }
}
//todo
@Override
public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws
ApplicationStorageManagementException {
return null;
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
validateImageArtifactNames(name);
String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase();
if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) {
imageArtifactPath += count;
}
File imageFile = new File(imageArtifactPath);
if (!imageFile.exists()) {
throw new ApplicationStorageManagementException(
"Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID);
} else {
try {
return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath);
} catch (FileNotFoundException e) {
throw new ApplicationStorageManagementException(
"File not found exception while trying to get the image artifact " + name + " for the "
+ "application " + applicationUUID, e);
} catch (IOException e) {
throw new ApplicationStorageManagementException("IO Exception while trying to detect the image "
+ "artifact " + name + " for the application " + applicationUUID, e);
}
}
// Application application = validateApplication(applicationUUID);
// validateImageArtifactNames(name);
// String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase();
//
// if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) {
// imageArtifactPath += count;
// }
// File imageFile = new File(imageArtifactPath);
// if (!imageFile.exists()) {
// throw new ApplicationStorageManagementException(
// "Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID);
// } else {
// try {
// return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath);
// } catch (FileNotFoundException e) {
// throw new ApplicationStorageManagementException(
// "File not found exception while trying to get the image artifact " + name + " for the "
// + "application " + applicationUUID, e);
// } catch (IOException e) {
// throw new ApplicationStorageManagementException("IO Exception while trying to detect the image "
// + "artifact " + name + " for the application " + applicationUUID, e);
// }
// }
}
/**
@ -311,7 +359,8 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
}
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease();
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().
getReleaseByUuid(applicationUuid);
if (applicationRelease == null) {
throw new NotFoundException(
"Application with UUID " + applicationUuid + " does not exist.");

@ -38,12 +38,12 @@ public class LifecycleStateManagerImpl implements LifecycleStateManager {
private static final Log log = LogFactory.getLog(LifecycleStateManagerImpl.class);
@Override
public List<LifecycleState> getLifecycleStates() throws LifecycleManagementException {
public List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifecycleManagementException {
List<LifecycleState> lifecycleStates = null;
try {
ConnectionManagerUtil.openDBConnection();
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStates = lifecycleStateDAO.getLifecycleStates();
lifecycleStates = lifecycleStateDAO.getLifecycleStates(appReleaseId);
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new LifecycleManagementException("Failed get lifecycle states.", e);
} finally {
@ -66,7 +66,7 @@ public class LifecycleStateManagerImpl implements LifecycleStateManager {
}
@Override
public void deleteLifecycleState(String identifier) throws LifecycleManagementException {
public void deleteLifecycleState(int identifier) throws LifecycleManagementException {
try {
ConnectionManagerUtil.openDBConnection();

@ -98,52 +98,53 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
private List<DeviceIdentifier> installApplication(String applicationUUID, List<DeviceIdentifier> deviceList,
String versionName) throws ApplicationManagementException {
List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
// Todo: try whether we can optimise this by sending bulk inserts to db
// Todo: atomicity is not maintained as deveice managment provider service uses separate db connection. fix this??
log.info("Install application: " + applicationUUID + "[" + versionName + "]" + " to: "
+ deviceList.size() + " devices.");
for (DeviceIdentifier device : deviceList) {
org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt
.common.DeviceIdentifier(device.getId(), device.getType());
try {
DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService();
if (!dmpService.isEnrolled(deviceIdentifier)) {
log.error("Device with ID: [" + device.getId() + "] is not enrolled to install the application.");
} else {
if (log.isDebugEnabled()) {
log.debug("Installing application to : " + device.getId());
}
//Todo: generating one time download link for the application and put install operation to device.
// put app install operation to the device
ProfileOperation operation = new ProfileOperation();
operation.setCode(INSTALL_APPLICATION);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad("{'type':'enterprise', 'url':'http://10.100.5.76:8000/app-debug.apk', 'app':'"
+ applicationUUID + "'}");
List<org.wso2.carbon.device.mgt.common.DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(deviceIdentifier);
dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
operation, deviceIdentifiers);
DeviceApplicationMapping deviceApp = new DeviceApplicationMapping();
deviceApp.setDeviceIdentifier(device.getId());
deviceApp.setApplicationUUID(applicationUUID);
deviceApp.setVersionName(versionName);
deviceApp.setInstalled(false);
dmpService.addDeviceApplicationMapping(deviceApp);
// DeviceManagementDAOFactory.openConnection();
// ApplicationManagementDAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
failedDeviceList.remove(device);
}
} catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) {
log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e);
}
return null;
// List<DeviceIdentifier> failedDeviceList = new ArrayList<>(deviceList);
// // Todo: try whether we can optimise this by sending bulk inserts to db
// // Todo: atomicity is not maintained as deveice managment provider service uses separate db connection. fix this??
// log.info("Install application: " + applicationUUID + "[" + versionName + "]" + " to: "
// + deviceList.size() + " devices.");
// for (DeviceIdentifier device : deviceList) {
// org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt
// .common.DeviceIdentifier(device.getId(), device.getType());
// try {
// DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService();
// if (!dmpService.isEnrolled(deviceIdentifier)) {
// log.error("Device with ID: [" + device.getId() + "] is not enrolled to install the application.");
// } else {
// if (log.isDebugEnabled()) {
// log.debug("Installing application to : " + device.getId());
// }
// //Todo: generating one time download link for the application and put install operation to device.
//
// // put app install operation to the device
// ProfileOperation operation = new ProfileOperation();
// operation.setCode(INSTALL_APPLICATION);
// operation.setType(Operation.Type.PROFILE);
// operation.setPayLoad("{'type':'enterprise', 'url':'http://10.100.5.76:8000/app-debug.apk', 'app':'"
// + applicationUUID + "'}");
// List<org.wso2.carbon.device.mgt.common.DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
// deviceIdentifiers.add(deviceIdentifier);
// dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
// operation, deviceIdentifiers);
//
// DeviceApplicationMapping deviceApp = new DeviceApplicationMapping();
// deviceApp.setDeviceIdentifier(device.getId());
// deviceApp.setApplicationUUID(applicationUUID);
// deviceApp.setVersionName(versionName);
// deviceApp.setInstalled(false);
// dmpService.addDeviceApplicationMapping(deviceApp);
//// DeviceManagementDAOFactory.openConnection();
//// ApplicationManagementDAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false);
// failedDeviceList.remove(device);
// }
// } catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) {
// log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e);
// }
// finally {
// DeviceManagementDAOFactory.closeConnection();
// }
}
return failedDeviceList;
// }
// return failedDeviceList;
}
}

@ -28,6 +28,7 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.util.List;
//todo need to work on business logic
/**
* This is the default implementation for the visibility manager.
*/
@ -35,39 +36,40 @@ public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager {
@Override
public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException {
if (visibility == null) {
visibility = new Visibility();
visibility.setType(Visibility.Type.PUBLIC);
}
if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) {
throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType()
+ "' but doesn't have any allowed list provided!");
}
boolean isTransactionStarted = false;
try {
isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
if (!isTransactionStarted) {
ConnectionManagerUtil.beginDBTransaction();
}
VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType());
visibilityDAO.delete(applicationID);
visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList());
if (!isTransactionStarted) {
ConnectionManagerUtil.commitDBTransaction();
}
return visibility;
} catch (ApplicationManagementException e) {
if (!isTransactionStarted) {
ConnectionManagerUtil.rollbackDBTransaction();
}
throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
+ applicationID, e);
} finally {
if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection();
}
}
return null;
// if (visibility == null) {
// visibility = new Visibility();
// visibility.setType(Visibility.Type.PUBLIC);
// }
// if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) {
// throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType()
// + "' but doesn't have any allowed list provided!");
// }
// boolean isTransactionStarted = false;
// try {
// isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
// if (!isTransactionStarted) {
// ConnectionManagerUtil.beginDBTransaction();
// }
// VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
// int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType());
// visibilityDAO.delete(applicationID);
// visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList());
// if (!isTransactionStarted) {
// ConnectionManagerUtil.commitDBTransaction();
// }
// return visibility;
// } catch (ApplicationManagementException e) {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.rollbackDBTransaction();
// }
// throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
// + applicationID, e);
// } finally {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
}
@Override
@ -87,28 +89,28 @@ public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager {
@Override
public void remove(int applicationID) throws VisibilityManagementException {
boolean isTransactionStarted = false;
try {
isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
if (!isTransactionStarted) {
ConnectionManagerUtil.beginDBTransaction();
}
VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
visibilityDAO.delete(applicationID);
if (!isTransactionStarted) {
ConnectionManagerUtil.commitDBTransaction();
}
} catch (ApplicationManagementException e) {
if (!isTransactionStarted) {
ConnectionManagerUtil.rollbackDBTransaction();
}
throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - "
+ applicationID, e);
} finally {
if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection();
}
}
// boolean isTransactionStarted = false;
// try {
// isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
// if (!isTransactionStarted) {
// ConnectionManagerUtil.beginDBTransaction();
// }
// VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
// visibilityDAO.delete(applicationID);
// if (!isTransactionStarted) {
// ConnectionManagerUtil.commitDBTransaction();
// }
// } catch (ApplicationManagementException e) {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.rollbackDBTransaction();
// }
// throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - "
// + applicationID, e);
// } finally {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
}
}

@ -66,7 +66,7 @@
<tasks>
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
<fileset dir="${basedir}/target">
<include name="api#application-mgt#v1.0.war" />
<include name="api#application-mgt-publisher#v1.0.war" />
</fileset>
</copy>
</tasks>

@ -168,7 +168,7 @@ public interface ApplicationReleaseManagementAPI {
@POST
@Path("/upload-artifacts/{uuid}")
@Path("/update-image-artifacts/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -195,12 +195,13 @@ public interface ApplicationReleaseManagementAPI {
response = ErrorResponse.class)
})
Response updateApplicationImageArtifacts(
@ApiParam(name = "appId", value = "ID of the application", required = true) @PathParam("appId") int applicatioId,
@ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID,
@Multipart(value = "icon") Attachment iconFile, @Multipart(value = "banner") Attachment bannerFile,
@Multipart(value = "screenshot") List<Attachment> screenshots);
@PUT
@Path("/upload-artifacts/{uuid}")
@Path("/update-artifacts/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -226,11 +227,10 @@ public interface ApplicationReleaseManagementAPI {
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response updateApplicationArtifacts(
Response updateApplicationArtifact(
@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(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot", required = false) List<Attachment> screenshots);
@Multipart("binaryFile") Attachment binaryFile );
@PUT
@Path("/{appId}/{uuid}")

@ -58,7 +58,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* Implementation of Application Management related APIs.
*/
@ -70,7 +69,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
//todo need to pass uuid
@GET
@Override
@Consumes("application/json")
@ -117,7 +115,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@GET
@Consumes("application/json")
@Path("/{appType}")
public Response getApplication(@PathParam("appType") String appType, @QueryParam("appName") String appName) {
public Response getApplication(
@PathParam("appType") String appType,
@QueryParam("appName") String appName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
@ -161,10 +161,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build();
}
}catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting the device type";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application";
log.error(msg, e);

@ -145,7 +145,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
try {
List<UnrestrictedRole> unrestrictedRoles = unrestrictedRoleManager.getUnrestrictedRoles(applicationId, tenantId);
if(unrestrictedRoles == null || applicationManager.isUserAllowable(unrestrictedRoles,userName)){
applicationReleases= applicationReleaseManager.getReleases(applicationId);
applicationReleases = applicationReleaseManager.getReleases(applicationId);
return Response.status(Response.Status.OK).entity(applicationReleases).build();
}
@ -204,7 +204,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
iconFileStream, bannerFileStream, attachments);
if (applicationRelease != null) {
applicationRelease = applicationReleaseManager.updateRelease(applicationUUID, applicationRelease);
applicationRelease = applicationReleaseManager.updateRelease(applicationId, applicationRelease);
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
@ -213,54 +213,52 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
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);
}
catch (ResourceManagementException e) {
log.error("Error occurred while updating 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);
}
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);
}
catch (ResourceManagementException e) {
log.error("Error occurred while updating 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);
}
}
//todo
@Override
@POST
@Path("/upload-image-artifacts/{uuid}")
public Response updateApplicationImageArtifacts(@PathParam("uuid") String applicationUUID,
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile,
@Path("/update-image-artifacts/{appId}/{uuid}")
public Response updateApplicationImageArtifacts(
@PathParam("appId") int appId,
@PathParam("uuid") String applicationUUID,
@Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationRelease applicationRelease = null;
try {
InputStream iconFileStream;
InputStream bannerFileStream;
InputStream iconFileStream = null;
InputStream bannerFileStream = null;
List<InputStream> attachments = new ArrayList<>();
if (iconFile != null) {
iconFileStream = iconFile.getDataHandler().getInputStream();
} else {
throw new ApplicationManagementException(
"Icon file is not uploaded for the application " + applicationUUID);
}
if (bannerFile != null) {
bannerFileStream = bannerFile.getDataHandler().getInputStream();
} else {
throw new ApplicationManagementException(
"Banner file is not uploaded for the application " + applicationUUID);
}
if (attachmentList != null && !attachmentList.isEmpty()) {
for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream());
}
} else {
throw new ApplicationManagementException(
"Screen-shot are not uploaded for the application " + applicationUUID);
}
// applicationStorageManager
// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
applicationRelease = applicationStorageManager.updateImageArtifacts
(appId, applicationUUID, iconFileStream, bannerFileStream, attachments);
applicationReleaseManager.updateRelease(appId,applicationRelease);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUUID).build();
} catch (NotFoundException e) {
@ -275,54 +273,53 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
"Exception while trying to read icon, " + "banner files for the application " +
applicationUUID, e), Response.Status.BAD_REQUEST);
}
// catch (ResourceManagementException e) {
// log.error("Error occurred while uploading the image artifacts of the application with the uuid "
// + applicationUUID, e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
//todo
@Override
@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) {
@Path("/update-artifacts/{appId}/{uuid}")
public Response updateApplicationArtifact(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuuid,
@Multipart("binaryFile") Attachment binaryFile) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationRelease applicationRelease = null;
try {
InputStream iconFileStream = null;
InputStream bannerFileStream = null;
List<InputStream> attachments = new ArrayList<>();
if (iconFile != null) {
iconFileStream = iconFile.getDataHandler().getInputStream();
}
if (bannerFile != null) {
bannerFileStream = bannerFile.getDataHandler().getInputStream();
}
if (attachmentList != null) {
for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream());
}
if (binaryFile != null) {
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationId, applicationUuuid,
binaryFile.getDataHandler().getInputStream());
applicationReleaseManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuuid).build();
}
// applicationStorageManager
// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
return Response.status(Response.Status.OK)
.entity("Successfully updated artifacts for the application " + applicationUUID).build();
return Response.status(Response.Status.BAD_REQUEST)
.entity("Uploading artifacts for the application is failed " + applicationUuuid).build();
} 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 " + applicationUuuid);
return APIUtil.getResponse(new ApplicationManagementException(
"Exception while trying to read icon, banner files for the application " +
applicationUUID, e), Response.Status.BAD_REQUEST);
applicationUuuid, e), Response.Status.BAD_REQUEST);
}
catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUuuid, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (ApplicationManagementException e) {
log.error("Error occurred while updating the image artifacts of the application with the uuid "
+ applicationUuuid, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
// catch (ResourceManagementException e) {
// log.error("Error occurred while uploading the image artifacts of the application with the uuid "
// + applicationUUID, e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
}
//todo
@Override
@DELETE
@Path("/release/{uuid}")

@ -45,16 +45,17 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
@GET
public Response getLifecycleStates() {
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
List<LifecycleState> lifecycleStates = new ArrayList<>();
try {
lifecycleStates = lifecycleStateManager.getLifecycleStates();
} catch (LifecycleManagementException e) {
String msg = "Error occurred while retrieving lifecycle states.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity(lifecycleStates).build();
return null;
// LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
// List<LifecycleState> lifecycleStates = new ArrayList<>();
// try {
// lifecycleStates = lifecycleStateManager.getLifecycleStates();
// } catch (LifecycleManagementException e) {
// String msg = "Error occurred while retrieving lifecycle states.";
// log.error(msg, e);
// return Response.status(Response.Status.BAD_REQUEST).build();
// }
// return Response.status(Response.Status.OK).entity(lifecycleStates).build();
}
@POST
@ -73,15 +74,16 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
@DELETE
@Path("/{identifier}")
public Response deleteLifecycleState(@PathParam("identifier") String identifier) {
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
try {
lifecycleStateManager.deleteLifecycleState(identifier);
} catch (LifecycleManagementException e) {
String msg = "Error occurred while deleting lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity("Lifecycle state deleted successfully.").build();
return null;
// LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
// try {
// lifecycleStateManager.deleteLifecycleState(identifier);
// } catch (LifecycleManagementException e) {
// String msg = "Error occurred while deleting lifecycle state.";
// log.error(msg, e);
// return Response.status(Response.Status.BAD_REQUEST).build();
// }
// return Response.status(Response.Status.OK).entity("Lifecycle state deleted successfully.").build();
}
// @PUT

@ -21,24 +21,13 @@ package org.wso2.carbon.device.application.mgt.store.api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
=======
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
>>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
=======
>>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import javax.ws.rs.core.Response;
@ -49,16 +38,12 @@ public class APIUtil {
private static Log log = LogFactory.getLog(APIUtil.class);
<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java
private static ApplicationManager applicationManager;
private static LifecycleStateManager lifecycleStateManager;
private static ApplicationReleaseManager applicationReleaseManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static CategoryManager categoryManager;
=======
>>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java
public static ApplicationManager getApplicationManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationManager applicationManager = (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
@ -70,20 +55,6 @@ public class APIUtil {
return applicationManager;
}
<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java
=======
public static PlatformManager getPlatformManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformManager platformManager = (PlatformManager) ctx.getOSGiService(PlatformManager.class, null);
if (platformManager == null) {
String msg = "Platform Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return platformManager;
}
>>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java
public static LifecycleStateManager getLifecycleStateManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
LifecycleStateManager lifecycleStateManager = (LifecycleStateManager) ctx
@ -130,55 +101,6 @@ public class APIUtil {
return applicationStorageManager;
}
/**
<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java
=======
* To get the Platform Storage Manager from the osgi context.
*
* @return PlatformStoreManager instance in the current osgi context.
*/
public static PlatformStorageManager getPlatformStorageManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformStorageManager platformStorageManager = (PlatformStorageManager) ctx
.getOSGiService(PlatformStorageManager.class, null);
if (platformStorageManager == null) {
String msg = "Platform Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return platformStorageManager;
}
/**
>>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java
* To get the Category Manager from the osgi context.
*
* @return CategoryManager instance in the current osgi context.
*/
public static CategoryManager getCategoryManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
CategoryManager categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
if (categoryManager == null) {
String msg = "Category Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return categoryManager;
}
public static Response getResponse(Exception ex, Response.Status status) {
return getResponse(ex.getMessage(), status);
}
public static Response getResponse(String message, Response.Status status) {
ErrorResponse errorMessage = new ErrorResponse();
errorMessage.setMessage(message);
if (status == null) {
status = Response.Status.INTERNAL_SERVER_ERROR;
}
errorMessage.setCode(status.getStatusCode());
return Response.status(status).entity(errorMessage).build();
}
/**
* To get the Subscription Manager from the osgi context.
@ -213,4 +135,19 @@ public class APIUtil {
}
return commentsManager;
}
public static Response getResponse(Exception ex, Response.Status status) {
return getResponse(ex.getMessage(), status);
}
public static Response getResponse(String message, Response.Status status) {
ErrorResponse errorMessage = new ErrorResponse();
errorMessage.setMessage(message);
if (status == null) {
status = Response.Status.INTERNAL_SERVER_ERROR;
}
errorMessage.setCode(status.getStatusCode());
return Response.status(status).entity(errorMessage).build();
}
}

@ -217,42 +217,6 @@ public interface ApplicationManagementAPI {
@QueryParam("appName") String appName
);
@GET
@Path("/release-artifacts/{uuid}/{version}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_OCTET_STREAM,
httpMethod = "GET",
value = "Get an application release",
notes = "This will return the application release indicated by Application UUID and version",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved the Application release.",
response = Attachment.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response getApplicationReleaseArtifacts(
@ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
@ApiParam(name = "Version", value = "Version of the Application release need to be retrieved", required = true) @PathParam("version") String version);
@GET
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ -284,38 +248,4 @@ public interface ApplicationManagementAPI {
@ApiParam(name = "ID", value = "Identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
@ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version);
@GET
@Path("/image-artifacts/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete the releases of a particular applicaion",
notes = "This will delete the releases or specific release of an application",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the Application release."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the release of a"
+ "particular application.",
response = ErrorResponse.class)
})
Response getApplicationImageArtifacts(
@ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
@ApiParam(name = "name", value = "Name of the artifact to be retrieved", required = true) @QueryParam("name") String name,
@ApiParam(name = "count", value = "Count of the screen-shot artifact to be retrieved", required = false) @QueryParam("count") int count);
}

@ -163,51 +163,4 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
// }
}
//todo We must remove following methods - By DLPDS
@Override
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/release-artifacts/{uuid}/{version}")
public Response getApplicationReleaseArtifacts(@PathParam("uuid") String applicationUUID,
@PathParam("version") String version) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
InputStream binaryFile = applicationStorageManager.getReleasedArtifacts(applicationUUID, version);
FileStreamingOutput fileStreamingOutput = new FileStreamingOutput(binaryFile);
Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(fileStreamingOutput);
response.header("Content-Disposition", "attachment; filename=\"" + version + "\"");
return response.build();
} catch (ApplicationStorageManagementException e) {
log.error("Error while retrieving the binary file of the application release for the application UUID " +
applicationUUID + " and version " + version, e);
if (e.getMessage().contains("Binary file does not exist")) {
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} else {
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}
@Override
@GET
@Path("/image-artifacts/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
public Response getApplicationImageArtifacts(@PathParam("uuid") String applicationUUID,
@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();
}
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(applicationUUID, name, count);
Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(imageArtifact);
return response.build();
} catch (ApplicationStorageManagementException e) {
log.error("Application Storage Management Exception while getting the image artifact " + name + " of "
+ "the application with UUID " + applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}

@ -41,7 +41,7 @@
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<id>publisher-copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
@ -50,7 +50,7 @@
<artifactItems>
<artifactItem>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.api
<artifactId>org.wso2.carbon.device.application.mgt.publisher.api
</artifactId>
<version>${project.version}</version>
<type>war</type>
@ -58,7 +58,30 @@
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#application-mgt#v1.0.war</destFileName>
<destFileName>api#application-mgt-publisher#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>store-copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.store.api
</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#application-mgt-store#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>

Loading…
Cancel
Save