Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

...

5 Commits

35
Jenkinsfile vendored

@ -5,7 +5,6 @@ pipeline {
environment {
def isPendingUpstreamDependenciesExists = false
def triggeredViaPush = false
SCANNER_HOME = tool 'sonar-scanner'
JAVA_HOME = '/usr/lib/jvm/java-11-openjdk'
PATH = "${JAVA_HOME}/bin:${env.PATH}"
}
@ -48,22 +47,6 @@ pipeline {
}
}
}
stage('Check SonarQube Installation') {
steps {
script {
echo "Initial JAVA_HOME: ${env.JAVA_HOME}"
echo "Initial PATH: ${env.PATH}"
withEnv(["JAVA_HOME=${env.JAVA_HOME}", "PATH=${env.JAVA_HOME}/bin:${env.PATH}"]) {
sh """
java -version
${SCANNER_HOME}/bin/sonar-scanner --version
"""
}
}
}
}
stage('Fetch Pending Upstream Dependencies') {
steps {
@ -111,24 +94,6 @@ pipeline {
}
}
}
stage('Code Quality Check') {
steps {
script {
def projectName = "device-mgt-core-${env.CHANGE_ID}"
def projectKey = "device-mgt-core-${env.CHANGE_ID}"
withSonarQubeEnv('sonar') {
sh """
$SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectName=${projectName} \
-Dsonar.projectKey=${projectKey} \
-Dsonar.java.binaries=target
"""
}
}
}
}
stage('Report Job Status') {
steps {

@ -48,6 +48,8 @@ import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import javax.ws.rs.core.Response;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -503,31 +505,29 @@ public class APIUtil {
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
applicationRelease.setRating(applicationReleaseDTO.getRating());
applicationRelease.setIconPath(
basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName());
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())){
basePath + Constants.ICON_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getIconName(), StandardCharsets.UTF_8));
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) {
applicationRelease.setBannerPath(
basePath + Constants.BANNER_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO
.getBannerName());
basePath + Constants.BANNER_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getBannerName(), StandardCharsets.UTF_8));
}
applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(),
applicationReleaseDTO.getAppHashValue()));
applicationRelease.setInstallerPath(
constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName1());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName1(), StandardCharsets.UTF_8));
}
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName2());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName2(), StandardCharsets.UTF_8));
}
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName3());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName3(), StandardCharsets.UTF_8));
}
applicationRelease.setScreenshots(screenshotPaths);
return applicationRelease;
@ -543,9 +543,12 @@ public class APIUtil {
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
UrlValidator urlValidator = new UrlValidator();
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName) ? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName;
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH +
appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName)
? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(installerName, StandardCharsets.UTF_8);
}
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {

@ -140,6 +140,11 @@ public class Constants {
public static final String DB_TYPE_POSTGRESQL = "PostgreSQL";
}
/**
* Query parameter for specifying the filename in the App artifact URL.
*/
public static final String FILE_NAME_PARAM = "?fileName=";
/**
* Directory name of the icon artifact that are saved in the file system.
*/

@ -54,6 +54,8 @@ public class Application implements Serializable {
private int memoryUsage;
@ApiModelProperty(name = "isActive", value = "Is the application actively running", required = true)
private boolean isActive;
@ApiModelProperty(name = "isSystemApp", value = "Is the application a system app", required = true)
private boolean isSystemApp;
@ApiModelProperty(name = "hourlyUsage", value = "App hourly usage")
private long hourlyUsage;
@ApiModelProperty(name = "dailyUsage", value = "App daily usage")
@ -186,6 +188,14 @@ public class Application implements Serializable {
isActive = active;
}
public boolean isSystemApp() {
return isSystemApp;
}
public void setSystemApp(boolean system) {
isSystemApp = system;
}
public long getHourlyUsage() {
return hourlyUsage;
}

@ -258,7 +258,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (installedApps.containsKey(newApp.getApplicationIdentifier())) {
Application oldApp = installedApps.get(newApp.getApplicationIdentifier());
if (oldApp.isActive() != newApp.isActive() || oldApp.getMemoryUsage() != newApp.getMemoryUsage()
|| !newApp.getVersion().equals(oldApp.getVersion())) {
|| !newApp.getVersion().equals(oldApp.getVersion()) || oldApp.isSystemApp() != newApp.isSystemApp()) {
newApp.setId(oldApp.getId());
appsToUpdate.put(newApp.getApplicationIdentifier(), newApp);
}

@ -56,8 +56,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, " +
"CATEGORY, VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID, " +
"APP_IDENTIFIER, MEMORY_USAGE, IS_ACTIVE, DEVICE_ID, ENROLMENT_ID) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
"APP_IDENTIFIER, MEMORY_USAGE, IS_ACTIVE, DEVICE_ID, ENROLMENT_ID, IS_SYSTEM_APP) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
for (Application application : applications) {
stmt.setString(1, application.getName());
@ -73,6 +73,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setBoolean(11, application.isActive());
stmt.setInt(12, deviceId);
stmt.setInt(13, enrolmentId);
stmt.setBoolean(14, application.isSystemApp());
stmt.addBatch();
}
stmt.executeBatch();
@ -91,7 +92,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
try {
conn = this.getConnection();
stmt = conn.prepareStatement("UPDATE DM_APPLICATION SET NAME = ?, PLATFORM = ?, CATEGORY = ?, " +
"VERSION = ?, TYPE = ?, LOCATION_URL = ?, IMAGE_URL = ?, MEMORY_USAGE = ?, IS_ACTIVE = ? " +
"VERSION = ?, TYPE = ?, LOCATION_URL = ?, IMAGE_URL = ?, MEMORY_USAGE = ?, IS_ACTIVE = ?, IS_SYSTEM_APP = ? " +
"WHERE ID = ?");
for (Application application : applications) {
@ -104,7 +105,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setString(7, application.getImageUrl());
stmt.setInt(8, application.getMemoryUsage());
stmt.setBoolean(9, application.isActive());
stmt.setInt(10, application.getId());
stmt.setBoolean(10, application.isSystemApp());
stmt.setInt(11, application.getId());
stmt.addBatch();
}
stmt.executeBatch();
@ -422,6 +424,46 @@ public class ApplicationDAOImpl implements ApplicationDAO {
return application;
}
private Application loadApplicationDetails(ResultSet rs) throws DeviceManagementDAOException {
ByteArrayInputStream bais;
ObjectInputStream ois;
Properties properties;
Application application = new Application();
try {
application.setId(rs.getInt("ID"));
application.setName(rs.getString("NAME"));
application.setType(rs.getString("TYPE"));
if (rs.getBytes("APP_PROPERTIES") != null) {
byte[] appProperties = rs.getBytes("APP_PROPERTIES");
bais = new ByteArrayInputStream(appProperties);
ois = new ObjectInputStream(bais);
properties = (Properties) ois.readObject();
application.setAppProperties(properties);
}
application.setCategory(rs.getString("CATEGORY"));
application.setImageUrl(rs.getString("IMAGE_URL"));
application.setLocationUrl(rs.getString("LOCATION_URL"));
application.setPlatform(rs.getString("PLATFORM"));
application.setVersion(rs.getString("VERSION"));
application.setMemoryUsage(rs.getInt("MEMORY_USAGE"));
application.setActive(rs.getBoolean("IS_ACTIVE"));
application.setSystemApp(rs.getBoolean("IS_SYSTEM_APP"));
application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER"));
} catch (IOException e) {
throw new DeviceManagementDAOException("IO error occurred fetch at app properties", e);
} catch (ClassNotFoundException e) {
throw new DeviceManagementDAOException("Class not found error occurred fetch at app properties", e);
} catch (SQLException e) {
throw new DeviceManagementDAOException("SQL error occurred fetch at application", e);
}
return application;
}
@Override
public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
throws DeviceManagementDAOException{
@ -565,6 +607,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
"APP_PROPERTIES, " +
"MEMORY_USAGE, " +
"IS_ACTIVE, " +
"IS_SYSTEM_APP, " +
"TENANT_ID " +
"FROM DM_APPLICATION " +
"WHERE DEVICE_ID = ? AND " +
@ -582,7 +625,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setInt(5, offset);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
application = loadApplication(rs);
application = loadApplicationDetails(rs);
applicationList.add(application);
}
}
@ -615,6 +658,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
"APP_PROPERTIES, " +
"MEMORY_USAGE, " +
"IS_ACTIVE, " +
"IS_SYSTEM_APP, " +
"TENANT_ID " +
"FROM DM_APPLICATION " +
"WHERE DEVICE_ID = ? AND " +
@ -628,7 +672,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
application = loadApplication(rs);
application = loadApplicationDetails(rs);
applicationList.add(application);
}
}

Loading…
Cancel
Save