use of org.maxkey.synchronizer.feishu.entity.FeishuDeptsResponse in project MaxKey by dromara.
the class FeishuOrganizationService method requestDepartment.
public FeishuDeptsResponse requestDepartment(String url, String deptId, String access_token) {
HttpRequestAdapter request = new HttpRequestAdapter();
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", AuthorizationHeaderUtils.createBearer(access_token));
String responseBody = request.get(String.format(url, deptId), headers);
FeishuDeptsResponse deptsResponse = JsonUtils.gson2Object(responseBody, FeishuDeptsResponse.class);
_logger.trace("response : " + responseBody);
return deptsResponse;
}
use of org.maxkey.synchronizer.feishu.entity.FeishuDeptsResponse in project MaxKey by dromara.
the class FeishuOrganizationService method requestDepartmentList.
public FeishuDeptsResponse requestDepartmentList(String access_token, String deptId) {
HttpRequestAdapter request = new HttpRequestAdapter();
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", AuthorizationHeaderUtils.createBearer(access_token));
String responseBody = request.get(String.format(DEPTS_URL, deptId), headers);
FeishuDeptsResponse deptsResponse = JsonUtils.gson2Object(responseBody, FeishuDeptsResponse.class);
_logger.trace("response : " + responseBody);
return deptsResponse;
}
use of org.maxkey.synchronizer.feishu.entity.FeishuDeptsResponse in project MaxKey by dromara.
the class FeishuOrganizationService method sync.
public void sync() {
_logger.info("Sync Feishu Organizations ...");
LinkedBlockingQueue<String> deptsQueue = new LinkedBlockingQueue<String>();
deptsQueue.add(ROOT_DEPT_ID);
// root
FeishuDeptsResponse rspRoot = requestDepartment(ROOT_DEPT_URL, ROOT_DEPT_ID, access_token);
Organizations rootOrganization = organizationsService.get(Organizations.ROOT_ORG_ID);
SynchroRelated rootSynchroRelated = buildSynchroRelated(rootOrganization, rspRoot.getData().getDepartment());
synchroRelatedService.updateSynchroRelated(this.synchronizer, rootSynchroRelated, Organizations.CLASS_TYPE);
// child
try {
while (deptsQueue.element() != null) {
FeishuDeptsResponse rsp = requestDepartmentList(access_token, deptsQueue.poll());
if (rsp.getCode() == 0 && rsp.getData().getItems() != null) {
for (FeishuDepts dept : rsp.getData().getItems()) {
_logger.debug("dept : id {} , Parent {} , Name {} , od {}", dept.getDepartment_id(), dept.getParent_department_id(), dept.getName(), dept.getOpen_department_id());
deptsQueue.add(dept.getOpen_department_id());
// synchro Related
SynchroRelated synchroRelated = synchroRelatedService.findByOriginId(this.synchronizer, dept.getOpen_department_id(), Organizations.CLASS_TYPE);
Organizations organization = buildOrganization(dept);
if (synchroRelated == null) {
organization.setId(organization.generateId());
organizationsService.insert(organization);
_logger.debug("Organizations : " + organization);
synchroRelated = buildSynchroRelated(organization, dept);
} else {
organization.setId(synchroRelated.getObjectId());
organizationsService.update(organization);
}
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, Organizations.CLASS_TYPE);
}
}
}
} catch (NoSuchElementException e) {
_logger.debug("Sync Department successful .");
}
}
Aggregations