Search in sources :

Example 1 with SynchroRelated

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;
}
Also used : SynchroRelated(org.maxkey.entity.SynchroRelated) Organizations(org.maxkey.entity.Organizations)

Example 2 with SynchroRelated

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();
    }
}
Also used : WorkWeixinDeptsResponse(org.maxkey.synchronizer.workweixin.entity.WorkWeixinDeptsResponse) Organizations(org.maxkey.entity.Organizations) SynchroRelated(org.maxkey.entity.SynchroRelated) WorkWeixinDepts(org.maxkey.synchronizer.workweixin.entity.WorkWeixinDepts)

Example 3 with SynchroRelated

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);
    }
}
Also used : Attribute(javax.naming.directory.Attribute) HashMap(java.util.HashMap) SynchroRelated(org.maxkey.entity.SynchroRelated) SearchResult(javax.naming.directory.SearchResult) UserInfo(org.maxkey.entity.UserInfo) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException)

Example 4 with SynchroRelated

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 .");
    }
}
Also used : OapiV2DepartmentListsubResponse(com.dingtalk.api.response.OapiV2DepartmentListsubResponse) Organizations(org.maxkey.entity.Organizations) SynchroRelated(org.maxkey.entity.SynchroRelated) OapiV2DepartmentGetResponse(com.dingtalk.api.response.OapiV2DepartmentGetResponse) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DeptBaseResponse(com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseResponse) NoSuchElementException(java.util.NoSuchElementException) ApiException(com.taobao.api.ApiException)

Example 5 with SynchroRelated

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;
}
Also used : SynchroRelated(org.maxkey.entity.SynchroRelated) Organizations(org.maxkey.entity.Organizations)

Aggregations

SynchroRelated (org.maxkey.entity.SynchroRelated)14 Organizations (org.maxkey.entity.Organizations)8 UserInfo (org.maxkey.entity.UserInfo)5 NamingException (javax.naming.NamingException)4 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Attribute (javax.naming.directory.Attribute)2 SearchControls (javax.naming.directory.SearchControls)2 SearchResult (javax.naming.directory.SearchResult)2 HistorySynchronizer (org.maxkey.entity.HistorySynchronizer)2 HttpRequestAdapter (org.maxkey.web.HttpRequestAdapter)2 DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)1 DingTalkClient (com.dingtalk.api.DingTalkClient)1 OapiV2UserListRequest (com.dingtalk.api.request.OapiV2UserListRequest)1 OapiV2DepartmentGetResponse (com.dingtalk.api.response.OapiV2DepartmentGetResponse)1 OapiV2DepartmentListsubResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse)1 DeptBaseResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseResponse)1 OapiV2UserListResponse (com.dingtalk.api.response.OapiV2UserListResponse)1 ListUserResponse (com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse)1