Search in sources :

Example 1 with VerbatimTimePeriod

use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.

the class TaxonXModsImport method makeOriginInfo.

/**
 * @param elModsName
 * @param ref
 */
private void makeOriginInfo(Element elOriginInfo, Reference ref) {
    Namespace nsMods = elOriginInfo.getNamespace();
    List<Content> contentList = elOriginInfo.getContent();
    // dateIssued
    Element elDateIssued = elOriginInfo.getChild("dateIssued", nsMods);
    if (elDateIssued != null) {
        String dateIssued = elDateIssued.getTextNormalize();
        contentList.remove(elDateIssued);
        VerbatimTimePeriod datePublished = TimePeriodParser.parseStringVerbatim(dateIssued);
        if (ref.getType().isPublication()) {
            ((IAuthoredPublicationBase) ref).setDatePublished(datePublished);
        } else {
            logger.warn("Reference has issue date but is not of type publication base. Date was not set");
        }
    }
    // dateIssued
    Element elPublisher = elOriginInfo.getChild("publisher", nsMods);
    if (elPublisher != null) {
        String publisher = elPublisher.getTextNormalize();
        contentList.remove(elPublisher);
        if (ref.getType().isPublication()) {
            ((IPublicationBase) ref).setPublisher(publisher);
        } else {
            logger.warn("Reference has publisher but is not of type publication base. Publisher was not set");
        }
    }
    removeEmptyContent(contentList);
    for (Content o : contentList) {
        logger.warn(o + " (in mods:originInfo) not yet implemented for mods import");
    }
    return;
}
Also used : VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) IPublicationBase(eu.etaxonomy.cdm.model.reference.IPublicationBase) Content(org.jdom.Content) Element(org.jdom.Element) Namespace(org.jdom.Namespace) IAuthoredPublicationBase(eu.etaxonomy.cdm.model.reference.IAuthoredPublicationBase)

Example 2 with VerbatimTimePeriod

use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.

the class Reference method clone.

// *********************** CLONE ********************************************************/
/**
 * Clones <i>this</i> reference. This is a shortcut that enables to create
 * a new instance that differs only slightly from <i>this</i> reference by
 * modifying only some of the attributes.
 *
 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
 * @see java.lang.Object#clone()
 */
@Override
public Reference clone() {
    try {
        Reference result = (Reference) super.clone();
        result.setDatePublished(datePublished != null ? (VerbatimTimePeriod) datePublished.clone() : null);
        // no changes to: title, authorship, hasProblem, nomenclaturallyRelevant, uri
        return result;
    } catch (CloneNotSupportedException e) {
        logger.warn("Object does not implement cloneable");
        e.printStackTrace();
        return null;
    }
}
Also used : VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) NoRecursiveInReference(eu.etaxonomy.cdm.validation.annotation.NoRecursiveInReference) InReference(eu.etaxonomy.cdm.validation.annotation.InReference)

Example 3 with VerbatimTimePeriod

use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.

the class GbifReferenceCsv2CdmConverter method map.

@Override
public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item) {
    List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
    Map<String, String> csv = item.map;
    Reference sourceReference = state.getTransactionalSourceReference();
    String sourceReferecenDetail = null;
    String id = getSourceId(item);
    TaxonBase<?> taxon = getTaxonBase(id, item, TaxonBase.class, state);
    if (isNotBlank(id) && taxon == null) {
        String message = "Taxon for id %s could not be found";
        message = String.format(message, id);
        fireWarningEvent(message, item, 8);
    }
    String strCreator = getValue(item, TermUri.DC_CREATOR);
    String strDate = getValue(item, TermUri.DC_DATE);
    String strTitle = getValue(item, TermUri.DC_TITLE);
    String strSource = getValue(item, TermUri.DC_SOURCE);
    String strIdentifier = getValue(item, TermUri.DC_IDENTIFIER);
    String strType = getValue(item, TermUri.DC_TYPE);
    Reference reference = ReferenceFactory.newGeneric();
    resultList.add(new MappedCdmBase<CdmBase>(reference));
    // author
    TeamOrPersonBase<?> author = handleCreator(strCreator);
    reference.setAuthorship(author);
    // date
    VerbatimTimePeriod publicationDate = handleDate(strDate);
    reference.setDatePublished(publicationDate);
    // title
    reference.setTitle(strTitle);
    // inreference
    Reference inRef = handleInRef(strSource);
    if (inRef != null) {
        reference.setInReference(inRef);
        resultList.add(new MappedCdmBase<>(inRef));
    }
    // URI
    handleIdentifier(strIdentifier, reference);
    // type
    handleType(reference, strType, taxon, resultList, item);
    return new ListReader<>(resultList);
}
Also used : ListReader(eu.etaxonomy.cdm.io.stream.ListReader) VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Reference(eu.etaxonomy.cdm.model.reference.Reference) ArrayList(java.util.ArrayList) MappedCdmBase(eu.etaxonomy.cdm.io.stream.MappedCdmBase) MappedCdmBase(eu.etaxonomy.cdm.io.stream.MappedCdmBase) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase)

