All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.envision.energy.demo.SimpleAssetSubDemo Maven / Gradle / Ivy
package com.envision.energy.demo;
import com.envision.energy.eos.exception.EOSClientException;
import com.envision.energy.eos.exception.SubscribeException;
import com.envision.energy.eos.sdk.EOSClient;
import com.envision.energy.eos.sdk.IAssetHandler;
import com.envision.energy.eos.sdk.IAssetService;
import com.envision.energy.eos.sdk.data.AssetChangeDetail;
import com.envision.energy.eos.sdk.data.AssetChangeResponse;
import com.envision.energy.util.AssetChangeEventUtil;
import com.google.common.collect.Lists;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.envision.energy.util.AssetChangeEventUtil.INSERT;
import static com.envision.energy.util.AssetChangeEventUtil.UPDATE;
import static com.envision.energy.util.AssetChangeEventUtil.DELETE;
/**
* @author zhensheng.cai
*/
public class SimpleAssetSubDemo {
private static Logger logger = LogManager.getLogger(SimpleAssetSubDemo.class);
private static String appKey = "xxxxxx";
private static String host = "xxxxxx";
private static String appSecret = "xxxxxx";
public static void startSimpleDemo(){
EOSClient client;
try {
client = new EOSClient(appKey, appSecret, host);
IAssetService service = client.getAssetService();
try {
service.subscribe(new IAssetHandler() {
@Override
public void assetChangeRead(AssetChangeResponse response) {
String event = response.getEvent();
List details = response.getData();
for (AssetChangeDetail detail : details) {
//发生变更的主数据ID
String mdmId = detail.getMdmId();
//变更的领域模型类型
int typeId = detail.getTypeId();
//变更主数据所属资产树上的祖先节点
String parentId = detail.getParentId();
System.out.println(String.format("mdmId: %s , event: %s , type:%s , ancestors:%s", mdmId, event, typeId, parentId));
}
}
},
AssetChangeEventUtil.subscribe(Arrays.asList(INSERT, UPDATE, DELETE)),
Arrays.asList("ancestorId1"), Arrays.asList(206));
service.subscribeAncestors(new IAssetHandler() {
@Override
public void assetChangeRead(AssetChangeResponse response) {
String event = response.getEvent();
List details = response.getData();
for (AssetChangeDetail detail : details) {
//发生变更的主数据ID
String mdmId = detail.getMdmId();
//变更的领域模型类型
int typeId = detail.getTypeId();
//变更主数据所属资产树上的祖先节点
String parentId = detail.getParentId();
System.out.println(String.format("mdmId: %s , event: %s , type:%s , ancestors:%s", mdmId, event, typeId, parentId));
}
}
} ,AssetChangeEventUtil.subscribe(Arrays.asList(INSERT, UPDATE, DELETE)), Arrays.asList("ancestorB"));
service.subscribeTypes(new IAssetHandler() {
@Override
public void assetChangeRead(AssetChangeResponse response) {
String event = response.getEvent();
List details = response.getData();
for (AssetChangeDetail detail : details) {
//发生变更的主数据ID
String mdmId = detail.getMdmId();
//变更的领域模型类型
int typeId = detail.getTypeId();
//变更主数据所属资产树上的祖先节点
String parentId = detail.getParentId();
System.out.println(String.format("mdmId: %s , event: %s , type:%s , ancestors:%s", mdmId, event, typeId, parentId));
}
}
},AssetChangeEventUtil.subscribe(Arrays.asList(INSERT, UPDATE, DELETE)), Arrays.asList(207));
} catch (SubscribeException e) {
logger.error("subscribe err ", e);
}
}
catch (EOSClientException e ){
logger.error("init client err ", e);
}
}
public static void main(String[] args) {
startSimpleDemo();
}
}