Search in sources :

Example 1 with MobileApplication

use of org.wso2.mdm.qsg.dto.MobileApplication in project product-iots by wso2.

the class QSGExecutor method main.

public static void main(String[] args) {
    boolean status = false;
    // prompt for the user's name
    /*
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter your email address and press enter : ");
        String email = scanner.next();
        if (!QSGUtils.isValidEmailAddress(email)) {
            do {
                System.out.print("Please enter a valid email address and press enter : ");
                email = scanner.next();
            } while (!QSGUtils.isValidEmailAddress(email));
        }
        */
    String email = "alex@example.com";
    // Setup the OAuth token
    String token = QSGUtils.getOAuthToken();
    if (token == null) {
        System.out.println("Unable to get the OAuth token. Please check the config.properties file.");
        System.exit(0);
    }
    HTTPInvoker.oAuthToken = token;
    // Creates the admin user
    System.out.println("Creating users ");
    status = UserOperations.createUser(iotAdminUser, iotAdminEmail, true);
    if (!status) {
        System.out.println("Unable to create the admin user. Please check the config.properties file.");
        System.exit(0);
    }
    status = UserOperations.changePassword(iotAdminUser, iotAdminPassword);
    if (!status) {
        System.out.println("Unable to change the password of the admin user. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    // Creates the emm user
    status = UserOperations.createUser(iotMobileUser, email, false);
    if (!status) {
        System.out.println("Unable to create the iot user ryan. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    status = UserOperations.changePassword(iotMobileUser, iotMobileUserPassword);
    if (!status) {
        System.out.println("Unable to change the password of the iot user. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    // Creates the emm-user role
    System.out.println("Creating iotMobileUser role");
    status = UserOperations.createRole(roleName, new String[] { iotMobileUser });
    if (!status) {
        System.out.println("Unable to create the emm user role. Terminating the IoTs QSG now.");
        System.exit(0);
    }
    System.out.println("Adding sample policies ");
    // Add the android policy
    status = PolicyOperations.createPasscodePolicy("android-passcode-policy1", Constants.DeviceType.ANDROID);
    if (!status) {
        System.out.println("Unable to create the android passcode policy. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    // Add the windows policy
    status = PolicyOperations.createPasscodePolicy("windows-passcode-policy1", Constants.DeviceType.WINDOWS);
    if (!status) {
        System.out.println("Unable to create the windows passcode policy. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    System.out.println("Upload the android application ");
    // Upload the android application
    MobileApplication application = AppOperations.uploadApplication(Constants.DeviceType.ANDROID, "con-app.apk", "application/vnd.android.package-archive");
    if (application == null) {
        System.out.println("Unable to upload the sample android application. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    // Upload the assets
    application = AppOperations.uploadAssets(Constants.DeviceType.ANDROID, application);
    if (application == null) {
        System.out.println("Unable to upload the assets for sample android application. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    System.out.println("Create the android application ");
    // Create application entry in publisher
    status = AppOperations.addApplication("WSO2Con-Android", application, true);
    if (!status) {
        System.out.println("Unable to create the android mobile application. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    System.out.println("Upload the iOS application ");
    // Add the iOS policy
    status = PolicyOperations.createPasscodePolicy("ios-passcode-policy1", Constants.DeviceType.IOS);
    if (!status) {
        System.out.println("Unable to create the ios passcode policy. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    // Upload the ios application
    MobileApplication iOSApplication = AppOperations.uploadApplication(Constants.DeviceType.IOS, "PNDemo.ipa", "application/octet-stream");
    iOSApplication.setVersion("1.0.0");
    // Upload the assets
    iOSApplication = AppOperations.uploadAssets(Constants.DeviceType.IOS, iOSApplication);
    if (iOSApplication == null) {
        System.out.println("Unable to upload the assets for sample iOS application. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    System.out.println("Create the iOS application ");
    // Create application entry in publisher
    status = AppOperations.addApplication("WSO2Con-iOS", iOSApplication, true);
    if (!status) {
        System.out.println("Unable to create the iOS mobile application. Terminating the IoTS QSG now.");
        System.exit(0);
    }
    System.out.println("Exit");
}
Also used : MobileApplication(org.wso2.mdm.qsg.dto.MobileApplication)

Example 2 with MobileApplication

use of org.wso2.mdm.qsg.dto.MobileApplication in project product-iots by wso2.

the class AppOperations method addApplication.

public static boolean addApplication(String name, MobileApplication mblApp, boolean isEnterpriseApp) {
    HashMap<String, String> headers = new HashMap<String, String>();
    String appEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherAppsUrl;
    // Set the application payload
    JSONObject application = new JSONObject();
    application.put("name", name);
    application.put("description", "Sample application");
    application.put("type", "enterprise");
    // Set appMeta data
    JSONObject appMeta = new JSONObject();
    appMeta.put("package", mblApp.getPackageId());
    appMeta.put("version", mblApp.getVersion());
    if (isEnterpriseApp) {
        application.put("marketType", "enterprise");
        appMeta.put("path", mblApp.getAppId());
    } else {
        application.put("marketType", "public");
    }
    application.put("provider", "admin");
    application.put("displayName", name);
    application.put("category", "Business");
    application.put("thumbnailUrl", mblApp.getIcon());
    application.put("version", mblApp.getVersion());
    application.put("banner", mblApp.getBanner());
    application.put("platform", mblApp.getPlatform());
    application.put("appType", mblApp.getPlatform());
    // application.put("appUrL", mblApp.getAppId());
    application.put("mediaType", "application/vnd.wso2-mobileapp+xml");
    // Set screenshots
    JSONArray screenshots = new JSONArray();
    screenshots.add(mblApp.getScreenshot1());
    screenshots.add(mblApp.getScreenshot2());
    screenshots.add(mblApp.getScreenshot3());
    application.put("appmeta", appMeta);
    application.put("screenshots", screenshots);
    // Set the headers
    headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
    HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(appEndpoint, application.toJSONString(), headers);
    if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
        return true;
    }
    return false;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONArray(org.json.simple.JSONArray)

Example 3 with MobileApplication

use of org.wso2.mdm.qsg.dto.MobileApplication in project product-iots by wso2.

the class AppOperations method uploadApplication.

public static MobileApplication uploadApplication(String platform, String appName, String appContentType) {
    String appUploadEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherMobileBinariesUrl;
    String filePath = "apps" + File.separator + platform + File.separator + appName;
    HTTPResponse httpResponse = HTTPInvoker.uploadFile(appUploadEndpoint, filePath, appContentType);
    if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
        JSONObject appMeta = null;
        MobileApplication application = new MobileApplication();
        try {
            appMeta = (JSONObject) new JSONParser().parse(httpResponse.getResponse());
            application.setPackageId((String) appMeta.get("package"));
            application.setAppId(QSGUtils.getResourceId((String) appMeta.get("path")));
            application.setVersion((String) appMeta.get("version"));
            application.setPlatform(platform);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return application;
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) MobileApplication(org.wso2.mdm.qsg.dto.MobileApplication) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 4 with MobileApplication

use of org.wso2.mdm.qsg.dto.MobileApplication in project product-iots by wso2.

the class AppOperations method getPublicApplication.

public static MobileApplication getPublicApplication(String packageId, String version, String platform) {
    MobileApplication application = new MobileApplication();
    application.setVersion(version);
    application.setPackageId(packageId);
    application.setPlatform(platform);
    return application;
}
Also used : MobileApplication(org.wso2.mdm.qsg.dto.MobileApplication)

Aggregations

MobileApplication (org.wso2.mdm.qsg.dto.MobileApplication)3 JSONObject (org.json.simple.JSONObject)2 HTTPResponse (org.wso2.mdm.qsg.dto.HTTPResponse)2 HashMap (java.util.HashMap)1 JSONArray (org.json.simple.JSONArray)1 JSONParser (org.json.simple.parser.JSONParser)1 ParseException (org.json.simple.parser.ParseException)1