Search in sources :

Example 1 with TimePeriod

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

the class DbTimePeriodMapper method getValue.

@Override
protected Object getValue(CdmBase cdmBase) {
    String result = null;
    TimePeriod timePeriod = (TimePeriod) super.getValue(cdmBase);
    if (timePeriod != null) {
        result = timePeriod.toString();
    }
    return result;
}
Also used : TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod)

Example 2 with TimePeriod

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

the class MediaExcelImport method firstPass.

@Override
protected void firstPass(MediaExcelImportState state) {
    Map<String, String> record = state.getOriginalRecord();
    String line = "row " + state.getCurrentLine() + ": ";
    String linePure = "row " + state.getCurrentLine();
    System.out.println(linePure);
    // taxon
    Taxon taxon = getTaxonByCdmId(state, COL_TAXON_UUID, COL_NAME_CACHE, COL_NAME_TITLE, COL_TAXON_TITLE, Taxon.class, linePure);
    // media
    Media media = Media.NewInstance();
    // description
    String description = record.get(COL_DESCRIPTION);
    if (isNotBlank(description)) {
        UUID descriptionLanguageUuid = state.getConfig().getDescriptionLanguageUuid();
        Language descriptionLanguage = getLanguage(state, descriptionLanguageUuid);
        descriptionLanguage = descriptionLanguage == null ? Language.UNKNOWN_LANGUAGE() : descriptionLanguage;
        media.putDescription(descriptionLanguage, description);
    }
    // title
    String title = record.get(COL_TITLE);
    if (isBlank(title)) {
        title = makeTitle(state, taxon, line);
    }
    if (isNotBlank(title)) {
        UUID titleLanguageUuid = state.getConfig().getTitleLanguageUuid();
        Language titleLanguage = getLanguage(state, titleLanguageUuid);
        titleLanguage = titleLanguage == null ? Language.UNKNOWN_LANGUAGE() : titleLanguage;
        media.putTitle(titleLanguage, title);
    }
    // copyright
    String copyright = record.get(COL_COPYRIGHT);
    if (isNotBlank(copyright)) {
        AgentBase<?> agent = makePerson(state, copyright, line);
        Rights right = Rights.NewInstance(RightsType.COPYRIGHT(), agent);
        right = state.getDeduplicationHelper().getExistingCopyright(right);
        media.addRights(right);
    }
    // artist
    String artistStr = record.get(COL_ARTIST);
    if (isNotBlank(artistStr)) {
        AgentBase<?> artist = makePerson(state, artistStr, line);
        media.setArtist(artist);
    }
    // date
    String dateStr = record.get(COL_DATE);
    if (isNotBlank(dateStr)) {
        TimePeriod timePeriod = TimePeriodParser.parseString(dateStr);
        if (timePeriod.getFreeText() != null) {
            String message = "Date could not be parsed: %s";
            message = String.format(message, dateStr);
            state.getResult().addWarning(message, null, line);
        }
        media.setMediaCreated(timePeriod);
    }
    // URLs
    List<URI> uris = getUrls(state, line);
    for (URI uri : uris) {
        handleUri(state, uri, media, line);
    }
    // for (URI baseUrl : state.getConfig().getBaseUrls()){
    // if (!baseUrl.toString().endsWith("/")){
    // baseUrl = URI.create(baseUrl.toString() +  "/"); //is this always correct?
    // }
    // String url = baseUrl + fileName;
    // readImage
    // }
    // source
    String id = null;
    String idNamespace = null;
    Reference reference = getSourceReference(state);
    media.addImportSource(id, idNamespace, reference, linePure);
    if (taxon == null) {
        return;
    }
    String taxonTitle = taxon.getName() == null ? taxon.getTitleCache() : isBlank(taxon.getName().getNameCache()) ? taxon.getName().getTitleCache() : taxon.getName().getNameCache();
    TaxonDescription taxonDescription = taxon.getOrCreateImageGallery(taxonTitle);
    TextData textData = taxonDescription.getOrCreateImageTextData();
    textData.addMedia(media);
}
Also used : TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Media(eu.etaxonomy.cdm.model.media.Media) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) URI(eu.etaxonomy.cdm.common.URI) Rights(eu.etaxonomy.cdm.model.media.Rights) Language(eu.etaxonomy.cdm.model.common.Language) TextData(eu.etaxonomy.cdm.model.description.TextData) UUID(java.util.UUID)

