Search in sources :

Example 1 with FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec in project vcell by virtualcell.

the class ROIMultiPaintManager method createFD.

private void createFD(boolean isFromSimulation, String fieldName, String annotation, Extent extent, Origin origin, String[] varNames, double[] times, ISize isize) throws Exception {
    FieldDataFileOperationSpec fdos = null;
    try {
        // temp-------
        FieldDataDBOperationSpec listExtDataIDSpec = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
        FieldDataDBOperationResults fdDBOperation = documentManager.fieldDataDBOperation(listExtDataIDSpec);
        for (int i = 0; i < fdDBOperation.extDataIDArr.length; i++) {
            if (fdDBOperation.extDataIDArr[i].getName().equals("fd")) {
                FieldDataDBOperationSpec createDeleteExtDataIDSpec = FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdDBOperation.extDataIDArr[i]);
                documentManager.fieldDataDBOperation(createDeleteExtDataIDSpec);
                break;
            }
        }
        // 
        // -----------
        FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(documentManager.getUser(), fieldName, annotation);
        FieldDataDBOperationResults fieldDataDBOperation = documentManager.fieldDataDBOperation(newExtDataIDSpec);
        fdos = new FieldDataFileOperationSpec();
        fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
        fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
        fdos.owner = documentManager.getUser();
        fdos.isize = isize;
        fdos.shortSpecData = new short[1][1][fdos.isize.getXYZ()];
        UShortImage[] allImages = initImageDataSetChannels[0].getAllImages();
        for (int i = 0; i < allImages.length; i++) {
            allImages[i].getPixels();
            System.arraycopy(allImages[i].getPixels(), 0, fdos.shortSpecData[0][0], i * allImages[i].getPixels().length, allImages[i].getPixels().length);
        }
        fdos.specEDI = fieldDataDBOperation.extDataID;
        fdos.annotation = annotation;
        if (!isFromSimulation) {
            fdos.extent = extent;
            fdos.origin = origin;
            fdos.varNames = varNames;
            fdos.times = times;
            // 
            // Subvolumes and Regions NOT implemented now
            // 
            fdos.cartesianMesh = CartesianMesh.createSimpleCartesianMesh(fdos.origin, fdos.extent, fdos.isize, new RegionImage(new // empty regions
            VCImageUncompressed(// empty regions
            null, // empty regions
            new byte[fdos.isize.getXYZ()], fdos.extent, fdos.isize.getX(), fdos.isize.getY(), fdos.isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
        }
        // Add to Server Disk
        documentManager.fieldDataFileOperation(fdos);
    // //Update FieldData window
    // Window[] windows = Window.getWindows();
    // for(int i=0;i<windows.length;i++) {
    // if(windows[i] instanceof FieldDataWindow) {
    // ((FieldDataWindow)windows[i]).getFieldDataWindowManger().fieldDataDBEvent(new FieldDataDBEvent(ROIMultiPaintManager.this));
    // break;
    // }
    // }
    } catch (Exception e) {
        try {
            // try to cleanup new ExtDataID
            if (fdos != null && fdos.specEDI != null) {
                documentManager.fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI));
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        throw e;
    }
}
Also used : FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) RegionImage(cbit.vcell.geometry.RegionImage) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec) Point(java.awt.Point) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException)

Example 2 with FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec 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) ParseException(java.text.ParseException) 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 3 with FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec 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 FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec 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)

Example 5 with FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec in project vcell by virtualcell.

the class FieldDataGUIPanel method addNewExternalData.

