use of cbit.vcell.field.FieldDataDBOperationResults in project vcell by virtualcell.
the class ClientDocumentManager method saveFieldData.
public ExternalDataIdentifier saveFieldData(FieldDataFileOperationSpec fdos, String fieldDataBaseName) throws DataAccessException {
FieldDataDBOperationResults fieldDataResults = fieldDataDBOperation(FieldDataDBOperationSpec.createGetExtDataIDsSpec(getUser()));
ExternalDataIdentifier[] existingExternalIDs = fieldDataResults.extDataIDArr;
// find available field data name (starting from init).
for (ExternalDataIdentifier externalID : existingExternalIDs) {
if (externalID.getName().equals(fieldDataBaseName)) {
fieldDataBaseName = TokenMangler.getNextEnumeratedToken(fieldDataBaseName);
}
}
FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(getUser(), fieldDataBaseName, "");
ExternalDataIdentifier eid = fieldDataDBOperation(newExtDataIDSpec).extDataID;
fdos.specEDI = eid;
fdos.annotation = "";
try {
// Add to Server Disk
FieldDataFileOperationResults fdor = fieldDataFileOperation(fdos);
LG.debug(fdor);
} catch (DataAccessException e) {
try {
// try to cleanup new ExtDataID
fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI));
} catch (Exception e2) {
// ignore
}
fdos.specEDI = null;
throw e;
}
return eid;
}
use of cbit.vcell.field.FieldDataDBOperationResults in project vcell by virtualcell.
the class ClientDocumentManager method substituteFieldFuncNames.
public void substituteFieldFuncNames(VCDocument vcDocument, VersionableTypeVersion originalOwner) throws DataAccessException, MathException, ExpressionException {
Vector<ExternalDataIdentifier> errorCleanupExtDataIDV = new Vector<ExternalDataIdentifier>();
try {
if (originalOwner == null || originalOwner.getVersion().getOwner().compareEqual(getUser())) {
// Substitution for FieldFunc not needed for new doc or if we own doc
return;
}
// Get Objects from Document that might need to have FieldFuncs replaced
Vector<Object> fieldFunctionContainer_mathDesc_or_simContextV = new Vector<Object>();
if (vcDocument instanceof MathModel) {
fieldFunctionContainer_mathDesc_or_simContextV.add(((MathModel) vcDocument).getMathDescription());
} else if (vcDocument instanceof BioModel) {
SimulationContext[] simContextArr = ((BioModel) vcDocument).getSimulationContexts();
for (int i = 0; i < simContextArr.length; i += 1) {
fieldFunctionContainer_mathDesc_or_simContextV.add(simContextArr[i]);
}
}
// Get original Field names
Vector<String> origFieldFuncNamesV = new Vector<String>();
for (int i = 0; i < fieldFunctionContainer_mathDesc_or_simContextV.size(); i += 1) {
Object fieldFunctionContainer = fieldFunctionContainer_mathDesc_or_simContextV.elementAt(i);
FieldFunctionArguments[] fieldFuncArgsArr = null;
if (fieldFunctionContainer instanceof MathDescription) {
fieldFuncArgsArr = FieldUtilities.getFieldFunctionArguments((MathDescription) fieldFunctionContainer);
} else if (fieldFunctionContainer instanceof SimulationContext) {
fieldFuncArgsArr = ((SimulationContext) fieldFunctionContainer).getFieldFunctionArguments();
}
for (int j = 0; j < fieldFuncArgsArr.length; j += 1) {
if (!origFieldFuncNamesV.contains(fieldFuncArgsArr[j].getFieldName())) {
origFieldFuncNamesV.add(fieldFuncArgsArr[j].getFieldName());
}
}
}
if (origFieldFuncNamesV.size() == 0) {
// No FieldFunctions to substitute
return;
}
FieldDataDBOperationResults copyNamesFieldDataOpResults = fieldDataDBOperation(FieldDataDBOperationSpec.createCopyNoConflictExtDataIDsSpec(getUser(), origFieldFuncNamesV.toArray(new String[0]), originalOwner));
errorCleanupExtDataIDV.addAll(copyNamesFieldDataOpResults.oldNameNewIDHash.values());
// Copy Field Data on Data Server FileSystem
for (String fieldname : origFieldFuncNamesV) {
KeyValue sourceSimDataKey = copyNamesFieldDataOpResults.oldNameOldExtDataIDKeyHash.get(fieldname);
if (sourceSimDataKey == null) {
throw new DataAccessException("Couldn't find original data key for FieldFunc " + fieldname);
}
ExternalDataIdentifier newExtDataID = copyNamesFieldDataOpResults.oldNameNewIDHash.get(fieldname);
getSessionManager().fieldDataFileOperation(FieldDataFileOperationSpec.createCopySimFieldDataFileOperationSpec(newExtDataID, sourceSimDataKey, originalOwner.getVersion().getOwner(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, getUser()));
}
// Finally substitute new Field names
for (int i = 0; i < fieldFunctionContainer_mathDesc_or_simContextV.size(); i += 1) {
Object fieldFunctionContainer = fieldFunctionContainer_mathDesc_or_simContextV.elementAt(i);
if (fieldFunctionContainer instanceof MathDescription) {
MathDescription mathDesc = (MathDescription) fieldFunctionContainer;
FieldUtilities.substituteFieldFuncNames(mathDesc, copyNamesFieldDataOpResults.oldNameNewIDHash);
} else if (fieldFunctionContainer instanceof SimulationContext) {
SimulationContext simContext = (SimulationContext) fieldFunctionContainer;
simContext.substituteFieldFuncNames(copyNamesFieldDataOpResults.oldNameNewIDHash);
}
}
fireFieldDataDB(new FieldDataDBEvent(this));
} catch (Exception e) {
e.printStackTrace();
// Cleanup
for (int i = 0; i < errorCleanupExtDataIDV.size(); i += 1) {
try {
fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(errorCleanupExtDataIDV.elementAt(i)));
} catch (Exception e2) {
// ignore, we tried to cleanup
}
try {
fieldDataFileOperation(FieldDataFileOperationSpec.createDeleteFieldDataFileOperationSpec(errorCleanupExtDataIDV.elementAt(i)));
} catch (Exception e1) {
// ignore, we tried to cleanup
}
}
throw new RuntimeException("Error copying Field Data \n" + e.getMessage());
}
}
use of cbit.vcell.field.FieldDataDBOperationResults in project vcell by virtualcell.
the class SimulationDatabaseDirect method getFieldDataIdentifierSpecs.
@Override
public FieldDataIdentifierSpec[] getFieldDataIdentifierSpecs(Simulation sim) throws DataAccessException {
try {
KeyValue simKey = sim.getKey();
if (lg.isTraceEnabled())
lg.trace("Get FieldDataIdentifierSpec for [" + simKey + "]");
FieldDataIdentifierSpec[] fieldDataIDSs = (FieldDataIdentifierSpec[]) simFieldDataIDMap.get(simKey);
if (fieldDataIDSs != null) {
return fieldDataIDSs;
}
FieldFunctionArguments[] fieldFuncArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
if (fieldFuncArgs == null || fieldFuncArgs.length == 0) {
fieldDataIDSs = new FieldDataIdentifierSpec[0];
simFieldDataIDMap.put(simKey, fieldDataIDSs);
return fieldDataIDSs;
}
fieldDataIDSs = new FieldDataIdentifierSpec[0];
User owner = sim.getVersion().getOwner();
FieldDataDBOperationSpec fieldDataDbOperationSpec = FieldDataDBOperationSpec.createGetExtDataIDsSpec(owner);
FieldDataDBOperationResults fieldDataDBOperationResults = databaseServerImpl.fieldDataDBOperation(owner, fieldDataDbOperationSpec);
ExternalDataIdentifier[] externalDataIDs = fieldDataDBOperationResults.extDataIDArr;
if (externalDataIDs != null && externalDataIDs.length != 0 && fieldFuncArgs != null && fieldFuncArgs.length > 0) {
Vector<FieldDataIdentifierSpec> fieldDataIdV = new Vector<FieldDataIdentifierSpec>();
for (int j = 0; fieldFuncArgs != null && j < fieldFuncArgs.length; j += 1) {
for (int i = 0; i < externalDataIDs.length; i += 1) {
if (externalDataIDs[i].getName().equals(fieldFuncArgs[j].getFieldName())) {
fieldDataIdV.add(new FieldDataIdentifierSpec(fieldFuncArgs[j], externalDataIDs[i]));
break;
}
}
}
if (fieldDataIdV.size() > 0) {
fieldDataIDSs = new FieldDataIdentifierSpec[fieldDataIdV.size()];
fieldDataIdV.copyInto(fieldDataIDSs);
}
}
simFieldDataIDMap.put(simKey, fieldDataIDSs);
return fieldDataIDSs;
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
throw new DataAccessException(ex.getMessage());
}
}
use of cbit.vcell.field.FieldDataDBOperationResults in project vcell by virtualcell.
the class FieldDataGUIPanel method updateJTree.
public void updateJTree(final RequestManager clientRequestManager) {
if (clientRequestManager == null) {
DefaultMutableTreeNode emptyNode = new DefaultMutableTreeNode("No Info Available");
getJTree1().setModel(new DefaultTreeModel(emptyNode));
} else {
DefaultMutableTreeNode startupNode = new DefaultMutableTreeNode("Gathering Field Data Information... (Please wait)");
getJTree1().setModel(new DefaultTreeModel(startupNode));
AsynchClientTask gatherInfo = new AsynchClientTask("gatherInfo", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
DocumentManager documentManager = clientRequestManager.getDocumentManager();
FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
String[] extDataAnnotArr = fieldDataDBOperationResults.extDataAnnotArr;
TreeMap<ExternalDataIdentifier, String> sortedExtDataIDTreeMap = new TreeMap<ExternalDataIdentifier, String>(new Comparator<ExternalDataIdentifier>() {
public int compare(ExternalDataIdentifier o1, ExternalDataIdentifier o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
for (int i = 0; i < externalDataIdentifierArr.length; i += 1) {
sortedExtDataIDTreeMap.put(externalDataIdentifierArr[i], extDataAnnotArr[i]);
}
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new InitializedRootNode("Field Data Info" + (externalDataIdentifierArr.length == 0 ? " (None Defined)" : "")));
Iterator<Entry<ExternalDataIdentifier, String>> sortIter = sortedExtDataIDTreeMap.entrySet().iterator();
while (sortIter.hasNext()) {
Entry<ExternalDataIdentifier, String> entry = sortIter.next();
DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(entry.getKey(), entry.getValue()));
mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList()));
rootNode.add(mainNode);
}
hashTable.put("rootNode", rootNode);
} catch (Exception e) {
DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode("Error Getting Field Data Information");
hashTable.put("rootNode", errorNode);
throw e;
}
}
};
AsynchClientTask updateTree = new AsynchClientTask("updateTree", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) hashTable.get("rootNode");
getJTree1().setModel(new DefaultTreeModel(rootNode));
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { gatherInfo, updateTree });
}
}
use of cbit.vcell.field.FieldDataDBOperationResults in project vcell by virtualcell.
the class VFrapXmlHelper method isAlreadyImported.
// double[] firstPostBleach = null;
// double[] prebleachAvg = null;
// BufferedImage[] roiComposite = null;
//
// public double[] getFirstPostBleach() {
// if(firstPostBleach == null) {
// throw new RuntimeException("Missing vFrap FirstPostbleach Image");
// } else {
// return firstPostBleach;
// }
// }
// public double[] getPrebleachAvg() {
// if(prebleachAvg == null) {
// throw new RuntimeException("Missing vFrap PrebleachAverage Image");
// } else {
// return prebleachAvg;
// }
// }
// public BufferedImage[] getRoiComposite() {
// if(roiComposite == null) {
// throw new RuntimeException("Missing vFrap RoiComposite Image");
// } else {
// return roiComposite;
// }
// }
public static boolean isAlreadyImported(String candidateName, DocumentManager documentManager) throws DataAccessException {
FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
for (ExternalDataIdentifier edi : externalDataIdentifierArr) {
if (candidateName.equals(edi.getName())) {
return true;
}
}
return false;
}
Aggregations