use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.
the class DatabaseWindowManager method accessPermissions.
/**
* Insert the method's description here.
* Creation date: (5/14/2004 5:35:55 PM)
*/
public void accessPermissions(final Component requester, final VersionInfo selectedVersionInfo) {
final GroupAccess groupAccess = selectedVersionInfo.getVersion().getGroupAccess();
final DocumentManager docManager = getRequestManager().getDocumentManager();
AsynchClientTask task1 = new AsynchClientTask("show dialog", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
getAclEditor().clearACLList();
getAclEditor().setACLState(new ACLEditor.ACLState(groupAccess));
Object choice = showAccessPermissionDialog(getAclEditor(), requester);
if (choice != null) {
hashTable.put("choice", choice);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("access permission", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Object choice = hashTable.get("choice");
if (choice != null && choice.equals("OK")) {
ACLEditor.ACLState aclState = getAclEditor().getACLState();
if (aclState != null) {
if (aclState.isAccessPrivate() || (aclState.getAccessList() != null && aclState.getAccessList().length == 0)) {
VersionInfo vInfo = null;
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.setGroupPrivate((BioModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.setGroupPrivate((MathModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.setGroupPrivate((GeometryInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.setGroupPrivate((VCImageInfo) selectedVersionInfo);
}
} else if (aclState.isAccessPublic()) {
VersionInfo vInfo = null;
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.setGroupPublic((BioModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.setGroupPublic((MathModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.setGroupPublic((GeometryInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.setGroupPublic((VCImageInfo) selectedVersionInfo);
}
} else {
String[] aclUserNames = aclState.getAccessList();
String[] originalGroupAccesNames = new String[0];
// Turn User[] into String[]
if (groupAccess instanceof GroupAccessSome) {
GroupAccessSome gas = (GroupAccessSome) groupAccess;
User[] originalUsers = gas.getNormalGroupMembers();
for (int i = 0; i < originalUsers.length; i += 1) {
originalGroupAccesNames = (String[]) BeanUtils.addElement(originalGroupAccesNames, originalUsers[i].getName());
}
}
// Determine users needing adding
String[] needToAddUsers = new String[0];
for (int i = 0; i < aclUserNames.length; i += 1) {
if (!BeanUtils.arrayContains(originalGroupAccesNames, aclUserNames[i])) {
System.out.println("Added user=" + aclUserNames[i]);
needToAddUsers = (String[]) BeanUtils.addElement(needToAddUsers, aclUserNames[i]);
}
}
// Determine users needing removing
String[] needToRemoveUsers = new String[0];
for (int i = 0; i < originalGroupAccesNames.length; i += 1) {
if (!BeanUtils.arrayContains(aclUserNames, originalGroupAccesNames[i])) {
System.out.println("Removed user=" + originalGroupAccesNames[i]);
needToRemoveUsers = (String[]) BeanUtils.addElement(needToRemoveUsers, originalGroupAccesNames[i]);
}
}
VersionInfo vInfo = null;
String errorNames = "";
// Add Users to Group Access List
for (int i = 0; i < needToAddUsers.length; i++) {
try {
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.addUserToGroup((BioModelInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.addUserToGroup((MathModelInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.addUserToGroup((GeometryInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.addUserToGroup((VCImageInfo) selectedVersionInfo, needToAddUsers[i]);
}
} catch (ObjectNotFoundException e) {
errorNames += "Error changing permissions.\n" + selectedVersionInfo.getVersionType().getTypeName() + " \"" + selectedVersionInfo.getVersion().getName() + "\" edition (" + selectedVersionInfo.getVersion().getDate() + ")\nnot found, " + "your model list may be out of date, please go to menu Server->Reconnect to refresh the model list" + "\n";
break;
} catch (DataAccessException e) {
errorNames += "Error adding user '" + needToAddUsers[i] + "' : " + e.getMessage() + "\n";
}
}
// Remove users from Group Access List
for (int i = 0; i < needToRemoveUsers.length; i++) {
try {
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.removeUserFromGroup((BioModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.removeUserFromGroup((MathModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.removeUserFromGroup((GeometryInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.removeUserFromGroup((VCImageInfo) selectedVersionInfo, needToRemoveUsers[i]);
}
} catch (DataAccessException e) {
errorNames += "Error Removing user '" + needToRemoveUsers[i] + "'\n -----" + e.getMessage() + "\n";
}
}
if (errorNames.length() > 0) {
if (DatabaseWindowManager.this.getComponent() != null) {
PopupGenerator.showErrorDialog(DatabaseWindowManager.this, errorNames);
} else {
DialogUtils.showErrorDialog(requester, errorNames);
}
accessPermissions(requester, selectedVersionInfo);
}
}
}
}
}
};
ClientTaskDispatcher.dispatch(requester, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.
the class DocumentWindowManager method openGeometryDocumentWindow.
/**
* Insert the method's description here.
* Creation date: (1/21/2006 10:45:13 AM)
*/
public void openGeometryDocumentWindow(final Geometry geom) {
AsynchClientTask task1 = new AsynchClientTask("opening geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
GeometryInfo geomInfo = getRequestManager().getDocumentManager().getGeometryInfo(geom.getVersion().getVersionKey());
hashTable.put("geomInfo", geomInfo);
} catch (ObjectNotFoundException e) {
if (getVCDocument().getVersion() != null && !getVCDocument().getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new RuntimeException("Opening a geometry document window for '" + geom.getName() + "' from\n" + "Model '" + getVCDocument().getName() + "' owned by user (" + getVCDocument().getVersion().getOwner().getName() + ")\n" + "FAILED because user (" + getRequestManager().getDocumentManager().getUser().getName() + ") does not have permission.\n" + "Save Model '" + getVCDocument().getName() + "' to your account to have full access to the geometry.");
} else {
throw e;
}
}
}
};
AsynchClientTask task2 = new AsynchClientTask("opening geometry", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
GeometryInfo geomInfo = (GeometryInfo) hashTable.get("geomInfo");
getRequestManager().openDocument(geomInfo, DocumentWindowManager.this, true);
}
};
ClientTaskDispatcher.dispatch(this.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.
the class ODESolverPlotSpecificationPanel method initConnections.
/**
* Initializes connections
* @exception java.lang.Exception The exception description.
*/
@SuppressWarnings({ "serial", "unchecked" })
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
getFilterPanel().addPropertyChangeListener(ivjEventHandler);
getYAxisChoice().addListSelectionListener(ivjEventHandler);
this.addPropertyChangeListener(ivjEventHandler);
getXAxisComboBox_frm().addItemListener(ivjEventHandler);
getLogSensCheckbox().addActionListener(ivjEventHandler);
getSensitivityParameterSlider().addChangeListener(ivjEventHandler);
connPtoP1SetTarget();
connPtoP3SetTarget();
getYAxisChoice().setCellRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
ODEDataInterface mdi = getMyDataInterface();
if (mdi == null) {
return this;
}
String varName = (String) value;
ColumnDescription cd = null;
try {
cd = mdi.getColumnDescription(varName);
} catch (ObjectNotFoundException e) {
e.printStackTrace();
}
if (cd instanceof FunctionColumnDescription && ((FunctionColumnDescription) cd).getIsUserDefined()) {
if (function_icon == null) {
function_icon = new ImageIcon(getClass().getResource("/icons/function_icon.png"));
}
setIcon(function_icon);
}
if (mdi.getDataSymbolMetadataResolver() != null && mdi.getDataSymbolMetadataResolver().getDataSymbolMetadata(varName) != null) {
DataSymbolMetadata dsm = mdi.getDataSymbolMetadataResolver().getDataSymbolMetadata(varName);
String tooltipString = dsm.tooltipString;
if (tooltipString == null) {
tooltipString = varName;
}
setToolTipText(tooltipString);
}
return this;
}
});
}
use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.
the class IssueTableModel method getSourceObjectPathDescription.
private String getSourceObjectPathDescription(VCDocument vcDocument, Issue issue) {
VCAssert.assertValid(issue);
Object source = issue.getSource();
{
IssueOrigin io = BeanUtils.downcast(IssueOrigin.class, source);
if (io != null) {
return io.getDescription();
}
}
if (vcDocument instanceof BioModel) {
BioModel bioModel = (BioModel) vcDocument;
String description = "";
if (source instanceof SymbolTableEntry) {
if (source instanceof SpeciesContext) {
description = "Model / Species";
} else if (source instanceof RbmObservable) {
description = "Model / Observables";
} else {
description = ((SymbolTableEntry) source).getNameScope().getPathDescription();
}
} else if (source instanceof MolecularType) {
description = "Model / Molecules";
} else if (source instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) source;
description = ((ReactionNameScope) reactionStep.getNameScope()).getPathDescription();
} else if (source instanceof ReactionRule) {
ReactionRule reactionRule = (ReactionRule) source;
description = ((ReactionRuleNameScope) reactionRule.getNameScope()).getPathDescription();
} else if (source instanceof SpeciesPattern) {
// if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
// description = "Model / Species";
// }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
// ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
// description = ((ReactionRuleNameScope)thing.getNameScope()).getPathDescription();
// }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
// description = "Model / Observables";
// } else {
System.err.println("Bad issue context for " + ((SpeciesPattern) source).toString());
description = ((SpeciesPattern) source).toString();
// }
} else if (source instanceof Structure) {
Structure structure = (Structure) source;
description = "Model / " + structure.getTypeName() + "(" + structure.getName() + ")";
} else if (source instanceof StructureMapping) {
StructureMapping structureMapping = (StructureMapping) source;
description = ((StructureMappingNameScope) structureMapping.getNameScope()).getPathDescription();
} else if (source instanceof OutputFunctionIssueSource) {
SimulationContext simulationContext = (SimulationContext) ((OutputFunctionIssueSource) source).getOutputFunctionContext().getSimulationOwner();
description = "App(" + simulationContext.getName() + ") / " + "Simulations" + " / " + "Output Functions";
} else if (source instanceof Simulation) {
Simulation simulation = (Simulation) source;
try {
SimulationContext simulationContext = bioModel.getSimulationContext(simulation);
description = "App(" + simulationContext.getName() + ") / Simulations";
} catch (ObjectNotFoundException e) {
e.printStackTrace();
description = "App(" + "unknown" + ") / Simulations";
}
} else if (source instanceof UnmappedGeometryClass) {
UnmappedGeometryClass unmappedGC = (UnmappedGeometryClass) source;
description = "App(" + unmappedGC.getSimulationContext().getName() + ") / Subdomain(" + unmappedGC.getGeometryClass().getName() + ")";
} else if (source instanceof GeometryContext) {
description = "App(" + ((GeometryContext) source).getSimulationContext().getName() + ")";
} else if (source instanceof ModelOptimizationSpec) {
description = "App(" + ((ModelOptimizationSpec) source).getSimulationContext().getName() + ") / Parameter Estimation";
} else if (source instanceof MicroscopeMeasurement) {
description = "App(" + ((MicroscopeMeasurement) source).getSimulationContext().getName() + ") / Microscope Measurements";
} else if (source instanceof SpatialObject) {
description = "App(" + ((SpatialObject) source).getSimulationContext().getName() + ") / Spatial Objects";
} else if (source instanceof SpatialProcess) {
description = "App(" + ((SpatialProcess) source).getSimulationContext().getName() + ") / Spatial Processes";
} else if (source instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) source;
description = "App(" + scs.getSimulationContext().getName() + ") / Specifications / Species";
} else if (source instanceof ReactionCombo) {
ReactionCombo rc = (ReactionCombo) source;
description = "App(" + rc.getReactionContext().getSimulationContext().getName() + ") / Specifications / Reactions";
} else if (source instanceof RbmModelContainer) {
IssueCategory ic = issue.getCategory();
switch(ic) {
case RbmMolecularTypesTableBad:
description = "Model / " + MolecularType.typeName + "s";
break;
case RbmReactionRulesTableBad:
description = "Model / Reactions";
break;
case RbmObservablesTableBad:
description = "Model / Observables";
break;
case RbmNetworkConstraintsBad:
description = "Network Constrains";
break;
default:
description = "Model";
break;
}
} else if (source instanceof SimulationContext) {
SimulationContext sc = (SimulationContext) source;
IssueCategory ic = issue.getCategory();
switch(ic) {
case RbmNetworkConstraintsBad:
description = "Specifications / Network";
break;
default:
description = "Application";
break;
}
} else if (source instanceof Model) {
description = "Model";
} else if (source instanceof BioEvent) {
return "Protocols / Events";
} else if (source instanceof MathDescription) {
return "Math Description";
} else {
System.err.println("unknown source type in IssueTableModel.getSourceObjectPathDescription(): " + source.getClass());
}
return description;
} else if (vcDocument instanceof MathModel) {
if (source instanceof Geometry) {
return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_GEOMETRY;
} else if (source instanceof OutputFunctionIssueSource) {
return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_OUTPUTFUNCTIONS;
} else if (source instanceof Simulation) {
return "Simulation(" + ((Simulation) source).getName() + ")";
} else {
return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_VCML;
}
} else {
System.err.println("unknown document type in IssueTableModel.getSourceObjectPathDescription()");
return "";
}
}
use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.
the class DataSetControllerImpl method fieldDataFileOperation.
public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws ObjectNotFoundException {
if (fieldDataFileOperationSpec.opType == FieldDataFileOperationSpec.FDOS_COPYSIM) {
Vector<File> removeFilesIfErrorV = new Vector<File>();
try {
int simJobIndex = fieldDataFileOperationSpec.sourceSimParamScanJobIndex;
// Determine style so file names can be constructed properly
VCSimulationDataIdentifier sourceSimDataID = new VCSimulationDataIdentifier(new VCSimulationIdentifier(fieldDataFileOperationSpec.sourceSimDataKey, fieldDataFileOperationSpec.sourceOwner), simJobIndex);
SimulationData simulationData = (SimulationData) getVCData(sourceSimDataID);
boolean isOldStyle = (simulationData.getResultsInfoObject() instanceof VCSimulationDataIdentifierOldStyle);
//
// log,mesh,zip,func
//
KeyValue origSimKey = fieldDataFileOperationSpec.sourceSimDataKey;
File meshFile_orig = simulationData.getMeshFile(false);
File funcFile_orig = simulationData.getFunctionsFile(false);
File subdomainFile_orig = simulationData.getSubdomainFile();
File fdLogFile_orig = simulationData.getLogFile();
File zipFile_orig = simulationData.getZipFile(false, 0);
boolean bCopySubdomainFile = subdomainFile_orig.exists();
// Dont' check subdomainFile_orig
if (!(meshFile_orig.exists() && funcFile_orig.exists() && fdLogFile_orig.exists() && zipFile_orig.exists())) {
throw new RuntimeException("Couldn't find all of the files required to copy sim");
}
File userDir = getPrimaryUserDir(fieldDataFileOperationSpec.owner, true);
File meshFile_new = new File(userDir, SimulationData.createCanonicalMeshFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, false));
File funcFile_new = new File(userDir, SimulationData.createCanonicalFunctionsFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, false));
File subdomainFile_new = new File(userDir, SimulationData.createCanonicalSubdomainFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, false));
File fdLogFile_new = new File(userDir, SimulationData.createCanonicalSimLogFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, false));
File zipFile_new = new File(userDir, SimulationData.createCanonicalSimZipFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, 0, false, false));
if (meshFile_new.exists() || funcFile_new.exists() || fdLogFile_new.exists() || zipFile_new.exists() || (bCopySubdomainFile && subdomainFile_new.exists())) {
throw new RuntimeException("File names required for new Field Data already exist on server");
}
removeFilesIfErrorV.add(funcFile_new);
removeFilesIfErrorV.add(meshFile_new);
removeFilesIfErrorV.add(fdLogFile_new);
// Simple copy of mesh and funcfile because they do not have to be changed
FileUtils.copyFile(meshFile_orig, meshFile_new, false, false, 8 * 1024);
FileUtils.copyFile(funcFile_orig, funcFile_new, false, false, 8 * 1024);
if (bCopySubdomainFile) {
FileUtils.copyFile(subdomainFile_orig, subdomainFile_new, false, false, 8 * 1024);
}
// Copy Log file and replace original simID with ExternalDataIdentifier id
BufferedWriter writer = null;
try {
String origLog = FileUtils.readFileToString(fdLogFile_orig);
String newLogStr;
String replace_new = SimulationData.createSimIDWithJobIndex(fieldDataFileOperationSpec.specEDI.getKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
if (isOldStyle) {
String replace_orig = SimulationData.createSimIDWithJobIndex(origSimKey, 0, true);
newLogStr = origLog.replaceAll(replace_orig, replace_new);
} else {
String replace_orig = SimulationData.createSimIDWithJobIndex(origSimKey, fieldDataFileOperationSpec.sourceSimParamScanJobIndex, false);
newLogStr = origLog.replaceAll(replace_orig, replace_new);
}
writer = new BufferedWriter(new FileWriter(fdLogFile_new));
writer.write(newLogStr);
writer.close();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (Exception e) {
/*ignore*/
}
;
}
//
// Copy zip file and rename entries
//
int zipIndex = 0;
while (true) {
// Loop because there might be more than 1 zip file for large datasets
zipFile_orig = simulationData.getZipFile(false, zipIndex);
if (!zipFile_orig.exists()) {
// done
break;
}
zipFile_new = new File(userDir, SimulationData.createCanonicalSimZipFileName(fieldDataFileOperationSpec.specEDI.getKey(), zipIndex, 0, false, false));
if (zipFile_new.exists()) {
throw new DataAccessException("new zipfile name " + zipFile_new.getAbsolutePath() + " already exists");
}
removeFilesIfErrorV.add(zipFile_new);
ZipFile inZipFile = null;
InputStream zis = null;
ZipOutputStream zos = null;
try {
inZipFile = new ZipFile(zipFile_orig);
;
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile_new)));
Enumeration<? extends ZipEntry> zipEntryEnum = inZipFile.getEntries();
while (zipEntryEnum.hasMoreElements()) {
ZipEntry zeIN = zipEntryEnum.nextElement();
byte[] zdataIN = new byte[(int) zeIN.getSize()];
int num = 0;
int numTotal = 0;
zis = new BufferedInputStream(inZipFile.getInputStream((ZipArchiveEntry) zeIN));
// long startTime = System.currentTimeMillis();
while ((num = zis.read(zdataIN, numTotal, zdataIN.length - numTotal)) != -1 && numTotal != zdataIN.length) {
numTotal += num;
}
// System.out.println("zipread time="+((System.currentTimeMillis()-startTime)/1000.0));
zis.close();
String newName;
String replace_new = SimulationData.createSimIDWithJobIndex(fieldDataFileOperationSpec.specEDI.getKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
if (isOldStyle) {
String replace_orig = SimulationData.createSimIDWithJobIndex(origSimKey, 0, true);
newName = zeIN.getName().replaceAll(replace_orig, replace_new);
} else {
String replace_orig = SimulationData.createSimIDWithJobIndex(origSimKey, fieldDataFileOperationSpec.sourceSimParamScanJobIndex, false);
newName = zeIN.getName().replaceAll(replace_orig, replace_new);
}
ZipEntry zeOUT = new ZipEntry(newName);
zeOUT.setComment(zeIN.getComment());
zeOUT.setCompressedSize(zeIN.getCompressedSize());
zeOUT.setCrc(zeIN.getCrc());
zeOUT.setExtra(zeIN.getExtra());
zeOUT.setMethod(zeIN.getMethod());
zeOUT.setSize(zeIN.getSize());
zeOUT.setTime(zeIN.getTime());
// startTime = System.currentTimeMillis();
zos.putNextEntry(zeOUT);
zos.write(zdataIN, 0, zdataIN.length);
// System.out.println("zipwrite time="+((System.currentTimeMillis()-startTime)/1000.0)+"\n");
}
} finally {
try {
if (zis != null) {
zis.close();
}
} catch (Exception e) {
/*ignore*/
}
;
try {
if (zos != null) {
zos.close();
}
} catch (Exception e) {
/*ignore*/
}
;
}
zipIndex += 1;
}
// Now see if we can read what we just wrote
return fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(fieldDataFileOperationSpec.specEDI.getKey(), fieldDataFileOperationSpec.owner, FieldDataFileOperationSpec.JOBINDEX_DEFAULT));
} catch (Exception e) {
e.printStackTrace();
try {
for (int i = 0; i < removeFilesIfErrorV.size(); i += 1) {
removeFilesIfErrorV.elementAt(i).delete();
}
} catch (Throwable e2) {
// ignore, we tried to cleanup
}
throw new RuntimeException("Error copying sim data to new Field Data\n" + e.getMessage());
}
} else if (fieldDataFileOperationSpec.opType == FieldDataFileOperationSpec.FDOS_ADD) {
if (fieldDataFileOperationSpec.cartesianMesh == null) {
throw new RuntimeException("Field Data Operation 'ADD' cartesianMesh cannot be null");
}
if (fieldDataFileOperationSpec.times == null || fieldDataFileOperationSpec.times.length == 0) {
throw new RuntimeException("Field Data Operation 'ADD' times cannot be null");
}
if (fieldDataFileOperationSpec.times[0] != 0) {
throw new RuntimeException("Field Data Operation 'ADD' first time must be 0.0");
}
if (fieldDataFileOperationSpec.varNames == null || fieldDataFileOperationSpec.varNames.length == 0) {
throw new RuntimeException("Field Data Operation 'ADD' variable names cannot be null");
}
if ((fieldDataFileOperationSpec.shortSpecData != null && fieldDataFileOperationSpec.doubleSpecData != null) || (fieldDataFileOperationSpec.shortSpecData == null && fieldDataFileOperationSpec.doubleSpecData == null)) {
throw new RuntimeException("Field Data Operation 'ADD' must have ONLY 1 data specifier, short or double");
}
if (fieldDataFileOperationSpec.shortSpecData != null && (fieldDataFileOperationSpec.shortSpecData.length != fieldDataFileOperationSpec.times.length || fieldDataFileOperationSpec.shortSpecData[0].length != fieldDataFileOperationSpec.varNames.length)) {
throw new RuntimeException("Field Data Operation 'ADD' 'short' data dimension does not match\n" + "times and variable names array lengths");
}
if (fieldDataFileOperationSpec.doubleSpecData != null && (fieldDataFileOperationSpec.doubleSpecData.length != fieldDataFileOperationSpec.times.length || fieldDataFileOperationSpec.doubleSpecData[0].length != fieldDataFileOperationSpec.varNames.length)) {
throw new RuntimeException("Field Data Operation 'ADD' 'double' data dimension does not match\n" + "times and variable names array lengths");
}
if (fieldDataFileOperationSpec.variableTypes == null || fieldDataFileOperationSpec.variableTypes.length == 0) {
throw new RuntimeException("Field Data Operation 'ADD' variable types cannot be null");
}
if (fieldDataFileOperationSpec.variableTypes.length != fieldDataFileOperationSpec.varNames.length) {
throw new RuntimeException("Field Data Operation 'ADD' variable types count does not match variable names count");
}
// byte[][][] allData = fieldDataFileOperationSpec.specData;
double[] times = fieldDataFileOperationSpec.times;
ExternalDataIdentifier dataset = fieldDataFileOperationSpec.specEDI;
String[] vars = fieldDataFileOperationSpec.varNames;
VariableType[] varTypes = fieldDataFileOperationSpec.variableTypes;
File userDir = null;
try {
userDir = getPrimaryUserDir(fieldDataFileOperationSpec.owner, true);
} catch (FileNotFoundException e) {
throw new RuntimeException("Couldn't create new user directory on server");
}
double[][][] convertedData = null;
if (fieldDataFileOperationSpec.doubleSpecData != null) {
convertedData = fieldDataFileOperationSpec.doubleSpecData;
} else {
// convert short to double
convertedData = new double[times.length][vars.length][];
for (int i = 0; i < times.length; i += 1) {
for (int j = 0; j < vars.length; j += 1) {
if (fieldDataFileOperationSpec.shortSpecData != null) {
convertedData[i][j] = new double[fieldDataFileOperationSpec.shortSpecData[i][j].length];
for (int k = 0; k < fieldDataFileOperationSpec.shortSpecData[i][j].length; k += 1) {
convertedData[i][j][k] = (double) (((int) fieldDataFileOperationSpec.shortSpecData[i][j][k]) & 0x0000FFFF);
}
} else {
throw new RuntimeException("no pixel data found");
}
}
}
}
// Write Log file
File fdLogFile = new File(userDir, SimulationData.createCanonicalSimLogFileName(dataset.getKey(), 0, false));
PrintStream ps = null;
File zipFile = new File(userDir, SimulationData.createCanonicalSimZipFileName(dataset.getKey(), 0, 0, false, false));
Vector<String> simFileNamesV = new Vector<String>();
try {
if (!fdLogFile.createNewFile()) {
throw new Exception("File.createNewFile() returned null");
}
ps = new PrintStream(fdLogFile);
for (int i = 0; i < times.length; i += 1) {
String simFilename = SimulationData.createCanonicalSimFilePathName(dataset.getKey(), i, 0, false);
simFileNamesV.add(simFilename);
ps.println(i + "\t" + simFilename + "\t" + zipFile.getName() + "\t" + times[i] + "");
}
ps.flush();
} catch (Exception e) {
throw new RuntimeException("Couldn't create log file " + fdLogFile.getAbsolutePath() + "\n" + e.getMessage());
} finally {
if (ps != null) {
ps.close();
}
}
// Write zipFile
java.util.zip.ZipOutputStream zipOut = null;
try {
java.io.BufferedOutputStream bout = new java.io.BufferedOutputStream(new java.io.FileOutputStream(zipFile));
zipOut = new java.util.zip.ZipOutputStream(bout);
for (int t = 0; t < times.length; t += 1) {
java.io.File temp = java.io.File.createTempFile("temp", null);
DataSet.writeNew(temp, vars, varTypes, fieldDataFileOperationSpec.isize, convertedData[t]);
java.util.zip.ZipEntry zipEntry = new java.util.zip.ZipEntry(simFileNamesV.get(t));
zipOut.putNextEntry(zipEntry);
// ----------------------------
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.io.FileInputStream(temp));
byte[] bytes = new byte[65536];
try {
int b = in.read(bytes);
while (b != -1) {
zipOut.write(bytes, 0, b);
b = in.read(bytes);
}
} catch (IOException e) {
throw new Exception("Error writing zip file bytes");
} finally {
// cleanup
in.close();
temp.delete();
}
// ----------------------------
}
} catch (Exception e) {
throw new RuntimeException("Couldn't create zip file " + zipFile.getAbsolutePath() + "\n" + e.getMessage());
} finally {
try {
zipOut.close();
} catch (IOException e) {
e.printStackTrace();
// ignore
}
}
// Write Mesh file
FileOutputStream fos = null;
File meshFile = null;
try {
CartesianMesh mesh = fieldDataFileOperationSpec.cartesianMesh;
meshFile = new File(userDir, SimulationData.createCanonicalMeshFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, false));
fos = new FileOutputStream(meshFile);
mesh.write(new PrintStream(fos));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Error writing mesh file " + meshFile.getAbsolutePath() + "\n" + e.getMessage());
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
// ignore
}
}
// Write Functionfile file
PrintStream ps2 = null;
File funcFile = null;
try {
funcFile = new File(userDir, SimulationData.createCanonicalFunctionsFileName(fieldDataFileOperationSpec.specEDI.getKey(), 0, false));
FileOutputStream fos2 = new FileOutputStream(funcFile);
ps2 = new PrintStream(fos2);
ps2.println("##---------------------------------------------" + "\n" + "## " + funcFile.getAbsolutePath() + "\n" + "##---------------------------------------------" + "\n");
ps2.flush();
ps2.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Error writing function file " + funcFile.getAbsolutePath() + "\n" + e.getMessage());
} finally {
if (ps2 != null) {
ps2.close();
}
}
try {
// return Info
return fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(fieldDataFileOperationSpec.specEDI.getKey(), fieldDataFileOperationSpec.owner, FieldDataFileOperationSpec.JOBINDEX_DEFAULT));
} catch (Exception e) {
e.printStackTrace();
// ignore
}
} else if (fieldDataFileOperationSpec.opType == FieldDataFileOperationSpec.FDOS_DEPENDANTFUNCS) {
throw new RuntimeException("This function is not currently used");
// //
// //Check for references to FieldData from users User Defined Functions
// //
// HashMap<String, KeyValue> dbFuncFileNamesAndSimKeys = null;
// try{
// dbFuncFileNamesAndSimKeys =
// FieldDataDBOperationDriver.getFunctionFileNamesAndSimKeys(
// fieldDataFileOperationSpec.specEDI.getOwner());
// }catch(Exception e){
// e.printStackTrace();
// throw new RuntimeException("couldn't get Function File names from Database\n"+e.getMessage());
// }
// //String regex = "^.*"+MathMLTags.FIELD+"\\s*\\(\\s*"+fieldDataFileOperationSpec.specEDI.getName()+"\\s*,.*$";
// String regex = "^.*?field\\s*\\(\\s*"+fieldDataFileOperationSpec.specEDI.getName()+"\\s*,.*?$";
// java.util.regex.Pattern pattern =
// java.util.regex.Pattern.compile(regex);//,java.util.regex.Pattern.MULTILINE|java.util.regex.Pattern.DOTALL);
// Matcher matcher = pattern.matcher("");
// Set<Map.Entry<String,KeyValue>> funcAndSimsES = dbFuncFileNamesAndSimKeys.entrySet();
// Vector<FieldDataFileOperationResults.FieldDataReferenceInfo> referencingFuncFileDescription =
// new Vector<FieldDataFileOperationResults.FieldDataReferenceInfo>();
// boolean bSearchSecondary =
// secondaryRootDirectory != null &&
// !primaryRootDirectory.equals(secondaryRootDirectory);
// TreeSet<String> searchedFuncFilesTS = new TreeSet<String>();
// Iterator<Map.Entry<String,KeyValue>> iter = funcAndSimsES.iterator();
// FunctionFileGenerator.FuncFileLineInfo funcfileInfo = null;
// while(iter.hasNext()){
// Map.Entry<String,KeyValue> currentEntry = iter.next();
// File currentFile = null;
// for (int i = 0; i < (bSearchSecondary?2:1); i++) {
// if(searchedFuncFilesTS.contains(currentEntry.getKey())){
// continue;
// }
// currentFile = new File(
// getUserDirectoryName(
// (i==0?primaryRootDirectory:secondaryRootDirectory),
// fieldDataFileOperationSpec.specEDI.getOwner()),currentEntry.getKey());
// if(!currentFile.exists()){
// continue;
// }
// searchedFuncFilesTS.add(currentEntry.getKey());
// LineNumberReader lineNumberReader = null;
// Vector<String> referringFieldfunctionNamesV = new Vector<String>();
// try{
// lineNumberReader = new LineNumberReader(new FileReader(currentFile));
// String funcFileLine = null;
// while((funcFileLine = lineNumberReader.readLine()) != null){
// funcfileInfo = FunctionFileGenerator.readFunctionLine(funcFileLine);
// if(funcfileInfo != null && funcfileInfo.functionExpr != null){
// matcher.reset(funcfileInfo.functionExpr);
// if(matcher.matches()){
// referringFieldfunctionNamesV.add(funcfileInfo.functionName);
// }
// }
// }
// lineNumberReader.close();
// if(referringFieldfunctionNamesV.size() > 0){
// FieldDataFileOperationResults.FieldDataReferenceInfo fieldDataReferenceInfo =
// FieldDataDBOperationDriver.getModelDescriptionForSimulation(
// fieldDataFileOperationSpec.specEDI.getOwner(), currentEntry.getValue());
// fieldDataReferenceInfo.funcNames = referringFieldfunctionNamesV.toArray(new String[0]);
// referencingFuncFileDescription.add(fieldDataReferenceInfo);
// // for (int j = 0; j < referringFieldfunctionNamesV.size(); j++) {
// // referencingFuncFileDescription.add(new String[][] {
// // referringFieldfunctionNamesV.elementAt(j),modelDescription});
// // }
// }
// }catch(Exception e){
// e.printStackTrace();
// throw new RuntimeException(e.getMessage(),e);
// }finally{
// if(lineNumberReader != null){try{lineNumberReader.close();}catch(Exception e){e.printStackTrace();}}
// }
// }
// }
// if(referencingFuncFileDescription.size() > 0){
// FieldDataFileOperationResults fdfor = new FieldDataFileOperationResults();
// fdfor.dependantFunctionInfo =
// referencingFuncFileDescription.toArray(new FieldDataFileOperationResults.FieldDataReferenceInfo[0]);
// return fdfor;
// }
// return null;
} else if (fieldDataFileOperationSpec.opType == FieldDataFileOperationSpec.FDOS_DELETE) {
//
if (cacheTable0 != null) {
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(fieldDataFileOperationSpec.specEDI.getKey(), fieldDataFileOperationSpec.specEDI.getOwner());
VCSimulationDataIdentifier simDataID = new VCSimulationDataIdentifier(vcSimID, FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
cacheTable0.removeAll(simDataID);
cacheTable0.removeAll(fieldDataFileOperationSpec.specEDI);
}
if (userExtDataIDH != null) {
userExtDataIDH.remove(fieldDataFileOperationSpec.specEDI.getOwner());
}
SimulationData simulationData = null;
try {
simulationData = (SimulationData) getVCData(fieldDataFileOperationSpec.specEDI);
} catch (Exception e) {
throw new ObjectNotFoundException(e.getMessage(), e);
}
File fdLogFile = simulationData.getLogFile();
File fdMeshFile = simulationData.getMeshFile(false);
File fdFunctionFile = simulationData.getFunctionsFile(true);
File fdSubdomainFile = simulationData.getSubdomainFile();
if (!fdLogFile.delete()) {
System.out.println("Couldn't delete log file " + fdLogFile.getAbsolutePath());
}
if (!fdMeshFile.delete()) {
System.out.println("Couldn't delete Mesh file " + fdMeshFile.getAbsolutePath());
}
if (!fdFunctionFile.delete()) {
System.out.println("Couldn't delete Functions file " + fdFunctionFile.getAbsolutePath());
}
if (fdSubdomainFile.exists() && fdSubdomainFile.delete()) {
System.out.println("Couldn't delete Subdomains file " + fdSubdomainFile.getAbsolutePath());
}
int index = 0;
while (true) {
File fdZipFile = simulationData.getZipFile(false, index);
if (index != 0 && !fdZipFile.exists()) {
break;
}
if (!fdZipFile.delete()) {
System.out.println("Couldn't delete zip file " + fdZipFile.getAbsolutePath());
}
index += 1;
}
return null;
} else if (fieldDataFileOperationSpec.opType == FieldDataFileOperationSpec.FDOS_INFO) {
try {
FieldDataFileOperationResults fdor = new FieldDataFileOperationResults();
VCDataIdentifier sourceSimDataID = new VCSimulationDataIdentifier(new VCSimulationIdentifier(fieldDataFileOperationSpec.sourceSimDataKey, fieldDataFileOperationSpec.sourceOwner), fieldDataFileOperationSpec.sourceSimParamScanJobIndex);
fdor.dataIdentifierArr = getDataIdentifiers(null, sourceSimDataID);
CartesianMesh mesh = getMesh(sourceSimDataID);
fdor.extent = mesh.getExtent();
fdor.origin = mesh.getOrigin();
fdor.iSize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
fdor.times = getDataSetTimes(sourceSimDataID);
return fdor;
} catch (FileNotFoundException e) {
throw new ObjectNotFoundException("Error FieldDataOp get INFO", e);
} catch (Exception e) {
throw new RuntimeException("Error FieldDataFileOperationSpec INFO Operation\n" + e.getMessage());
}
}
throw new RuntimeException("Field data operation " + fieldDataFileOperationSpec.opType + " unknown.");
}
Aggregations