/** * @param bean * @param progressListener * @return * @throws NotEnoughDiskSpaceException * @throws FileBrokerException * @throws JMSException * @throws IOException * @throws Exception */ public boolean uploadToCacheIfNeeded(DataBean bean, CopyProgressListener progressListener) throws NotEnoughDiskSpaceException, FileBrokerException, JMSException, IOException, Exception { try { bean.getLock().readLock().lock(); // upload only if not already available in cache or storage if (Session.getSession() .getServiceAccessor() .getFileBrokerClient() .isAvailable(bean.getId(), bean.getSize(), bean.getChecksum(), FileBrokerArea.CACHE) || Session.getSession() .getServiceAccessor() .getFileBrokerClient() .isAvailable( bean.getId(), bean.getSize(), bean.getChecksum(), FileBrokerArea.STORAGE)) { return false; } // need to upload return upload(bean, FileBrokerArea.CACHE, progressListener); } finally { bean.getLock().readLock().unlock(); } }
private void doImportSequence() { try { new SequenceImportDialog(Session.getSession().getApplication()); } catch (Exception me) { Session.getSession().getApplication().reportException(me); } }
private void doCreateFromText() { try { new CreateFromTextDialog(Session.getSession().getApplication()); } catch (Exception me) { Session.getSession().getApplication().reportException(me); } }
private boolean upload( DataBean dataBean, FileBrokerArea area, CopyProgressListener progressListener) throws Exception { // check if content is still available if (dataBean.getContentLocations().size() == 0) { return false; } // try to upload try { String checksum = Session.getSession() .getServiceAccessor() .getFileBrokerClient() .addFile( dataBean.getId(), area, getContentStream(dataBean, DataNotAvailableHandling.EXCEPTION_ON_NA), getContentLength(dataBean), progressListener); setOrVerifyChecksum(dataBean, checksum); } catch (Exception e) { logger.warn("could not upload data: " + dataBean.getName(), e); throw e; } return true; }
public void addContentLocationForDataBean(DataBean bean, StorageMethod method, URL url) throws ContentLengthException, IOException { ContentLocation location = new ContentLocation(method, getHandlerFor(method), url); try { setOrVerifyContentLength(bean, getContentLength(location)); } catch (IOException e) { throw new IOException("content length not available: " + e); } catch (ContentLengthException e) { try { DataManager manager = Session.getSession().getDataManager(); String msg; msg = "Wrong content length for dataset " + bean.getName() + ". " + " In ContentLocation " + location.getUrl() + ", length is " + getContentLength(location) + " bytes. "; msg += "Content locations: "; for (ContentLocation loc : manager.getContentLocationsForDataBeanSaving(bean)) { msg += loc.getUrl() + " " + manager.getContentLength(loc) + " bytes, "; } throw new ContentLengthException(msg); } catch (IOException e1) { logger.error("another exception while handling " + Exceptions.getStackTrace(e), e); } } bean.addContentLocation(location); }
public void connectChildren(final List<? extends DataItem> children, final DataFolder parent) { final ArrayList<AddTypeTagsCallable> callables = new ArrayList<>(); final ArrayList<DataItemCreatedEvent> events = new ArrayList<>(); // edit databeans in EDT ThreadUtils.runInEDT( new Runnable() { @Override public void run() { for (DataItem child : children) { // was it already connected? boolean wasConnected = child.getParent() != null; if (!wasConnected) { // prepare event, but don't send it yet events.add(new DataItemCreatedEvent(child)); } // connect to this child.setParent(parent); // add parent.children.add(child); // prepare type tagging callables if (child instanceof DataBean) { callables.add(new AddTypeTagsCallable((DataBean) child)); } } } }); // run type tagging in parallel in background threads try { // run callables and wait until all have finished List<Future<Object>> futures = executor.invokeAll(callables); for (Future<Object> future : futures) { // check callable for exception, and throw if found future.get(); } // dispatch events in EDT ThreadUtils.runInEDT( new Runnable() { @Override public void run() { for (DataItemCreatedEvent event : events) { dispatchEvent(event); } } }); } catch (InterruptedException | ExecutionException e) { Session.getSession().getApplication().reportExceptionThreadSafely(e); } }
public boolean uploadToStorageIfNeeded(DataBean bean) throws Exception { // check if already in storage if (Session.getSession() .getServiceAccessor() .getFileBrokerClient() .isAvailable(bean.getId(), bean.getSize(), bean.getChecksum(), FileBrokerArea.STORAGE)) { return true; } // move from cache if possible if (Session.getSession() .getServiceAccessor() .getFileBrokerClient() .moveFromCacheToStorage(bean.getId())) { return true; } // upload return upload(bean, FileBrokerArea.STORAGE, null); }
/** * Reset import screen. This can be used while creating totally new instance of import screen or * just resetting the default. * * @param setVisibleAfterReset set import screen frame visible after it has been reseted */ public void resetImportScreen(boolean setVisibleAfterReset) { application = Session.getSession().getApplication(); // If frame exists, set visibility to false while resetting if (frame != null) { frame.setVisible(false); } // Create new instances of conversion model, column type manager and trimmers conversionModel = new ConversionModel(this); columnTypeManager = new ColumnTypeManager(0); dataTrimmer = new DataTrimmer(); // Ignore first dataTrimmer.addIgnoreColumnNumber(0); flagTrimmer = new DataTrimmer(); flagTrimmer.addIgnoreColumnNumber(0); // Table has to be first to get references right tableFrame = new TableInternalFrame(this); toolsFrame = new ToolsInternalFrame(this); conversionModel.addConversionChangeListener(tableFrame); columnTypeManager.addColumnTypeChangeListener(tableFrame); columnTypeManager.addColumnTypeChangeListener(toolsFrame); frame = new JFrame("Import tool"); mainSplit = new JSplitPane(); frame.setLayout(new BorderLayout()); frame.setSize(IMPORT_SCREEN_SIZE); mainSplit.setOrientation(JSplitPane.HORIZONTAL_SPLIT); mainSplit.setDividerLocation(TOOLS_FRAME_WIDTH); mainSplit.setLeftComponent(toolsFrame); mainSplit.setRightComponent(tableFrame); mainSplit.getLeftComponent().setMinimumSize(new Dimension(150, 0)); mainSplit.setResizeWeight(0); frame.add(mainSplit, BorderLayout.CENTER); // Reset buttons changeStepPanel = null; frame.add(getChangeStepButtonsPanel(), BorderLayout.SOUTH); if (setVisibleAfterReset) { frame.setVisible(true); } }
/** * Creates a new instance of AutomatedMovement * * @param projection * @param worker */ public AutomatedMovement(Projection projection, Worker worker) { this.projection = projection; this.worker = worker; this.taskQueue = new LinkedList<Task>(); // this.obj = new Object(); Session.getSession() .getApplication() .addClientEventListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt instanceof VisualisationMethodChangedEvent) { AutomatedMovement.this.kill(); } } }); }
private InputStream getBaseContentStream(DataBean bean, DataNotAvailableHandling naHandling) throws IOException { // try local content locations first ContentLocation location = getClosestContentLocation(bean); if (location != null) { // local available TODO maybe check if it really is available return location.getHandler().getInputStream(location); } // try from filebroker Exception remoteException; try { return Session.getSession() .getServiceAccessor() .getFileBrokerClient() .getInputStream(bean.getId()); } catch (Exception e) { remoteException = e; } // not available switch (naHandling) { case EMPTY_ON_NA: return new ByteArrayInputStream(new byte[] {}); case INFOTEXT_ON_NA: return new ByteArrayInputStream(DATA_NA_INFOTEXT.getBytes()); case NULL_ON_NA: return null; default: String message = "data contents not available"; if (remoteException != null) { message += ": " + remoteException.getMessage(); } throw new RuntimeException(message, remoteException); } }
/** * Returns content size in bytes. Returns -1 if data is not available. * * <p>Size reported by content location is stored in DataBean in read from there when possible. */ public Long getContentLength(DataBean bean) { if (bean.getSize() == null) { try { ContentLocation location = getClosestContentLocation(bean); if (location != null) { bean.setSize(getContentLength(location)); } else { Long size = Session.getSession() .getServiceAccessor() .getFileBrokerClient() .getContentLength(bean.getId()); if (size != null) { bean.setSize(size); } else { return -1l; } } } catch (Exception e) { throw new RuntimeException(e); } } return bean.getSize(); }
private void createOperations() { for (OperationType operationType : sessionType.getOperation()) { String operationSessionId = operationType.getId(); // check for unique id if (operationRecords.containsKey(operationSessionId)) { logger.warn("duplicate operation id: " + operationSessionId); continue; } OperationRecord operationRecord = new OperationRecord(); // name id operationRecord.setNameID(createNameID(operationType.getName())); // category operationRecord.setCategoryName(operationType.getCategory()); String colorString = operationType.getCategoryColor(); if (colorString != null) { operationRecord.setCategoryColor(Color.decode(colorString)); } // module operationRecord.setModule(operationType.getModule()); // parameters for (ParameterType parameterType : operationType.getParameter()) { operationRecord.addParameter( parameterType.getName().getId(), parameterType.getName().getDisplayName(), parameterType.getName().getDescription(), parameterType.getValue()); } // source code String sourceCodeFileName = operationType.getSourceCodeFile(); if (sourceCodeFileName != null && !sourceCodeFileName.isEmpty()) { String sourceCode = null; try { sourceCode = getSourceCode(sourceCodeFileName); } catch (Exception e) { logger.warn("could not load source code from " + sourceCodeFileName); } // might be null, is ok operationRecord.setSourceCode(sourceCode); } // update names, category from the current version of the tool OperationDefinition currentTool; currentTool = Session.getSession() .getApplication() .getOperationDefinitionBestMatch( operationRecord.getNameID().getID(), operationRecord.getModule(), operationRecord.getCategoryName()); if (currentTool != null) { operationRecord.getNameID().setDisplayName(currentTool.getDisplayName()); operationRecord.getNameID().setDescription(currentTool.getDescription()); if (currentTool.getCategory().getModule() != null) { operationRecord.setModule(currentTool.getCategory().getModule().getModuleName()); } operationRecord.setCategoryName(currentTool.getCategoryName()); operationRecord.setCategoryColor(currentTool.getCategory().getColor()); for (ParameterRecord parameterRecord : operationRecord.getParameters()) { Parameter currentParameter = currentTool.getParameter(parameterRecord.getNameID().getID()); if (currentParameter != null) { parameterRecord.getNameID().setDisplayName(currentParameter.getDisplayName()); parameterRecord.getNameID().setDescription(currentParameter.getDescription()); } } } // store the operation record operationRecords.put(operationSessionId, operationRecord); operationTypes.put(operationRecord, operationType); } }
@Override public void taskToDo() { List<ImportItem> dataItems = new ArrayList<ImportItem>(); boolean hasNext = files.hasNext(); File currentFile = null; try { do { // Write file to disk conversionModel.writeToFile(informator); // Throws exceptions // Import files to application and create the DataBeans if (application != null) { for (File outputFile : conversionModel.getOutputFiles()) { ImportItem item = new ImportItem(outputFile); item.setType(Session.getSession().getDataManager().getContentType("text/tab")); item.setFilename(outputFile.getName()); dataItems.add(item); } } // Get next file hasNext = files.hasNext(); if (hasNext) { currentFile = files.next(); conversionModel.setInputFile(currentFile); } if (hasNext) { informator.setMessage("Writing data to disk from file " + currentFile.getName()); } } while (hasNext && importSession.getUseSameDescriptions()); application.importGroup(dataItems, importSession.getDestinationFolder()); } // Catch exceptions catch (ClosedByInterruptException cbie) { // Do nothing } catch (Exception ex) { if (application != null) { application.reportException(ex); } else { ex.printStackTrace(); } } finally { // All files wrote with the same description if (!hasNext) { // Reset the import screen and do not show it after resetting resetImportScreen(false); resetImportSession(); // Initialize the first step, but do no show it gotoFirstStep(); } else { // Reset the import screen and show it again after resetting resetImportScreen(true); conversionModel.setInputFile(currentFile); // Update table and chop the data from input file updateTable(false); // Initialize the first step and show it gotoFirstStep(); } } }