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

prerna.reactor.algorithms.xray.GetLocalSchemaReactor Maven / Gradle / Ivy

The newest version!
package prerna.reactor.algorithms.xray;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import prerna.algorithm.api.SemossDataType;
import prerna.engine.api.IDatabaseEngine;
import prerna.masterdatabase.utility.MasterDatabaseUtility;
import prerna.reactor.AbstractReactor;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.ReactorKeysEnum;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.Utility;

public class GetLocalSchemaReactor extends AbstractReactor {
	public GetLocalSchemaReactor() {
		this.keysToGet = new String[] { ReactorKeysEnum.DATABASE.getKey() };
	}

	@Override
	public NounMetadata execute() {
		organizeKeys();
		String engineId = this.keyValue.get(this.keysToGet[0]);
		if (engineId == null) {
			throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.DATABASE.getKey());
		}
		engineId = MasterDatabaseUtility.testDatabaseIdIfAlias(engineId);
		IDatabaseEngine engine = Utility.getDatabase(engineId);
		Set concepts = MasterDatabaseUtility.getConceptsWithinDatabaseRDBMS(engineId);

		// tablename: [{name, type}]
		HashMap> tableDetails = new HashMap>();
		for (String table : concepts) {
			// ignore default concept value
			ArrayList allCols = new ArrayList();
			HashMap colInfo = new HashMap();
			colInfo.put("name", table);
			String dataType = MasterDatabaseUtility.getBasicDataType(engineId, table, null);;
			if (dataType != null) {
				dataType = SemossDataType.convertStringToDataType(dataType).toString();
			} else {
				dataType = SemossDataType.STRING.toString();
			}
			colInfo.put("type", dataType);
			allCols.add(colInfo);
			List properties = MasterDatabaseUtility.getSpecificConceptProperties(table, engineId);
			for (String prop : properties) {
				HashMap propInfo = new HashMap();
				propInfo.put("name", prop);
				dataType = MasterDatabaseUtility.getBasicDataType(engineId, prop, table);;
				if (dataType != null) {
					if(dataType.contains("TYPE:")) {
						dataType = dataType.replace("TYPE:", "");
					}
					dataType = SemossDataType.convertStringToDataType(dataType).toString();
				} else {
					dataType = SemossDataType.STRING.toString();
				}
				propInfo.put("type", dataType);
				allCols.add(propInfo);
			}
			tableDetails.put(table, allCols);
		}

		HashMap ret = new HashMap();
		ret.put("databaseName", engine.getEngineName());
		ret.put("tables", tableDetails);

		return new NounMetadata(ret, PixelDataType.CUSTOM_DATA_STRUCTURE, PixelOperationType.CODE_EXECUTION);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy