SynchronizersController.java 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 

package org.maxkey.web.contorller;

M
MaxKey 已提交
20 21
import java.util.HashMap;
import java.util.List;
22 23 24 25
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.constants.ConstantsOperateMessage;
import org.maxkey.entity.Synchronizers;
import org.maxkey.persistence.service.SynchronizersService;
M
MaxKey 已提交
26 27
import org.maxkey.synchronizer.ISynchronizerService;
import org.maxkey.util.StringUtils;
28 29 30 31 32 33 34 35 36 37 38
import org.maxkey.web.WebContext;
import org.maxkey.web.message.Message;
import org.maxkey.web.message.MessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
M
MaxKey 已提交
39
import org.springframework.web.bind.annotation.RequestParam;
40 41 42 43 44 45 46 47 48 49 50 51 52
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping(value={"/synchronizers"})
public class SynchronizersController {
	final static Logger _logger = LoggerFactory.getLogger(SynchronizersController.class);
	
	@Autowired
	@Qualifier("synchronizersService")
	SynchronizersService synchronizerssService;
	
M
MaxKey 已提交
53 54 55 56 57 58 59 60
	private static HashMap<String,String> synchronizerMap =new HashMap<String,String>();

	static {
		synchronizerMap.put("1", "ldapSynchronizerService");
		synchronizerMap.put("2", "activeDirectorySynchronizerService");
		synchronizerMap.put("3", "dingdingSynchronizerService");
		synchronizerMap.put("4", "workweixinSynchronizerService");
	}
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
	
	@RequestMapping(value={"/list"})
	public ModelAndView groupsList(){
		return new ModelAndView("synchronizers/synchronizersList");
	}
	
	
	
	@RequestMapping(value = { "/grid" })
	@ResponseBody
	public JpaPageResults<Synchronizers> queryDataGrid(@ModelAttribute("synchronizers") Synchronizers synchronizers) {
		_logger.debug(""+synchronizers);
		return synchronizerssService.queryPageResults(synchronizers);
	}

	

	
	@RequestMapping(value = { "/forwardUpdate/{id}" })
	public ModelAndView forwardUpdate(@PathVariable("id") String id) {
		ModelAndView modelAndView=new ModelAndView("synchronizers/synchronizerUpdate");
		Synchronizers synchronizers=synchronizerssService.get(id);
		modelAndView.addObject("model",synchronizers);
		return modelAndView;
	}
	

	
	/**
	 * 修改
	 * @param group
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value={"/update"})  
	public Message update(@ModelAttribute("synchronizers") Synchronizers synchronizers) {
		_logger.debug("-update  synchronizers :" + synchronizers);
		
		if (synchronizerssService.update(synchronizers)) {
			return  new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),MessageType.success);
			
		} else {
			return  new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error);
		}
		
	}
M
MaxKey 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	
	/**
	 * 修改
	 * @param group
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value={"/sync"})  
	public Message sync(@RequestParam("id") String id) {
		_logger.debug("-update  synchronizers ids :" + id);
		
		List<String> ids = StringUtils.string2List(id, ",");
		try {
			for(String sysId : ids) {
				Synchronizers  synchronizer  = synchronizerssService.get(sysId);
				_logger.debug("synchronizer " + synchronizer);
				ISynchronizerService synchronizerService = (ISynchronizerService)WebContext.getBean(synchronizerMap.get(sysId));
				synchronizerService.setSynchronizer(synchronizer);
				synchronizerService.sync();
			}
		}catch(Exception e) {
			_logger.error("synchronizer Exception " , e);
			return  new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error);
		}
		return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),MessageType.success);
	}
133 134

}