@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.logging.LogFactory ;
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants ;
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.AppStoreApplication ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.EnterpriseApplication ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.EnterpriseApplication ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.HostedAppxApplication ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.HostedAppxApplication ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.HostedMSIApplication ;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.HostedMSIApplication ;
@ -62,64 +63,26 @@ public class MDMWindowsOperationUtil {
switch ( application . getType ( ) ) {
switch ( application . getType ( ) ) {
case ENTERPRISE :
case ENTERPRISE :
operation . setCode ( MDMAppConstants . WindowsConstants . INSTALL_ENTERPRISE_APPLICATION ) ;
EnterpriseApplication enterpriseApplication = new EnterpriseApplication ( ) ;
EnterpriseApplication enterpriseApplication = new EnterpriseApplication ( ) ;
if ( appType . equalsIgnoreCase ( MDMAppConstants . WindowsConstants . APPX ) ) {
createEnterpriseAppPayload ( appType , metaJsonArray , enterpriseApplication ) ;
HostedAppxApplication hostedAppxApplication = new HostedAppxApplication ( ) ;
operation . setCode ( MDMAppConstants . WindowsConstants . INSTALL_ENTERPRISE_APPLICATION ) ;
List < String > dependencyPackageList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < metaJsonArray . size ( ) ; i + + ) {
JsonElement metaElement = metaJsonArray . get ( i ) ;
JsonObject metaObject = metaElement . getAsJsonObject ( ) ;
if ( MDMAppConstants . WindowsConstants . APPX_PACKAGE_URI . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedAppxApplication . setPackageUri ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_PACKAGE_FAMILY_NAME . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedAppxApplication . setPackageFamilyName ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_DEPENDENCY_PACKAGE_URL . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
dependencyPackageList . add ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
hostedAppxApplication . setDependencyPackageUri ( dependencyPackageList ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_CERTIFICATE_HASH . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
hostedAppxApplication . setCertificateHash ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_ENCODED_CERT_CONTENT . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
hostedAppxApplication . setEncodedCertificate ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
}
enterpriseApplication . setHostedAppxApplication ( hostedAppxApplication ) ;
} else if ( appType . equalsIgnoreCase ( MDMAppConstants . WindowsConstants . MSI ) ) {
HostedMSIApplication hostedMSIApplication = new HostedMSIApplication ( ) ;
for ( int i = 0 ; i < metaJsonArray . size ( ) ; i + + ) {
JsonElement metaElement = metaJsonArray . get ( i ) ;
JsonObject metaObject = metaElement . getAsJsonObject ( ) ;
if ( MDMAppConstants . WindowsConstants . MSI_PRODUCT_ID . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setProductId ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . MSI_CONTENT_URI . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setContentUrl ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . MSI_FILE_HASH . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setFileHash ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
}
enterpriseApplication . setHostedMSIApplication ( hostedMSIApplication ) ;
}
operation . setPayLoad ( enterpriseApplication . toJSON ( ) ) ;
operation . setPayLoad ( enterpriseApplication . toJSON ( ) ) ;
break ;
break ;
case PUBLIC :
AppStoreApplication appStoreApplication = new AppStoreApplication ( ) ;
appStoreApplication . setType ( application . getType ( ) . toString ( ) ) ;
appStoreApplication . setPackageIdentifier ( application . getIdentifier ( ) ) ;
operation . setCode ( MDMAppConstants . WindowsConstants . INSTALL_STORE_APPLICATION ) ;
operation . setPayLoad ( appStoreApplication . toJSON ( ) ) ;
break ;
case WEB_CLIP :
case WEB_CLIP :
operation . setCode ( MDMAppConstants . WindowsConstants . INSTALL_WEB_CLIP_APPLICATION ) ;
WebClipApplication webClipApplication = new WebClipApplication ( ) ;
WebClipApplication webClipApplication = new WebClipApplication ( ) ;
webClipApplication . setUrl ( application . getLocation ( ) ) ;
webClipApplication . setUrl ( application . getLocation ( ) ) ;
webClipApplication . setName ( application . getName ( ) ) ;
webClipApplication . setName ( application . getName ( ) ) ;
webClipApplication . setIcon ( application . getIconImage ( ) ) ;
webClipApplication . setIcon ( application . getIconImage ( ) ) ;
webClipApplication . setProperties ( application . getProperties ( ) ) ;
webClipApplication . setProperties ( application . getProperties ( ) ) ;
webClipApplication . setType ( application . getType ( ) . toString ( ) ) ;
webClipApplication . setType ( application . getType ( ) . toString ( ) ) ;
operation . setCode ( MDMAppConstants . WindowsConstants . INSTALL_WEB_CLIP_APPLICATION ) ;
operation . setPayLoad ( webClipApplication . toJSON ( ) ) ;
operation . setPayLoad ( webClipApplication . toJSON ( ) ) ;
break ;
break ;
default :
default :
@ -148,64 +111,26 @@ public class MDMWindowsOperationUtil {
switch ( application . getType ( ) ) {
switch ( application . getType ( ) ) {
case ENTERPRISE :
case ENTERPRISE :
operation . setCode ( MDMAppConstants . WindowsConstants . UNINSTALL_ENTERPRISE_APPLICATION ) ;
EnterpriseApplication enterpriseApplication = new EnterpriseApplication ( ) ;
EnterpriseApplication enterpriseApplication = new EnterpriseApplication ( ) ;
if ( appType . equalsIgnoreCase ( MDMAppConstants . WindowsConstants . APPX ) ) {
createEnterpriseAppPayload ( appType , metaJsonArray , enterpriseApplication ) ;
HostedAppxApplication hostedAppxApplication = new HostedAppxApplication ( ) ;
operation . setCode ( MDMAppConstants . WindowsConstants . UNINSTALL_ENTERPRISE_APPLICATION ) ;
List < String > dependencyPackageList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < metaJsonArray . size ( ) ; i + + ) {
JsonElement metaElement = metaJsonArray . get ( i ) ;
JsonObject metaObject = metaElement . getAsJsonObject ( ) ;
if ( MDMAppConstants . WindowsConstants . APPX_PACKAGE_URI . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedAppxApplication . setPackageUri ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_PACKAGE_FAMILY_NAME . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedAppxApplication . setPackageFamilyName ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_DEPENDENCY_PACKAGE_URL . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
dependencyPackageList . add ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
hostedAppxApplication . setDependencyPackageUri ( dependencyPackageList ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_CERTIFICATE_HASH . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
hostedAppxApplication . setCertificateHash ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_ENCODED_CERT_CONTENT . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
hostedAppxApplication . setEncodedCertificate ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
}
enterpriseApplication . setHostedAppxApplication ( hostedAppxApplication ) ;
} else if ( appType . equalsIgnoreCase ( MDMAppConstants . WindowsConstants . MSI ) ) {
HostedMSIApplication hostedMSIApplication = new HostedMSIApplication ( ) ;
for ( int i = 0 ; i < metaJsonArray . size ( ) ; i + + ) {
JsonElement metaElement = metaJsonArray . get ( i ) ;
JsonObject metaObject = metaElement . getAsJsonObject ( ) ;
if ( MDMAppConstants . WindowsConstants . MSI_PRODUCT_ID . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setProductId ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . MSI_CONTENT_URI . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setContentUrl ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . MSI_FILE_HASH . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setFileHash ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
}
enterpriseApplication . setHostedMSIApplication ( hostedMSIApplication ) ;
}
operation . setPayLoad ( enterpriseApplication . toJSON ( ) ) ;
operation . setPayLoad ( enterpriseApplication . toJSON ( ) ) ;
break ;
break ;
case PUBLIC :
AppStoreApplication appStoreApplication = new AppStoreApplication ( ) ;
appStoreApplication . setType ( application . getType ( ) . toString ( ) ) ;
appStoreApplication . setPackageIdentifier ( application . getIdentifier ( ) ) ;
operation . setCode ( MDMAppConstants . WindowsConstants . UNINSTALL_STORE_APPLICATION ) ;
operation . setPayLoad ( appStoreApplication . toJSON ( ) ) ;
break ;
case WEB_CLIP :
case WEB_CLIP :
operation . setCode ( MDMAppConstants . WindowsConstants . UNINSTALL_WEB_CLIP_APPLICATION ) ;
WebClipApplication webClipApplication = new WebClipApplication ( ) ;
WebClipApplication webClipApplication = new WebClipApplication ( ) ;
webClipApplication . setUrl ( application . getLocation ( ) ) ;
webClipApplication . setUrl ( application . getLocation ( ) ) ;
webClipApplication . setName ( application . getName ( ) ) ;
webClipApplication . setName ( application . getName ( ) ) ;
webClipApplication . setIcon ( application . getIconImage ( ) ) ;
webClipApplication . setIcon ( application . getIconImage ( ) ) ;
webClipApplication . setProperties ( application . getProperties ( ) ) ;
webClipApplication . setProperties ( application . getProperties ( ) ) ;
webClipApplication . setType ( application . getType ( ) . toString ( ) ) ;
webClipApplication . setType ( application . getType ( ) . toString ( ) ) ;
operation . setCode ( MDMAppConstants . WindowsConstants . UNINSTALL_WEB_CLIP_APPLICATION ) ;
operation . setPayLoad ( webClipApplication . toJSON ( ) ) ;
operation . setPayLoad ( webClipApplication . toJSON ( ) ) ;
default :
default :
String msg = "Application type " + application . getType ( ) + " is not supported" ;
String msg = "Application type " + application . getType ( ) + " is not supported" ;
@ -216,6 +141,67 @@ public class MDMWindowsOperationUtil {
return operation ;
return operation ;
}
}
/ * *
* Helper method to create enterprise APPX and MSI app payloads for both install and uninstall operations
* @param appType contains whether the app type is APPX or MSI
* @param metaJsonArray JSON array containing metadata of APPX and MSI apps
* @param enterpriseApplication { @link EnterpriseApplication } contains operation payload content that will be sent to the device
* /
private static void createEnterpriseAppPayload ( String appType , JsonArray metaJsonArray , EnterpriseApplication enterpriseApplication ) {
JsonElement metaElement ;
JsonObject metaObject ;
if ( MDMAppConstants . WindowsConstants . APPX . equalsIgnoreCase ( appType ) ) {
HostedAppxApplication hostedAppxApplication = new HostedAppxApplication ( ) ;
List < String > dependencyPackageList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < metaJsonArray . size ( ) ; i + + ) {
metaElement = metaJsonArray . get ( i ) ;
metaObject = metaElement . getAsJsonObject ( ) ;
if ( MDMAppConstants . WindowsConstants . APPX_PACKAGE_URI . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedAppxApplication . setPackageUri ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_PACKAGE_FAMILY_NAME . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedAppxApplication . setPackageFamilyName ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_DEPENDENCY_PACKAGE_URL . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
dependencyPackageList . add ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
hostedAppxApplication . setDependencyPackageUri ( dependencyPackageList ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_CERTIFICATE_HASH . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
hostedAppxApplication . setCertificateHash ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . APPX_ENCODED_CERT_CONTENT . equals ( metaObject . get ( "key" ) . getAsString ( ) )
& & metaObject . has ( "value" ) ) {
hostedAppxApplication . setEncodedCertificate ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
}
enterpriseApplication . setHostedAppxApplication ( hostedAppxApplication ) ;
} else if ( MDMAppConstants . WindowsConstants . MSI . equalsIgnoreCase ( appType ) ) {
HostedMSIApplication hostedMSIApplication = new HostedMSIApplication ( ) ;
for ( int i = 0 ; i < metaJsonArray . size ( ) ; i + + ) {
metaElement = metaJsonArray . get ( i ) ;
metaObject = metaElement . getAsJsonObject ( ) ;
if ( MDMAppConstants . WindowsConstants . MSI_PRODUCT_ID . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setProductId ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . MSI_CONTENT_URI . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setContentUrl ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
else if ( MDMAppConstants . WindowsConstants . MSI_FILE_HASH . equals ( metaObject . get ( "key" ) . getAsString ( ) ) ) {
hostedMSIApplication . setFileHash ( metaObject . get ( "value" ) . getAsString ( ) . trim ( ) ) ;
}
}
enterpriseApplication . setHostedMSIApplication ( hostedMSIApplication ) ;
}
}
/ * *
/ * *
* Method to get the installer file extension type for windows type apps ( either appx or msi )
* Method to get the installer file extension type for windows type apps ( either appx or msi )
*
*
@ -223,8 +209,7 @@ public class MDMWindowsOperationUtil {
* @return string extension of the windows app types ( either appx or msi )
* @return string extension of the windows app types ( either appx or msi )
* /
* /
public static String windowsAppType ( String installerName ) {
public static String windowsAppType ( String installerName ) {
String extension = installerName . substring ( installerName . lastIndexOf ( "." ) + 1 ) ;
return installerName . substring ( installerName . lastIndexOf ( "." ) + 1 ) ;
return extension ;
}
}
/ * *
/ * *
@ -234,8 +219,7 @@ public class MDMWindowsOperationUtil {
* @return the metaData Json String as Json Array
* @return the metaData Json String as Json Array
* /
* /
public static JsonArray jsonStringToArray ( String metaData ) {
public static JsonArray jsonStringToArray ( String metaData ) {
JsonArray metaJsonArray = new JsonParser ( ) . parse ( metaData ) . getAsJsonArray ( ) ;
return new JsonParser ( ) . parse ( metaData ) . getAsJsonArray ( ) ;
return metaJsonArray ;
}
}