Search in sources :

Example 1 with Person

use of eu.etaxonomy.cdm.model.agent.Person in project cdmlib by cybertaxonomy.

the class IpniService method buildAuthorList.

private List<Person> buildAuthorList(InputStream content, ICdmRepository repository, IIpniServiceConfigurator iConfig) throws IOException {
    IpniServiceAuthorConfigurator config = (IpniServiceAuthorConfigurator) iConfig;
    List<Person> result = new ArrayList<>();
    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
    String headerLine = reader.readLine();
    if (headerLine != null) {
        Map<Integer, String> parameterMap = getParameterMap(headerLine);
        String line = reader.readLine();
        while (isNotBlank(line)) {
            Person author = getAuthorFromLine(line, parameterMap, repository, config);
            result.add(author);
            line = reader.readLine();
        }
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 2 with Person

use of eu.etaxonomy.cdm.model.agent.Person in project cdmlib by cybertaxonomy.

the class IpniService method getAuthorFromLine.

private Person getAuthorFromLine(String line, Map<Integer, String> categoryMap, ICdmRepository repository, IpniServiceAuthorConfigurator config) {
    // Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
    String[] splits = line.split("%");
    Map<String, String> valueMap = fillValueMap(categoryMap, splits);
    Person person = Person.NewInstance();
    person.setNomenclaturalTitle(valueMap.get(STANDARD_FORM));
    person.setGivenName(valueMap.get(DEFAULT_AUTHOR_FORENAME));
    person.setFamilyName(valueMap.get(DEFAULT_AUTHOR_SURNAME));
    Reference citation = getIpniCitation(repository);
    // id, version
    person.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Author", citation, valueMap.get(VERSION));
    // dates
    TimePeriod lifespan = TimePeriodParser.parseString(valueMap.get(DATES));
    person.setLifespan(lifespan);
    // alternative_names
    String alternativeNames = valueMap.get(ALTERNATIVE_NAMES);
    if (isNotBlank(alternativeNames)) {
        String[] alternativeNameSplits = alternativeNames.split("%");
        for (String alternativeName : alternativeNameSplits) {
            if (alternativeName.startsWith(">")) {
                alternativeName = alternativeName.substring(1);
            }
            Extension.NewInstance(person, alternativeName, ExtensionType.INFORMAL_CATEGORY());
        }
    }
    return person;
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 3 with Person

use of eu.etaxonomy.cdm.model.agent.Person in project cdmlib by cybertaxonomy.

the class GbifJsonOccurrenceParser method parseJsonRecords.

/**
 * Parses the given {@link JSONArray} for occurrences.
 * @param jsonString JSON data as an {@link JSONArray}
 * @return the found occurrences as a collection of {@link GbifResponse}
 */
private static Collection<GbifResponse> parseJsonRecords(JSONArray jsonArray) {
    Collection<GbifResponse> results = new ArrayList<>();
    String[] tripleId = new String[3];
    String string;
    for (Object o : jsonArray) {
        // parse every record
        tripleId = new String[3];
        if (o instanceof JSONObject) {
            String dataSetKey = null;
            GbifDataSetProtocol dataSetProtocol = null;
            DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
            TaxonName name = null;
            JSONObject record = (JSONObject) o;
            if (record.has(DATASET_PROTOCOL)) {
                dataSetProtocol = GbifDataSetProtocol.parseProtocol(record.getString(DATASET_PROTOCOL));
            }
            if (record.has(DATASET_KEY)) {
                dataSetKey = record.getString(DATASET_KEY);
            }
            if (record.has(COUNTRY_CODE)) {
                string = record.getString(COUNTRY_CODE);
                Country country = Country.getCountryByIso3166A2(string);
                if (country != null) {
                    derivedUnitFacade.setCountry(country);
                }
            }
            if (record.has(LOCALITY)) {
                string = record.getString(LOCALITY);
                derivedUnitFacade.setLocality(string);
            }
            if (record.has("species")) {
                Rank rank = null;
                if (record.has(TAXON_RANK)) {
                    string = record.getString(TAXON_RANK);
                    try {
                        rank = Rank.getRankByLatinName(string);
                    } catch (UnknownCdmTypeException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                if (rank != null) {
                    if (record.has(NOMENCLATURALCODE)) {
                        string = record.getString(NOMENCLATURALCODE);
                        if (string.equals(NomenclaturalCode.ICZN.getTitleCache())) {
                            name = TaxonNameFactory.NewZoologicalInstance(rank);
                        } else if (string.equals(NomenclaturalCode.ICNAFP.getTitleCache())) {
                            name = TaxonNameFactory.NewBotanicalInstance(rank);
                        } else if (string.equals(NomenclaturalCode.ICNP.getTitleCache())) {
                            name = TaxonNameFactory.NewBacterialInstance(rank);
                        } else if (string.equals(NomenclaturalCode.ICNCP.getTitleCache())) {
                            name = TaxonNameFactory.NewCultivarInstance(rank);
                        } else if (string.equals(NomenclaturalCode.ICVCN.getTitleCache())) {
                            name = TaxonNameFactory.NewViralInstance(rank);
                        } else if (string.equals("ICN")) {
                            name = TaxonNameFactory.NewBotanicalInstance(rank);
                        }
                    } else {
                        if (record.has(KINGDOM)) {
                            if (record.getString(KINGDOM).equals(PLANTAE)) {
                                name = TaxonNameFactory.NewBotanicalInstance(rank);
                            } else if (record.getString(KINGDOM).equals(ANIMALIA)) {
                                name = TaxonNameFactory.NewZoologicalInstance(rank);
                            } else if (record.getString(KINGDOM).equals(FUNGI)) {
                                name = TaxonNameFactory.NewBotanicalInstance(rank);
                            } else if (record.getString(KINGDOM).equals(BACTERIA)) {
                                name = TaxonNameFactory.NewBacterialInstance(rank);
                            } else {
                                name = TaxonNameFactory.NewNonViralInstance(rank);
                            }
                        } else {
                            name = TaxonNameFactory.NewNonViralInstance(rank);
                        }
                    }
                    if (name == null) {
                        name = TaxonNameFactory.NewNonViralInstance(rank);
                    }
                    if (record.has(GENUS)) {
                        name.setGenusOrUninomial(record.getString(GENUS));
                    }
                    if (record.has(SPECIFIC_EPITHET)) {
                        name.setSpecificEpithet(record.getString(SPECIFIC_EPITHET));
                    }
                    if (record.has(INFRASPECIFIC_EPITHET)) {
                        name.setInfraSpecificEpithet(record.getString(INFRASPECIFIC_EPITHET));
                    }
                    if (record.has(SCIENTIFIC_NAME)) {
                        name.setTitleCache(record.getString(SCIENTIFIC_NAME), true);
                    }
                }
                DeterminationEvent detEvent = DeterminationEvent.NewInstance();
                if (record.has(IDENTIFIED_BY)) {
                    Person determiner = Person.NewTitledInstance(record.getString(IDENTIFIED_BY));
                    detEvent.setDeterminer(determiner);
                }
                detEvent.setTaxonName(name);
                detEvent.setPreferredFlag(true);
                derivedUnitFacade.addDetermination(detEvent);
            }
            // GPS location
            Point location = Point.NewInstance();
            derivedUnitFacade.setExactLocation(location);
            try {
                if (record.has(LATITUDE)) {
                    String lat = record.getString(LATITUDE);
                    location.setLatitudeByParsing(lat);
                }
                if (record.has(LONGITUDE)) {
                    String lon = record.getString(LONGITUDE);
                    location.setLongitudeByParsing(lon);
                }
            } catch (ParseException e) {
                logger.error("Could not parse GPS coordinates", e);
            }
            if (record.has(GEOREFERENCE_PROTOCOL)) {
                String geo = record.getString(GEOREFERENCE_PROTOCOL);
                ReferenceSystem referenceSystem = null;
                // to check which reference system is used?
                if (ReferenceSystem.WGS84().getLabel().contains(geo)) {
                    referenceSystem = ReferenceSystem.WGS84();
                } else if (ReferenceSystem.GOOGLE_EARTH().getLabel().contains(geo)) {
                    referenceSystem = ReferenceSystem.GOOGLE_EARTH();
                } else if (ReferenceSystem.GAZETTEER().getLabel().contains(geo)) {
                    referenceSystem = ReferenceSystem.GAZETTEER();
                }
                location.setReferenceSystem(referenceSystem);
            }
            if (record.has(ELEVATION)) {
                try {
                    // parse integer and strip of unit
                    string = record.getString(ELEVATION);
                    int length = string.length();
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < length; i++) {
                        if (Character.isDigit(string.charAt(i))) {
                            builder.append(string.charAt(i));
                        } else {
                            break;
                        }
                    }
                    derivedUnitFacade.setAbsoluteElevation(Integer.parseInt(builder.toString()));
                } catch (NumberFormatException e) {
                    logger.warn("Could not parse elevation", e);
                }
            }
            // Date (Gathering Period)
            TimePeriod timePeriod = TimePeriod.NewInstance();
            derivedUnitFacade.setGatheringPeriod(timePeriod);
            // TODO what happens with eventDate??
            if (record.has(YEAR)) {
                timePeriod.setStartYear(record.getInt(YEAR));
            }
            if (record.has(MONTH)) {
                timePeriod.setStartMonth(record.getInt(MONTH));
            }
            if (record.has(DAY)) {
                timePeriod.setStartDay(record.getInt(DAY));
            }
            if (record.has(RECORDED_BY)) {
                Person person = Person.NewTitledInstance(record.getString(RECORDED_BY));
                // FIXME check data base if collector already present
                derivedUnitFacade.setCollector(person);
            }
            // collector number (fieldNumber OR recordNumber)
            if (record.has(FIELD_NUMBER)) {
                derivedUnitFacade.setFieldNumber(record.getString(FIELD_NUMBER));
            }
            // collector number (fieldNumber OR recordNumber)
            if (record.has(RECORD_NUMBER)) {
                derivedUnitFacade.setFieldNumber(record.getString(RECORD_NUMBER));
            }
            if (record.has(EVENT_REMARKS)) {
                derivedUnitFacade.setGatheringEventDescription(record.getString(EVENT_REMARKS));
            }
            if (record.has(OCCURRENCE_REMARKS)) {
                derivedUnitFacade.setEcology(record.getString(OCCURRENCE_REMARKS));
            }
            if (record.has(COLLECTION_CODE)) {
                String collectionCode = record.getString(COLLECTION_CODE);
                tripleId[2] = collectionCode;
                // FIXME: check data base for existing collections
                eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
                collection.setCode(collectionCode);
                if (record.has(INSTITUTION_CODE)) {
                    Institution institution = Institution.NewNamedInstance(record.getString(INSTITUTION_CODE));
                    institution.setCode(record.getString(INSTITUTION_CODE));
                    collection.setInstitute(institution);
                }
                derivedUnitFacade.setCollection(collection);
            }
            if (record.has(CATALOG_NUMBER)) {
                derivedUnitFacade.setCatalogNumber(record.getString(CATALOG_NUMBER));
                derivedUnitFacade.setAccessionNumber(record.getString(CATALOG_NUMBER));
                tripleId[0] = record.getString(CATALOG_NUMBER);
            }
            if (record.has(INSTITUTION_CODE)) {
                derivedUnitFacade.setAccessionNumber(record.getString(INSTITUTION_CODE));
                tripleId[1] = record.getString(INSTITUTION_CODE);
            }
            if (record.has(OCCURENCE_ID)) {
                IdentifiableSource source = IdentifiableSource.NewDataImportInstance((record.getString(OCCURENCE_ID)));
                derivedUnitFacade.addSource(source);
            }
            if (record.has(MULTIMEDIA)) {
                // http://ww2.bgbm.org/herbarium/images/B/-W/08/53/B_-W_08537%20-00%201__3.jpg
                JSONArray multimediaArray = record.getJSONArray(MULTIMEDIA);
                JSONObject mediaRecord;
                SpecimenOrObservationType type = null;
                for (Object object : multimediaArray) {
                    // parse every record
                    Media media = Media.NewInstance();
                    URI uri = null;
                    CdmImageInfo imageInf = null;
                    if (object instanceof JSONObject) {
                        mediaRecord = (JSONObject) object;
                        if (mediaRecord.has("identifier")) {
                            try {
                                uri = new URI(mediaRecord.getString("identifier"));
                                imageInf = MediaInfoFileReader.legacyFactoryMethod(uri).readBaseInfo().getCdmImageInfo();
                            } catch (URISyntaxException | IOException | HttpException e) {
                                e.printStackTrace();
                            }
                        // media.addIdentifier(mediaRecord.getString("identifier"), null);
                        }
                        if (mediaRecord.has("references")) {
                        }
                        if (mediaRecord.has("format")) {
                        }
                        if (mediaRecord.has("type")) {
                            if (mediaRecord.get("type").equals("StillImage")) {
                                type = SpecimenOrObservationType.StillImage;
                            }
                        }
                    }
                    ImageFile imageFile = ImageFile.NewInstance(uri, null, imageInf);
                    MediaRepresentation representation = MediaRepresentation.NewInstance();
                    representation.addRepresentationPart(imageFile);
                    media.addRepresentation(representation);
                    derivedUnitFacade.addDerivedUnitMedia(media);
                }
            // identifier=http://ww2.bgbm.org/herbarium/images/B/-W/08/53/B_-W_08537%20-00%201__3.jpg
            // references=http://ww2.bgbm.org/herbarium/view_biocase.cfm?SpecimenPK=136628
            // format=image/jpeg
            // type=StillImage
            }
            // create dataset URL
            URI uri = null;
            try {
                uri = UriUtils.createUri(new URL(GbifQueryServiceWrapper.BASE_URL), "/v1/dataset/" + dataSetKey + "/endpoint", null, null);
            } catch (MalformedURLException e) {
                logger.error("Endpoint URI could not be created!", e);
            } catch (URISyntaxException e) {
                logger.error("Endpoint URI could not be created!", e);
            }
            results.add(new GbifResponse(derivedUnitFacade, uri, dataSetProtocol, tripleId, name));
        }
    }
    return results;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) MalformedURLException(java.net.MalformedURLException) ImageFile(eu.etaxonomy.cdm.model.media.ImageFile) ArrayList(java.util.ArrayList) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) Institution(eu.etaxonomy.cdm.model.agent.Institution) URISyntaxException(java.net.URISyntaxException) DeterminationEvent(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent) ReferenceSystem(eu.etaxonomy.cdm.model.location.ReferenceSystem) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) CdmImageInfo(eu.etaxonomy.cdm.common.media.CdmImageInfo) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) HttpException(org.apache.http.HttpException) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) JSONArray(net.sf.json.JSONArray) Media(eu.etaxonomy.cdm.model.media.Media) Rank(eu.etaxonomy.cdm.model.name.Rank) Point(eu.etaxonomy.cdm.model.location.Point) IOException(java.io.IOException) Point(eu.etaxonomy.cdm.model.location.Point) JSONObject(net.sf.json.JSONObject) Country(eu.etaxonomy.cdm.model.location.Country) JSONObject(net.sf.json.JSONObject) ParseException(java.text.ParseException) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 4 with Person

