|
|
@ -17,9 +17,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationReleaseArtifactPaths;
|
|
|
|
|
|
|
|
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.services.ApplicationStorageManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
|
|
@ -29,7 +29,8 @@ 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.ApplicationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
|
|
|
|
|
|
|
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 java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
@ -37,42 +38,54 @@ import java.io.InputStream;
|
|
|
|
public class AppmDataHandlerImpl implements AppmDataHandler {
|
|
|
|
public class AppmDataHandlerImpl implements AppmDataHandler {
|
|
|
|
|
|
|
|
|
|
|
|
private UIConfiguration uiConfiguration;
|
|
|
|
private UIConfiguration uiConfiguration;
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(AppmDataHandlerImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AppmDataHandlerImpl(UIConfiguration config) {
|
|
|
|
public AppmDataHandlerImpl(UIConfiguration config) {
|
|
|
|
this.uiConfiguration = config;
|
|
|
|
this.uiConfiguration = config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public UIConfiguration getUIConfiguration() throws ApplicationManagementException {
|
|
|
|
public UIConfiguration getUIConfiguration() {
|
|
|
|
return this.uiConfiguration;
|
|
|
|
return this.uiConfiguration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
// throws ApplicationManagementException
|
|
|
|
public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException {
|
|
|
|
public InputStream getArtifactStream(String uuid, String artifactName) {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
|
|
|
ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
|
|
|
String artifactPath;
|
|
|
|
String artifactPath;
|
|
|
|
|
|
|
|
String appReleaseHashValue;
|
|
|
|
String appReleaseHashValue = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
appReleaseHashValue = applicationReleaseDAO.getReleaseHashValue(uuid, tenantId);
|
|
|
|
appReleaseHashValue = applicationReleaseDAO.getReleaseHashValue(uuid, tenantId);
|
|
|
|
|
|
|
|
if (appReleaseHashValue == null) {
|
|
|
|
|
|
|
|
String msg = "Could't find application release for UUID: " + uuid + ". Hence try with valid UUID.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
artifactPath = appReleaseHashValue + Constants.FORWARD_SLASH + artifactName;
|
|
|
|
artifactPath = appReleaseHashValue + Constants.FORWARD_SLASH + artifactName;
|
|
|
|
return applicationStorageManager.getFileSttream(artifactPath);
|
|
|
|
InputStream inputStream = applicationStorageManager.getFileSttream(artifactPath);
|
|
|
|
|
|
|
|
if (inputStream == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't file the file in the file system. File path: " + artifactPath;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return inputStream;
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
// todo throw
|
|
|
|
String msg =
|
|
|
|
// throw new ApplicationManagementException();
|
|
|
|
"Error occurred when retrieving application release hash value for given application release UUID: "
|
|
|
|
// e.printStackTrace();
|
|
|
|
+ uuid;
|
|
|
|
}catch (ApplicationStorageManagementException e) {
|
|
|
|
log.error(msg);
|
|
|
|
// todo throw
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
// throw new ApplicationManagementException();
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
String msg = "Error occurred when getting input stream of the " + artifactName + " file.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|