Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void saveLoginCount(Workspace__c wsp)
- {
- String sessionKey = LoginUtils.sessionKey;
- if(sessionKey != null){//SessionId is present, so login entry is already done, So no need to do again
- return;
- }
- String userId = UserInfo.getUserId();
- // 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];
- // list<ViewTracker__c> oldLoginEntrys = Utils.filterRecords(oldLoginEntry);
- // if(oldLoginEntrys?.size() > 0){
- // return;
- // }
- //AppConfigUtil appConfig = AppConfigUtil.getInstance();
- //isExternal=appConfig.isCustomerProfileAssigned(); //customer Profile
- Wrapper.WorkspaceWrapper workspaceObjWrapper = new Wrapper.WorkspaceWrapper();
- workspaceObjWrapper.workspace = wsp;
- workspaceObjWrapper.isPresentMode = false;
- CSRAccessBO accessBO = RequestScopeDataUtils.getInstance().getCSRAccessBO(workspaceObjWrapper);
- //System.debug('SANJAY accessBO -->'+accessBO);
- isExternal = accessBO != null ? accessBO.isCustomerUser():false;
- //System.debug('For Tracking Entry '+isExternal);
- SObject [] cleanList1;
- //String userId = UserInfo.getUserId();
- //Check for login entry in the room
- 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];
- List< ViewTracker__c> vtListTimeCheck= Utils.filterRecords(vtListTimeCheckBase);
- if(vtListTimeCheck.size()>0)
- {
- ViewTracker__c vtTime = vtListTimeCheck[0];
- Long activityTime = vtTime.Activity_Date__c.getTime(); //in milliseconds
- Long currentTime = Datetime.now().getTime(); // in milliseconds
- Long timeDiff = currentTime - activityTime;
- if(timeDiff < 120000)
- {
- return; //if second login entry is getting created within 2 minutes, ignore it and do not insert in view tracker
- }
- }
- //Check for first time login entry in the room
- 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];
- List< ViewTracker__c> vtListLoginTimeCheck= Utils.filterRecords(vtListLoginTimeCheckBase);
- if(vtListLoginTimeCheck.size()>0)
- {
- ViewTracker__c vtTime = vtListLoginTimeCheck[0];
- Long activityTime = vtTime.Activity_Date__c.getTime(); //in milliseconds
- Long currentTime = Datetime.now().getTime(); // in milliseconds
- Long timeDiff = currentTime - activityTime;
- if(timeDiff < 120000)
- {
- return; //if second login entry is getting created within 2 minutes, ignore it and do not insert in view tracker
- }
- }
- List<ViewTracker__c> vtListBase=[Select Id,Date__c,Event_Specific_Name__c,message__c,
- Type__c,User__c,UserType__c,OpportunityId__c,Opportunity_Stage__c
- 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
- Workspace__c=:wsp.Id];
- List<ViewTracker__c> vtList= Utils.filterRecords(vtListBase);
- List<Wrapper.TrackingWrapper> twList = new List<Wrapper.TrackingWrapper>();
- Wrapper.TrackingWrapper tw = new Wrapper.TrackingWrapper();
- tw.workspaceId = wsp.Id;
- if(isExternal){
- if(vtList.isEmpty()){
- tw.eventSubType = Constants.TRACK_FIRST_TIME_LOGIN;
- }
- //tw.sessionId = sessionId;
- tw.eventType = Constants.TYPE_LOGIN;
- tw.activityOrigin='Email';
- tw.activityOriginSubType=origin;
- }
- else
- tw.eventType = Constants.TRACK_SALESREP_VIEW_ROOM;
- tw.statusCode = Wrapper.STATUS_UPDATION_SUCCESS;
- tw.userId = userId;
- tw.canContribute = true;
- List<String> eventTypes = new List<String>{Constants.TYPE_LOGIN,Constants.TRACK_SALESREP_VIEW_ROOM};
- if(uId != null && !String.isBlank(uId)){
- 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];
- List<ViewTracker__c> vtList1= Utils.filterRecords(vtListBase1);
- if(vtList1.size() > 0 && vtList1[0].PlayId__c != null){
- tw.playId = vtList1[0].PlayId__c;
- }
- if(vtList1.size() > 0 && vtList1[0].Parent__c != null && vtList1[0].Parent__r.UUID__c != null){
- tw.UUID = vtList1[0].Parent__r.UUID__c;
- }else{
- tw.UUID = uId;
- }
- }
- if(SmartRoomV3Controller.urlUID != 'NONE')
- {
- tw.ClientSessionID = SmartRoomV3Controller.urlUID;
- }
- ViewTrackerService vts = new ViewTrackerService();
- twList.add(tw);
- //System.debug('tw ------------ '+tw);
- try{
- String currentUserId = UserInfo.getUserId();
- 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');
- User loggedInUser = (User)Utils.filterRecords(loggedInUserBase);
- if(isExternal){
- SRCoreNotificationMgr.createCustomerVisitNotification(wsp,loggedInUser);
- new WorkspaceController().sendFirstTimeLoginNotification(wsp,loggedInUser);
- }
- else if(AppConfigUtil.getInstance().isPartnerProfileAssigned()) /
- {
- SRCoreNotificationMgr.createCustomerVisitNotification(wsp,loggedInUser);
- }
- List<String> roomIds = new List<String>{wsp.Id};
- List<String> userTypeList = new List<String>();
- String searchString = '';
- List<String> userIdList = new List<String>{userId};
- Map<String,Object> orderLimitOffset = new Map<String,Object>();
- List<String> fieldsList = new List<String>{'Id','Stage__c'};
- List<SR_Member__c> memebrsList = new SRCoreMembersSelector().selectMembersByUserAndType(roomIds,userIdList,userTypeList,fieldsList,searchString,orderLimitOffset);
- //System.debug('memebrsList---------->'+memebrsList);
- for(SR_Member__c member : memebrsList){
- String invitationStatus = member.Stage__c;
- if(invitationStatus != null && invitationStatus != '')
- {
- if(member.Stage__c.contains(Constants.WORKSPACE_USER_SHARE_INVITE_SUCCESS) ||
- member.Stage__c.equals(Constants.WORKSPACE_USER_SHARE_JOINED) ||
- member.Stage__c.equals(Constants.WORKSPACE_USER_SHARED))
- member.Stage__c = Constants.WORKSPACE_USER_SHARE_JOINED;
- }
- }
- SRMembersService.updateSRMember(memebrsList);
- /* cleanList1=AccessCheck.getInstance().updateCheck((new map<Id,SR_Member__c>(memebrsList)),new List<String>{'Stage__c'});
- //System.debug('cleanList1 ------------ '+cleanList1);
- if(cleanList1 != null && cleanList1.size()>0)
- update cleanList1; */
- }catch(DMLException e) {
- //System.debug('check Exception ========'+e);
- }
- //vts.saveViewTracker(twList);
- new SmartRoomV3ControllerElevated().saveViewTracker(twList);
- }
Advertisement
Add Comment
Please, Sign In to add comment