Skip to content

Commit

Permalink
API 2.3.0 Testing: IAMService, notification management
Browse files Browse the repository at this point in the history
  • Loading branch information
arihantjain97 authored and JuziAha committed Apr 7, 2023
1 parent 8c0f8ea commit 2b84535
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 26 deletions.
16 changes: 14 additions & 2 deletions src/main/java/com/envisioniot/example/sample/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import com.envisioniot.example.sample.aep.appportal.AppPortalApp;
import com.envisioniot.example.sample.aep.bpm.BpmApp;
import com.envisioniot.example.sample.aep.iamservice.IAMApp;
import com.envisioniot.example.sample.aep.iamservice.LogIn;
import com.envisioniot.example.sample.aep.notificationmanagement.NotificationManagementApp;
import com.envisioniot.example.sample.edp.streamprocessing.StreamProcessingApp;
import com.envisioniot.example.sample.edp.tsdbdata.TSDBDataApp;
import com.envisioniot.example.sample.edp.tsdbpolicy.TSDBPolicyApp;
Expand Down Expand Up @@ -118,8 +121,8 @@ public static void main(String[] args) {
// Asset Service
// https://support.envisioniot.com/docs/asset-api/en/2.3.0/overview.html

AssetApp asset = new AssetApp();
asset.assetAppGeneral(accessKey, secretKey, orgId, url);
/* AssetApp asset = new AssetApp();
asset.assetAppGeneral(accessKey, secretKey, orgId, url);*/


// Alert
Expand All @@ -146,8 +149,17 @@ public static void main(String[] args) {
/* AppPortalApp appPortalApp = new AppPortalApp();
appPortalApp.appPortalGeneral(accessKey, secretKey, orgId, url);*/

/*
BpmApp bpmApp = new BpmApp();
bpmApp.bpmAppGeneral(accessKey, secretKey, orgId, url);
*/

/* IAMApp iamApp = new IAMApp();
iamApp.IAMAppGeneral(accessKey, secretKey, orgId, url);*/

/* NotificationManagementApp notificationManagementApp = new NotificationManagementApp();
notificationManagementApp.notificationManagementApp(accessKey, secretKey, orgId, url);*/


}

Expand Down
26 changes: 2 additions & 24 deletions src/main/java/com/envisioniot/example/sample/aep/bpm/BpmApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,6 @@
public class BpmApp {
public void bpmAppGeneral(String accessKey, String secretKey, String orgId, String url) {

// JSON structure testing. Ignore in sample code.

// Type 1: https://www.envisioniot.com/docs/api/en/2.3.0/overview.html#pagination-request-struct
JSONObject type1SortersJSON = new JSONObject();
type1SortersJSON.put("field", "started");
type1SortersJSON.put("order", "ASC");
JSONArray type1SortersArray = new JSONArray();
type1SortersArray.add(type1SortersJSON);
JSONObject type1JSON = new JSONObject();
type1JSON.put("pageNo", 0);
type1JSON.put("pageSize", 3);
type1JSON.put("sorters", type1SortersArray);

// Type 2: https://www.envisioniot.com/docs/bpm-api/en/2.3.0/process/query_process_instance.html#pagination-struct
JSONObject type2SortersJSON = new JSONObject();
type2SortersJSON.put("field", "started");
type2SortersJSON.put("order", "asc");
JSONArray type2SortersArray = new JSONArray();
type2SortersArray.add(type2SortersJSON);
JSONObject type2JSON = new JSONObject();
type2JSON.put("current", 0);
type2JSON.put("pageSize", 3);
type2JSON.put("sorts", type2SortersArray);

/*
* 1. Login Session
* you need to follow this flow to make your own session control
Expand Down Expand Up @@ -231,6 +207,7 @@ public void bpmAppGeneral(String accessKey, String secretKey, String orgId, Stri
(accessKey, secretKey, url, accessToken, "4c40da46-a9eb-11ec-ad0f-8e1ac2659f4c", completeTaskParams);*/

// Claim And Complete Task
/*
ClaimAndCompleteTask claimandcompletetask = new ClaimAndCompleteTask();
HashMap<String, Object> claimAndCompleteTaskParams = new HashMap<>();
Expand All @@ -256,6 +233,7 @@ public void bpmAppGeneral(String accessKey, String secretKey, String orgId, Stri
claimandcompletetask.claimAndCompleteTask
(accessKey, secretKey, url, accessToken, "484a641c-a9f1-11ec-ad0f-8e1ac2659f4c", claimAndCompleteTaskParams);
*/


}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (C), 2015-2022, Envision
* FileName: GetOrganization
* Author: arihant.jain
* Date: 24/3/2022
* Description:
* History:
* <author> <time> <version> <desc>
*/

package com.envisioniot.example.sample.aep.iamservice;

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.example.sample.utility.Request;

/**
* https://www.envisioniot.com/docs/iam-api/en/2.3.0/get_org.html <br>
*
* @author arihant.jain
* @create 24/3/2022
* @since --
*/

public class GetOrganization {
public JSONObject getOrganization(
String accessKey,
String secretKey,
String url,
String orgId,
String bearerToken)
{
Request request = new Request();
request.setHeaderParam("Authorization", "Bearer " + bearerToken);
request.setHeaderParam("Content-Type", "application/json");
request.setBodyParams("id", orgId);
request.setMethod("POST");

try {
JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
.url(url + "/enos-iam-service/v2.0/organization/info")
.getResponse(request, JSONObject.class);

return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (C), 2015-2022, Envision
* FileName: GetSessionInformation
* Author: arihant.jain
* Date: 23/3/2022
* Description:
* History:
* <author> <time> <version> <desc>
*/

package com.envisioniot.example.sample.aep.iamservice;

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.example.sample.utility.Request;

/**
* https://www.envisioniot.com/docs/iam-api/en/2.3.0/get_session_information.html <br>
*
* @author arihant.jain
* @create 23/3/2022
* @since --
*/

public class GetSessionInformation {
public JSONObject getSessionInformation(
String accessKey,
String secretKey,
String url,
String bearerToken)
{

Request request = new Request();
request.setHeaderParam("Authorization", "Bearer " + bearerToken);

request.setMethod("POST");

try {
JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
.url(url + "/enos-iam-service/v2.0/session/info")
.getResponse(request, JSONObject.class);

//System.out.println(response);
return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (C), 2015-2022, Envision
* FileName: IAMApp
* Author: arihant.jain
* Date: 23/3/2022
* Description:
* History:
* <author> <time> <version> <desc>
*/

package com.envisioniot.example.sample.aep.iamservice;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;

/**
* https://www.envisioniot.com/docs/iam-api/en/2.3.0/overview.html <br>
*
* @author arihant.jain
* @create 23/3/2022
* @since --
*/

public class IAMApp {
public void IAMAppGeneral(String accessKey, String secretKey, String orgId, String url) {

// Log In
LogIn login = new LogIn();
// Log In: Declaring optional parameters
HashMap<String, Object> logInOptionalParameters = new HashMap<>();
logInOptionalParameters.put("clientIp", "10.81.2.169");
logInOptionalParameters.put("expireInterval", 950);
logInOptionalParameters.put("captcha", "yourCaptcha");
//logInOptionalParameters.put("keyId", "yourKeyID");
JSONObject data = login.logIn
(accessKey, secretKey, url, 0, null, "yourPrincipal", "yourCredentials", logInOptionalParameters);
String bearerToken = (String) data.get("sessionId");

// Get Session Information
GetSessionInformation getSessionInformation = new GetSessionInformation();
getSessionInformation.getSessionInformation(accessKey, secretKey, url, bearerToken);
//getSessionInformation.getSessionInformation(accessKey, secretKey, url, " ");

// Get Organization
GetOrganization getOrganization = new GetOrganization();
getOrganization.getOrganization(accessKey, secretKey, url, orgId, bearerToken);

// List User Organization
ListUserOrganization listuserorganization = new ListUserOrganization();
listuserorganization.listUserOrganization(accessKey, secretKey, url, bearerToken);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (C), 2015-2022, Envision
* FileName: ListUserOrganization
* Author: arihant.jain
* Date: 24/3/2022
* Description:
* History:
* <author> <time> <version> <desc>
*/

package com.envisioniot.example.sample.aep.iamservice;

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.example.sample.utility.Request;

/**
* https://www.envisioniot.com/docs/iam-api/en/2.3.0/list_user_organization.html <br>
*
* @author arihant.jain
* @create 24/3/2022
* @since --
*/

public class ListUserOrganization {
public JSONObject listUserOrganization(
String accessKey,
String secretKey,
String url,
String bearerToken)
{
Request request = new Request();
request.setHeaderParam("Authorization", "Bearer " + bearerToken);
request.setMethod("POST");

try {
JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
.url(url + "/enos-iam-service/v2.0/user/organization/list")
.getResponse(request, JSONObject.class);

return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (C), 2015-2022, Envision
* FileName: LogIn
* Author: arihant.jain
* Date: 23/3/2022
* Description:
* History:
* <author> <time> <version> <desc>
*/

package com.envisioniot.example.sample.aep.iamservice;

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.example.sample.utility.Request;

import java.util.HashMap;

/**
* https://www.envisioniot.com/docs/iam-api/en/2.3.0/login.html <br>
*
* @author arihant.jain
* @create 23/3/2022
* @since --
*/

public class LogIn {
public JSONObject logIn(
String accessKey,
String secretKey,
String url,
Object authType,
String linkName,
String principal,
String credentials,
HashMap<String, Object> logInOptionalParams)
{

Request request = new Request();
request.setBodyParams("principal", principal);
request.setBodyParams("credentials", credentials);
request.setBodyParams("authType", authType);
if(linkName != null){ request.setBodyParams("linkName", linkName); }
if(logInOptionalParams != null){ request.setBodyParams(logInOptionalParams); }

request.setMethod("POST");

try {
JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
.url(url + "/enos-iam-service/v2.0/login")
.getResponse(request, JSONObject.class);

System.out.println(response);
return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;

}
}
Loading

0 comments on commit 2b84535

Please sign in to comment.