This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package type validation while uploading the package(s).
- Loading branch information
1 parent
22a4e8c
commit 24b3f04
Showing
5 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...g/app/com/microsoft/azure/iotsolutions/uiconfig/webservice/v1/helpers/PackagesHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.microsoft.azure.iotsolutions.uiconfig.webservice.v1.helpers; | ||
|
||
import com.microsoft.azure.iotsolutions.uiconfig.services.exceptions.InvalidConfigurationException; | ||
import com.microsoft.azure.iotsolutions.uiconfig.services.models.PackageType; | ||
import com.microsoft.azure.sdk.iot.service.Configuration; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import play.libs.Json; | ||
|
||
import static play.libs.Json.fromJson; | ||
|
||
public class PackagesHelper { | ||
|
||
/** | ||
* This function is used to verify if the package type and package contents are | ||
* compatible. for eg:- if package type is DeviceConfiguration it should contain | ||
* "devicesContent" object. | ||
*/ | ||
public static boolean verifyPackageType(String packageContent, String packageType) { | ||
if (packageType.equals(PackageType.edgeManifest.toString()) && isEdgePackage(packageContent)) { | ||
return true; | ||
} else if (packageType.equals(PackageType.deviceConfiguration.toString()) | ||
&& !(isEdgePackage(packageContent))) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static boolean isEdgePackage(String packageContent) { | ||
final Configuration pckgContent = fromJson(Json.parse(packageContent), Configuration.class); | ||
|
||
if (MapUtils.isNotEmpty(pckgContent.getContent().getModulesContent()) && | ||
MapUtils.isEmpty(pckgContent.getContent().getDeviceContent())) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters