Search in sources :

Example 11 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class SDDDocumentBuilder method buildRepresentation.

/**
 * Builds a Representation element using a Reference
 */
public void buildRepresentation(ElementImpl element, IDatabase reference) throws ParseException {
    // create <Representation> element
    ElementImpl representation = new ElementImpl(document, REPRESENTATION);
    element.appendChild(representation);
    buildLabel(representation, reference.getTitleCache());
    Set<Annotation> annotations = ((Reference) reference).getAnnotations();
    Iterator<Annotation> iterator = annotations.iterator();
    String detailText = null;
    if (iterator.hasNext()) {
        Annotation annotation = iterator.next();
        detailText = annotation.getText();
    }
    if (detailText != null && !detailText.equals("")) {
        ElementImpl detail = new ElementImpl(document, DETAIL);
        detail.appendChild(document.createTextNode(detailText));
        representation.appendChild(detail);
    }
    Set<Media> rm = ((Reference) reference).getMedia();
    if (rm != null && rm.size() > 0) {
        ElementImpl mediaObject;
        for (int i = 0; i < rm.size(); i++) {
            mediaObject = new ElementImpl(document, MEDIA_OBJECT);
            mediasCount = buildReference((Media) rm.toArray()[i], medias, REF, mediaObject, "m", mediasCount);
            representation.appendChild(mediaObject);
        }
    }
}
Also used : ElementImpl(org.apache.xerces.dom.ElementImpl) Reference(eu.etaxonomy.cdm.model.reference.Reference) Media(eu.etaxonomy.cdm.model.media.Media) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) Annotation(eu.etaxonomy.cdm.model.common.Annotation)

Example 12 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class SDDDocumentBuilder method buildScope.

/**
 * Builds Scope associated with a CodedDescription
 */
public void buildScope(ElementImpl element, TaxonDescription taxonDescription) throws ParseException {
    // <Scope>
    // <TaxonName ref="t1"/>
    // <Citation ref="p1" location="p. 30"/>
    // </Scope>
    ElementImpl scope = new ElementImpl(document, SCOPE);
    Taxon taxon = taxonDescription.getTaxon();
    if (taxon != null) {
        TaxonName taxonName = taxon.getName();
        if (taxonName != null) {
            String ref = taxonNames.get(taxonName);
            if (!ref.equals("")) {
                ElementImpl taxonNameEl = new ElementImpl(document, TAXON_NAME);
                taxonNameEl.setAttribute(REF, ref);
                scope.appendChild(taxonNameEl);
            }
        }
    }
    Set<Reference> descriptionSources = new HashSet<Reference>();
    for (IdentifiableSource source : taxonDescription.getSources()) {
        descriptionSources.add(source.getCitation());
    }
    for (Iterator<Reference> rb = descriptionSources.iterator(); rb.hasNext(); ) {
        Reference descriptionSource = rb.next();
        if (descriptionSource.getType().equals(ReferenceType.Article)) {
            ElementImpl citation = new ElementImpl(document, CITATION);
            articlesCount = buildReference(descriptionSource, articles, REF, citation, "p", articlesCount);
            Set<Annotation> annotations = descriptionSource.getAnnotations();
            for (Iterator<Annotation> a = annotations.iterator(); a.hasNext(); ) {
                Annotation annotation = a.next();
                AnnotationType annotationType = annotation.getAnnotationType();
                if (annotationType != null) {
                    String type = annotationType.getLabel();
                    if (type.equals("location")) {
                        citation.setAttribute("location", annotation.getText());
                    }
                }
            }
            scope.appendChild(citation);
        }
    }
    element.appendChild(scope);
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) Annotation(eu.etaxonomy.cdm.model.common.Annotation) AnnotationType(eu.etaxonomy.cdm.model.common.AnnotationType) ElementImpl(org.apache.xerces.dom.ElementImpl) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) HashSet(java.util.HashSet)

Example 13 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class SDDDocumentBuilder method buildTechnicalMetadata.

