
prerna.reactor.database.upload.ParseMetamodelReactor Maven / Gradle / Ivy
The newest version!
package prerna.reactor.database.upload;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import prerna.poi.main.helper.CSVFileHelper;
import prerna.reactor.AbstractReactor;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.execptions.SemossPixelException;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.UploadInputUtility;
public class ParseMetamodelReactor extends AbstractReactor {
protected static final String DIR_SEPARATOR = java.nio.file.FileSystems.getDefault().getSeparator();
public ParseMetamodelReactor() {
this.keysToGet = new String[] { UploadInputUtility.FILE_PATH, UploadInputUtility.SPACE, UploadInputUtility.DELIMITER,
UploadInputUtility.ROW_COUNT, UploadInputUtility.PROP_FILE };
}
@Override
public NounMetadata execute() {
organizeKeys();
String csvFilePath = UploadInputUtility.getFilePath(this.store, this.insight);
if(!new File(csvFilePath).exists()) {
throw new IllegalArgumentException("Unable to locate file");
}
String delimiter = UploadInputUtility.getDelimiter(this.store);
char delim = delimiter.charAt(0);
CSVFileHelper helper = new CSVFileHelper();
helper.setDelimiter(delim);
helper.parse(csvFilePath);
return new NounMetadata(generateMetaModelFromProp(helper), PixelDataType.MAP);
}
/**
* Generates the Meta model data based on the definition of the prop file
*/
private Map generateMetaModelFromProp(CSVFileHelper helper) {
Map metamodel = UploadInputUtility.getMetamodelFromPropFile(this.store, this.insight);
if (metamodel == null) {
String error = "Unable to read metamodel prop file.";
NounMetadata noun = new NounMetadata(error, PixelDataType.CONST_STRING, PixelOperationType.ERROR);
SemossPixelException exception = new SemossPixelException(noun);
exception.setContinueThreadOfExecution(false);
throw exception;
}
// get file location and file name
String filePath = helper.getFileLocation();
String file = filePath.substring(filePath.lastIndexOf(DIR_SEPARATOR) + DIR_SEPARATOR.length(),
filePath.lastIndexOf("."));
try {
file = file.substring(0, file.indexOf("_____UNIQUE"));
} catch (Exception e) {
// just in case that fails, this shouldnt because if its a filename
// it should have a "."
file = filePath.substring(filePath.lastIndexOf(DIR_SEPARATOR) + DIR_SEPARATOR.length(), filePath.lastIndexOf("."));
}
// store file path and file name to send to FE
metamodel.put("fileLocation", filePath);
metamodel.put("fileName", file);
metamodel.put("headerModifications", helper.getChangedHeaders());
// adding an empty map for consistency
metamodel.put("additionalDataTypes", new HashMap());
// need to close the helper
helper.clear();
return metamodel;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy