Search in sources :

Example 1 with FieldDataDBOperationResults

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;
}
Also used : FieldDataFileOperationResults(cbit.vcell.field.io.FieldDataFileOperationResults) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec) DataAccessException(org.vcell.util.DataAccessException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 2 with FieldDataDBOperationResults

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());
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) KeyValue(org.vcell.util.document.KeyValue) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) MathDescription(cbit.vcell.math.MathDescription) BigString(org.vcell.util.BigString) SimulationContext(cbit.vcell.mapping.SimulationContext) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) BioModel(cbit.vcell.biomodel.BioModel) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException)

Example 3 with FieldDataDBOperationResults

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());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException)

Example 4 with FieldDataDBOperationResults

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 });
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeMap(java.util.TreeMap) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) Entry(java.util.Map.Entry) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec)

Example 5 with FieldDataDBOperationResults

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;
}
Also used : ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec)

Aggregations

FieldDataDBOperationResults (cbit.vcell.field.FieldDataDBOperationResults)7 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)6 FieldDataDBOperationSpec (cbit.vcell.field.FieldDataDBOperationSpec)4 DataAccessException (org.vcell.util.DataAccessException)4 XmlParseException (cbit.vcell.xml.XmlParseException)3 Vector (java.util.Vector)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)3 KeyValue (org.vcell.util.document.KeyValue)3 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)2 MathException (cbit.vcell.math.MathException)2 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 Hashtable (java.util.Hashtable)2 PermissionException (org.vcell.util.PermissionException)2 BioModel (cbit.vcell.biomodel.BioModel)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 DocumentManager (cbit.vcell.clientdb.DocumentManager)1 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 FieldDataFileOperationResults (cbit.vcell.field.io.FieldDataFileOperationResults)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1