// #############
// # BUILD DOM #
// #############
/**
 * Builds TechnicalMetadata associated with the SDD file
 */
public void buildTechnicalMetadata(ElementImpl baselement) throws ParseException {
    // create TechnicalMetadata
    ElementImpl technicalMetadata = new ElementImpl(document, TECHNICAL_METADATA);
    // select different databases associated to different descriptions TODO
    List<Reference> references = cdmSource.getReferences();
    Iterator<Reference> iterator = references.iterator();
    boolean database = false;
    IDatabase d = ReferenceFactory.newDatabase();
    while ((iterator.hasNext()) && (!database)) {
        Reference reference = iterator.next();
        if (reference.getType().equals(ReferenceType.Database)) {
            d = reference;
        }
    }
    DateTime dt = d.getCreated();
    String date = dt.toString().substring(0, 19);
    technicalMetadata.setAttribute("created", date);
    ElementImpl generator = new ElementImpl(document, GENERATOR);
    generator.setAttribute("name", "EDIT CDM");
    generator.setAttribute("version", "v1");
    generator.setAttribute("notes", "This SDD file has been generated by the SDD export functionality of the EDIT platform for Cybertaxonomy - Copyright (c) 2008");
    technicalMetadata.appendChild(generator);
    baselement.appendChild(technicalMetadata);
}
Also used : ElementImpl(org.apache.xerces.dom.ElementImpl) IDatabase(eu.etaxonomy.cdm.model.reference.IDatabase) Reference(eu.etaxonomy.cdm.model.reference.Reference) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) DateTime(org.joda.time.DateTime)

Example 14 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class SpecimenImportBase method linkDeterminationEvent.

/**
 * join DeterminationEvent to the Taxon Object
 * @param state : the ABCD import state
 * @param taxon: the current Taxon
 * @param preferredFlag :if the current name is preferred
 * @param derivedFacade : the derived Unit Facade
 */
