List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.metaeffekt.core.inventory.processor.MavenCentralGroupIdProcessor.java
License:Apache License
private void updateGroupId(CloseableHttpClient client, HttpGet request, Artifact artifact) throws IOException, HttpException, DocumentException, URISyntaxException { final String id = artifact.getId(); String version = artifact.getVersion(); if (!StringUtils.hasText(version)) { // we need to make a good guess: version = artifact.deriveVersionFromId(); }/* w w w . j a va 2 s. c o m*/ if (!StringUtils.hasText(version)) { return; } String artifactId = artifact.extractArtifactId(id, version); if (!StringUtils.hasText(artifactId)) { return; } String replacedUri = URI_PATTERN_ARTIFACT_SEARCH.replaceAll("\\$\\{artifactId\\}", artifactId); replacedUri = replacedUri.replaceAll("\\$\\{artifactVersion\\}", version.replace(" ", "")); request.setURI(new URI(replacedUri)); LOG.info(replacedUri); CloseableHttpResponse response = client.execute(request); try { SAXReader reader = new SAXReader(); Document document = reader.read(response.getEntity().getContent()); @SuppressWarnings("unchecked") List<Node> node = document.selectNodes("//response/result/doc/str[@name='g']"); String groupIds = null; for (Node node2 : node) { if (groupIds == null) { groupIds = node2.getText(); } else { groupIds += "|" + node2.getText(); } } if (groupIds != null) { if (!groupIds.contains("|")) { artifact.setVersion(version); artifact.setGroupId(groupIds); artifact.setArtifactId(null); artifact.deriveArtifactId(); LOG.info("Updated groupId for artifact {}: {}", id, groupIds); } else { LOG.info("Update of groupId skipped. Found groupId ambiguous: {}", groupIds); } } } finally { response.close(); } }
From source file:org.metaeffekt.core.inventory.processor.MavenCentralVersionProcessor.java
License:Apache License
private void updateLatestVersion(CloseableHttpClient client, HttpGet request, Artifact artifact, final LRUMap queryCache) throws URISyntaxException, IOException, HttpException, DocumentException { String artifactId = artifact.getId(); int index = artifactId.indexOf("-" + artifact.getVersion()); if (index != -1) { artifactId = artifactId.substring(0, index); }/*www . j ava 2 s .c o m*/ if (StringUtils.hasText(artifact.getGroupId())) { String[] groupIds = artifact.getGroupId().split("\\|"); String latestVersions = null; for (int i = 0; i < groupIds.length; i++) { String replacedUri = URI_PATTERN_ARTIFACT_RESOLVE.replaceAll("\\$\\{artifactId\\}", artifactId.replace(" ", "-")); replacedUri = replacedUri.replaceAll("\\$\\{groupId\\}", groupIds[i].replace(" ", "")); LOG.info("Querying: {}", replacedUri); String latestVersion = (String) queryCache.get(replacedUri); String latestVersionMethod1 = null; if (latestVersion == null) { request.setURI(new URI(replacedUri)); CloseableHttpResponse response = client.execute(request); try { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { SAXReader reader = new SAXReader(); Document document = reader.read(response.getEntity().getContent()); Node node; LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); List<String> timestamps = new ArrayList<String>(); @SuppressWarnings("unchecked") List<Node> docNodes = document.selectNodes("//response/result/doc"); if (docNodes != null) { for (Object result : docNodes) { Node resultNode = (Node) result; node = resultNode.selectSingleNode("str[@name='v']"); String version = node.getText(); node = resultNode.selectSingleNode("long[@name='timestamp']"); String timestamp = node.getText(); // the timestamp alone may have duplicated // therefore we append the version timestamp = timestamp + version; map.put(timestamp, version); timestamps.add(timestamp); } if (!timestamps.isEmpty()) { Collections.sort(timestamps); latestVersionMethod1 = map.get(timestamps.get(timestamps.size() - 1)); } } } } finally { response.close(); } // method2 String replacedUri2 = URI_PATTERN_ARTIFACT_RESOLVE_METHOD2.replaceAll("\\$\\{artifactId\\}", artifactId.replace(" ", "-")); replacedUri2 = replacedUri2.replaceAll("\\$\\{groupId\\}", groupIds[i].replace(" ", "")); request.setURI(new URI(replacedUri2)); response = client.execute(request); String latestVersionMethod2 = null; try { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { SAXReader reader = new SAXReader(); Document document = reader.read(response.getEntity().getContent()); int numEntries = Integer .parseInt(document.selectSingleNode("//response/result").valueOf("@numFound")); if (numEntries == 1) { Node node = document .selectSingleNode("//response/result/doc/str[@name='latestVersion']"); if (node != null) { latestVersionMethod2 = node.getText(); } } } } finally { response.close(); } if (latestVersionMethod1 != null) { latestVersion = latestVersionMethod1; if (!latestVersionMethod1.equals(latestVersionMethod2)) { latestVersion = latestVersion + "|" + latestVersionMethod2; } } else { latestVersion = latestVersionMethod2; } if (latestVersion == null) { latestVersion = "n.a."; } if (latestVersions == null) { latestVersions = latestVersion; } else { latestVersions += "|" + latestVersion; } queryCache.put(replacedUri, latestVersions); } else { latestVersions = latestVersion; } } LOG.info("Latest version: {}", latestVersions); artifact.setLatestAvailableVersion(latestVersions); } }
From source file:org.mskcc.cbio.oncokb.quest.VariantAnnotationXMLV2.java
private static Gene parseGene(Node node, String genePath) { GeneBo geneBo = ApplicationContextSingleton.getGeneBo(); Gene gene = null;/*w w w . ja va 2 s .c o m*/ Node entrezGeneIdNode = node.selectSingleNode(genePath + "/entrez_gene_id"); Node hugoSymbolNode = node.selectSingleNode(genePath + "/hgnc_symbol"); if (entrezGeneIdNode != null) { int entrezId = Integer.parseInt(entrezGeneIdNode.getText()); gene = geneBo.findGeneByEntrezGeneId(entrezId); } if (gene == null && hugoSymbolNode != null) { String symbol = hugoSymbolNode.getText(); gene = geneBo.findGeneByHugoSymbol(symbol); } if (gene == null) { // a gene not in system gene = new Gene(); gene.setEntrezGeneId(Integer.parseInt(entrezGeneIdNode.getText())); gene.setHugoSymbol(hugoSymbolNode.getText()); } return gene; }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static List<ClinicalData> parsePatientClinicalData(Node patientNode, String patientId, int cancerStudyId) { List<ClinicalData> clinicalData = new ArrayList<ClinicalData>(); // Node node = patientNode.selectSingleNode("PtProtocolStudyId"); // if (node!=null) { // clinicalData.add(new ClinicalData(cancerStudyId, patientId, "PATIENT_ID", node.getText())); // }//from ww w . jav a2s .c om Node node = patientNode.selectSingleNode("PtRace"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "RACE", node.getText())); } node = patientNode.selectSingleNode("PtRegistrationAge"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "AGE", node.getText())); } node = patientNode.selectSingleNode("Categories/Category/Category"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "PATIENT_CATEGORY", node.getText())); } node = patientNode.selectSingleNode("ClinicalStages/ClinicalStage/ClinStageT"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "CLIN_T_Stage", node.getText())); } node = patientNode.selectSingleNode("ClinicalStages/ClinicalStage/ClinStageN"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "CLIN_N_Stage", node.getText())); } node = patientNode.selectSingleNode("ClinicalStages/ClinicalStage/ClinStageM"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "CLIN_M_Stage", node.getText())); } node = patientNode.selectSingleNode("Pathologies/Pathology/PathHistology"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "HISTOLOGY", node.getText())); } node = patientNode.selectSingleNode("Pathologies/Pathology/PathResult"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "PATH_RESULT", node.getText())); } node = patientNode .selectSingleNode("Pathologies/Pathology/PathologyStageGrades/PathologyStageGrade/PathStageT"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "PATH_T_STAGE", node.getText())); } node = patientNode .selectSingleNode("Pathologies/Pathology/PathologyStageGrades/PathologyStageGrade/PathStageN"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "PATH_N_STAGE", node.getText())); } node = patientNode .selectSingleNode("Pathologies/Pathology/PathologyStageGrades/PathologyStageGrade/PathStageM"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "PATH_M_STAGE", node.getText())); } node = patientNode.selectSingleNode("Pathologies/Pathology/ProstateBiopsyPaths/ProstateBiopsyPath/PathGG1"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "GLEASON_SCORE_1", node.getText())); } node = patientNode.selectSingleNode("Pathologies/Pathology/ProstateBiopsyPaths/ProstateBiopsyPath/PathGG2"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "GLEASON_SCORE_2", node.getText())); } node = patientNode.selectSingleNode("Pathologies/Pathology/ProstateBiopsyPaths/ProstateBiopsyPath/PathGGS"); if (node != null) { clinicalData.add(new ClinicalData(cancerStudyId, patientId, "GLEASON_SCORE", node.getText())); } return clinicalData; }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseMedicalTherapies(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> treatmentNodes = patientNode.selectNodes("MedicalTherapies/MedicalTherapy"); for (Node treatmentNode : treatmentNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("TREATMENT"); clinicalEvent.addEventDatum("TREATMENT_TYPE", "Medical Therapy"); Node node = treatmentNode.selectSingleNode("MedTxDate"); if (node == null) { System.err.println("no date"); continue; }// w w w . j a va 2 s. co m clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = treatmentNode.selectSingleNode("MedTxStopDate"); if (node != null) { clinicalEvent.setStopDate(Long.parseLong(node.getText())); } node = treatmentNode.selectSingleNode("MedTxType"); if (node != null) { clinicalEvent.addEventDatum("SUBTYPE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxIndication"); if (node != null) { clinicalEvent.addEventDatum("INDICATION", node.getText()); } node = treatmentNode.selectSingleNode("MedTxAgent"); if (node != null) { clinicalEvent.addEventDatum("AGENT", node.getText()); } node = treatmentNode.selectSingleNode("MedTxDose"); if (node != null) { clinicalEvent.addEventDatum("DOSE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxTotalDose"); if (node != null) { clinicalEvent.addEventDatum("TOTAL_DOSE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxUnits"); if (node != null) { clinicalEvent.addEventDatum("UNIT", node.getText()); } node = treatmentNode.selectSingleNode("MedTxSchedule"); if (node != null) { clinicalEvent.addEventDatum("SCHEDULE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxRoute"); if (node != null) { clinicalEvent.addEventDatum("ROUTE", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseRadiationTherapies(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> treatmentNodes = patientNode.selectNodes("RadiationTherapies/RadiationTherapy"); for (Node treatmentNode : treatmentNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("TREATMENT"); clinicalEvent.addEventDatum("TREATMENT_TYPE", "Radiation Therapy"); Node node = treatmentNode.selectSingleNode("RadTxDate"); if (node == null) { System.err.println("no date"); continue; }/* w w w . j a v a2 s . c om*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = treatmentNode.selectSingleNode("RadTxStopDate"); if (node != null) { clinicalEvent.setStopDate(Long.parseLong(node.getText())); } node = treatmentNode.selectSingleNode("RadTxType"); if (node != null) { clinicalEvent.addEventDatum("SUBTYPE", node.getText()); } node = treatmentNode.selectSingleNode("RadTxIndication"); if (node != null) { clinicalEvent.addEventDatum("INDICATION", node.getText()); } node = treatmentNode.selectSingleNode("RadTxIntent"); if (node != null) { clinicalEvent.addEventDatum("INTENT", node.getText()); } node = treatmentNode.selectSingleNode("RadTxDosePerFraction"); if (node != null) { clinicalEvent.addEventDatum("DOSE_PER_FRACTION", node.getText()); } node = treatmentNode.selectSingleNode("RadTxTotalDose"); if (node != null) { clinicalEvent.addEventDatum("TOTAL_DOSE", node.getText()); } node = treatmentNode.selectSingleNode("RadTxUnits"); if (node != null) { clinicalEvent.addEventDatum("UNIT", node.getText()); } node = treatmentNode.selectSingleNode("RadTxNumFractions"); if (node != null) { clinicalEvent.addEventDatum("NUM_FRACTIONS", node.getText()); } node = treatmentNode.selectSingleNode("RadTxTarget"); if (node != null) { clinicalEvent.addEventDatum("TARGET", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseBrachyTherapies(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> treatmentNodes = patientNode.selectNodes("BrachyTherapies/BrachyTherapy"); for (Node treatmentNode : treatmentNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("TREATMENT"); clinicalEvent.addEventDatum("TREATMENT_TYPE", "Brachytherapy"); Node node = treatmentNode.selectSingleNode("BrachyDate"); if (node == null) { System.err.println("no date"); continue; }//from w ww . j av a 2 s. co m clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = treatmentNode.selectSingleNode("BrachyIsotope"); if (node != null) { clinicalEvent.addEventDatum("BRACHY_ISOTOPE", node.getText()); } node = treatmentNode.selectSingleNode("BrachyPrescribedDose"); if (node != null) { clinicalEvent.addEventDatum("DOSE", node.getText()); } node = treatmentNode.selectSingleNode("BrachyDoseNotes"); if (node != null) { clinicalEvent.addEventDatum("DOSE_NOTES", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseDiagnostics(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> diagnosticNodes = patientNode.selectNodes("Diagnostics/Diagnostic"); for (Node diagnosticNode : diagnosticNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("DIAGNOSTIC"); Node node = diagnosticNode.selectSingleNode("DxDate"); if (node == null) { System.err.println("no date"); continue; }/*from www . jav a 2 s . co m*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = diagnosticNode.selectSingleNode("DxType"); if (node != null) { clinicalEvent.addEventDatum("DIAGNOSTIC_TYPE", node.getText()); } node = diagnosticNode.selectSingleNode("DxTarget"); if (node != null) { clinicalEvent.addEventDatum("TARGET", node.getText()); } node = diagnosticNode.selectSingleNode("DxResult"); if (node != null) { clinicalEvent.addEventDatum("RESULT", node.getText()); } node = diagnosticNode.selectSingleNode("DxNotes"); if (node != null) { clinicalEvent.addEventDatum("NOTES", node.getText()); } node = diagnosticNode.selectSingleNode("DxSide"); if (node != null) { clinicalEvent.addEventDatum("SIDE", node.getText()); } node = diagnosticNode.selectSingleNode("DxStatus"); if (node != null) { clinicalEvent.addEventDatum("STATUS", node.getText()); } node = diagnosticNode.selectSingleNode("ImgBaseline"); if (node != null) { clinicalEvent.addEventDatum("BASELINE", node.getText()); } node = diagnosticNode.selectSingleNode("DxNumNewTumors"); if (node != null) { clinicalEvent.addEventDatum("NUM_NEW_TUMORS", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseLabTests(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> labTestNodes = patientNode.selectNodes("LabTests/LabTest"); for (Node labTestNode : labTestNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("LAB_TEST"); Node node = labTestNode.selectSingleNode("LabDate"); if (node == null) { System.err.println("no date"); continue; }/*from w w w . j a va 2s. c om*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = labTestNode.selectSingleNode("LabTest"); if (node == null) { System.err.println("no lab test name"); continue; } clinicalEvent.addEventDatum("TEST", node.getText()); node = labTestNode.selectSingleNode("LabResult"); if (node == null) { System.err.println("no lab result"); continue; } clinicalEvent.addEventDatum("RESULT", node.getText()); node = labTestNode.selectSingleNode("LabUnits"); if (node != null) { clinicalEvent.addEventDatum("UNIT", node.getText()); } node = labTestNode.selectSingleNode("LabNormalRange"); if (node != null) { clinicalEvent.addEventDatum("NORMAL_RANGE", node.getText()); } node = labTestNode.selectSingleNode("LabNotes"); if (node != null) { clinicalEvent.addEventDatum("NOTES", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseClinicalEventsFromSpecimen(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> specimenAccessionNodes = patientNode.selectNodes("SpecimenAccessions/SpecimenAccession"); for (Node specimenAccessionNode : specimenAccessionNodes) { Node node = specimenAccessionNode.selectSingleNode("AccessionDate"); if (node == null) { System.err.println("no date"); continue; }/*from ww w . j a va2 s. c o m*/ long date = Long.parseLong(node.getText()); String site = null, type = null, instrument = null; node = specimenAccessionNode.selectSingleNode("AccessionAnatomicSite"); if (node != null) { site = node.getText(); } node = specimenAccessionNode.selectSingleNode("AccessionVisitType"); if (node != null) { type = node.getText(); } node = specimenAccessionNode.selectSingleNode("AccessionProcInstrument"); if (node != null) { instrument = node.getText(); } List<Node> specimenNodes = specimenAccessionNode.selectNodes("Specimens/Specimen"); for (Node specimenNode : specimenNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("SPECIMEN"); clinicalEvent.setStartDate(date); if (site != null) { clinicalEvent.addEventDatum("SPECIMEN_SITE", site); } if (type != null) { clinicalEvent.addEventDatum("ANATOMIC_SITE", type); } if (instrument != null) { clinicalEvent.addEventDatum("PROC_INSTRUMENT", instrument); } addAllDataUnderNode(clinicalEvent, Element.class.cast(specimenNode)); clinicalEvents.add(clinicalEvent); } } }