View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-2-28 下午06:47:27
4    */
5   package gboat2.web.action;
6   
7   import gboat2.base.core.annotation.Domain;
8   import gboat2.base.core.annotation.Module;
9   import gboat2.base.core.annotation.Operation;
10  import gboat2.base.core.annotation.Operations;
11  import gboat2.base.core.annotation.Preference;
12  import gboat2.base.core.logging.IBusinessLogService;
13  import gboat2.base.core.logging.Level;
14  import gboat2.base.core.web.BaseActionSupport;
15  import gboat2.base.core.web.JsonResultSupport;
16  import gboat2.web.business.IOrganDefineBusiness;
17  import gboat2.web.model.OrganDefine;
18  
19  import java.util.Arrays;
20  import java.util.Date;
21  import java.util.LinkedList;
22  import java.util.List;
23  
24  import org.apache.commons.lang3.StringUtils;
25  import org.apache.struts2.convention.annotation.ParentPackage;
26  import org.apache.struts2.convention.annotation.ResultPath;
27  import org.osgi.framework.Bundle;
28  import org.osgi.framework.ServiceReference;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  import org.springframework.beans.factory.annotation.Autowired;
32  
33  /**
34   * 组织定义
35   * @author zhaop
36   * @since jdk1.6
37   * @date 2012-2-28
38   *  
39   */
40  @SuppressWarnings("serial")
41  @ResultPath(value = "/content/organDefine")
42  @Domain(value = OrganDefine.class)
43  @Preference("/系统配置/组织机构设置")
44  @Module(name = "组织机构定义管理", desc = "管理组织机构定义")
45  @Operations(value = {
46  	@Operation(name = "新增组织机构", code = "add", desc="新增组织机构"), 
47  	@Operation(name = "编辑", code = "edit", desc="编辑组织机构"), 
48      @Operation(name = "删除", code = "delete", desc="删除组织机构") 
49  })
50  @ParentPackage("desktop")
51  public class OrganDefineAction extends BaseActionSupport {
52  	private static Logger logger = LoggerFactory.getLogger(OrganDefineAction.class);
53  	@Autowired
54  	private IBusinessLogService loggerService;
55  	@Autowired
56  	private IOrganDefineBusiness organDefineService;
57  	
58  	public String showService(){
59  		String s = "未注册bundle服务";
60  		List<String> bundleServices = new LinkedList<String>();
61  		Bundle[] bundles = context.getBundles();
62  		List<String> objectClasses;
63  		for(Bundle bundle : bundles){
64  			//平台bundle的groupId为gboat2开头,业务bundle的groupId为glodon开头
65  			if(bundle.getSymbolicName().startsWith("gboat2")||bundle.getSymbolicName().startsWith("glodon")){
66  				logger.debug("----------"+bundle+"------------");
67  				try{
68  					ServiceReference[] services = bundle.getRegisteredServices();
69  					for(ServiceReference service : services){
70  						String[] keys = service.getPropertyKeys();
71  						for(String key : keys){
72  							if(key.equals("objectClass")){
73  								objectClasses = Arrays.asList((String[])service.getProperty(key));
74  								logger.debug(key+" --> "+objectClasses);
75  								if(objectClasses.contains("gboat2.web.service.IOrganizationService")){
76  									bundleServices.add(bundle.getSymbolicName()+"#"+service.getProperty("org.springframework.osgi.bean.name"));
77  								}
78  							}else{
79  								logger.debug(key+" --> "+service.getProperty(key));
80  							}
81  						}
82  					}
83  				}catch(Throwable e){
84  					logger.warn("failed to read service from "+bundle+". "+e.getMessage());
85  				}
86  			}
87  		}
88  		logger.info("find organdefine services : "+bundleServices);
89  		if(bundleServices.size() == 0) {
90  			bundleServices.add(s);
91  		}
92  		JsonResultSupport.output(JsonResultSupport.wrap(bundleServices, true));
93  		return null;
94  	}
95  	
96  	@Override
97  	public String ajaxDelete() {
98  		loggerService.log(Level.INFO, "删除", "删除组织机构 : " + ((OrganDefine) organDefineService.get(OrganDefine.class, getSID())).getOrganDefineName());
99  		return super.ajaxDelete();
100 	}
101 	
102 	@Override
103 	public String ajaxSave() {
104 		OrganDefine organDefine = (OrganDefine) getModel();
105 		String type = StringUtils.isEmpty(organDefine.getOrganDefineId()) ? "新增" : "编辑";
106 		loggerService.log(Level.INFO, type, type + "组织机构 : " + organDefine.getOrganDefineName());
107 		organDefine.setCommitTime(new Date());
108 		organDefine.setStatus("0");
109 	    return super.ajaxSave();
110 	}
111 }