Example 3 with TimePeriod

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

the class MarkupSpecimenImport method handleGathering.

private void handleGathering(MarkupImportState state, XMLEventReader readerOrig, XMLEvent parentEvent, DerivedUnitFacade facade) throws XMLStreamException {
    checkNoAttributes(parentEvent);
    boolean hasCollector = false;
    boolean hasFieldNum = false;
    LookAheadEventReader reader = new LookAheadEventReader(parentEvent.asStartElement(), readerOrig);
    // elements
    while (reader.hasNext()) {
        XMLEvent next = readNoWhitespace(reader);
        if (isMyEndingElement(next, parentEvent)) {
            if (!hasCollector) {
                if (state.getCurrentCollector() == null) {
                    checkMandatoryElement(hasCollector, parentEvent.asStartElement(), COLLECTOR);
                } else {
                    facade.setCollector(state.getCurrentCollector());
                }
            }
            checkMandatoryElement(hasFieldNum, parentEvent.asStartElement(), FIELD_NUM);
            return;
        } else if (isStartingElement(next, COLLECTOR)) {
            hasCollector = true;
            String collectorStr = getCData(state, reader, next);
            TeamOrPersonBase<?> collector = createCollector(state, collectorStr);
            facade.setCollector(collector);
            state.setCurrentCollector(collector);
        } else if (isStartingElement(next, ALTERNATIVE_COLLECTOR)) {
            handleNotYetImplementedElement(next);
        } else if (isStartingElement(next, FIELD_NUM)) {
            hasFieldNum = true;
            String fieldNumStr = getCData(state, reader, next);
            facade.setFieldNumber(fieldNumStr);
        } else if (isStartingElement(next, ALTERNATIVE_FIELD_NUM)) {
            handleAlternativeFieldNumber(state, reader, next, facade.innerFieldUnit());
        } else if (isStartingElement(next, COLLECTION_TYPE_STATUS)) {
            handleNotYetImplementedElement(next);
        } else if (isStartingElement(next, COLLECTION_AND_TYPE)) {
            handleGatheringCollectionAndType(state, reader, next, facade);
        } else if (isStartingElement(next, ALTERNATIVE_COLLECTION_TYPE_STATUS)) {
            handleNotYetImplementedElement(next);
        } else if (isStartingElement(next, SUB_GATHERING)) {
            handleNotYetImplementedElement(next);
        } else if (isStartingElement(next, COLLECTION)) {
            handleNotYetImplementedElement(next);
        } else if (isStartingElement(next, LOCALITY)) {
            handleLocality(state, reader, next, facade);
        } else if (isStartingElement(next, FULL_NAME)) {
            // can be any
            Rank defaultRank = Rank.SPECIES();
            INonViralName nvn = createNameByCode(state, defaultRank);
            handleFullName(state, reader, nvn, next);
            TaxonName name = TaxonName.castAndDeproxy(nvn);
            DeterminationEvent.NewInstance(name, facade.innerDerivedUnit() != null ? facade.innerDerivedUnit() : facade.innerFieldUnit());
        } else if (isStartingElement(next, DATES)) {
            TimePeriod timePeriod = handleDates(state, reader, next);
            facade.setGatheringPeriod(timePeriod);
        } else if (isStartingElement(next, GATHERING_NOTES)) {
            handleAmbigousManually(state, reader, next.asStartElement());
        } else if (isStartingElement(next, NOTES)) {
            handleNotYetImplementedElement(next);
        } else if (next.isCharacters()) {
            String text = next.asCharacters().getData().trim();
            if (isPunctuation(text)) {
            // do nothing
            } else if (state.isSpecimenType() && charIsSimpleType(text)) {
            // do nothing
            } else if ((text.equals("=") || text.equals("(")) && reader.nextIsStart(ALTERNATIVE_FIELD_NUM)) {
            // do nothing
            } else if ((text.equals(").") || text.equals(")")) && reader.previousWasEnd(ALTERNATIVE_FIELD_NUM)) {
            // do nothing
            } else if (charIsOpeningOrClosingBracket(text)) {
            // for now we don't do anything, however in future brackets may have semantics
            } else {
                // TODO
                String message = "Unrecognized text: %s";
                fireWarningEvent(String.format(message, text), next, 6);
            }
        } else {
            handleUnexpectedElement(next);
        }
    }
    throw new IllegalStateException("Collection has no closing tag.");
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) TeamOrPersonBase(eu.etaxonomy.cdm.model.agent.TeamOrPersonBase) TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) XMLEvent(javax.xml.stream.events.XMLEvent) Rank(eu.etaxonomy.cdm.model.name.Rank) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 4 with TimePeriod

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

