Resolve conflicts

feature/appm-store/pbac
geethkokila 6 years ago
commit 0dea5cd0aa

@ -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<Tag> 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<UnrestrictedRole> 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<ApplicationRelease> applicationReleases;
public int getId() {

@ -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() {

@ -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<String> 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<String> getNextStates() {
return nextStates;
}

@ -93,6 +93,20 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</jacoco-agent.destfile>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

@ -33,7 +33,7 @@ public interface LifecycleStateDAO {
List<LifecycleState> 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;

@ -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) {

@ -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);

@ -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;

@ -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);
}
}

@ -20,4 +20,9 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="ApplicationManagementCore">
<test name="Util classes tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.application.mgt.core.ArtifactParserTest"/>
</classes>
</test>
</suite>

@ -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",

@ -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<InputStream> attachments = new ArrayList<>();
List<ApplicationRelease> 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<Attachment> 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());

@ -2196,7 +2196,10 @@
<googlecode.plist.version>1.8</googlecode.plist.version>
<net.dongliu.version>2.4.2</net.dongliu.version>
<<<<<<< HEAD
=======
>>>>>>> 625589decc78a4f3da8091a227c0fac6e2617c9e
<!--websocket related lib versions-->
<tomcat.websocket.version>7.0.85</tomcat.websocket.version>
<javax.websocket.version>1.0</javax.websocket.version>

Loading…
Cancel
Save