@SuppressWarnings("rawtypes")
protected void linkDeterminationEvent(STATE state, Taxon taxon, boolean preferredFlag, DerivedUnitFacade derivedFacade, String identifierStr, String dateStr, String modifier) {
    SpecimenImportConfiguratorBase config = state.getConfig();
    if (logger.isDebugEnabled()) {
        logger.info("start linkdetermination with taxon:" + taxon.getUuid() + ", " + taxon);
    }
    DeterminationEvent determinationEvent = DeterminationEvent.NewInstance();
    // determinationEvent.setTaxon(taxon);
    determinationEvent.setTaxonName(taxon.getName());
    determinationEvent.setPreferredFlag(preferredFlag);
    determinationEvent.setIdentifiedUnit(state.getDerivedUnitBase());
    if (state.getPersonStore().get(identifierStr) != null) {
        determinationEvent.setActor((AgentBase) state.getPersonStore().get(identifierStr));
    } else if (identifierStr != null) {
        Person identifier = Person.NewTitledInstance(identifierStr);
        determinationEvent.setActor(identifier);
    }
    if (dateStr != null) {
        determinationEvent.setTimeperiod(TimePeriodParser.parseString(dateStr));
    }
    if (modifier != null) {
        if (modifier.equals("cf.")) {
            determinationEvent.setModifier(DefinedTerm.DETERMINATION_MODIFIER_CONFER());
        } else if (modifier.equals("aff.")) {
            determinationEvent.setModifier(DefinedTerm.DETERMINATION_MODIFIER_AFFINIS());
        }
    }
    state.getDerivedUnitBase().addDetermination(determinationEvent);
    if (logger.isDebugEnabled()) {
        logger.debug("NB TYPES INFO: " + state.getDataHolder().getStatusList().size());
    }
    for (SpecimenTypeDesignationStatus specimenTypeDesignationstatus : state.getDataHolder().getStatusList()) {
        if (specimenTypeDesignationstatus != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("specimenTypeDesignationstatus :" + specimenTypeDesignationstatus);
            }
            ICdmRepository cdmAppController = config.getCdmAppController();
            if (cdmAppController == null) {
                cdmAppController = this;
            }
            specimenTypeDesignationstatus = HibernateProxyHelper.deproxy(cdmAppController.getTermService().find(specimenTypeDesignationstatus.getUuid()), SpecimenTypeDesignationStatus.class);
            // Designation
            TaxonName name = taxon.getName();
            SpecimenTypeDesignation designation = SpecimenTypeDesignation.NewInstance();
            designation.setTypeStatus(specimenTypeDesignationstatus);
            designation.setTypeSpecimen(state.getDerivedUnitBase());
            name.addTypeDesignation(designation, false);
        }
    }
    save(state.getDerivedUnitBase(), state);
    for (String[] fullReference : state.getDataHolder().getReferenceList()) {
        String strReference = fullReference[0];
        String citationDetail = fullReference[1];
        String citationURL = fullReference[2];
        List<Reference> references = getReferenceService().listByTitleWithRestrictions(Reference.class, "strReference", MatchMode.EXACT, null, null, null, null, null);
        if (!references.isEmpty()) {
            Reference reference = null;
            for (Reference refe : references) {
                if (refe.getTitleCache().equalsIgnoreCase(strReference)) {
                    reference = refe;
                    break;
                }
            }
            if (reference == null) {
                reference = ReferenceFactory.newGeneric();
                reference.setTitleCache(strReference, true);
                save(reference, state);
            }
            determinationEvent.addReference(reference);
        }
    }
    save(state.getDerivedUnitBase(), state);
    if (config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations() && preferredFlag) {
        // do not add IndividualsAssociation to non-preferred taxa
        if (logger.isDebugEnabled()) {
            logger.debug("isDoCreateIndividualsAssociations");
        }
        makeIndividualsAssociation(state, taxon, determinationEvent);
        save(state.getDerivedUnitBase(), state);
    }
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) SpecimenTypeDesignationStatus(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) ICdmRepository(eu.etaxonomy.cdm.api.application.ICdmRepository) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) DeterminationEvent(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 15 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class SpecimenImportBase method sourceNotLinkedToElement.

private <T extends OriginalSourceBase> boolean sourceNotLinkedToElement(ISourceable<T> sourcable, Reference reference, String microReference) {
    Set<T> linkedSources = sourcable.getSources();
    for (T is : linkedSources) {
        Reference unitReference = is.getCitation();
        String unitMicroReference = is.getCitationMicroReference();
        boolean refMatch = false;
        boolean microMatch = false;
        try {
            if (unitReference == null && reference == null) {
                refMatch = true;
            }
            if (unitReference != null && reference != null) {
                if (unitReference.getTitleCache().equalsIgnoreCase(reference.getTitleCache())) {
                    refMatch = true;
                }
            }
        } catch (Exception e) {
        }
        try {
            if (unitMicroReference == null && microReference == null) {
                microMatch = true;
            }
            if (unitMicroReference != null && microReference != null) {
                if (unitMicroReference.equalsIgnoreCase(microReference)) {
                    microMatch = true;
                }
            }
        } catch (Exception e) {
        }
        if (microMatch && refMatch) {
            return false;
        }
    }
    return true;
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString)

Aggregations

Reference (eu.etaxonomy.cdm.model.reference.Reference)426 Test (org.junit.Test)123 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)103 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)92 ArrayList (java.util.ArrayList)59 Classification (eu.etaxonomy.cdm.model.taxon.Classification)42 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)41 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)41 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)39 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)38 DataSet (org.unitils.dbunit.annotation.DataSet)37 Person (eu.etaxonomy.cdm.model.agent.Person)34 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)34 IntextReference (eu.etaxonomy.cdm.model.common.IntextReference)31 INomenclaturalReference (eu.etaxonomy.cdm.model.reference.INomenclaturalReference)31 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)30 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)30 UUID (java.util.UUID)30 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)27 HashSet (java.util.HashSet)23