Example usage for javax.xml.bind JAXBIntrospector getElementName

List of usage examples for javax.xml.bind JAXBIntrospector getElementName

Introduction

In this page you can find the example usage for javax.xml.bind JAXBIntrospector getElementName.

Prototype

public abstract QName getElementName(Object jaxbElement);

Source Link

Document

Get xml element qname for jaxbElement.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getExaminationMetaData(final Patient patient, final BiospecimenMetaData patientMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (patient.getExaminations() != null) {
        List<Examination> examinations = patient.getExaminations().getExamination();
        if (examinations != null) {
            // Get examination meta-data for the patient
            for (final Examination examination : examinations) {
                BiospecimenMetaData examinationMetaData = BiospecimenMetaData.newInstance(patientMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(examination.getBcrExaminationUuid());
                examinationMetaData.setBarcode(examination.getBcrExaminationBarcode().getValue());
                setUUID(examinationMetaData, uuid, archive);
                examinationMetaData.setUuidType(jaxbIntrospector.getElementName(examination).getLocalPart());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? examinationMetaData.getBarcode()
                                : examinationMetaData.getUuid(), examinationMetaData);
            }//from  w w  w.j a  v a  2  s .co  m
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getSlideMetaData(final Portion portion, final BiospecimenMetaData portionMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws UUIDException, ProcessorException {
    if (portion.getSlides() != null) {
        List<Slide> slides = portion.getSlides().getSlide();
        if (slides != null) {
            // Get slide meta-data for the sample
            for (final Slide slide : slides) {
                BiospecimenMetaData slideMetaData = BiospecimenMetaData.newInstance(portionMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(slide.getBcrSlideUuid());
                String slideBarcode = slide.getBcrSlideBarcode().getValue();
                slideMetaData.setBarcode(slideBarcode);
                slideMetaData.setSlide(getSlideForBarcode(slideBarcode));
                setUUID(slideMetaData, uuid, archive);
                slideMetaData.setUuidType(jaxbIntrospector.getElementName(slide).getLocalPart());
                slideMetaData.setSlideLayer(slide.getSectionLocation().getValue().toLowerCase());
                biospecimenMetaDataByUUIDORBarcode.put(
                        (uuid == null || uuid.isEmpty()) ? slideMetaData.getBarcode() : slideMetaData.getUuid(),
                        slideMetaData);//from   www.j a v  a2  s .  com
                logger.info("BiospecimenMetaDataProcessor: Processed slide with UUID " + slideMetaData.getUuid()
                        + " and parent " + slideMetaData.getParentUUID());
            }
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getShipmentPortionMetaData(final Sample sample, final BiospecimenMetaData sampleMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (sample.getPortions() != null) {
        List<ShipmentPortion> shipmentPortions = sample.getPortions().getShipmentPortion();
        if (shipmentPortions != null) {
            // Get shipment portion meta-data for the sample
            for (final ShipmentPortion shipmentPortion : shipmentPortions) {
                BiospecimenMetaData shipmentPortionMetaData = BiospecimenMetaData.newInstance(sampleMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(shipmentPortion.getBcrShipmentPortionUuid());
                shipmentPortionMetaData/*  w  ww .j  a v  a 2s .  co m*/
                        .setBarcode(shipmentPortion.getShipmentPortionBcrAliquotBarcode().getValue());
                setUUID(shipmentPortionMetaData, uuid, archive);
                shipmentPortionMetaData
                        .setUuidType(jaxbIntrospector.getElementName(shipmentPortion).getLocalPart());
                shipmentPortionMetaData.setPortionId(shipmentPortion.getPortionNumber().getValue().toString());
                shipmentPortionMetaData.setPlateId(shipmentPortion.getPlateId().getValue());
                shipmentPortionMetaData.setReceivingCenter(shipmentPortion.getCenterId().getValue());
                shipmentPortionMetaData.setCenterCode(shipmentPortion.getCenterId().getValue());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? shipmentPortionMetaData.getBarcode()
                                : shipmentPortionMetaData.getUuid(), shipmentPortionMetaData);
            }
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

/**
 * Extracts biospecimen meta-data from a clinical XML file and returns a list of {@link BiospecimenMetaData}
 * objects. Each object represents a single XML meta-data element.
 *
 * @param xmlFile   - the XML file to extract biospecimen meta-data from
 * @param qcContext - qcContext//from ww w.  ja  va2 s  .c  o  m
 * @return a list of {@link BiospecimenMetaData} objects, with each object representing a single meta-data element
 * @throws UUIDException      if an error occurs while attempting to generate a UUID for a specific meta-data
 *                            element when not provided in the XML
 * @throws ProcessorException if errors occur while attempting extract meta-data
 */
protected List<BiospecimenMetaData> handleBiospecimenMetaData(final File xmlFile, final QcContext qcContext)
        throws UUIDException, ProcessorException {
    logger.debug("starting handleBiospecimenMetadata");
    final Archive archive = qcContext.getArchive();
    // Unmarshal the XML file into a JAXB generated object
    TcgaBcr tcgaBcr;
    UnmarshalResult unmarshalResult;
    JAXBIntrospector jaxbIntrospector;
    try {
        unmarshalResult = JAXBUtil.unmarshal(xmlFile, TcgaBcr.class, true, false);
        tcgaBcr = (TcgaBcr) unmarshalResult.getJaxbObject();
        jaxbIntrospector = JAXBUtil.getJAXBIntrospector(TcgaBcr.class);
        logger.debug("JAXB Unmarshalling of BiospecimenMetadata done");
    } catch (Exception e) {
        logger.info(e);
        throw new ProcessorException(e.getMessage());
    }

    Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode;
    List<BiospecimenMetaData> biospecimenMetaData = null;
    if (tcgaBcr != null) {
        final Patient patient = tcgaBcr.getPatient();
        if (patient != null) {
            biospecimenMetaDataByUUIDORBarcode = new LinkedHashMap<String, BiospecimenMetaData>();
            final BiospecimenMetaData patientMetaData = new BiospecimenMetaData();
            final String uuid = JAXBUtil.getJAXBObjectValue(patient.getBcrPatientUuid());
            patientMetaData.setBarcode(patient.getBcrPatientBarcode().getValue());
            setUUID(patientMetaData, uuid, archive);
            patientMetaData.setUuidType(jaxbIntrospector.getElementName(patient).getLocalPart());
            patientMetaData.setBcr(archive.getTheCenter().getCenterId().toString());
            patientMetaData.setBatch(archive.getSerialIndex());
            patientMetaData.setDisease(archive.getTheTumor().getTumorName());
            patientMetaData.setParticipantId(patient.getPatientId().getValue());
            patientMetaData.setTissueSourceSite(patient.getTissueSourceSite().getValue());
            biospecimenMetaDataByUUIDORBarcode.put(
                    (uuid == null || uuid.isEmpty()) ? patientMetaData.getBarcode() : patientMetaData.getUuid(),
                    patientMetaData);
            logger.debug("Patient metadata done");
            // Get the transform of JAXB object into a list of meta-data entity objects
            getSampleMetaData(patient, patientMetaData, biospecimenMetaDataByUUIDORBarcode, jaxbIntrospector,
                    archive);
            logger.debug("Sample metadata done");
            getDrugMetaData(patient, patientMetaData, biospecimenMetaDataByUUIDORBarcode, jaxbIntrospector,
                    archive);
            logger.debug("Drug metadata done");
            getRadiationMetaData(patient, patientMetaData, biospecimenMetaDataByUUIDORBarcode, jaxbIntrospector,
                    archive);
            logger.debug("Radiation metadata done");
            getExaminationMetaData(patient, patientMetaData, biospecimenMetaDataByUUIDORBarcode,
                    jaxbIntrospector, archive);
            logger.debug("Examination metadata done");
            getSurgeryMetaData(patient, patientMetaData, biospecimenMetaDataByUUIDORBarcode, jaxbIntrospector,
                    archive);
            logger.debug("Surgery metadata done");
            biospecimenMetaData = new ArrayList<BiospecimenMetaData>(
                    biospecimenMetaDataByUUIDORBarcode.values());
            // Persist the meta-data                
            if (!biospecimenMetaDataByUUIDORBarcode.isEmpty()) {

                // Get the existing meta data from the data base and warn the user if the meta data is changed.
                final Map<String, BiospecimenMetaData> existingBiospecimenMetaData = uuidHierarchyQueries
                        .getMetaData(new ArrayList<String>(biospecimenMetaDataByUUIDORBarcode.keySet()));
                logger.debug("Get existing metadata: " + existingBiospecimenMetaData);
                logger.debug("Persisting metadata starting");
                uuidHierarchyQueries.persistUUIDHierarchy(biospecimenMetaData);
                logger.debug("Persisting metadata done");
                final List<BiospecimenMetaData> updatedMetaData = new ArrayList<BiospecimenMetaData>();

                // get the updatedMetadata
                for (final String existingUUIDOrBarcode : existingBiospecimenMetaData.keySet()) {
                    updatedMetaData.add(biospecimenMetaDataByUUIDORBarcode.get(existingUUIDOrBarcode));
                }
                // remove the metadata that are not changed
                updatedMetaData.removeAll(existingBiospecimenMetaData.values());
                if (updatedMetaData.size() > 0) {
                    final StringBuffer warning = new StringBuffer();

                    for (final BiospecimenMetaData metaData : updatedMetaData) {
                        warning.append("Meta data was updated: ");
                        // get the existing meta data. Key can be either uuid or barcode
                        BiospecimenMetaData existingMetaData = existingBiospecimenMetaData
                                .get(metaData.getUuid());
                        existingMetaData = (existingMetaData == null)
                                ? existingBiospecimenMetaData.get(metaData.getBarcode())
                                : existingMetaData;
                        warning.append(existingMetaData.getMetaDataString()).append("-->")
                                .append(metaData.getMetaDataString());
                        qcContext.addWarning(warning.toString());
                        warning.delete(0, warning.length());
                    }

                }

            }
        }
        processControls(tcgaBcr);
    }

    return biospecimenMetaData;
}