This commit is contained in:
MaxKey 2023-10-14 20:02:05 +08:00
commit 9c262146a4
4 changed files with 412 additions and 363 deletions

View File

@ -1,32 +1,27 @@
/* /*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top] * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.maxkey.synchronizer.jdbc; package org.dromara.maxkey.synchronizer.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.constants.ConstsStatus; import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.DbTableMetaData; import org.dromara.maxkey.entity.DbTableMetaData;
import org.dromara.maxkey.entity.HistorySynchronizer;
import org.dromara.maxkey.entity.Organizations; import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.synchronizer.AbstractSynchronizerService; import org.dromara.maxkey.synchronizer.AbstractSynchronizerService;
import org.dromara.maxkey.synchronizer.ISynchronizerService; import org.dromara.maxkey.synchronizer.ISynchronizerService;
@ -35,107 +30,126 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service import java.sql.Connection;
public class JdbcOrganizationService extends AbstractSynchronizerService implements ISynchronizerService{ import java.sql.ResultSet;
final static Logger _logger = LoggerFactory.getLogger(JdbcOrganizationService.class); import java.sql.SQLException;
static ArrayList< ColumnFieldMapper> mapperList = new ArrayList< ColumnFieldMapper>(); import java.sql.Statement;
import java.util.ArrayList;
public void sync() {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
if(StringUtils.isNotBlank(synchronizer.getOrgFilters())){
_logger.info("Sync Org Filters {}",synchronizer.getOrgFilters());
conn = JdbcUtils.connect(
synchronizer.getProviderUrl(),
synchronizer.getPrincipal(),
synchronizer.getCredentials(),
synchronizer.getDriverClass());
stmt = conn.createStatement();
rs = stmt.executeQuery(synchronizer.getOrgFilters());
while(rs.next()) {
Organizations org = buildOrganization(rs);
Organizations queryOrg = this.organizationsService.get(org.getId());
if(queryOrg == null) {
organizationsService.insert(org);
}else{
this.organizationsService.update(org);
}
}
}
} catch (Exception e) {
_logger.error("Exception " , e);
}finally {
JdbcUtils.release(conn, stmt, rs);
}
}
public Organizations buildOrganization(ResultSet rs) throws SQLException {
DbTableMetaData meta = JdbcUtils.getMetaData(rs);
Organizations org = new Organizations();
for (ColumnFieldMapper mapper :mapperList ) {
if(meta.getColumnsMap().containsKey(mapper.getColumn())) {
Object value = null;
if(mapper.getType().equalsIgnoreCase("String")) {
value = rs.getString(mapper.getColumn());
}else {
value = rs.getInt(mapper.getColumn());
}
if(value != null ) {
try {
PropertyUtils.setSimpleProperty(org, mapper.getField(), value);
} catch (Exception e) {
_logger.error("setSimpleProperty {}" , e);
}
}
}
}
org.setId(org.generateId());
org.setInstId(this.synchronizer.getInstId());
if(meta.getColumnsMap().containsKey("status")) {
org.setStatus(rs.getInt("status"));
}else {
org.setStatus(ConstsStatus.ACTIVE);
}
_logger.debug("Organization {}" , org);
return org;
}
static { @Service
mapperList.add(new ColumnFieldMapper("id" , "id","String")); public class JdbcOrganizationService extends AbstractSynchronizerService implements ISynchronizerService {
mapperList.add(new ColumnFieldMapper("orgcode" , "orgCode","String")); final static Logger _logger = LoggerFactory.getLogger(JdbcOrganizationService.class);
mapperList.add(new ColumnFieldMapper("orgname" , "orgName","String")); static ArrayList<ColumnFieldMapper> mapperList = new ArrayList<>();
mapperList.add(new ColumnFieldMapper("fullname" , "fullName","String"));
mapperList.add(new ColumnFieldMapper("parentid" , "parentId","String")); @Override
mapperList.add(new ColumnFieldMapper("parentcode" , "parentCode","String")); public void sync() {
mapperList.add(new ColumnFieldMapper("parentname" , "parentName","String")); Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
if (StringUtils.isNotBlank(synchronizer.getOrgFilters())) {
_logger.info("Sync Org Filters {}", synchronizer.getOrgFilters());
conn = JdbcUtils.connect(
synchronizer.getProviderUrl(),
synchronizer.getPrincipal(),
synchronizer.getCredentials(),
synchronizer.getDriverClass());
stmt = conn.createStatement();
rs = stmt.executeQuery(synchronizer.getOrgFilters());
while (rs.next()) {
Organizations org = buildOrganization(rs);
Organizations queryOrg = organizationsService.get(org.getId());
if (queryOrg == null) {
organizationsService.insert(org);
} else {
organizationsService.update(org);
}
}
}
} catch (Exception e) {
_logger.error("Exception ", e);
} finally {
JdbcUtils.release(conn, stmt, rs);
}
}
public Organizations buildOrganization(ResultSet rs) throws SQLException {
DbTableMetaData meta = JdbcUtils.getMetaData(rs);
Organizations org = new Organizations();
for (ColumnFieldMapper mapper : mapperList) {
if (meta.getColumnsMap().containsKey(mapper.getColumn())) {
Object value = null;
if (mapper.getType().equalsIgnoreCase("String")) {
value = rs.getString(mapper.getColumn());
} else {
value = rs.getInt(mapper.getColumn());
}
if (value != null) {
try {
PropertyUtils.setSimpleProperty(org, mapper.getField(), value);
} catch (Exception e) {
_logger.error("setSimpleProperty {}", e);
}
}
}
}
org.setId(org.generateId());
org.setInstId(synchronizer.getInstId());
if (meta.getColumnsMap().containsKey("status")) {
org.setStatus(rs.getInt("status"));
} else {
org.setStatus(ConstsStatus.ACTIVE);
}
_logger.debug("Organization {}", org);
HistorySynchronizer historySynchronizer = new HistorySynchronizer();
historySynchronizer.setId(historySynchronizer.generateId());
historySynchronizer.setSyncId(synchronizer.getId());
historySynchronizer.setSyncName(synchronizer.getName());
historySynchronizer.setObjectId(org.getId());
historySynchronizer.setObjectName(org.getOrgName());
historySynchronizer.setObjectType(Organizations.class.getSimpleName());
historySynchronizer.setInstId(synchronizer.getInstId());
historySynchronizer.setResult("success");
historySynchronizerService.insert(historySynchronizer);
mapperList.add(new ColumnFieldMapper("type" , "type","String")); return org;
mapperList.add(new ColumnFieldMapper("codepath" , "codePath","String"));
mapperList.add(new ColumnFieldMapper("namepath" , "namePath","String")); }
mapperList.add(new ColumnFieldMapper("level" , "level","Int"));
mapperList.add(new ColumnFieldMapper("haschild" , "hasChild","String"));
mapperList.add(new ColumnFieldMapper("division" , "division","String")); static {
mapperList.add(new ColumnFieldMapper("country" , "country","String")); mapperList.add(new ColumnFieldMapper("id", "id", "String"));
mapperList.add(new ColumnFieldMapper("region" , "region","String")); mapperList.add(new ColumnFieldMapper("orgcode", "orgCode", "String"));
mapperList.add(new ColumnFieldMapper("locality" , "locality","String")); mapperList.add(new ColumnFieldMapper("orgname", "orgName", "String"));
mapperList.add(new ColumnFieldMapper("street" , "street","String")); mapperList.add(new ColumnFieldMapper("fullname", "fullName", "String"));
mapperList.add(new ColumnFieldMapper("address" , "address","String")); mapperList.add(new ColumnFieldMapper("parentid", "parentId", "String"));
mapperList.add(new ColumnFieldMapper("contact" , "contact","String")); mapperList.add(new ColumnFieldMapper("parentcode", "parentCode", "String"));
mapperList.add(new ColumnFieldMapper("postalcode" , "postalCode","String")); mapperList.add(new ColumnFieldMapper("parentname", "parentName", "String"));
mapperList.add(new ColumnFieldMapper("phone" , "phone","String"));
mapperList.add(new ColumnFieldMapper("fax" , "fax","String")); mapperList.add(new ColumnFieldMapper("type", "type", "String"));
mapperList.add(new ColumnFieldMapper("email" , "email","String")); mapperList.add(new ColumnFieldMapper("codepath", "codePath", "String"));
mapperList.add(new ColumnFieldMapper("sortindex" , "sortIndex","Int")); mapperList.add(new ColumnFieldMapper("namepath", "namePath", "String"));
mapperList.add(new ColumnFieldMapper("ldapdn" , "ldapDn","String")); mapperList.add(new ColumnFieldMapper("level", "level", "Int"));
mapperList.add(new ColumnFieldMapper("description" , "description","String")); mapperList.add(new ColumnFieldMapper("haschild", "hasChild", "String"));
mapperList.add(new ColumnFieldMapper("status" , "status","int")); mapperList.add(new ColumnFieldMapper("division", "division", "String"));
} mapperList.add(new ColumnFieldMapper("country", "country", "String"));
mapperList.add(new ColumnFieldMapper("region", "region", "String"));
mapperList.add(new ColumnFieldMapper("locality", "locality", "String"));
mapperList.add(new ColumnFieldMapper("street", "street", "String"));
mapperList.add(new ColumnFieldMapper("address", "address", "String"));
mapperList.add(new ColumnFieldMapper("contact", "contact", "String"));
mapperList.add(new ColumnFieldMapper("postalcode", "postalCode", "String"));
mapperList.add(new ColumnFieldMapper("phone", "phone", "String"));
mapperList.add(new ColumnFieldMapper("fax", "fax", "String"));
mapperList.add(new ColumnFieldMapper("email", "email", "String"));
mapperList.add(new ColumnFieldMapper("sortindex", "sortIndex", "Int"));
mapperList.add(new ColumnFieldMapper("ldapdn", "ldapDn", "String"));
mapperList.add(new ColumnFieldMapper("description", "description", "String"));
mapperList.add(new ColumnFieldMapper("status", "status", "int"));
}
} }

View File

@ -1,31 +1,26 @@
/* /*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top] * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.maxkey.synchronizer.jdbc; package org.dromara.maxkey.synchronizer.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.PropertyUtils;
import org.dromara.maxkey.constants.ConstsStatus; import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.DbTableMetaData; import org.dromara.maxkey.entity.DbTableMetaData;
import org.dromara.maxkey.entity.HistorySynchronizer;
import org.dromara.maxkey.entity.UserInfo; import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.synchronizer.AbstractSynchronizerService; import org.dromara.maxkey.synchronizer.AbstractSynchronizerService;
import org.dromara.maxkey.synchronizer.ISynchronizerService; import org.dromara.maxkey.synchronizer.ISynchronizerService;
@ -35,170 +30,188 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service import java.sql.Connection;
public class JdbcUsersService extends AbstractSynchronizerService implements ISynchronizerService{ import java.sql.ResultSet;
final static Logger _logger = LoggerFactory.getLogger(JdbcUsersService.class); import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
static ArrayList< ColumnFieldMapper> mapperList = new ArrayList< ColumnFieldMapper>(); @Service
public class JdbcUsersService extends AbstractSynchronizerService implements ISynchronizerService {
public void sync() { final static Logger _logger = LoggerFactory.getLogger(JdbcUsersService.class);
_logger.info("Sync Jdbc Users...");
Connection conn = null; static ArrayList<ColumnFieldMapper> mapperList = new ArrayList<>();
Statement stmt = null;
ResultSet rs = null; @Override
public void sync() {
try { _logger.info("Sync Jdbc Users...");
if(StringUtils.isNotBlank(synchronizer.getOrgFilters())){ Connection conn = null;
_logger.info("Sync User Filters {}",synchronizer.getOrgFilters()); Statement stmt = null;
conn = JdbcUtils.connect( ResultSet rs = null;
synchronizer.getProviderUrl(),
synchronizer.getPrincipal(), try {
synchronizer.getCredentials(), if (StringUtils.isNotBlank(synchronizer.getUserFilters())) {
synchronizer.getDriverClass()); _logger.info("Sync User Filters {}", synchronizer.getUserFilters());
conn = JdbcUtils.connect(
stmt = conn.createStatement(); synchronizer.getProviderUrl(),
rs = stmt.executeQuery(synchronizer.getUserFilters()); synchronizer.getPrincipal(),
long insertCount = 0; synchronizer.getCredentials(),
long updateCount = 0; synchronizer.getDriverClass());
long readCount = 0;
while(rs.next()) { stmt = conn.createStatement();
UserInfo user = buildUserInfo(rs); rs = stmt.executeQuery(synchronizer.getUserFilters());
UserInfo queryUser = this.userInfoService.findByUsername(user.getUsername()); long insertCount = 0;
readCount ++; long updateCount = 0;
if(queryUser == null) { long readCount = 0;
if(user.getPassword().indexOf("{") > -1 && user.getPassword().indexOf("}") > -1) { while (rs.next()) {
userInfoService.insert(user,false); UserInfo user = buildUserInfo(rs);
}else { UserInfo queryUser = userInfoService.findByUsername(user.getUsername());
//passwordEncoder readCount++;
userInfoService.insert(user,true); if (queryUser == null) {
} if (user.getPassword().indexOf("{") > -1 && user.getPassword().indexOf("}") > -1) {
user.setBadPasswordCount(1); userInfoService.insert(user, false);
insertCount++; } else {
}else{ //passwordEncoder
//no need update password , set null userInfoService.insert(user, true);
user.setPassword(null); }
userInfoService.update(user); user.setBadPasswordCount(1);
updateCount++; insertCount++;
} } else {
_logger.trace("read Count {} , insert Count {} , updateCount {} " , readCount,insertCount,updateCount); //no need update password , set null
} user.setPassword(null);
_logger.info("read Count {} , insert Count {} , updateCount {} " , readCount,insertCount,updateCount); userInfoService.update(user);
} updateCount++;
} catch (Exception e) { }
_logger.error("Exception " , e); _logger.trace("read Count {} , insert Count {} , updateCount {} ", readCount, insertCount, updateCount);
}finally { }
JdbcUtils.release(conn, stmt, rs); _logger.info("read Count {} , insert Count {} , updateCount {} ", readCount, insertCount, updateCount);
} }
} } catch (Exception e) {
_logger.error("Exception ", e);
public UserInfo buildUserInfo(ResultSet rs) throws SQLException { } finally {
DbTableMetaData meta = JdbcUtils.getMetaData(rs); JdbcUtils.release(conn, stmt, rs);
UserInfo user = new UserInfo(); }
//basic }
for (ColumnFieldMapper mapper :mapperList ) {
if(meta.getColumnsMap().containsKey(mapper.getColumn())) { public UserInfo buildUserInfo(ResultSet rs) throws SQLException {
Object value = null; DbTableMetaData meta = JdbcUtils.getMetaData(rs);
if(mapper.getType().equalsIgnoreCase("String")) { UserInfo user = new UserInfo();
value = rs.getString(mapper.getColumn()); //basic
}else { for (ColumnFieldMapper mapper : mapperList) {
value = rs.getInt(mapper.getColumn()); if (meta.getColumnsMap().containsKey(mapper.getColumn())) {
} Object value = null;
if(value != null ) { if (mapper.getType().equalsIgnoreCase("String")) {
try { value = rs.getString(mapper.getColumn());
PropertyUtils.setSimpleProperty(user, mapper.getField(), value); } else {
} catch (Exception e) { value = rs.getInt(mapper.getColumn());
_logger.error("setSimpleProperty {}" , e); }
} if (value != null) {
} try {
} PropertyUtils.setSimpleProperty(user, mapper.getField(), value);
} } catch (Exception e) {
_logger.error("setSimpleProperty {}", e);
if(meta.getColumnsMap().containsKey("status")) { }
user.setStatus(rs.getInt("status")); }
}else { }
user.setStatus(ConstsStatus.ACTIVE); }
}
user.setInstId(this.synchronizer.getInstId()); if (meta.getColumnsMap().containsKey("status")) {
user.setStatus(rs.getInt("status"));
//password } else {
if(meta.getColumnsMap().containsKey("password")) { user.setStatus(ConstsStatus.ACTIVE);
user.setPassword(rs.getString("password")); }
}else { user.setInstId(synchronizer.getInstId());
//后4位
String last4Char = "6666"; //password
if(StringUtils.isNotBlank(user.getIdCardNo())) { if (meta.getColumnsMap().containsKey("password")) {
last4Char = user.getIdCardNo().substring(user.getIdCardNo().length() - 4); user.setPassword(rs.getString("password"));
}else if(StringUtils.isNotBlank(user.getMobile())) { } else {
last4Char = user.getMobile().substring(user.getMobile().length() - 4); //后4位
}else if(StringUtils.isNotBlank(user.getEmployeeNumber())) { String last4Char = "6666";
last4Char = user.getEmployeeNumber().substring(user.getEmployeeNumber().length() - 4); if (StringUtils.isNotBlank(user.getIdCardNo())) {
} last4Char = user.getIdCardNo().substring(user.getIdCardNo().length() - 4);
user.setPassword(user.getUsername()+"@M"+last4Char); } else if (StringUtils.isNotBlank(user.getMobile())) {
} last4Char = user.getMobile().substring(user.getMobile().length() - 4);
} else if (StringUtils.isNotBlank(user.getEmployeeNumber())) {
_logger.debug("User {} " , user); last4Char = user.getEmployeeNumber().substring(user.getEmployeeNumber().length() - 4);
return user; }
} user.setPassword(user.getUsername() + "@M" + last4Char);
}
static {
mapperList.add(new ColumnFieldMapper("id" , "id","String")); HistorySynchronizer historySynchronizer = new HistorySynchronizer();
mapperList.add(new ColumnFieldMapper("username" , "userName","String")); historySynchronizer.setId(historySynchronizer.generateId());
mapperList.add(new ColumnFieldMapper("picture" , "picture","String")); historySynchronizer.setSyncId(synchronizer.getId());
mapperList.add(new ColumnFieldMapper("displayname" , "displayName","String")); historySynchronizer.setSyncName(synchronizer.getName());
mapperList.add(new ColumnFieldMapper("nickname" , "nickName","String")); historySynchronizer.setObjectId(user.getId());
mapperList.add(new ColumnFieldMapper("mobile" , "mobile","String")); historySynchronizer.setObjectName(user.getUsername());
mapperList.add(new ColumnFieldMapper("email" , "email","String")); historySynchronizer.setObjectType(UserInfo.class.getSimpleName());
mapperList.add(new ColumnFieldMapper("birthdate" , "birthDate","String")); historySynchronizer.setInstId(synchronizer.getInstId());
mapperList.add(new ColumnFieldMapper("usertype" , "userType","String")); historySynchronizer.setResult("success");
mapperList.add(new ColumnFieldMapper("userstate" , "userState","String")); historySynchronizerService.insert(historySynchronizer);
mapperList.add(new ColumnFieldMapper("windowsaccount" , "windowsAccount","String")); _logger.debug("User {} ", user);
mapperList.add(new ColumnFieldMapper("givenname" , "givenName","String"));
mapperList.add(new ColumnFieldMapper("middlename" , "middleName","String")); return user;
mapperList.add(new ColumnFieldMapper("married" , "married","Int")); }
mapperList.add(new ColumnFieldMapper("gender" , "gender","Int"));
mapperList.add(new ColumnFieldMapper("idtype" , "idType","Int")); static {
mapperList.add(new ColumnFieldMapper("idcardno" , "idCardNo","String")); mapperList.add(new ColumnFieldMapper("id", "id", "String"));
mapperList.add(new ColumnFieldMapper("website" , "webSite","String")); mapperList.add(new ColumnFieldMapper("username", "username", "String"));
mapperList.add(new ColumnFieldMapper("startworkdate" , "startWorkDate","String")); mapperList.add(new ColumnFieldMapper("picture", "picture", "String"));
//work mapperList.add(new ColumnFieldMapper("displayname", "displayName", "String"));
mapperList.add(new ColumnFieldMapper("workcountry" , "workCountry","String")); mapperList.add(new ColumnFieldMapper("nickname", "nickName", "String"));
mapperList.add(new ColumnFieldMapper("workregion" , "workRegion","String")); mapperList.add(new ColumnFieldMapper("mobile", "mobile", "String"));
mapperList.add(new ColumnFieldMapper("worklocality" , "workLocality","String")); mapperList.add(new ColumnFieldMapper("email", "email", "String"));
mapperList.add(new ColumnFieldMapper("workstreetaddress" , "workStreetAddress","String")); mapperList.add(new ColumnFieldMapper("birthdate", "birthDate", "String"));
mapperList.add(new ColumnFieldMapper("workaddressformatted" , "workAddressFormatted","String")); mapperList.add(new ColumnFieldMapper("usertype", "userType", "String"));
mapperList.add(new ColumnFieldMapper("workemail" , "workEmail","String")); mapperList.add(new ColumnFieldMapper("userstate", "userState", "String"));
mapperList.add(new ColumnFieldMapper("workphonenumber" , "workPhoneNumber","String")); mapperList.add(new ColumnFieldMapper("windowsaccount", "windowsAccount", "String"));
mapperList.add(new ColumnFieldMapper("workpostalcode" , "workPostalCode","String")); mapperList.add(new ColumnFieldMapper("givenname", "givenName", "String"));
mapperList.add(new ColumnFieldMapper("workfax" , "workFax","String")); mapperList.add(new ColumnFieldMapper("middlename", "middleName", "String"));
mapperList.add(new ColumnFieldMapper("workofficename" , "workOfficeName","String")); mapperList.add(new ColumnFieldMapper("married", "married", "Int"));
//home mapperList.add(new ColumnFieldMapper("gender", "gender", "Int"));
mapperList.add(new ColumnFieldMapper("homecountry" , "homeCountry","String")); mapperList.add(new ColumnFieldMapper("idtype", "idType", "Int"));
mapperList.add(new ColumnFieldMapper("homeregion" , "homeRegion","String")); mapperList.add(new ColumnFieldMapper("idcardno", "idCardNo", "String"));
mapperList.add(new ColumnFieldMapper("homelocality" , "homeLocality","String")); mapperList.add(new ColumnFieldMapper("website", "webSite", "String"));
mapperList.add(new ColumnFieldMapper("homestreetaddress" , "homeStreetAddress","String")); mapperList.add(new ColumnFieldMapper("startworkdate", "startWorkDate", "String"));
mapperList.add(new ColumnFieldMapper("homeaddressformatted" , "homeAddressFormatted","String")); //work
mapperList.add(new ColumnFieldMapper("homeemail" , "homeEmail","String")); mapperList.add(new ColumnFieldMapper("workcountry", "workCountry", "String"));
mapperList.add(new ColumnFieldMapper("homephonenumber" , "homePhonenumber","String")); mapperList.add(new ColumnFieldMapper("workregion", "workRegion", "String"));
mapperList.add(new ColumnFieldMapper("homepostalcode" , "homePostalCode","String")); mapperList.add(new ColumnFieldMapper("worklocality", "workLocality", "String"));
mapperList.add(new ColumnFieldMapper("homefax" , "homeFax","String")); mapperList.add(new ColumnFieldMapper("workstreetaddress", "workStreetAddress", "String"));
//company mapperList.add(new ColumnFieldMapper("workaddressformatted", "workAddressFormatted", "String"));
mapperList.add(new ColumnFieldMapper("employeenumber" , "employeeNumber","String")); mapperList.add(new ColumnFieldMapper("workemail", "workEmail", "String"));
mapperList.add(new ColumnFieldMapper("costcenter" , "costCenter","String")); mapperList.add(new ColumnFieldMapper("workphonenumber", "workPhoneNumber", "String"));
mapperList.add(new ColumnFieldMapper("organization" , "organization","String")); mapperList.add(new ColumnFieldMapper("workpostalcode", "workPostalCode", "String"));
mapperList.add(new ColumnFieldMapper("division" , "division","String")); mapperList.add(new ColumnFieldMapper("workfax", "workFax", "String"));
mapperList.add(new ColumnFieldMapper("departmentid" , "departmentId","String")); mapperList.add(new ColumnFieldMapper("workofficename", "workOfficeName", "String"));
mapperList.add(new ColumnFieldMapper("department" , "department","String")); //home
mapperList.add(new ColumnFieldMapper("jobtitle" , "jobTitle","String")); mapperList.add(new ColumnFieldMapper("homecountry", "homeCountry", "String"));
mapperList.add(new ColumnFieldMapper("joblevel" , "jobLevel","String")); mapperList.add(new ColumnFieldMapper("homeregion", "homeRegion", "String"));
mapperList.add(new ColumnFieldMapper("managerid" , "managerId","String")); mapperList.add(new ColumnFieldMapper("homelocality", "homeLocality", "String"));
mapperList.add(new ColumnFieldMapper("manager" , "manager","String")); mapperList.add(new ColumnFieldMapper("homestreetaddress", "homeStreetAddress", "String"));
mapperList.add(new ColumnFieldMapper("assistantid" , "assistantId","String")); mapperList.add(new ColumnFieldMapper("homeaddressformatted", "homeAddressFormatted", "String"));
mapperList.add(new ColumnFieldMapper("assistant" , "assistant","String")); mapperList.add(new ColumnFieldMapper("homeemail", "homeEmail", "String"));
mapperList.add(new ColumnFieldMapper("entrydate" , "entrydate","String")); mapperList.add(new ColumnFieldMapper("homephonenumber", "homePhonenumber", "String"));
mapperList.add(new ColumnFieldMapper("quitdate" , "quitdate","String")); mapperList.add(new ColumnFieldMapper("homepostalcode", "homePostalCode", "String"));
mapperList.add(new ColumnFieldMapper("ldapdn" , "ldapDn","String")); mapperList.add(new ColumnFieldMapper("homefax", "homeFax", "String"));
//company
mapperList.add(new ColumnFieldMapper("description" , "description","String")); mapperList.add(new ColumnFieldMapper("employeenumber", "employeeNumber", "String"));
mapperList.add(new ColumnFieldMapper("status" , "status","String")); mapperList.add(new ColumnFieldMapper("costcenter", "costCenter", "String"));
} mapperList.add(new ColumnFieldMapper("organization", "organization", "String"));
mapperList.add(new ColumnFieldMapper("division", "division", "String"));
mapperList.add(new ColumnFieldMapper("departmentid", "departmentId", "String"));
mapperList.add(new ColumnFieldMapper("department", "department", "String"));
mapperList.add(new ColumnFieldMapper("jobtitle", "jobTitle", "String"));
mapperList.add(new ColumnFieldMapper("joblevel", "jobLevel", "String"));
mapperList.add(new ColumnFieldMapper("managerid", "managerId", "String"));
mapperList.add(new ColumnFieldMapper("manager", "manager", "String"));
mapperList.add(new ColumnFieldMapper("assistantid", "assistantId", "String"));
mapperList.add(new ColumnFieldMapper("assistant", "assistant", "String"));
mapperList.add(new ColumnFieldMapper("entrydate", "entrydate", "String"));
mapperList.add(new ColumnFieldMapper("quitdate", "quitdate", "String"));
mapperList.add(new ColumnFieldMapper("ldapdn", "ldapDn", "String"));
mapperList.add(new ColumnFieldMapper("description", "description", "String"));
mapperList.add(new ColumnFieldMapper("status", "status", "String"));
}
} }

View File

@ -2,10 +2,10 @@
<div> <div>
<form nz-form [formGroup]="formGroup" (ngSubmit)="onSubmit($event)" se-container="1"> <form nz-form [formGroup]="formGroup" (ngSubmit)="onSubmit($event)" se-container="1">
<nz-form-item> <nz-form-item>
<nz-form-label [nzMd]="6" nzFor="id">{{ 'mxk.text.id' | i18n }}</nz-form-label> <nz-form-label [nzMd]="6" nzFor="name">{{ 'mxk.synchronizers.name' | i18n }}</nz-form-label>
<nz-form-control [nzMd]="18" nzErrorTip="The input is not valid id!"> <nz-form-control [nzMd]="18" nzErrorTip="The input is not valid id!">
<input [(ngModel)]="form.model.id" disabled="{{ isEdit }}" [ngModelOptions]="{ standalone: true }" nz-input <input [(ngModel)]="form.model.name" [ngModelOptions]="{ standalone: true }" nz-input
name="id" id="id" /> name="name" id="name" />
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
<nz-form-item> <nz-form-item>
@ -195,4 +195,4 @@
<div *nzModalFooter> <div *nzModalFooter>
<button nz-button nzType="default" (click)="onClose($event)">{{ 'mxk.text.close' | i18n }}</button> <button nz-button nzType="default" (click)="onClose($event)">{{ 'mxk.text.close' | i18n }}</button>
<button nz-button nzType="primary" (click)="onSubmit($event)">{{ 'mxk.text.submit' | i18n }}</button> <button nz-button nzType="primary" (click)="onSubmit($event)">{{ 'mxk.text.submit' | i18n }}</button>
</div> </div>

View File

@ -1,26 +1,25 @@
/* /*
* Copyright [2021] [MaxKey of copyright http://www.maxkey.top] * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.maxkey.web.config.contorller; package org.dromara.maxkey.web.config.contorller;
import java.util.List;
import org.dromara.maxkey.authn.annotation.CurrentUser; import org.dromara.maxkey.authn.annotation.CurrentUser;
import org.dromara.maxkey.crypto.password.PasswordReciprocal; import org.dromara.maxkey.crypto.password.PasswordReciprocal;
import org.dromara.maxkey.entity.Connectors;
import org.dromara.maxkey.entity.Message; import org.dromara.maxkey.entity.Message;
import org.dromara.maxkey.entity.Synchronizers; import org.dromara.maxkey.entity.Synchronizers;
import org.dromara.maxkey.entity.UserInfo; import org.dromara.maxkey.entity.UserInfo;
@ -28,81 +27,104 @@ import org.dromara.maxkey.persistence.service.SynchronizersService;
import org.dromara.maxkey.synchronizer.ISynchronizerService; import org.dromara.maxkey.synchronizer.ISynchronizerService;
import org.dromara.maxkey.util.StringUtils; import org.dromara.maxkey.util.StringUtils;
import org.dromara.maxkey.web.WebContext; import org.dromara.maxkey.web.WebContext;
import org.dromara.mybatis.jpa.entity.JpaPageResults;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.List;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping(value={"/config/synchronizers"}) @RequestMapping(value = {"/config/synchronizers"})
public class SynchronizersController { public class SynchronizersController {
static final Logger logger = LoggerFactory.getLogger(SynchronizersController.class); static final Logger logger = LoggerFactory.getLogger(SynchronizersController.class);
@Autowired @Autowired
SynchronizersService synchronizersService; SynchronizersService synchronizersService;
@RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @RequestMapping(value = {"/fetch"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody @ResponseBody
public ResponseEntity<?> fetch(Synchronizers synchronizers,@CurrentUser UserInfo currentUser) { public ResponseEntity<?> fetch(Synchronizers synchronizers, @CurrentUser UserInfo currentUser) {
logger.debug("fetch {}" , synchronizers); logger.debug("fetch {}", synchronizers);
synchronizers.setInstId(currentUser.getInstId()); synchronizers.setInstId(currentUser.getInstId());
return new Message<JpaPageResults<Synchronizers>>( return new Message<>(
synchronizersService.fetchPageResults(synchronizers)).buildResponse(); synchronizersService.fetchPageResults(synchronizers)).buildResponse();
} }
@RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @RequestMapping(value = {"/get/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> get(@PathVariable("id") String id) { public ResponseEntity<?> get(@PathVariable("id") String id) {
Synchronizers synchronizers=synchronizersService.get(id); Synchronizers synchronizers = synchronizersService.get(id);
synchronizers.setCredentials(PasswordReciprocal.getInstance().decoder(synchronizers.getCredentials())); synchronizers.setCredentials(PasswordReciprocal.getInstance().decoder(synchronizers.getCredentials()));
return new Message<Synchronizers>(synchronizers).buildResponse(); return new Message<>(synchronizers).buildResponse();
} }
@ResponseBody @ResponseBody
@RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) @RequestMapping(value = {"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> update(@RequestBody Synchronizers synchronizers,@CurrentUser UserInfo currentUser) { public ResponseEntity<?> add(@RequestBody Synchronizers synchronizers, @CurrentUser UserInfo currentUser) {
logger.debug("-update : {}" , synchronizers); logger.debug("-add : {}", synchronizers);
synchronizers.setInstId(currentUser.getInstId()); synchronizers.setInstId(currentUser.getInstId());
synchronizers.setCredentials(PasswordReciprocal.getInstance().encode(synchronizers.getCredentials())); if (StringUtils.isNotBlank(synchronizers.getCredentials())) {
if (synchronizersService.update(synchronizers)) { synchronizers.setCredentials(PasswordReciprocal.getInstance().encode(synchronizers.getCredentials()));
return new Message<Synchronizers>(Message.SUCCESS).buildResponse(); }
} else { if (synchronizersService.insert(synchronizers)) {
return new Message<Synchronizers>(Message.FAIL).buildResponse(); return new Message<Synchronizers>(Message.SUCCESS).buildResponse();
} } else {
} return new Message<Synchronizers>(Message.FAIL).buildResponse();
}
@ResponseBody }
@RequestMapping(value={"/synchr"})
public ResponseEntity<?> synchr(@RequestParam("id") String id) { @ResponseBody
logger.debug("-sync ids : {}" , id); @RequestMapping(value = {"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> update(@RequestBody Synchronizers synchronizers, @CurrentUser UserInfo currentUser) {
List<String> ids = StringUtils.string2List(id, ","); logger.debug("-update : {}", synchronizers);
try { synchronizers.setInstId(currentUser.getInstId());
for(String sysId : ids) { synchronizers.setCredentials(PasswordReciprocal.getInstance().encode(synchronizers.getCredentials()));
Synchronizers synchronizer = synchronizersService.get(sysId); if (synchronizersService.update(synchronizers)) {
synchronizer.setCredentials(PasswordReciprocal.getInstance().decoder(synchronizer.getCredentials())); return new Message<Synchronizers>(Message.SUCCESS).buildResponse();
logger.debug("synchronizer {}" , synchronizer); } else {
ISynchronizerService synchronizerService = WebContext.getBean(synchronizer.getService(),ISynchronizerService.class); return new Message<Synchronizers>(Message.FAIL).buildResponse();
if(synchronizerService != null) { }
synchronizerService.setSynchronizer(synchronizer); }
synchronizerService.sync();
}else { @ResponseBody
logger.info("synchronizer {} not exist .",synchronizer.getService()); @RequestMapping(value = {"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
} public ResponseEntity<?> delete(@RequestParam("ids") String ids) {
} logger.debug("-delete ids : {} ", ids);
}catch(Exception e) { if (synchronizersService.deleteBatch(ids)) {
logger.error("synchronizer Exception " , e); return new Message<Connectors>(Message.SUCCESS).buildResponse();
return new Message<Synchronizers>(Message.FAIL).buildResponse(); } else {
return new Message<Connectors>(Message.FAIL).buildResponse();
} }
return new Message<Synchronizers>(Message.SUCCESS).buildResponse(); }
}
@ResponseBody
@RequestMapping(value = {"/synchr"})
public ResponseEntity<?> synchr(@RequestParam("id") String id) {
logger.debug("-sync ids : {}", id);
List<String> ids = StringUtils.string2List(id, ",");
try {
for (String sysId : ids) {
Synchronizers synchronizer = synchronizersService.get(sysId);
synchronizer.setCredentials(PasswordReciprocal.getInstance().decoder(synchronizer.getCredentials()));
logger.debug("synchronizer {}", synchronizer);
ISynchronizerService synchronizerService = WebContext.getBean(synchronizer.getService(), ISynchronizerService.class);
if (synchronizerService != null) {
synchronizerService.setSynchronizer(synchronizer);
synchronizerService.sync();
} else {
logger.info("synchronizer {} not exist .", synchronizer.getService());
}
}
} catch (Exception e) {
logger.error("synchronizer Exception ", e);
return new Message<Synchronizers>(Message.FAIL).buildResponse();
}
return new Message<Synchronizers>(Message.SUCCESS).buildResponse();
}
} }