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);
}
}
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations