/*     */ package psdi.webclient.beans.servicedesk;
/*     */ 
/*     */ import java.rmi.RemoteException;
/*     */ import java.util.Iterator;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import psdi.app.person.PersonRemote;
/*     */ import psdi.app.person.PersonSetRemote;
/*     */ import psdi.app.ticket.TKTemplate;
/*     */ import psdi.app.ticket.TKTemplateSetRemote;
/*     */ import psdi.app.ticket.TicketRemote;
/*     */ import psdi.mbo.MboRemote;
/*     */ import psdi.mbo.MboSetRemote;
/*     */ import psdi.mbo.SqlFormat;
/*     */ import psdi.security.UserInfo;
/*     */ import psdi.util.MXException;
/*     */ import psdi.util.MXSession;
/*     */ import psdi.webclient.system.beans.AppBean;
/*     */ import psdi.webclient.system.beans.DataBean;
/*     */ import psdi.webclient.system.controller.AppInstance;
/*     */ import psdi.webclient.system.controller.BoundControl;
/*     */ import psdi.webclient.system.controller.BoundControl.BoundAttribute;
/*     */ import psdi.webclient.system.controller.PageInstance;
/*     */ import psdi.webclient.system.controller.RequestHandler;
/*     */ import psdi.webclient.system.controller.SessionContext;
/*     */ import psdi.webclient.system.controller.Utility;
/*     */ import psdi.webclient.system.controller.WebClientEvent;
/*     */ import psdi.webclient.system.session.WebClientSession;
/*     */ 
/*     */ public class ServReqsAppBean extends AppBean
/*     */ {
/*     */   protected void initialize()
/*     */     throws MXException, RemoteException
/*     */   {
/*  51 */     this.hasTableData = true;
/*  52 */     super.initialize();
/*  53 */     this.hasTableData = false;
/*     */ 
/*  55 */     if ((this.clientSession.getCurrentEvent().getAdditionalEvent() != null) && (this.clientSession.getCurrentEvent().getAdditionalEvent().equals("SRMEVENT")))
/*     */     {
/*  59 */       long id = this.clientSession.getCurrentEvent().getUniqueId();
/*  60 */       moveToUniqueId(id);
/*     */     }
/*     */     else
/*     */     {
/*  64 */       insert();
/*  65 */       setValue("reportedby", getMbo().getUserInfo().getPersonId());
/*  66 */       String affectedperson = getString("affectedperson");
/*  67 */       if ((affectedperson != null) && (!affectedperson.equals("")))
/*     */       {
/*  69 */         PersonSetRemote personMboSet = (PersonSetRemote)getMbo().getMboSet("AFFECTEDPERSON");
/*  70 */         if (!personMboSet.isEmpty())
/*     */         {
/*  72 */           PersonRemote personMbo = (PersonRemote)personMboSet.getMbo(0);
/*     */ 
/*  74 */           if (personMbo.getBoolean("LOCTOSERVREQ"))
/*     */           {
/*  76 */             setValue("location", personMbo.getString("LOCATION"));
/*     */           }
/*     */         }
/*     */       }
/*     */ 
/*  81 */       String valuestring = this.clientSession.getCurrentEvent().getAdditionalEventValue();
/*  82 */       String templateid = null;
/*     */ 
/*  84 */       if (valuestring != null) {
/*  85 */         for (String kv : valuestring.split("\\|"))
/*     */         {
/*  87 */           String[] v = kv.split("=");
/*  88 */           if ((v != null) && (v.length == 2))
/*     */           {
/*  90 */             if (!"templateid".equals(v[0]))
/*     */               continue;
/*  92 */             templateid = v[1];
/*     */           }
/*     */           else
/*     */           {
/*  97 */             v = kv.split("%3D");
/*  98 */             if ((v == null) || (v.length != 2))
/*     */               continue;
/* 100 */             if (!"templateid".equals(v[0]))
/*     */               continue;
/* 102 */             templateid = v[1];
/*     */           }
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 108 */       if (templateid != null)
/*     */         try {
/* 110 */           TicketRemote ticketRemote = (TicketRemote)getMbo();
/* 111 */           SqlFormat sqf = new SqlFormat("templateid = :1");
/* 112 */           sqf.setObject(1, "TKTEMPLATE", "templateid", templateid);
/* 113 */           TKTemplateSetRemote tktemplateSetMbo = (TKTemplateSetRemote)ticketRemote.getMboSet("QITKTEMPLATE2", "TKTEMPLATE", sqf.format());
/* 114 */           if (tktemplateSetMbo.count() == 1) {
/* 115 */             ticketRemote.applyTemplate((TKTemplate)tktemplateSetMbo.getMbo(0));
/* 116 */             fireDataChangedEvent();
/* 117 */           } else if (tktemplateSetMbo.count() == 0) {
/* 118 */             Utility.showMessageBox(this.sessionContext.getCurrentEvent(), "ticket", "qiticketnotemplatematchfound", null);
/* 119 */             this.sessionContext.queueRefreshEvent();
/*     */           } else {
/* 121 */             Utility.showMessageBox(this.sessionContext.getCurrentEvent(), "ticket", "qiticketmutltipletemplate", null);
/* 122 */             this.sessionContext.queueRefreshEvent();
/*     */           }
/*     */         } catch (MXException mxe) {
/* 125 */           Utility.showMessageBox(this.sessionContext.getCurrentEvent(), mxe);
/*     */         }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int newrecord()
/*     */     throws MXException, RemoteException
/*     */   {
/* 137 */     Utility.sendEvent(new WebClientEvent("dialogclose", this.app.getCurrentPageId(), null, this.sessionContext));
/* 138 */     AppInstance currentApp = this.sessionContext.getCurrentApp();
/* 139 */     PageInstance currentPage = currentApp.getCurrentPage();
/*     */ 
/* 143 */     String controlId = null;
/* 144 */     if ((this.boundInputs != null) && (!this.boundInputs.isEmpty()))
/*     */     {
/* 146 */       Iterator controls = this.boundInputs.keySet().iterator();
/* 147 */       while (controls.hasNext())
/*     */       {
/* 149 */         Object key = controls.next();
/* 150 */         BoundControl value = (BoundControl)this.boundInputs.get(key);
/* 151 */         Iterator ite = value.getBoundAttributes();
/*     */ 
/* 153 */         while (ite.hasNext())
/*     */         {
/* 155 */           if (!((BoundControl.BoundAttribute)ite.next()).getDataAttribute().equalsIgnoreCase("description"))
/*     */             continue;
/* 157 */           controlId = key.toString();
/*     */         }
/*     */ 
/* 162 */         if (controlId != null) {
/*     */           break;
/*     */         }
/*     */       }
/*     */     }
/* 167 */     currentPage.put("currentfocus", controlId + "_textbox");
/* 168 */     this.sessionContext.queueEvent(new WebClientEvent("setfieldfocus", currentPage.getPageId(), null, this.sessionContext));
/* 169 */     initialize();
/*     */ 
/* 171 */     return 1;
/*     */   }
/*     */ 
/*     */   public int viewdetails()
/*     */     throws MXException, RemoteException
/*     */   {
/* 179 */     MXSession mxs = this.sessionContext.getMXSession();
/* 180 */     UserInfo userInfo = mxs.getUserInfo();
/*     */ 
/* 182 */     String loggedInUser = userInfo.getPersonId();
/* 183 */     String affectedperson = getMbo().getString("affectedperson");
/* 184 */     String reportedby = getMbo().getString("reportedby");
/*     */ 
/* 187 */     String appValue = this.sessionContext.getCurrentEvent().getValueString();
/* 188 */     if ((appValue == null) || (appValue.equals("")))
/*     */     {
/* 190 */       appValue = "viewsr";
/*     */     }
/*     */ 
/* 193 */     if ((!affectedperson.equals(loggedInUser)) && (!reportedby.equals(loggedInUser)))
/*     */     {
/* 195 */       Utility.showMessageBox(this.sessionContext.getCurrentEvent(), "access", "notauthorized", null);
/* 196 */       return 1;
/*     */     }
/*     */ 
/* 199 */     Utility.sendEvent(new WebClientEvent("dialogclose", this.app.getCurrentPageId(), null, this.sessionContext));
/*     */ 
/* 201 */     DataBean appBean = Utility.getDataSource(this.sessionContext, this.app.getAppHandler());
/* 202 */     long uid = appBean.getMbo().getInt("ticketuid");
/* 203 */     this.sessionContext.queueEvent(new WebClientEvent("changeapp", this.app.getId(), appValue, null, null, uid, this.sessionContext));
/*     */ 
/* 205 */     return 1;
/*     */   }
/*     */ 
/*     */   public synchronized void saverecord()
/*     */     throws MXException
/*     */   {
/* 215 */     checkForAppError();
/*     */ 
/* 217 */     if (this.mboSetRemote == null) {
/* 218 */       return;
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/* 223 */       MboRemote newMbo = null;
/* 224 */       if (isNewRow())
/*     */       {
/*     */         try
/*     */         {
/* 228 */           long uniqueId = getUniqueIdValue();
/* 229 */           this.mboSetRemote.save();
/* 230 */           newMbo = getMboForUniqueId(uniqueId);
/*     */         }
/*     */         catch (NullPointerException e)
/*     */         {
/*     */         }
/*     */ 
/*     */       }
/*     */       else
/*     */       {
/* 240 */         autoInitiateWorkflow();
/* 241 */         if (this.app.get("wfinitiated") != null)
/*     */         {
/* 243 */           if (this.app.get("wfinitiated").equals("false"))
/*     */           {
/* 245 */             fireStructureChangedEvent();
/* 246 */             RequestHandler.showDialog(this.sessionContext, "srsubmit");
/*     */           }
/*     */         }
/* 249 */         return;
/*     */       }
/* 251 */       if (newMbo == null)
/*     */       {
/* 253 */         this.currentRecordData = null;
/* 254 */         this.currentRow = -1;
/*     */       }
/*     */       else
/*     */       {
/* 258 */         this.currentRecordData = newMbo.getMboData(getAttributes());
/*     */ 
/* 261 */         autoInitiateWorkflow();
/*     */       }
/*     */ 
/* 264 */       if (this.app.get("wfinitiated") != null)
/*     */       {
/* 266 */         if (this.app.get("wfinitiated").equals("false"))
/*     */         {
/* 268 */           fireStructureChangedEvent();
/* 269 */           RequestHandler.showDialog(this.sessionContext, "srsubmit");
/*     */         }
/*     */       }
/*     */     }
/*     */     catch (RemoteException e)
/*     */     {
/* 275 */       handleRemoteException(e);
/*     */     }
/*     */   }
/*     */ }

/* Location:           D:\maxapp\MAXIMO.ear\maximouiweb.war\WEB-INF\classes\
 * Qualified Name:     psdi.webclient.beans.servicedesk.ServReqsAppBean
 * JD-Core Version:    0.6.0
 */