the class SpecimenCdmExcelImport method makeDeterminationEvent.

private DeterminationEvent makeDeterminationEvent(SpecimenCdmExcelImportState state, DeterminationLight determination, Taxon taxon) {
    DeterminationEvent event = DeterminationEvent.NewInstance();
    // taxon
    event.setTaxon(taxon);
    // date
    TimePeriod date = TimePeriodParser.parseString(determination.determinedWhen);
    event.setTimeperiod(date);
    // by
    // FIXME bracketAuthors and teams not yet implemented!!!
    List<String> authors = new ArrayList<String>();
    if (StringUtils.isNotBlank(determination.determinedBy)) {
        authors.add(determination.determinedBy);
    }
    TeamOrPersonBase<?> actor = getOrMakeAgent(state, authors);
    TeamOrPersonBase<?> secAuthor = taxon.getSec() == null ? null : taxon.getSec().getAuthorship();
    if (actor != null && secAuthor != null && secAuthor.getTitleCache().equals(actor.getTitleCache()) && secAuthor.getNomenclaturalTitleCache().equals(actor.getNomenclaturalTitleCache())) {
        actor = secAuthor;
    }
    event.setActor(actor);
    // TODO
    if (StringUtils.isNotBlank(determination.modifier)) {
        logger.warn("DeterminationModifiers not yet implemented for specimen import");
    }
    // notes
    if (StringUtils.isNotEmpty(determination.notes)) {
        Annotation annotation = Annotation.NewInstance(determination.notes, AnnotationType.EDITORIAL(), Language.DEFAULT());
        event.addAnnotation(annotation);
    }
    return event;
}
Also used : TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) ArrayList(java.util.ArrayList) DeterminationEvent(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent) Annotation(eu.etaxonomy.cdm.model.common.Annotation)

Example 5 with TimePeriod

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

the class SpecimenSythesysExcelImport method start.

/*
     * Store the unit with it's Gathering informations in the CDM
     */