Example 4 with VerbatimTimePeriod

use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.

the class DefaultTcsXmlPlaceholders method makePublicationDetailed.

/* (non-Javadoc)
	 * @see tcsxml.ITcsXmlPlaceholderClass#makePublicationDetailed(tcsxml.TcsXmlImportConfigurator, org.jdom.Element, eu.etaxonomy.cdm.model.reference.Reference)
	 */
@Override
public boolean makePublicationDetailed(TcsXmlImportConfigurator config, Element elPublicationDetailed, Reference publication) {
    ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
    if (config == null) {
        return false;
    }
    if (elPublicationDetailed == null) {
        return true;
    } else {
        publication.setProtectedTitleCache(false);
    }
    String childName;
    Namespace tcsNs = config.getTcsXmlNamespace();
    for (Object o : elPublicationDetailed.getChildren()) {
        Element element = (Element) o;
        String value = element.getTextNormalize();
        childName = "Title";
        if (element.getName().equalsIgnoreCase(childName) && element.getNamespace().equals(tcsNs)) {
            publication.setTitle(value);
            continue;
        }
        childName = "DatePublished";
        if (element.getName().equalsIgnoreCase(childName) && element.getNamespace().equals(tcsNs)) {
            VerbatimTimePeriod datePublished = TimePeriodParser.parseStringVerbatim(value);
            publication.setDatePublished(datePublished);
            continue;
        }
        logger.warn("Unhandled Publication Detailed child element: " + element.getName());
    }
    // TODO implement EDIT TcsMetaData extension
    if (logger.isDebugEnabled()) {
        logger.debug("PublicationDetailed element found: " + elPublicationDetailed.getName());
    }
    return success.getValue();
}
Also used : VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Example 5 with VerbatimTimePeriod

use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.

the class TaxonXModsExtractor method addRelatedMods.

/**
 * @param item
 * @param modsMap
 */
