Search in sources :

Example 1 with CommonPbModel

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);
}
Also used : CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) FXML(javafx.fxml.FXML)

Example 2 with CommonPbModel

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());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) ResourceExtractor(org.cirdles.commons.util.ResourceExtractor) Test(org.junit.Test)

Example 3 with CommonPbModel

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());
}
Also used : Task(org.cirdles.squid.tasks.Task) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) Expression(org.cirdles.squid.tasks.expressions.Expression) BigDecimal(java.math.BigDecimal) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) Test(org.junit.Test)

Example 4 with CommonPbModel

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);
        }
    }
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) Task(org.cirdles.squid.tasks.Task) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) TaskInterface(org.cirdles.squid.tasks.TaskInterface) ParametersModelComparator(org.cirdles.squid.parameters.ParametersModelComparator) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel)

Example 5 with CommonPbModel

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;
}
Also used : Path(java.nio.file.Path) Task(org.cirdles.squid.tasks.Task) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) JAXBException(javax.xml.bind.JAXBException) ShrimpDataFileInterface(org.cirdles.squid.shrimp.ShrimpDataFileInterface) SquidProject(org.cirdles.squid.projects.SquidProject) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) ResourceExtractor(org.cirdles.commons.util.ResourceExtractor) SAXException(org.xml.sax.SAXException) BufferedWriter(java.io.BufferedWriter) ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) SquidException(org.cirdles.squid.exceptions.SquidException) TaskInterface(org.cirdles.squid.tasks.TaskInterface) IndexIsoptopesEnum(org.cirdles.squid.constants.Squid3Constants.IndexIsoptopesEnum) ZipUtility.extractZippedFile(org.cirdles.squid.utilities.fileUtilities.ZipUtility.extractZippedFile) File(java.io.File)

Aggregations

CommonPbModel (org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel)7 File (java.io.File)4 PhysicalConstantsModel (org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel)4 ReferenceMaterialModel (org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel)4 Task (org.cirdles.squid.tasks.Task)4 IOException (java.io.IOException)3 SquidException (org.cirdles.squid.exceptions.SquidException)3 ParametersModelComparator (org.cirdles.squid.parameters.ParametersModelComparator)3 TaskInterface (org.cirdles.squid.tasks.TaskInterface)3 BigDecimal (java.math.BigDecimal)2 FXML (javafx.fxml.FXML)2 JAXBException (javax.xml.bind.JAXBException)2 ResourceExtractor (org.cirdles.commons.util.ResourceExtractor)2 ZipUtility.extractZippedFile (org.cirdles.squid.utilities.fileUtilities.ZipUtility.extractZippedFile)2 Test (org.junit.Test)2 SAXException (org.xml.sax.SAXException)2 BufferedWriter (java.io.BufferedWriter)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1