public boolean start(SpecimenSynthesysExcelImportConfigurator config) {
    boolean result = true;
    // refreshTransaction();
    try {
        /**
         * SPECIMEN OR OBSERVATION OR LIVING
         */
        DerivedUnitFacade derivedUnitFacade = getFacade();
        derivedUnitBase = derivedUnitFacade.innerDerivedUnit();
        // set catalogue number (unitID)
        derivedUnitFacade.setCatalogNumber(unitID);
        derivedUnitFacade.setAccessionNumber(accessionNumber);
        if (!originalsource.isEmpty()) {
            Reference reference = ReferenceFactory.newGeneric();
            reference.setTitleCache(originalsource, true);
            derivedUnitBase.addSource(OriginalSourceType.Import, originalsource, "", reference, "");
        } else {
            derivedUnitBase.addSource(OriginalSourceType.Import, unitID, "", ref, ref.getCitation());
        }
        // manage institution
        if (!institutionCode.isEmpty()) {
            Institution institution = getInstitution(config);
            // manage collection
            if (!collectionCode.isEmpty()) {
                Collection collection = getCollection(institution, config);
                // link specimen & collection
                derivedUnitFacade.setCollection(collection);
            }
        }
        /**
         * GATHERING EVENT
         */
        // gathering event
        UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(getTermService(), locality, languageIso, longitude, latitude, gatheringAgent, gatheringTeam, config);
        // country
        UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
        unitsGatheringArea.useTDWGareas(this.useTDWGarea);
        // unitsGatheringArea.setConfig(config, getOccurrenceService(),getTermService());
        unitsGatheringArea.setParams(isocountry, country, config, getTermService(), getVocabularyService());
        DefinedTermBase areaCountry = unitsGatheringArea.getCountry();
        // copy gathering event to facade
        GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
        // join gatheringEvent to fieldObservation
        derivedUnitFacade.setGatheringEvent(gatheringEvent);
        derivedUnitFacade.setLocality(gatheringEvent.getLocality());
        derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
        // derivedUnitFacade.setCollector(gatheringEvent.getCollector());
        derivedUnitFacade.setCountry((NamedArea) areaCountry);
        for (DefinedTermBase<?> area : unitsGatheringArea.getAreas()) {
            derivedUnitFacade.addCollectingArea((NamedArea) area);
        }
        if (gatheringNotes != null && !gatheringNotes.isEmpty()) {
            derivedUnitFacade.setFieldNotes(gatheringNotes);
        }
        /*
             * merge AND STORE DATA
             */
        // getTermService().saveOrUpdate(areaCountry);// TODO save area sooner
        getTermService().saveLanguageData(unitsGatheringEvent.getLocality());
        // add gathering date
        if (keepAtomisedDate && (!gatheringYear.isEmpty() || !gatheringMonth.isEmpty() || !gatheringDay.isEmpty())) {
            Calendar calendar = Calendar.getInstance();
            if (!gatheringYear.isEmpty()) {
                TimePeriod tp = TimePeriod.NewInstance(Integer.parseInt(gatheringYear));
                if (!gatheringMonth.isEmpty()) {
                    tp.setStartMonth(Integer.parseInt(gatheringMonth));
                    if (!gatheringDay.isEmpty()) {
                        tp.setStartDay(Integer.parseInt(gatheringDay));
                    }
                }
                unitsGatheringEvent.setGatheringDate(tp);
            }
        } else {
            if (!gatheringDate.isEmpty()) {
                TimePeriod tp = TimePeriodParser.parseString(gatheringDate);
                unitsGatheringEvent.setGatheringDate(tp);
            }
        }
        // add fieldNumber
        derivedUnitFacade.setFieldNumber(fieldNumber);
        // add Multimedia URLs
        if (multimediaObjects.size() > 0) {
            for (String multimediaObject : multimediaObjects) {
                Media media;
                try {
                    media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
                    derivedUnitFacade.addDerivedUnitMedia(media);
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        getOccurrenceService().saveOrUpdate(derivedUnitBase);
        setTaxonName(config);
        // refreshTransaction();
        if (DEBUG) {
            logger.info("saved new specimen ...");
        }
    } catch (Exception e) {
        logger.warn("Error when reading record!!");
        e.printStackTrace();
        result = false;
    }
    if (DEBUG) {
        logger.info("commit done");
    }
    // app.close();
    return result;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) GatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent) UnitsGatheringEvent(eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent) MalformedURLException(java.net.MalformedURLException) UnitsGatheringArea(eu.etaxonomy.cdm.io.specimen.UnitsGatheringArea) Reference(eu.etaxonomy.cdm.model.reference.Reference) TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) Calendar(java.util.Calendar) Media(eu.etaxonomy.cdm.model.media.Media) Institution(eu.etaxonomy.cdm.model.agent.Institution) UnitsGatheringEvent(eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) Collection(eu.etaxonomy.cdm.model.occurrence.Collection)

Aggregations

TimePeriod (eu.etaxonomy.cdm.model.common.TimePeriod)30 VerbatimTimePeriod (eu.etaxonomy.cdm.model.common.VerbatimTimePeriod)12 Test (org.junit.Test)11 Institution (eu.etaxonomy.cdm.model.agent.Institution)5 Person (eu.etaxonomy.cdm.model.agent.Person)5 DerivedUnitFacade (eu.etaxonomy.cdm.api.facade.DerivedUnitFacade)4 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 Team (eu.etaxonomy.cdm.model.agent.Team)3 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 NamedArea (eu.etaxonomy.cdm.model.location.NamedArea)3 Media (eu.etaxonomy.cdm.model.media.Media)3 Rank (eu.etaxonomy.cdm.model.name.Rank)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 GatheringEvent (eu.etaxonomy.cdm.model.occurrence.GatheringEvent)3 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)3 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 URI (eu.etaxonomy.cdm.common.URI)2 UnitsGatheringArea (eu.etaxonomy.cdm.io.specimen.UnitsGatheringArea)2 UnitsGatheringEvent (eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent)2