1 23 24 package org.infoglue.cms.treeservice; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletException ; 32 33 import org.apache.log4j.Logger; 34 import org.infoglue.cms.controllers.usecases.structuretool.ViewSiteNodeTreeUCC; 35 import org.infoglue.cms.controllers.usecases.structuretool.ViewSiteNodeTreeUCCFactory; 36 import org.infoglue.cms.entities.structure.SiteNodeVO; 37 import org.infoglue.cms.net.CommunicationEnvelope; 38 import org.infoglue.cms.net.Node; 39 import org.infoglue.cms.security.InfoGlueAuthenticationFilter; 40 import org.infoglue.cms.security.InfoGluePrincipal; 41 42 43 public class SiteNodeService extends JServiceBuilder 44 { 45 private final static Logger logger = Logger.getLogger(SiteNodeService.class.getName()); 46 47 public void init(ServletConfig config) throws ServletException  48 { 49 super.init(config); 50 } 51 52 53 public CommunicationEnvelope execute(CommunicationEnvelope envelope) 54 { 55 CommunicationEnvelope responseEnvelope = new CommunicationEnvelope(); 56 57 try 58 { 59 String action = envelope.getAction(); 60 logger.info("ACTION:" + action); 61 62 if(action.equals("selectRootNode")) 63 { 64 responseEnvelope = getRootSiteNode(envelope); 65 } 66 if(action.equals("selectNode")) 67 { 68 responseEnvelope = getSiteNode(envelope); 69 } 70 else if(action.equals("selectChildNodes")) 71 { 72 responseEnvelope = getChildSiteNodes(envelope); 73 } 74 88 logger.info("Executing in SiteNodeService..."); 89 } 90 catch (Exception e) 91 { 92 responseEnvelope.setStatus("1"); 93 e.printStackTrace(); 94 } 95 return responseEnvelope; 96 } 97 98 101 public CommunicationEnvelope getRootSiteNode(CommunicationEnvelope envelope) 102 { 103 CommunicationEnvelope responseEnvelope = new CommunicationEnvelope(); 104 105 try 106 { 107 List arguments = (List )envelope.getNodes(); 108 Integer repositoryId = ((Node)arguments.get(0)).getId(); 109 logger.info("repositoryId:" + repositoryId); 110 ViewSiteNodeTreeUCC viewSiteNodeTreeUCC = ViewSiteNodeTreeUCCFactory.newViewSiteNodeTreeUCC(); 111 SiteNodeVO siteNodeVO = viewSiteNodeTreeUCC.getRootSiteNode(repositoryId, getInfoGluePrincipal()); 112 logger.info("siteNodeVO:" + siteNodeVO.getSiteNodeId() + " " + siteNodeVO.getName()); 113 Node node = new Node(); 114 node.setId(siteNodeVO.getSiteNodeId()); 115 node.setName(siteNodeVO.getName()); 116 node.setIsBranch(siteNodeVO.getIsBranch()); 117 118 List nodes = new ArrayList (); 119 nodes.add(node); 120 responseEnvelope.setNodes(nodes); 121 } 122 catch (Exception e) 123 { 124 responseEnvelope.setStatus("1"); 125 e.printStackTrace(); 126 } 127 return responseEnvelope; 128 } 129 130 133 public CommunicationEnvelope getSiteNode(CommunicationEnvelope envelope) 134 { 135 CommunicationEnvelope responseEnvelope = new CommunicationEnvelope(); 136 137 try 138 { 139 List arguments = (List )envelope.getNodes(); 140 Integer siteNodeId = ((Node)arguments.get(0)).getId(); 141 logger.info("siteNodeId:" + siteNodeId); 142 ViewSiteNodeTreeUCC viewSiteNodeTreeUCC = ViewSiteNodeTreeUCCFactory.newViewSiteNodeTreeUCC(); 143 SiteNodeVO siteNodeVO = viewSiteNodeTreeUCC.getSiteNode(siteNodeId); 144 logger.info("siteNodeVO:" + siteNodeVO.getSiteNodeId() + " " + siteNodeVO.getName()); 145 Node node = new Node(); 146 node.setId(siteNodeVO.getSiteNodeId()); 147 node.setName(siteNodeVO.getName()); 148 node.setIsBranch(siteNodeVO.getIsBranch()); 149 150 List nodes = new ArrayList (); 151 nodes.add(node); 152 responseEnvelope.setNodes(nodes); 153 } 154 catch (Exception e) 155 { 156 responseEnvelope.setStatus("1"); 157 e.printStackTrace(); 158 } 159 return responseEnvelope; 160 } 161 162 163 166 public CommunicationEnvelope getChildSiteNodes(CommunicationEnvelope envelope) 167 { 168 CommunicationEnvelope responseEnvelope = new CommunicationEnvelope(); 169 170 try 171 { 172 List arguments = (List )envelope.getNodes(); 173 Integer siteNodeId = ((Node)arguments.get(0)).getId(); 174 logger.info("siteNodeId:" + siteNodeId); 175 176 ViewSiteNodeTreeUCC viewSiteNodeTreeUCC = ViewSiteNodeTreeUCCFactory.newViewSiteNodeTreeUCC(); 177 List childSiteNodes = viewSiteNodeTreeUCC.getSiteNodeChildren(siteNodeId); 178 179 List nodes = new ArrayList (); 180 Iterator childIterator = childSiteNodes.iterator(); 181 182 while(childIterator.hasNext()) 183 { 184 SiteNodeVO siteNodeVO = (SiteNodeVO)childIterator.next(); 185 Node node = new Node(); 186 node.setId(siteNodeVO.getSiteNodeId()); 187 node.setName(siteNodeVO.getName()); 188 node.setIsBranch(siteNodeVO.getIsBranch()); 189 nodes.add(node); 190 } 191 192 responseEnvelope.setNodes(nodes); 193 } 194 catch (Exception e) 195 { 196 responseEnvelope.setStatus("1"); 197 e.printStackTrace(); 198 } 199 return responseEnvelope; 200 } 201 202 203 206 207 public InfoGluePrincipal getInfoGluePrincipal() 208 { 209 return (InfoGluePrincipal)this.request.getSession().getAttribute(InfoGlueAuthenticationFilter.INFOGLUE_FILTER_USER); 210 } 211 212 } | Popular Tags |