/** * Removes a previously uploaded result file. * * @param alternative Alternative the file was uploaded for. * @param sampleObject Sample the file was uploaded for. */ public void removeResultFile(Alternative alternative, SampleObject sampleObject) { DigitalObject resultFile = alternative.getExperiment().getResults().put(sampleObject, new DigitalObject()); bytestreamsToRemove.add(resultFile.getPid()); alternative.getExperiment().getResults().put(sampleObject, new DigitalObject()); }
/** Characterises results for all alternatives. */ public void characteriseResults() { List<Alternative> runnableAlternatives = getRunnableAlternatives(); List<SampleObject> allRecords = plan.getSampleRecordsDefinition().getRecords(); for (Alternative alternative : runnableAlternatives) { Experiment exp = alternative.getExperiment(); for (SampleObject record : allRecords) { DigitalObject u = exp.getResults().get(record); if (u.isDataExistent() && (u.getFitsXMLString() == null)) { characteriseFits(u); } } } }
/** * Method responsible for uploading a result file. * * @param resultFile File to upload. * @param alternative Alternative the file was uploaded for. * @param sampleObject Sample the file was uploaded for. * @throws StorageException is thrown if any error occurs at uploading the result file. */ public void uploadResultFile( DigitalObject resultFile, Alternative alternative, SampleObject sampleObject) throws StorageException { digitalObjectManager.moveDataToStorage(resultFile); addedBytestreams.add(resultFile.getPid()); characteriseFits(resultFile); alternative.getExperiment().getResults().put(sampleObject, resultFile); }
/** * Adds an executable plan t2flow to the parent. * * @param t2flow the t2flow to add * @param parent the parent element of the element to create * @return the newly created element or null if none was created * @throws TavernaParserException if the workflow could not be parsed * @throws StorageException if the data could not be loaded */ private Element addPreservationActionPlanT2flow(DigitalObject t2flow, Element parent) throws TavernaParserException, StorageException { Element executablePlan = null; if (t2flow != null && t2flow.isDataExistent()) { executablePlan = parent.addElement("executablePlan").addAttribute("type", "t2flow"); if (!addDigitalObjectData) { // Add only DigitalObject ID, it can be replaced later executablePlan.setText(String.valueOf(t2flow.getId())); } else { DigitalObject t2flowObject = t2flow; try { if (t2flowObject.getData().getData() == null || t2flowObject.getData().getData().length == 0) { t2flowObject = digitalObjectManager.getCopyOfDataFilledDigitalObject(t2flowObject); } T2FlowParser parser = T2FlowParser.createParser(new ByteArrayInputStream(t2flowObject.getData().getData())); Document doc = parser.getDoc(); executablePlan.add(doc.getRootElement()); } finally { t2flowObject = null; } } } return executablePlan; }
/** * Adds data for the preservation action plan to the parent element. * * @param collectionProfile source of the data * @param parent the parent element of the element to create * @return the newly created element or null if none was created * @throws ParserException if the collection profile could not be parsed * @throws StorageException if the data could not be loaded */ private Element addPreservationActionPlanData(CollectionProfile collectionProfile, Element parent) throws ParserException, StorageException { Element collection = null; if (collectionProfile != null) { collection = parent.addElement("collection"); collection.addAttribute("uid", collectionProfile.getCollectionID()); // TODO: Collection has no name // collection.addAttribute("name", // p.getSampleRecordsDefinition().getCollectionProfile().getCollectionID()); // Objects Element objects = parent.addElement("objects"); DigitalObject profileObject = collectionProfile.getProfile(); try { if (profileObject != null && profileObject.isDataExistent()) { if (!addDigitalObjectData) { objects.setText(String.valueOf(profileObject.getId())); } else { if (profileObject.getData().getData() == null || profileObject.getData().getData().length == 0) { profileObject = digitalObjectManager.getCopyOfDataFilledDigitalObject(profileObject); } C3POProfileParser parser = new C3POProfileParser(); parser.read(new ByteArrayInputStream(profileObject.getData().getData()), false); List<String> objectIdentifiers = parser.getObjectIdentifiers(); for (String objectIdentifier : objectIdentifiers) { objects.addElement("object").addAttribute("uid", objectIdentifier); } } } } finally { profileObject = null; } } return collection; }
/** * Generates an executable plan. * * @param planName the plan name * @param alternative the alternative to base the workflow on * @param measures the measures to include in the workflow * @param sourceMimetype the source mimetype of the workflow * @param targetMimetype the target mimetype of the workflow * @return an executable plan * @throws PlanningException if an error occurred during generation */ @Asynchronous public Future<DigitalObject> generateExecutablePlan( final String planName, final Alternative alternative, final List<String> measures, final String sourceMimetype, final String targetMimetype) throws PlanningException { DigitalObject workflow = new DigitalObject(); String name = planName + " - " + alternative.getName(); T2FlowExecutablePlanGenerator generator = new T2FlowExecutablePlanGenerator(name, user.getFullName()); // Add ports generator.addSourcePort(); generator.addTargetPort(); // Migration action PreservationActionDefinition action = alternative.getAction(); if (action != null) { try { WorkflowDescription wf = MyExperimentRESTClient.getWorkflow(action.getDescriptor()); if (wf != null) { HashMap<String, String> parameters = new HashMap<String, String>(); for (Parameter p : action.getParams()) { parameters.put(p.getName(), p.getValue()); } wf.readMetadata(); String workflowContent = MyExperimentRESTClient.getWorkflowContent(wf); generator.setMigrationComponent(wf, workflowContent, parameters); } else { log.warn(String.format("The workflow [%s] could not be found.", action.getDescriptor())); } } catch (Exception e) { throw new PlanningException( "An error occured querying myExperiment migration component", e); } } // Add QA components addQaComponents(generator, measures, sourceMimetype, targetMimetype); // Create digital object ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(out); try { generator.generate(writer); } catch (IOException e) { log.warn("An error occured generating the executable plan.", e.getMessage()); throw new PlanningException("An error occured generating the executable plan.", e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { log.warn( "An error occured closing the executable plan generator writer.", e.getMessage()); throw new PlanningException( "An error occured closing the executable plan generator writer.", e); } } } byte[] data = out.toByteArray(); ByteStream bsData = new ByteStream(); bsData.setData(data); workflow.setContentType("application/vnd.taverna.t2flow+xml"); workflow.setData(bsData); workflow.setFullname(FileUtils.makeFilename(name + ".t2flow")); return new AsyncResult<DigitalObject>(workflow); }