public static AsynchClientTask[] addNewExternalData(final Component requester, final FieldDataGUIPanel fieldDataGUIPanel, final boolean isFromSimulation) {
    final RequestManager clientRequestManager = fieldDataGUIPanel.fieldDataWindowManager.getLocalRequestManager();
    AsynchClientTask task1 = new AsynchClientTask("creating field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Check if this is ImageJ op, if so, this task unnecessary
            if (hashTable.get(USER_DEFINED_FDOS) != null && hashTable.get(FIELD_NAME) != null) {
                return;
            }
            // Allow user to review/change info about fielddata
            FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
            String initialExtDataName = (String) hashTable.get("initFDName");
            fdos.specEDI = null;
            FieldDataInfoPanel fdip = new FieldDataInfoPanel();
            fdip.setSimulationMode(isFromSimulation);
            fdip.initISize(fdos.isize);
            fdip.initIOrigin(fdos.origin);
            fdip.initIExtent(fdos.extent);
            fdip.initTimes(fdos.times);
            fdip.initNames(TokenMangler.fixTokenStrict(initialExtDataName), fdos.varNames);
            fdip.setAnnotation(fdos.annotation);
            FieldDataFileOperationSpec userDefinedFDOS = new FieldDataFileOperationSpec();
            while (true) {
                int choice = PopupGenerator.showComponentOKCancelDialog(requester, fdip, "Create new field data");
                if (choice == JOptionPane.OK_OPTION) {
                    // Check values
                    try {
                        userDefinedFDOS.extent = fdip.getExtent();
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(requester, "Problem with Extent values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
                        continue;
                    }
                    try {
                        userDefinedFDOS.origin = fdip.getOrigin();
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(requester, "Problem with Origin values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
                        continue;
                    }
                    try {
                        userDefinedFDOS.varNames = fdip.getVariableNames();
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(requester, "Problem with Variable names. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
                        continue;
                    }
                    userDefinedFDOS.annotation = fdip.getAnnotation();
                    userDefinedFDOS.times = fdip.getTimes();
                    try {
                        fieldDataGUIPanel.checkFieldDataName(fdip.getFieldName());
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(requester, "Error saving Field Data Name to Database. Try again.\n" + e.getMessage(), e);
                        continue;
                    }
                    hashTable.put(USER_DEFINED_FDOS, userDefinedFDOS);
                    hashTable.put(FIELD_NAME, fdip.getFieldName());
                    break;
                } else {
                    throw UserCancelException.CANCEL_GENERIC;
                }
            }
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("saving field data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Add to Server Disk
            // save Database
            FieldDataFileOperationSpec tempFDOS = (FieldDataFileOperationSpec) hashTable.get(USER_DEFINED_FDOS);
            String fieldName = (String) hashTable.get(FIELD_NAME);
            FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
            DocumentManager documentManager = clientRequestManager.getDocumentManager();
            FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(documentManager.getUser(), fieldName, tempFDOS.annotation);
            tempFDOS.specEDI = documentManager.fieldDataDBOperation(newExtDataIDSpec).extDataID;
            fdos.specEDI = tempFDOS.specEDI;
            fdos.annotation = tempFDOS.annotation;
            try {
                if (!isFromSimulation) {
                    fdos.extent = tempFDOS.extent;
                    fdos.origin = tempFDOS.origin;
                    fdos.varNames = tempFDOS.varNames;
                    fdos.times = tempFDOS.times;
                    // 
                    // Subvolumes and Regions NOT implemented now
                    // 
                    fdos.cartesianMesh = CartesianMesh.createSimpleCartesianMesh(fdos.origin, fdos.extent, fdos.isize, new RegionImage(new // empty regions
                    VCImageUncompressed(// empty regions
                    null, // empty regions
                    new byte[fdos.isize.getXYZ()], fdos.extent, fdos.isize.getX(), fdos.isize.getY(), fdos.isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
                }
                // Add to Server Disk
                documentManager.fieldDataFileOperation(fdos);
            } catch (Exception e) {
                try {
                    // try to cleanup new ExtDataID
                    documentManager.fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI));
                } catch (Exception e2) {
                // ignore
                }
                fdos.specEDI = null;
                throw e;
            }
        }
    };
    AsynchClientTask task3 = new AsynchClientTask("refreshing field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
            DefaultMutableTreeNode root = ((DefaultMutableTreeNode) fieldDataGUIPanel.getJTree1().getModel().getRoot());
            if (root.getChildCount() == 0) {
                fieldDataGUIPanel.updateJTree(clientRequestManager);
            } else {
                int alphabeticalIndex = -1;
                for (int i = 0; i < root.getChildCount(); i += 1) {
                    if ((((FieldDataMainList) ((DefaultMutableTreeNode) root.getChildAt(i)).getUserObject())).externalDataIdentifier.getName().compareToIgnoreCase(fdos.specEDI.getName()) > 0) {
                        alphabeticalIndex = i;
                        break;
                    }
                }
                if (alphabeticalIndex == -1) {
                    alphabeticalIndex = root.getChildCount();
                }
                DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(fdos.specEDI, fdos.annotation));
                mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList()));
                ((DefaultTreeModel) fieldDataGUIPanel.getJTree1().getModel()).insertNodeInto(mainNode, root, alphabeticalIndex);
            }
        }
    };
    return new AsynchClientTask[] { task1, task2, task3 };
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Hashtable(java.util.Hashtable) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) DocumentManager(cbit.vcell.clientdb.DocumentManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) RequestManager(cbit.vcell.client.RequestManager) ClientRequestManager(cbit.vcell.client.ClientRequestManager) RegionImage(cbit.vcell.geometry.RegionImage) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec)

Aggregations

FieldDataDBOperationSpec (cbit.vcell.field.FieldDataDBOperationSpec)7 FieldDataDBOperationResults (cbit.vcell.field.FieldDataDBOperationResults)6 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)5 UserCancelException (org.vcell.util.UserCancelException)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)3 RegionImage (cbit.vcell.geometry.RegionImage)3 ImageException (cbit.image.ImageException)2 DocumentManager (cbit.vcell.clientdb.DocumentManager)2 FieldDataFileOperationResults (cbit.vcell.field.io.FieldDataFileOperationResults)2 XmlParseException (cbit.vcell.xml.XmlParseException)2 Hashtable (java.util.Hashtable)2 DataFormatException (java.util.zip.DataFormatException)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 DataAccessException (org.vcell.util.DataAccessException)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 UtilCancelException (org.vcell.util.UtilCancelException)2 VCImageUncompressed (cbit.image.VCImageUncompressed)1 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)1