private void addRelatedMods(Node node, Map<String, String> modsMap, Reference ref) {
    NodeList tmp = node.getChildNodes();
    NodeList partNodes = null;
    NodeList children = null;
    List<String> originInfo = null;
    List<String> partList = null;
    VerbatimTimePeriod date;
    String publisher = "";
    String publishplace = "";
    String pstart = "";
    String pend = "";
    Map<String, String> mapmap = null;
    Map<String, String> relatedInfoMap = new HashMap<String, String>();
    List<String> roleList = new ArrayList<String>();
    String content = "";
    relatedInfoMap.put("type", node.getAttributes().getNamedItem("type").getNodeValue());
    Reference inRef = null;
    for (int j = 0; j < tmp.getLength(); j++) {
        Node childNode = tmp.item(j);
        String childNodeName = childNode.getNodeName();
        if (childNodeName.equalsIgnoreCase("#text") && childNode.getTextContent().matches("\\s*")) {
        // do nothing
        } else if (childNodeName.equalsIgnoreCase("mods:titleInfo")) {
            content = childNode.getTextContent().trim();
            if (!content.isEmpty()) {
                relatedInfoMap.put("titleInfo", content);
                if (node.getAttributes().getNamedItem("type").getNodeValue().equalsIgnoreCase("host")) {
                    List<Reference> references = importer.getReferenceService().list(Reference.class, 0, 0, null, null);
                    boolean refFound = false;
                    for (Reference tmpRef : references) {
                        if (tmpRef.getTitleCache().equalsIgnoreCase(content)) {
                            refFound = true;
                            inRef = tmpRef;
                        }
                    }
                    if (!refFound) {
                        inRef = getBestInreference(ref);
                        if (inRef == null) {
                            inRef = ReferenceFactory.newGeneric();
                        }
                        // book.setTitleCache(content,true);
                        inRef.setTitle(content);
                    }
                    if ((ref.getInReference() == null) || !ref.getInReference().equals(inRef)) {
                        ref.setInReference(inRef);
                    } else {
                    // TODO
                    }
                }
            }
        } else if (childNodeName.equalsIgnoreCase("mods:originInfo")) {
            children = childNode.getChildNodes();
            originInfo = new ArrayList<String>();
            for (int i = 0; i < children.getLength(); i++) {
                content = children.item(i).getTextContent().trim();
                if (!content.isEmpty()) {
                    originInfo.add(children.item(i).getNodeName() + ":" + content);
                    if (children.item(i).getNodeName().contains("dateIssued")) {
                        ref.setDatePublished(TimePeriodParser.parseStringVerbatim(content));
                    }
                }
                publisher = "";
                publishplace = "";
                if (children.item(i).getNodeName().contains("publisher")) {
                    try {
                        publisher = children.item(i).getChildNodes().item(0).getTextContent().trim();
                    // System.out.println("PUBLISHER "+publisher);
                    } catch (Exception e) {
                        System.out.println("oups " + e);
                    }
                }
                if (children.item(i).getNodeName().contains("place")) {
                    try {
                        publishplace = children.item(i).getTextContent().trim();
                    // System.out.println("PUBLISHED "+publishplace);
                    } catch (Exception e) {
                        System.out.println("oups " + e);
                    }
                }
                if (publishplace.isEmpty() && !publisher.isEmpty()) {
                    ref.setPublisher(publisher);
                }
                if (!publishplace.isEmpty() && !publisher.isEmpty()) {
                    ref.setPublisher(publisher, publishplace);
                }
            }
            relatedInfoMap.put("originInfo", StringUtils.join(originInfo.toArray(), SPLITTER));
        } else if (childNodeName.equalsIgnoreCase("mods:name")) {
        // handled later
        } else if (childNodeName.equalsIgnoreCase("mods:part")) {
            children = childNode.getChildNodes();
            partList = new ArrayList<String>();
            for (int i = 0; i < children.getLength(); i++) {
                mapmap = new HashMap<String, String>();
                if (children.item(i).getNodeName().equalsIgnoreCase("#text") && children.item(i).getTextContent().matches("\\s*")) {
                // do nothing
                } else if (children.item(i).getNodeName().equalsIgnoreCase("mods:date")) {
                    content = children.item(i).getTextContent().trim();
                    if (!content.isEmpty()) {
                        date = TimePeriodParser.parseStringVerbatim(content);
                        // TODO need to check if date belongs to ref or inref
                        ref.setDatePublished(date);
                    }
                } else if (children.item(i).getNodeName().equalsIgnoreCase("mods:detail") && children.item(i).getAttributes().getNamedItem("type").getNodeValue().equalsIgnoreCase("volume")) {
                    partNodes = children.item(i).getChildNodes();
                    for (int k = 0; k < partNodes.getLength(); k++) {
                        if (partNodes.item(k).getNodeName().equalsIgnoreCase("mods:number")) {
                            content = partNodes.item(k).getTextContent().trim();
                            if (!content.isEmpty()) {
                                ref.setVolume(content);
                            }
                        }
                    }
                } else if (children.item(i).getNodeName().equalsIgnoreCase("mods:extent")) {
                    mapmap.put("unit", children.item(i).getAttributes().getNamedItem("unit").getNodeValue());
                    partNodes = children.item(i).getChildNodes();
                    pstart = "";
                    pend = "";
                    for (int k = 0; k < partNodes.getLength(); k++) {
                        if (partNodes.item(k).getNodeName().equalsIgnoreCase("mods:start")) {
                            content = partNodes.item(k).getTextContent().trim();
                            if (!content.isEmpty()) {
                                mapmap.put("start", content);
                                pstart = content;
                            }
                        }
                        if (partNodes.item(k).getNodeName().equalsIgnoreCase("mods:end")) {
                            content = partNodes.item(k).getTextContent().trim();
                            if (!content.isEmpty()) {
                                mapmap.put("end", content);
                                pend = content;
                            }
                        }
                    }
                    // System.out.println("SET PAGES "+pstart+"-"+pend);
                    ref.setPages(pstart + "-" + pend);
                } else {
                    logger.warn("mods:part not yet supported: " + children.item(i).getNodeName());
                }
                partList.add(mapmap.toString());
            }
            modsMap.put("part", StringUtils.join(partList.toArray(), SPLITTER));
        } else {
            logger.warn("relatedItem child not yet supported: " + childNodeName);
        }
    }
    handleModsNames(children, inRef);
    relatedInfoMap.put("relatedRoles", StringUtils.join(roleList.toArray(), SPLITTER));
    modsMap.put("relatedInfo", relatedInfoMap.toString());
}
Also used : VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) HashMap(java.util.HashMap) Reference(eu.etaxonomy.cdm.model.reference.Reference) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

VerbatimTimePeriod (eu.etaxonomy.cdm.model.common.VerbatimTimePeriod)29 Reference (eu.etaxonomy.cdm.model.reference.Reference)15 Test (org.junit.Test)6 Team (eu.etaxonomy.cdm.model.agent.Team)4 Person (eu.etaxonomy.cdm.model.agent.Person)3 Annotation (eu.etaxonomy.cdm.model.common.Annotation)3 ImportResult (eu.etaxonomy.cdm.io.common.ImportResult)2 RisReferenceImportConfigurator (eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator)2 TimePeriod (eu.etaxonomy.cdm.model.common.TimePeriod)2 NomenclaturalStatus (eu.etaxonomy.cdm.model.name.NomenclaturalStatus)2 Rank (eu.etaxonomy.cdm.model.name.Rank)2 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)2 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)2 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Element (org.jdom.Element)2 Namespace (org.jdom.Namespace)2 Property (com.hp.hpl.jena.rdf.model.Property)1 Statement (com.hp.hpl.jena.rdf.model.Statement)1