f1lam3ntx0

Untitled

Feb 22nd, 2024
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.25 KB | None | 0 0
  1. public static void saveLoginCount(Workspace__c wsp)
  2.     {
  3.         String sessionKey = LoginUtils.sessionKey;
  4.         if(sessionKey != null){//SessionId is present, so login entry is already done, So no need to do again
  5.             return;
  6.         }
  7.        
  8.         String userId = UserInfo.getUserId();
  9.         // list<ViewTracker__c> oldLoginEntry = [SELECT Id,  Type__c, UserType__c, User__c, Workspace__c, SessionId__c FROM ViewTracker__c where Type__c =:Constants.TYPE_LOGIN and Workspace__c =:wsp.id and (SessionId__c =:sessionId  OR Createddate >:basetime) AND User__c =: userId];
  10.         // list<ViewTracker__c> oldLoginEntrys = Utils.filterRecords(oldLoginEntry);
  11.         // if(oldLoginEntrys?.size() > 0){
  12.         //  return;
  13.         // }
  14.         //AppConfigUtil appConfig = AppConfigUtil.getInstance();
  15.         //isExternal=appConfig.isCustomerProfileAssigned();    //customer Profile
  16.         Wrapper.WorkspaceWrapper workspaceObjWrapper = new Wrapper.WorkspaceWrapper();
  17.         workspaceObjWrapper.workspace = wsp;
  18.         workspaceObjWrapper.isPresentMode = false;
  19.         CSRAccessBO accessBO = RequestScopeDataUtils.getInstance().getCSRAccessBO(workspaceObjWrapper);
  20.         //System.debug('SANJAY accessBO -->'+accessBO);
  21.         isExternal = accessBO != null ? accessBO.isCustomerUser():false;
  22.         //System.debug('For Tracking Entry '+isExternal);
  23.         SObject [] cleanList1;
  24.         //String userId = UserInfo.getUserId();
  25.        
  26.  
  27.         //Check for login entry in the room
  28.         List<ViewTracker__c> vtListTimeCheckBase = [Select Id, Activity_Date__c from  ViewTracker__c where Type__c=:Constants.TYPE_LOGIN AND Workspace__c=:wsp.Id AND User__c=:userId order by Activity_Date__c DESC LIMIT 1];
  29.         List< ViewTracker__c> vtListTimeCheck= Utils.filterRecords(vtListTimeCheckBase);
  30.         if(vtListTimeCheck.size()>0)
  31.         {
  32.             ViewTracker__c vtTime = vtListTimeCheck[0];
  33.             Long activityTime = vtTime.Activity_Date__c.getTime(); //in milliseconds
  34.             Long currentTime = Datetime.now().getTime(); // in milliseconds
  35.             Long timeDiff = currentTime - activityTime;
  36.             if(timeDiff < 120000)
  37.             {
  38.                 return; //if second login entry is getting created within 2 minutes, ignore it and do not insert in view tracker
  39.             }
  40.         }
  41.  
  42.         //Check for first time login entry in the room
  43.         List<ViewTracker__c> vtListLoginTimeCheckBase = [Select Id, Activity_Date__c from  ViewTracker__c where Type__c=:Constants.TYPE_LOGIN AND Event_Subtype__c=: Constants.TRACK_FIRST_TIME_LOGIN AND Workspace__c=:wsp.Id AND User__c=:userId order by Activity_Date__c DESC LIMIT 1];
  44.         List< ViewTracker__c> vtListLoginTimeCheck= Utils.filterRecords(vtListLoginTimeCheckBase);
  45.         if(vtListLoginTimeCheck.size()>0)
  46.         {
  47.             ViewTracker__c vtTime = vtListLoginTimeCheck[0];
  48.             Long activityTime = vtTime.Activity_Date__c.getTime(); //in milliseconds
  49.             Long currentTime = Datetime.now().getTime(); // in milliseconds
  50.             Long timeDiff = currentTime - activityTime;
  51.             if(timeDiff < 120000)
  52.             {
  53.                 return; //if second login entry is getting created within 2 minutes, ignore it and do not insert in view tracker
  54.             }
  55.         }
  56.  
  57.        
  58.         List<ViewTracker__c> vtListBase=[Select Id,Date__c,Event_Specific_Name__c,message__c,
  59.                                     Type__c,User__c,UserType__c,OpportunityId__c,Opportunity_Stage__c
  60.                                     from  ViewTracker__c where (Type__c=:Constants.TRACK_FIRST_TIME_LOGIN or (Type__c=:Constants.TYPE_LOGIN and Event_Subtype__c=: Constants.TRACK_FIRST_TIME_LOGIN)) AND User__c=:userId AND UserType__c=:'External' AND
  61.                                     Workspace__c=:wsp.Id];
  62.         List<ViewTracker__c> vtList= Utils.filterRecords(vtListBase);
  63.  
  64.        
  65.         List<Wrapper.TrackingWrapper> twList = new List<Wrapper.TrackingWrapper>();
  66.         Wrapper.TrackingWrapper tw = new Wrapper.TrackingWrapper();
  67.         tw.workspaceId = wsp.Id;
  68.         if(isExternal){
  69.             if(vtList.isEmpty()){
  70.                 tw.eventSubType = Constants.TRACK_FIRST_TIME_LOGIN;
  71.             }
  72.             //tw.sessionId = sessionId;
  73.             tw.eventType = Constants.TYPE_LOGIN;
  74.             tw.activityOrigin='Email';
  75.             tw.activityOriginSubType=origin;
  76.         }
  77.         else   
  78.             tw.eventType = Constants.TRACK_SALESREP_VIEW_ROOM;
  79.         tw.statusCode = Wrapper.STATUS_UPDATION_SUCCESS;
  80.         tw.userId = userId;
  81.        
  82.         tw.canContribute = true;
  83.         List<String> eventTypes = new List<String>{Constants.TYPE_LOGIN,Constants.TRACK_SALESREP_VIEW_ROOM};
  84.         if(uId != null && !String.isBlank(uId)){
  85.             List<ViewTracker__c> vtListBase1=[Select Id,PlayId__c,Parent__c,Parent__r.UUID__c from  ViewTracker__c where UUID__c =: uId AND Type__c NOT IN : eventTypes Limit 1];
  86.             List<ViewTracker__c> vtList1= Utils.filterRecords(vtListBase1);
  87.             if(vtList1.size() > 0 && vtList1[0].PlayId__c != null){
  88.                 tw.playId = vtList1[0].PlayId__c;
  89.             }
  90.             if(vtList1.size() > 0 && vtList1[0].Parent__c != null && vtList1[0].Parent__r.UUID__c != null){
  91.                 tw.UUID = vtList1[0].Parent__r.UUID__c;
  92.             }else{
  93.                 tw.UUID = uId;
  94.             }
  95.         }
  96.  
  97.         if(SmartRoomV3Controller.urlUID != 'NONE')
  98.         {
  99.             tw.ClientSessionID = SmartRoomV3Controller.urlUID;
  100.         }
  101.         ViewTrackerService vts = new ViewTrackerService();
  102.         twList.add(tw);
  103.         //System.debug('tw ------------ '+tw);
  104.         try{
  105.             String currentUserId = UserInfo.getUserId();
  106.             User loggedInUserBase = Database.query('Select Title,Id,Name,SmallPhotoUrl,Username,FullPhotoUrl,FirstName,LastName,Email,Profile.Name,Phone,UserPreferencesShowEmailToExternalUsers,UserPreferencesShowWorkPhoneToExternalUsers,ContactId,Account.Name,Contact.Title,Contact.Account.Name,AccountId,contact.AccountId from User Where Id=:currentUserId');
  107.             User loggedInUser = (User)Utils.filterRecords(loggedInUserBase);
  108.        
  109.             if(isExternal){                        
  110.                 SRCoreNotificationMgr.createCustomerVisitNotification(wsp,loggedInUser);
  111.                 new WorkspaceController().sendFirstTimeLoginNotification(wsp,loggedInUser);
  112.             }
  113.             else if(AppConfigUtil.getInstance().isPartnerProfileAssigned()) /
  114.             {
  115.                
  116.                 SRCoreNotificationMgr.createCustomerVisitNotification(wsp,loggedInUser);
  117.             }  
  118.            
  119.             List<String> roomIds = new List<String>{wsp.Id};
  120.             List<String> userTypeList = new List<String>();
  121.            
  122.             String searchString = '';
  123.             List<String> userIdList = new List<String>{userId};
  124.             Map<String,Object> orderLimitOffset = new Map<String,Object>();
  125.             List<String> fieldsList = new List<String>{'Id','Stage__c'};
  126.             List<SR_Member__c> memebrsList = new SRCoreMembersSelector().selectMembersByUserAndType(roomIds,userIdList,userTypeList,fieldsList,searchString,orderLimitOffset);
  127.             //System.debug('memebrsList---------->'+memebrsList);
  128.            
  129.             for(SR_Member__c member : memebrsList){
  130.                 String invitationStatus = member.Stage__c;
  131.                 if(invitationStatus != null && invitationStatus != '')
  132.                 {
  133.                     if(member.Stage__c.contains(Constants.WORKSPACE_USER_SHARE_INVITE_SUCCESS) ||
  134.                         member.Stage__c.equals(Constants.WORKSPACE_USER_SHARE_JOINED) ||
  135.                         member.Stage__c.equals(Constants.WORKSPACE_USER_SHARED))
  136.                             member.Stage__c = Constants.WORKSPACE_USER_SHARE_JOINED;   
  137.                 }
  138.             }
  139.             SRMembersService.updateSRMember(memebrsList);        
  140.         /*    cleanList1=AccessCheck.getInstance().updateCheck((new map<Id,SR_Member__c>(memebrsList)),new List<String>{'Stage__c'});
  141.                 //System.debug('cleanList1 ------------ '+cleanList1);
  142.             if(cleanList1 != null && cleanList1.size()>0)
  143.                 update cleanList1; */
  144.         }catch(DMLException e) {
  145.             //System.debug('check Exception ========'+e);
  146.         }
  147.         //vts.saveViewTracker(twList);
  148.         new SmartRoomV3ControllerElevated().saveViewTracker(twList);
  149. }
Advertisement
Add Comment
Please, Sign In to add comment