use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class ParametersManagerGUIController method commonPbEditEmptyMod.
@FXML
private void commonPbEditEmptyMod(ActionEvent event) {
isEditingCommonPb = true;
commonPbModel = new CommonPbModel();
setUpCommonPb();
commonPbModelEditable(true);
setUpCommonPbMenuItems(true, true);
}
use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class CommonPbXMLConverterTest method testCommonPbXMLConverter.
@Test
public void testCommonPbXMLConverter() {
try {
ResourceExtractor extractor = new ResourceExtractor(CommonPbModel.class);
File initialFile = extractor.extractResourceAsFile("Stacey-Kramers@559.0Ma (z6266) v.1.0.xml");
CommonPbModel model = new CommonPbModel();
model = (CommonPbModel) model.readXMLObject(initialFile.getAbsolutePath(), false);
File convertedFile = new File("commonPbCopy.xml");
model.serializeXMLObject(convertedFile.getAbsolutePath());
model = (CommonPbModel) model.readXMLObject(convertedFile.getAbsolutePath(), false);
File convertedConvertedFile = new File("commonPbCopyOfCopy.xml");
model.serializeXMLObject(convertedConvertedFile.getAbsolutePath());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(convertedFile);
Element initialElement = doc.getRootElement();
doc = builder.build(convertedConvertedFile);
Element convertedElement = doc.getRootElement();
convertedFile.delete();
convertedConvertedFile.delete();
assertTrue(ElementComparer.compareElements(initialElement, convertedElement));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class ParametersManagerTests method testCommonPbValueEntry.
@Test
public void testCommonPbValueEntry() throws SquidException {
BigDecimal num = new BigDecimal(Double.MAX_VALUE);
ParametersModel mod = new CommonPbModel();
mod.setModelName("a;sldkfja;sldkfj;alskdfjsja;sldkfj");
Task task = new Task();
task.setCommonPbModel(mod);
mod.getValues()[4].setValue(num);
task.updateParametersFromModels();
Expression exp = task.getExpressionByName(BuiltInExpressionsDataDictionary.DEFCOM_86);
assertTrue(exp != null && getDoubleValueOfExpressionWithOneConstantNodeChild(exp) == num.doubleValue());
}
use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class SquidUIController method synchronizeTaskLabDataAndSquidVersion.
private void synchronizeTaskLabDataAndSquidVersion() throws SquidException {
if (squidProject != null && squidProject.getTask() != null) {
TaskInterface task = squidProject.getTask();
SquidProject.setProjectChanged(((Task) task).synchronizeTaskVersion());
(((Task) task).verifySquidLabDataParameters()).forEach(model -> {
if (model instanceof PhysicalConstantsModel) {
squidLabData.addPhysicalConstantsModel(model);
squidLabData.getPhysicalConstantsModels().sort(new ParametersModelComparator());
} else if (model instanceof CommonPbModel) {
squidLabData.addcommonPbModel(model);
squidLabData.getCommonPbModels().sort(new ParametersModelComparator());
} else if (model instanceof ReferenceMaterialModel) {
squidLabData.addReferenceMaterial(model);
squidLabData.getReferenceMaterials().sort(new ParametersModelComparator());
}
});
squidProject.setReferenceMaterialModel(task.getReferenceMaterialModel());
squidProject.setConcentrationReferenceMaterialModel(task.getConcentrationReferenceMaterialModel());
if (SquidProject.isProjectChanged()) {
// dec 2021 for issue #674
task.setExtPErrU(squidProject.getExtPErrU());
task.setExtPErrTh(squidProject.getExtPErrTh());
// next two lines make sure 15-digit rounding is used by reprocessing data
task.setChanged(true);
task.setupSquidSessionSpecsAndReduceAndReport(true);
((Task) task).initTaskDefaultSquidReportTables(true);
ProjectFileUtilities.serializeSquidProject(squidProject, projectFileName);
SquidMessageDialog.showInfoDialog("The project file has been updated for this version of Squid3.\n", primaryStageWindow);
}
}
}
use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class SquidReportingService method generateReports.
public Path generateReports(String myProjectName, String myFileName, InputStream prawnFile, InputStream taskFile, boolean useSBM, boolean userLinFits, String refMatFilter, String concRefMatFilter, String preferredIndexIsotopeName) throws IOException, SquidException {
IndexIsoptopesEnum preferredIndexIsotope = IndexIsoptopesEnum.valueOf(preferredIndexIsotopeName);
// Posix attributes added to support web service on Linux - ignoring windows for now
Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ);
// detect if prawnfile is zipped
boolean prawnIsZip = false;
String fileName = "";
if (myFileName == null) {
fileName = DEFAULT_PRAWNFILE_NAME;
} else if (myFileName.toLowerCase().endsWith(".zip")) {
fileName = FilenameUtils.removeExtension(myFileName);
prawnIsZip = true;
} else {
fileName = myFileName;
}
SquidProject squidProject = new SquidProject(myProjectName, GEOCHRON);
prawnFileHandler = squidProject.getPrawnFileHandler();
Path reportsZip = null;
Path reportsFolder = null;
try {
Path uploadDirectory = Files.createTempDirectory("upload");
Path uploadDirectory2 = Files.createTempDirectory("upload2");
Path prawnFilePath;
Path taskFilePath;
if (prawnIsZip) {
Path prawnFilePathZip = uploadDirectory.resolve("prawn-file.zip");
Files.copy(prawnFile, prawnFilePathZip);
prawnFilePath = extractZippedFile(prawnFilePathZip.toFile(), uploadDirectory.toFile());
// dec 2021 in response to Snyk Path Traversal issue: https://app.snyk.io/org/bowring/project/7dd848fc-362b-4514-a91c-3c04628633ac
if (!prawnFilePath.normalize().startsWith(uploadDirectory))
throw new IOException("Zip entry contained path traversal");
} else {
prawnFilePath = uploadDirectory.resolve("prawn-file.xml");
Files.copy(prawnFile, prawnFilePath);
}
taskFilePath = uploadDirectory2.resolve("task-file.xls");
Files.copy(taskFile, taskFilePath);
File squidTaskFile = taskFilePath.toFile();
ShrimpDataFileInterface prawnFileData = prawnFileHandler.unmarshallPrawnFileXML(prawnFilePath.toString(), true);
squidProject.setPrawnFile(prawnFileData);
squidProject.setDelimiterForUnknownNames("-");
squidProject.preProcessPrawnSession();
squidProject.updateFilterForRefMatSpotNames(refMatFilter);
squidProject.updateFilterForRefMatSpotNames(concRefMatFilter);
squidProject.replaceCurrentTaskWithImportedSquid25Task(squidTaskFile);
TaskInterface task = squidProject.getTask();
// hard-wired for now
task.setTaskType(Squid3Constants.TaskTypeEnum.GEOCHRON);
ResourceExtractor extractor = new ResourceExtractor(CommonPbModel.class);
File commPbModelFile = extractor.extractResourceAsFile("Stacey-Kramers@559.0Ma (z6266) v.1.0.xml");
CommonPbModel commPbModel = new CommonPbModel();
commPbModel = (CommonPbModel) commPbModel.readXMLObject(commPbModelFile.getAbsolutePath(), false);
task.setCommonPbModel(commPbModel);
extractor = new ResourceExtractor(PhysicalConstantsModel.class);
File physConstModelFile = extractor.extractResourceAsFile("Squid 2.5 Default Physical Constants Model v.1.0.xml");
PhysicalConstantsModel physConstModel = new PhysicalConstantsModel();
physConstModel = (PhysicalConstantsModel) physConstModel.readXMLObject(physConstModelFile.getAbsolutePath(), false);
task.setPhysicalConstantsModel(physConstModel);
extractor = new ResourceExtractor(ReferenceMaterialModel.class);
File refMatModelFile = extractor.extractResourceAsFile("z6266 ID-TIMS (559.0 Ma) v.1.0.xml");
ReferenceMaterialModel refMatModel = new ReferenceMaterialModel();
refMatModel = (ReferenceMaterialModel) refMatModel.readXMLObject(refMatModelFile.getAbsolutePath(), false);
task.setReferenceMaterialModel(refMatModel);
task.setConcentrationReferenceMaterialModel(refMatModel);
task.setExtPErrU(0.75);
task.setExtPErrTh(0.75);
task.setUseSBM(useSBM);
task.setUserLinFits(userLinFits);
task.setSelectedIndexIsotope(preferredIndexIsotope);
task.setSquidAllowsAutoExclusionOfSpots(true);
// process task
task.applyTaskIsotopeLabelsToMassStationsAndUpdateTask();
Path calamariReportsFolderAliasParent = Files.createTempDirectory("reports-destination");
Path calamariReportsFolderAlias = calamariReportsFolderAliasParent.resolve("Squid3ReportsFromWebService");
File reportsDestinationFile = calamariReportsFolderAlias.toFile();
reportsEngine = prawnFileHandler.getReportsEngine();
prawnFileHandler.initReportsEngineWithCurrentPrawnFileName(fileName);
reportsEngine.setFolderToWriteCalamariReports(reportsDestinationFile);
((Task) task).initTaskDefaultSquidReportTables(true);
// for web service, need to set
prawnFileHandler.setCurrentPrawnSourceFileLocation(fileName);
if (squidProject.hasReportsFolder()) {
squidProject.getPrawnFileHandler().getReportsEngine().writeProjectAudit();
squidProject.getPrawnFileHandler().getReportsEngine().writeTaskAudit();
squidProject.getPrawnFileHandler().getReportsEngine().writeSummaryReportsForReferenceMaterials();
squidProject.produceReferenceMaterialPerSquid25CSV(true);
squidProject.produceSelectedReferenceMaterialReportCSV();
squidProject.getPrawnFileHandler().getReportsEngine().writeSummaryReportsForUnknowns();
squidProject.produceUnknownsPerSquid25CSV(true);
squidProject.produceUnknownsBySampleForETReduxCSV(true);
squidProject.produceSelectedUnknownsReportCSV();
squidProject.produceUnknownsWeightedMeanSortingFieldsCSV();
squidProject.getTask().producePerScanReportsToFiles();
}
Files.delete(prawnFilePath);
reportsFolder = Paths.get(reportsEngine.getFolderToWriteCalamariReports().getParentFile().getPath());
} catch (IOException | JAXBException | SAXException | SquidException iOException) {
Path config = Files.createTempFile("SquidWebServiceMessage", "txt", PosixFilePermissions.asFileAttribute(perms));
try (BufferedWriter writer = Files.newBufferedWriter(config, StandardCharsets.UTF_8)) {
writer.write("Squid Reporting web service was not able to process supplied files.");
writer.newLine();
writer.write(iOException.getMessage());
writer.newLine();
}
File message = config.toFile();
Path messageDirectory = Files.createTempDirectory("message");
Path messageFilePath = messageDirectory.resolve("Squid Web Service Message.txt");
Files.copy(message.toPath(), messageFilePath);
reportsFolder = messageFilePath.getParent();
}
reportsZip = ZipUtility.recursivelyZip(reportsFolder);
FileUtilities.recursiveDelete(reportsFolder);
return reportsZip;
}
Aggregations