use of eu.etaxonomy.cdm.model.agent.Person in project cdmlib by cybertaxonomy.

the class User method NewInstance.

public static User NewInstance(String personTitle, String username, String pwd) {
    User user = NewInstance(username, pwd);
    Person userPerson = Person.NewTitledInstance(personTitle);
    user.setPerson(userPerson);
    return user;
}
Also used : Person(eu.etaxonomy.cdm.model.agent.Person)

Example 5 with Person

use of eu.etaxonomy.cdm.model.agent.Person in project cdmlib by cybertaxonomy.

the class SDDDocumentBuilder method buildRefAgent.

/**
 * Builds an element Agent referring to Agent defined later in the SDD file
 */
public void buildRefAgent(ElementImpl element, TeamOrPersonBase ag, String role) throws ParseException {
    if (ag instanceof Person) {
        Person p = (Person) ag;
        ElementImpl agent = new ElementImpl(document, AGENT);
        if (ag.getMarkers() != null) {
            Set<Marker> markers = ag.getMarkers();
            for (Iterator<Marker> m = markers.iterator(); m.hasNext(); ) {
                Marker marker = m.next();
                if (marker.getMarkerType().getLabel().equals("editor")) {
                    agent.setAttribute(ROLE, "edt");
                }
            }
        } else {
            agent.setAttribute(ROLE, role);
        }
        agentsCount = buildReference(p, agents, REF, agent, "a", agentsCount);
        element.appendChild(agent);
    }
    if (ag instanceof Team) {
        Team team = (Team) ag;
        for (int i = 0; i < team.getTeamMembers().size(); i++) {
            Person author = team.getTeamMembers().get(i);
            ElementImpl agent = new ElementImpl(document, AGENT);
            if (author.getMarkers() != null) {
                Set<Marker> markers = author.getMarkers();
                if (!markers.isEmpty()) {
                    for (Iterator<Marker> m = markers.iterator(); m.hasNext(); ) {
                        Marker marker = m.next();
                        if (marker.getMarkerType().getLabel().equals("editor")) {
                            agent.setAttribute(ROLE, "edt");
                        }
                    }
                } else {
                    agent.setAttribute(ROLE, role);
                }
            } else {
                agent.setAttribute(ROLE, role);
            }
            if (author.getSources() != null) {
                IdentifiableSource os = (IdentifiableSource) author.getSources().toArray()[0];
                String id = os.getIdInSource();
                if (id != null) {
                    if (!id.equals("")) {
                        if (!agents.containsValue(id)) {
                            agent.setAttribute(REF, id);
                        } else if (!agents.containsValue("a" + (agentsCount + 1))) {
                            agent.setAttribute(REF, "a" + (agentsCount + 1));
                            agentsCount++;
                        } else {
                            agent.setAttribute(REF, id + (agentsCount + 1));
                            agentsCount++;
                        }
                    } else {
                        agent.setAttribute(REF, "a" + (agentsCount + 1));
                        agentsCount++;
                    }
                } else {
                    agent.setAttribute(REF, "a" + (agentsCount + 1));
                    agentsCount++;
                }
            } else {
                agent.setAttribute(REF, "a" + (agentsCount + 1));
                agentsCount++;
            }
            agents.put(author, agent.getAttribute(REF));
            element.appendChild(agent);
        }
    }
}
Also used : ElementImpl(org.apache.xerces.dom.ElementImpl) Team(eu.etaxonomy.cdm.model.agent.Team) Marker(eu.etaxonomy.cdm.model.common.Marker) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) Person(eu.etaxonomy.cdm.model.agent.Person)

Aggregations

Person (eu.etaxonomy.cdm.model.agent.Person)154 Test (org.junit.Test)62 Team (eu.etaxonomy.cdm.model.agent.Team)56 Reference (eu.etaxonomy.cdm.model.reference.Reference)34 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)33 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)27 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)21 DataSet (org.unitils.dbunit.annotation.DataSet)19 ArrayList (java.util.ArrayList)17 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)15 Institution (eu.etaxonomy.cdm.model.agent.Institution)14 ExpectedDataSet (org.unitils.dbunit.annotation.ExpectedDataSet)13 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)12 DerivationEvent (eu.etaxonomy.cdm.model.occurrence.DerivationEvent)9 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)9 Before (org.junit.Before)9 URI (eu.etaxonomy.cdm.common.URI)8 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)8 Media (eu.etaxonomy.cdm.model.media.Media)8 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)8