diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java index 401611ea9a7..eb08e78034b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java @@ -19,72 +19,73 @@ package org.wso2.carbon.device.application.mgt.common; -import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import java.util.List; -/** - * Application represents the an Application in Application Store. - */ + +@ApiModel(value = "Application", description = "Application represents the an Application in Application Store") public class Application { - @Exclude + @ApiModelProperty(name = "id", + value = "The ID given to the application when it is stored in the APPM database") private int id; - /** - * Name of the application - */ + @ApiModelProperty(name = "name", + value = "Name of the application", + required = true) private String name; - /** - * Category of the application. - * e.g: Educational, Gaming, Travel, Entertainment etc. - */ + @ApiModelProperty(name = "appCategory", + value = "Category of the application", + required = true, + example = "Educational, Gaming, Travel, Entertainment etc") private String appCategory; - /** - * Type of the application - * e.g. Mobile, Web, Web Clip etc - */ + @ApiModelProperty(name = "type", + value = "Type of the application", + required = true, + example = "Mobile, Web, Web Clip etc") private String type; - /** - * Subscription type of the application. - * e.g: PAID, FREE - */ + @ApiModelProperty(name = "subType", + value = "Subscription type of the application", + required = true, + example = "PAID, FREE") private String subType; - /** - * Payment currency of the application and the default value is '$'. - */ + @ApiModelProperty(name = "paymentCurrency", + value = "Payment currency of the application", + required = true, + example = "$") private String paymentCurrency; - /** - * List of application tags - */ + @ApiModelProperty(name = "tags", + value = "List of application tags") private List tags; - /** - * Application creating user - */ + @ApiModelProperty(name = "user", + value = "Application creating user") private User user; - /** - * List of roles that users should have to access the application - */ + @ApiModelProperty(name = "unrestrictedRoles", + value = "List of roles that users should have to access the application") private List unrestrictedRoles; - /** - * If unrestricted roles are defined then isRestricted value is true otherwise it is false. - */ + @ApiModelProperty(name = "isRestricted", + value = "If unrestricted roles are defined then isRestricted value is true otherwise it is false") private boolean isRestricted; - /** - * Related device type of the application. - * e.g: IoS, Android, Arduino, RaspberryPi etc - */ + @ApiModelProperty(name = "deviceType", + value = "Related device type of the application", + required = true, + example = "IoS, Android, Arduino, RaspberryPi etc") private String deviceType; + @ApiModelProperty(name = "applicationReleases", + value = "List of application releases", + required = true) private List applicationReleases; public int getId() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index 6c425ab8c8c..2d23fed141b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -18,107 +18,91 @@ */ package org.wso2.carbon.device.application.mgt.common; -import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; -import java.sql.Timestamp; - -/** - * This class holds the details when releasing an Application to application store. - */ +@ApiModel(value = "ApplicationRelease", description = "This class holds the details when releasing an Application to application store") public class ApplicationRelease { - @Exclude + @ApiModelProperty(name = "id", + value = "ID of the application release") private int id; - /** - * Version of the application release - */ + @ApiModelProperty(name = "version", + value = "Version of the application release") private String version; - /** - * UUID of the application release - */ + @ApiModelProperty(name = "uuid", + value = "UUID of the application release") private String uuid; - /** - * Application storing location - */ + @ApiModelProperty(name = "appStoredLoc", + value = "Application storing location") private String appStoredLoc; - /** - * Banner file storing location - */ + @ApiModelProperty(name = "bannerLoc", + value = "Banner file storing location") private String bannerLoc; - /** - * Screenshot storing location - */ + @ApiModelProperty(name = "screenshotLoc1", + value = "Screenshot storing location") private String screenshotLoc1; - /** - * Screenshot storing location - */ + @ApiModelProperty(name = "screenshotLoc2", + value = "Screenshot storing location") private String screenshotLoc2; - /** - * Screenshot storing location - */ + @ApiModelProperty(name = "screenshotLoc3", + value = "Screenshot storing location") private String screenshotLoc3; - /** - * Application release creator - */ + @ApiModelProperty(name = "iconLoc", + value = "icon file storing location") + private String iconLoc; + + @ApiModelProperty(name = "applicationCreator", + value = "Application release creator") private String applicationCreator; - /** - * Release type of the application release - * e.g: alpha, beta etc - */ + @ApiModelProperty(name = "releaseType", + value = "Release type of the application release", + required = true, + example = "alpha, beta etc") private String releaseType; - /** - * Price of the application release - */ + @ApiModelProperty(name = "price", + value = "Price of the application release", + required = true) private Double price; - /** - * icon file storing location - */ - private String iconLoc; - - /** - * Hash value of the application release - */ + @ApiModelProperty(name = "appHashValue", + value = "Hash value of the application release") private String appHashValue; - /** - * If application release is shared with all tenants it is eqal to 1 otherwise 0 - */ + @ApiModelProperty(name = "isSharedWithAllTenants", + value = "If application release is shared with all tenants it is eqal to 1 otherwise 0", + required = true) private int isSharedWithAllTenants; - /** - * MEta data of the application release - */ + @ApiModelProperty(name = "metaData", + value = "Meta data of the application release", + required = true) private String metaData; - /** - * Number of users who has rated the application release - */ + @ApiModelProperty(name = "ratedUsers", + value = "Number of users who has rated the application release") private int ratedUsers; - /** - * Rating value of the application release - */ + @ApiModelProperty(name = "rating", + value = "Rating value of the application release") private Double rating; - /** - * URL which is used for WEB-CLIP - */ + @ApiModelProperty(name = "url", + value = "URL which is used for WEB-CLIP") private String url; - /** - * Latest Lifecycle state of the application release - */ + @ApiModelProperty(name = "lifecycleState", + value = "Latest Lifecycle state of the application release") private LifecycleState lifecycleState; public int getRatedUsers() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java index fdb1a27c51d..2c0dc8349bb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java @@ -19,28 +19,41 @@ package org.wso2.carbon.device.application.mgt.common; import java.sql.Timestamp; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.util.List; +@ApiModel(value = "LifecycleState", description = "LifecycleState represents the an Lifecycle state for an application release") public class LifecycleState { + @ApiModelProperty(name = "id", + value = "ID of the application release lifecycle", + required = true) private int id; + @ApiModelProperty(name = "currentState", + value = "Current state of the application release", + required = true) private String currentState; + @ApiModelProperty(name = "previousState", + value = "Previous state of the application release", + required = true) private String previousState; + @ApiModelProperty(name = "nextStates", + value = "Next possible transferring states from the current state") private List nextStates; + @ApiModelProperty(name = "updatedBy", + value = "Username who is update the application release state") private String updatedBy; + @ApiModelProperty(name = "updatedAt", + value = "Timestamp of the lifecycle has been updated") private Timestamp updatedAt; - private int tenantId; - - private int releaseId; - - private int appId; - public int getId() { return id; } @@ -81,30 +94,6 @@ public class LifecycleState { this.updatedAt = updatedAt; } - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } - - public int getReleaseId() { - return releaseId; - } - - public void setReleaseId(int releaseId) { - this.releaseId = releaseId; - } - - public int getAppId() { - return appId; - } - - public void setAppId(int appId) { - this.appId = appId; - } - public List getNextStates() { return nextStates; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index c5043c346fe..932265189f6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -93,6 +93,20 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + src/test/resources/testng.xml + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + file:src/test/resources/log4j.properties + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java index d9d12356ec2..6fec1ee2b03 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java @@ -33,7 +33,7 @@ public interface LifecycleStateDAO { List getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException; - void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException; + void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException; void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index e2a0b0198ab..c9286d0ffc0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -92,7 +92,6 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); - lifecycleState.setTenantId(rs.getInt("TENANT_ID")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleStates.add(lifecycleState); @@ -109,7 +108,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif } @Override - public void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException { + public void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException { Connection conn = null; PreparedStatement stmt = null; try { @@ -119,10 +118,10 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif stmt = conn.prepareStatement(sql); stmt.setString(1, state.getCurrentState()); stmt.setString(2, state.getPreviousState()); - stmt.setInt(3, state.getTenantId()); + stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); - stmt.setInt(5, state.getReleaseId()); - stmt.setInt(6, state.getAppId()); + stmt.setInt(5, releaseId); + stmt.setInt(6, appId); stmt.executeUpdate(); } catch (DBConnectionException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 2dfad505f27..6ffa3699604 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -126,21 +126,23 @@ public class ApplicationManagerImpl implements ApplicationManager { "Invalid payload. Application creating payload should contains one application release, but " + "the payload contains more than one"); } - ConnectionManagerUtil.commitDBTransaction(); applicationRelease = application.getApplicationReleases().get(0); applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO(). createRelease(applicationRelease, application.getId(), tenantId); + LifecycleState lifecycleState = new LifecycleState(); - lifecycleState.setAppId(application.getId()); - lifecycleState.setReleaseId(applicationRelease.getId()); lifecycleState.setUpdatedBy(userName); - lifecycleState.setTenantId(tenantId); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState); + LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); + lifecycleStateDAO.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); + applicationRelease.setLifecycleState(lifecycleState); applicationReleases.add(applicationRelease); application.setApplicationReleases(applicationReleases); + + ConnectionManagerUtil.commitDBTransaction(); } return application; @@ -155,7 +157,12 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg, e); ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException(msg, e); - } finally { + } catch (LifeCycleManagementDAOException e) { + String msg = "Error occurred while adding application lifecycle state"; + log.error(msg, e); + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationManagementException(msg, e); + }finally { ConnectionManagerUtil.closeDBConnection(); } } @@ -399,7 +406,6 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - newAppLifecycleState.setTenantId(tenantId); newAppLifecycleState.setUpdatedBy(userName); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); storedLocations.add(applicationRelease.getAppHashValue()); @@ -437,7 +443,6 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - newAppLifecycleState.setTenantId(tenantId); newAppLifecycleState.setUpdatedBy(userName); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); }else{ @@ -710,17 +715,12 @@ public class ApplicationManagerImpl implements ApplicationManager { Application application = validateApplication(applicationId); ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid); LifecycleStateDAO lifecycleStateDAO; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - if (application != null) { - state.setAppId(applicationId); - } - if (applicationRelease != null) { - state.setReleaseId(applicationRelease.getId()); - } if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) { validateLifecycleState(state); lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - lifecycleStateDAO.addLifecycleState(state); + lifecycleStateDAO.addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId); } } catch (LifeCycleManagementDAOException | DBConnectionException e) { throw new ApplicationManagementException("Failed to add lifecycle state", e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java index f7fa79de60e..09b37e4e789 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.UUID; +import java.nio.file.Files; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ArtifactParserTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ArtifactParserTest.java new file mode 100644 index 00000000000..a8bb924ad5b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ArtifactParserTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.application.mgt.core; + +import com.dd.plist.NSDictionary; +import net.dongliu.apk.parser.bean.ApkMeta; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.wso2.carbon.device.application.mgt.core.exception.ParsingException; +import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + +public class ArtifactParserTest { + private static final String APK_FILE = "src/test/resources/util/app-debug.apk"; + private static final String APK_FILE_INVALID = "src/test/resources/util/app-debug1.apk"; + private static final String IPA_FILE = "src/test/resources/util/iOSMDMAgent.ipa"; + private static final String IPA_FILE_INVALID = "src/test/resources/util/iOSMDMAgent1.ipa"; + + @Test + public void testReadAndroidManifestFile() throws FileNotFoundException, ParsingException { + InputStream apk = new FileInputStream(APK_FILE); + ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(apk); + Assert.assertEquals(apkMeta.getVersionName(), "1.0", "APK version name extraction failed."); + Assert.assertEquals(apkMeta.getPackageName(), "com.games.inosh.myapplication", + "APK package name extraction failed."); + } + + @Test(expectedExceptions = java.io.FileNotFoundException.class) + public void testReadAndroidManifestInvalidFile() throws FileNotFoundException, ParsingException { + InputStream apk = new FileInputStream(APK_FILE_INVALID); + ArtifactsParser.readAndroidManifestFile(apk); + } + + @Test + public void testReadiOSManifestFile() throws FileNotFoundException, ParsingException { + InputStream ipa = new FileInputStream(IPA_FILE); + NSDictionary ipaDictionary = ArtifactsParser.readiOSManifestFile(ipa); + Assert.assertEquals(ipaDictionary.objectForKey(ArtifactsParser.IPA_BUNDLE_IDENTIFIER_KEY).toString(), + "org.wso2.carbon.emm.ios.agent.inosh", "IPA bundle ID extraction failed."); + Assert.assertEquals(ipaDictionary.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString(), + "GA", "IPA file version name extraction failed."); + } + + @Test(expectedExceptions = java.io.FileNotFoundException.class) + public void testReadiOSManifestInvalidFile() throws FileNotFoundException, ParsingException { + InputStream ipa = new FileInputStream(IPA_FILE_INVALID); + ArtifactsParser.readiOSManifestFile(ipa); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml index 0af96a3777a..ca512950bcb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml @@ -20,4 +20,9 @@ + + + + + \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/app-debug.apk b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/app-debug.apk new file mode 100644 index 00000000000..52bb95ed215 Binary files /dev/null and b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/app-debug.apk differ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/iOSMDMAgent.ipa b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/iOSMDMAgent.ipa new file mode 100644 index 00000000000..13af8f3cdb8 Binary files /dev/null and b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/iOSMDMAgent.ipa differ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index b7d73018c54..aee5a524e3b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -279,10 +279,6 @@ public interface ApplicationManagementAPI { value = "The application that need to be created.", required = true) @Valid Application application, - @ApiParam( - name = "applicationRelease", - value = "Application Release") - @Valid ApplicationRelease applicationRelease, @ApiParam( name = "binaryFile", value = "Binary file of uploading application", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index f36ef23f831..7c4fe746c35 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -109,7 +109,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Consumes("application/json") public Response createApplication( @Valid Application application, - @Valid ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment binaryFile, @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @@ -120,18 +119,24 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { InputStream bannerFileStream; List attachments = new ArrayList<>(); List applicationReleases = new ArrayList<>(); + ApplicationRelease applicationRelease; try { - if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) { return Response.status(Response.Status.BAD_REQUEST).build(); - } else if (binaryFile == null && ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + } + if (ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + applicationRelease = application.getApplicationReleases().get(0); applicationRelease = applicationStorageManager .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), null); - } else if (binaryFile != null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + } else { + applicationRelease = application.getApplicationReleases().get(0); applicationRelease = applicationStorageManager .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), binaryFile.getDataHandler().getInputStream()); + if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } } iconFileStream = iconFile.getDataHandler().getInputStream(); @@ -140,13 +145,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { for (Attachment screenshot : attachmentList) { attachments.add(screenshot.getDataHandler().getInputStream()); } - - if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } applicationRelease = applicationStorageManager.uploadImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments); - applicationRelease.setUuid(UUID.randomUUID().toString()); applicationReleases.add(applicationRelease); application.setApplicationReleases(applicationReleases); @@ -452,6 +452,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { private boolean isValidAppCreatingRequest(Attachment binaryFile, Attachment iconFile, Attachment bannerFile, List attachmentList, Application application){ + if (application.getApplicationReleases().size() > 1) { + log.error( + "Invalid application creating request. Application creating request must have single application " + + "release. Application name:" + application.getName() + " and type: " + + application.getType()); + return false; + } + if (iconFile == null) { log.error("Icon file is not found for the application release. Application name: " + application.getName() + " and type: " + application.getType()); diff --git a/pom.xml b/pom.xml index b142d1fefc4..ee4b6ff4109 100644 --- a/pom.xml +++ b/pom.xml @@ -2196,7 +2196,10 @@ 1.8 2.4.2 +<<<<<<< HEAD +======= +>>>>>>> 625589decc78a4f3da8091a227c0fac6e2617c9e 7.0.85 1.0