All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prerna.auth.SyncUserAppsThread Maven / Gradle / Ivy

The newest version!
package prerna.auth;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.http.HttpSession;

import prerna.cluster.util.ClusterUtil;
import prerna.util.Constants;

public class SyncUserAppsThread implements Runnable {
	protected static final Logger classLogger = LogManager.getLogger(SyncUserAppsThread.class);

	Collection workspaceIds = null;
	Collection assetIds = null;
	
	public SyncUserAppsThread(User user) {
		this.workspaceIds = user.getWorkspaceEngineMap().values();
		this.assetIds = user.getWorkspaceEngineMap().values();
	}
	
	public SyncUserAppsThread(Collection workspaceIds, Collection assetIds) {
		this.workspaceIds = workspaceIds;
		this.assetIds = assetIds;
	}
	
	public SyncUserAppsThread(String workspaceId, String assetId) {
		if(workspaceId != null) {
			this.workspaceIds = new ArrayList();
			this.workspaceIds.add(workspaceId);
		}
		if(assetId != null) {
			this.assetIds = new ArrayList();
			this.assetIds.add(assetId);
		}
	}
	
	@Override
	public void run() {
		execute(this.workspaceIds, this.assetIds);
	}
	
	public static void execute(HttpSession session) {
		if(ClusterUtil.IS_CLUSTER) {
			Collection workspaceIds = null;
			Collection assetIds = null;
			
			// now push all the values to be stored
			User user = (User) session.getAttribute(Constants.SESSION_USER);
			if(user != null) {
				workspaceIds = user.getWorkspaceEngineMap().values();
				assetIds = user.getAssetEngineMap().values();
			} else {
				// grab the maps from the session
				if(session.getAttribute(Constants.USER_WORKSPACE_IDS) != null) {
					workspaceIds = ((Map) session.getAttribute(Constants.USER_WORKSPACE_IDS)).values();
				}
				if(session.getAttribute(Constants.USER_ASSET_IDS) != null) {
					assetIds = ((Map) session.getAttribute(Constants.USER_ASSET_IDS)).values();
				}
			}
			
			execute(workspaceIds, assetIds);
		}
	}
	
	public static void execute(Collection workspaceIds, Collection assetIds) {
		// now push all the values to be stored
		if(ClusterUtil.IS_CLUSTER) {
			if(workspaceIds != null) {
				for(String workspaceAppId : workspaceIds) {
					try {
						ClusterUtil.pushUserWorkspace(workspaceAppId, false);
					} catch (Exception e) {
						classLogger.error(Constants.STACKTRACE, e);
					}
				}
			}
			if(assetIds != null) {
				for(String assetAppId : assetIds) {
					try {
						ClusterUtil.pushUserWorkspace(assetAppId, true);
					} catch (Exception e) {
						classLogger.error(Constants.STACKTRACE, e);
					}
				}
			}
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy