use of org.maxkey.entity.SynchroRelated in project MaxKey by dromara.
the class WorkweixinOrganizationService method buildOrganization.
public Organizations buildOrganization(WorkWeixinDepts dept) {
// Parent
SynchroRelated synchroRelatedParent = synchroRelatedService.findByOriginId(this.synchronizer, dept.getParentid() + "", Organizations.CLASS_TYPE);
Organizations org = new Organizations();
org.setName(dept.getName());
org.setCode(dept.getId() + "");
org.setParentId(synchroRelatedParent.getObjectId());
org.setParentName(synchroRelatedParent.getObjectName());
org.setSortIndex(dept.getOrder());
org.setInstId(this.synchronizer.getInstId());
org.setStatus(ConstsStatus.ACTIVE);
org.setDescription("WorkWeixin");
return org;
}
use of org.maxkey.entity.SynchroRelated in project MaxKey by dromara.
the class WorkweixinOrganizationService method sync.
public void sync() {
_logger.info("Sync Workweixin Organizations ...");
try {
WorkWeixinDeptsResponse rsp = requestDepartmentList(access_token);
for (WorkWeixinDepts dept : rsp.getDepartment()) {
_logger.debug("dept : " + dept.getId() + " " + dept.getName() + " " + dept.getParentid());
// root
if (dept.getId() == ROOT_DEPT_ID) {
Organizations rootOrganization = organizationsService.get(Organizations.ROOT_ORG_ID);
SynchroRelated rootSynchroRelated = buildSynchroRelated(rootOrganization, dept);
synchroRelatedService.updateSynchroRelated(this.synchronizer, rootSynchroRelated, Organizations.CLASS_TYPE);
} else {
// synchro Related
SynchroRelated synchroRelated = synchroRelatedService.findByOriginId(this.synchronizer, dept.getId() + "", 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 (Exception e) {
e.printStackTrace();
}
}
use of org.maxkey.entity.SynchroRelated in project MaxKey by dromara.
the class ActiveDirectoryUsersService method sync.
public void sync() {
_logger.info("Sync ActiveDirectory Users...");
loadOrgsByInstId(this.synchronizer.getInstId(), Organizations.ROOT_ORG_ID);
try {
SearchControls constraints = new SearchControls();
constraints.setSearchScope(ldapUtils.getSearchScope());
String filter = StringUtils.isNotBlank(this.getSynchronizer().getFilters()) ? getSynchronizer().getFilters() : "(&(objectClass=User))";
NamingEnumeration<SearchResult> results = ldapUtils.getConnection().search(ldapUtils.getBaseDN(), filter, constraints);
long recordCount = 0;
while (null != results && results.hasMoreElements()) {
Object obj = results.nextElement();
if (obj instanceof SearchResult) {
SearchResult sr = (SearchResult) obj;
if (sr.getNameInNamespace().contains("CN=Users,") || sr.getNameInNamespace().contains("OU=Domain Controllers,")) {
_logger.trace("Skip 'CN=Users' or 'OU=Domain Controllers' . ");
continue;
}
_logger.debug("Sync User {} , name [{}] , NameInNamespace [{}]", (++recordCount), sr.getName(), sr.getNameInNamespace());
HashMap<String, Attribute> attributeMap = new HashMap<String, Attribute>();
NamingEnumeration<? extends Attribute> attrs = sr.getAttributes().getAll();
while (null != attrs && attrs.hasMoreElements()) {
Attribute objAttrs = attrs.nextElement();
_logger.trace("attribute {} : {}", objAttrs.getID(), ActiveDirectoryUtils.getAttrStringValue(objAttrs));
attributeMap.put(objAttrs.getID().toLowerCase(), objAttrs);
}
String originId = DigestUtils.md5B64(sr.getNameInNamespace());
UserInfo userInfo = buildUserInfo(attributeMap, sr.getName(), sr.getNameInNamespace());
if (userInfo != null) {
userInfo.setPassword(userInfo.getUsername() + UserInfo.DEFAULT_PASSWORD_SUFFIX);
userInfoService.saveOrUpdate(userInfo);
_logger.info("userInfo " + userInfo);
SynchroRelated synchroRelated = new SynchroRelated(userInfo.getId(), userInfo.getUsername(), userInfo.getDisplayName(), UserInfo.CLASS_TYPE, synchronizer.getId(), synchronizer.getName(), originId, userInfo.getDisplayName(), "", "", synchronizer.getInstId());
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, UserInfo.CLASS_TYPE);
}
}
}
// ldapUtils.close();
} catch (NamingException e) {
_logger.error("NamingException ", e);
}
}
use of org.maxkey.entity.SynchroRelated in project MaxKey by dromara.
the class DingtalkOrganizationService method sync.
public void sync() {
_logger.info("Sync Dingtalk Organizations ...");
LinkedBlockingQueue<Long> deptsQueue = new LinkedBlockingQueue<Long>();
deptsQueue.add(ROOT_DEPT_ID);
try {
// root
Organizations rootOrganization = organizationsService.get(Organizations.ROOT_ORG_ID);
OapiV2DepartmentGetResponse rootDeptRsp = requestDepartment(access_token, ROOT_DEPT_ID);
_logger.debug("root dept deptId {} , name {} , parentId {}", rootDeptRsp.getResult().getDeptId(), rootDeptRsp.getResult().getName(), rootDeptRsp.getResult().getParentId());
// root
SynchroRelated rootSynchroRelated = buildSynchroRelated(rootOrganization, rootDeptRsp.getResult().getDeptId() + "", rootDeptRsp.getResult().getName(), rootDeptRsp.getResult().getParentId() + "");
synchroRelatedService.updateSynchroRelated(this.synchronizer, rootSynchroRelated, Organizations.CLASS_TYPE);
while (deptsQueue.element() != null) {
OapiV2DepartmentListsubResponse rsp = requestDepartmentList(access_token, deptsQueue.poll());
for (DeptBaseResponse dept : rsp.getResult()) {
_logger.debug("dept deptId {} , name {} , parentId {} ", dept.getDeptId(), dept.getName(), dept.getParentId());
deptsQueue.add(dept.getDeptId());
// synchro Related
SynchroRelated synchroRelated = synchroRelatedService.findByOriginId(this.synchronizer, dept.getDeptId() + "", 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.getDeptId() + "", dept.getName(), dept.getParentId() + "");
} else {
organization.setId(synchroRelated.getObjectId());
organizationsService.update(organization);
}
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, Organizations.CLASS_TYPE);
_logger.debug("Organizations : " + organization);
}
}
} catch (ApiException e) {
e.printStackTrace();
} catch (NoSuchElementException e) {
_logger.debug("Sync Department successful .");
}
}
use of org.maxkey.entity.SynchroRelated in project MaxKey by dromara.
the class FeishuOrganizationService method buildOrganization.
public Organizations buildOrganization(FeishuDepts dept) {
// Parent
SynchroRelated synchroRelatedParent = synchroRelatedService.findByOriginId(this.synchronizer, dept.getParent_department_id(), Organizations.CLASS_TYPE);
Organizations org = new Organizations();
org.setCode(dept.getDepartment_id() + "");
org.setName(dept.getName());
org.setFullName(dept.getName());
org.setParentId(synchroRelatedParent.getObjectId());
org.setParentName(synchroRelatedParent.getObjectName());
org.setSortIndex(Integer.parseInt(dept.getOrder()));
org.setInstId(this.synchronizer.getInstId());
org.setStatus(ConstsStatus.ACTIVE);
org.setDescription("Feishu");
return org;
}
Aggregations