Search in sources :

Example 1 with AgentBase

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

the class TestCdmDbComparator method retrieveAllTables.

private Map<String, List<String>> retrieveAllTables(CdmApplicationController appCtr) {
    Map<String, List<String>> tables = new HashMap<>(table_list.length);
    List<String> agentTableContent = new ArrayList<>(MAX_ROWS);
    List<? extends AgentBase> agents = appCtr.getAgentService().list(null, MAX_ROWS, 0, null, null);
    for (AgentBase agent : agents) {
        // TODO: Want the entire row as string not just toString() of the object.
        agentTableContent.add(agent.toString());
    }
    tables.put("agents", agentTableContent);
    // List<Annotation> annotations = appCtr.getTermService().getAllAnnotations(MAX_ROWS, 0);
    List<String> definedTermBaseTableContent = new ArrayList<>(MAX_ROWS);
    List<DefinedTermBase> definedTermBases = appCtr.getTermService().list(null, MAX_ROWS, 0, null, null);
    for (DefinedTermBase definedTermBase : definedTermBases) {
        definedTermBaseTableContent.add(definedTermBase.toString());
    }
    tables.put("definedTermBases", definedTermBaseTableContent);
    // List<DescriptionBase> descriptionBases = appCtr.getDescriptionService().getAllDescriptionBases(MAX_ROWS, 0);
    // List<DescriptionElementBase> descriptionElementBases = appCtr.getDescriptionService().getAllDescriptionElementBases(MAX_ROWS, 0);
    // List<HomotypicalGroup> homotypicalGroups = appCtr.getNameService().getAllHomotypicalGroups(MAX_ROWS, 0);
    List<LanguageString> languageStrings = appCtr.getTermService().getAllLanguageStrings(MAX_ROWS, 0);
    // List<Marker> markers = appCtr.getTermService().getAllMarkers(MAX_ROWS, 0);
    // List<NameRelationship> nameRelationships = appCtr.getNameService().getAllNameRelationships(MAX_ROWS, 0);
    List<NomenclaturalStatus> nomenclaturalStatus = appCtr.getNameService().getAllNomenclaturalStatus(MAX_ROWS, 0);
    // List<OriginalSource> originalSources = appCtr.getNameService().getAllOriginalSources(MAX_ROWS, 0);
    List<Reference> references = appCtr.getReferenceService().list(null, MAX_ROWS, 0, null, null);
    List<Representation> representations = appCtr.getTermService().getAllRepresentations(MAX_ROWS, 0);
    List<SpecimenOrObservationBase> specimenOrObservationBases = appCtr.getOccurrenceService().list(null, MAX_ROWS, 0, null, null);
    // List<TaxonBase> taxonBases = appCtr.getTaxonService().getAllTaxa(MAX_ROWS, 0);
    // List<TaxonName> taxonNames = appCtr.getNameService().getAllNames(MAX_ROWS, 0);
    // List<TaxonRelationship> taxonRelationships = appCtr.getTaxonService().getAllTaxonRelationships(MAX_ROWS, 0);
    List<TermVocabulary> termVocabularies = appCtr.getVocabularyService().list(null, MAX_ROWS, 0, null, null);
    List<TypeDesignationBase<?>> typeDesignationBases = appCtr.getNameService().getAllTypeDesignations(MAX_ROWS, 0);
    return tables;
}
Also used : HashMap(java.util.HashMap) Reference(eu.etaxonomy.cdm.model.reference.Reference) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) ArrayList(java.util.ArrayList) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) Representation(eu.etaxonomy.cdm.model.term.Representation) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with AgentBase

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

the class AgentServiceImpl method delete.

@Override
@Transactional(readOnly = false)
public DeleteResult delete(UUID agentUUID) {
    DeleteResult result = new DeleteResult();
    if (agentUUID == null) {
        result.setAbort();
        result.addException(new Exception("Can't delete object without UUID."));
        return result;
    }
    AgentBase base = dao.load(agentUUID);
    result = isDeletable(agentUUID, null);
    if (result.isOk()) {
        if (base instanceof Team) {
            Team baseTeam = (Team) base;
            List<Person> members = baseTeam.getTeamMembers();
            List<Person> temp = new ArrayList<>();
            for (Person member : members) {
                temp.add(member);
            }
            for (Person member : temp) {
                members.remove(member);
            }
        }
        saveOrUpdate(base);
        dao.delete(base);
        result.addDeletedObject(base);
    }
    return result;
}
Also used : AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) ArrayList(java.util.ArrayList) Team(eu.etaxonomy.cdm.model.agent.Team) Person(eu.etaxonomy.cdm.model.agent.Person) MergeException(eu.etaxonomy.cdm.strategy.merge.MergeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AgentBase

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

the class TaxonXNomenclatureImport method doElType.

private boolean doElType(Element elType, SimpleSpecimen simpleSpecimen, TaxonXImportConfigurator config) {
    // type
    String text = elType.getTextNormalize();
    if (text.endsWith(";")) {
        text = text + " ";
    }
    String[] type = text.split(";");
    if (type.length != 3) {
        if (text.equals("")) {
            logger.info("<nomenclature><type> is empty: " + getBracketSourceName(config));
        } else {
            logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
        }
        simpleSpecimen.setTitleCache(elType.getTextNormalize());
    } else {
        String strLocality = type[0].trim();
        if (!"".equals(strLocality)) {
        // simpleSpecimen.setLocality(strLocality);
        }
        String strCollector = type[1].trim();
        if (!"".equals(strCollector)) {
            AgentBase collector = Person.NewTitledInstance(strCollector);
        // simpleSpecimen.setCollector(collector);
        }
        String strCollectorNumber = type[2].trim();
        if (!"".equals(strCollectorNumber)) {
        // simpleSpecimen.setCollectorsNumber(strCollectorNumber);
        }
        String title = CdmUtils.concat(" ", new String[] { strLocality, strCollector, strCollectorNumber });
        simpleSpecimen.setTitleCache(title);
    }
    return true;
}
Also used : AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase)

Example 4 with AgentBase

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

the class TaxonXNomenclatureImport method doCollectionEvent.

/**
 * Reads the collection_event tag, creates the according data and stores it.
 * TODO under work
 * @param elNomenclature
 * @param nsTaxonx
 * @param taxonBase
 * @return
 */
private boolean doCollectionEvent(TaxonXImportConfigurator config, Element elNomenclature, Namespace nsTaxonx, TaxonBase taxonBase) {
    boolean result = false;
    if (elNomenclature == null) {
        return false;
    }
    Element elCollectionEvent = elNomenclature.getChild("collection_event", nsTaxonx);
    if (elCollectionEvent == null) {
        return result;
    }
    Element elLocality = elCollectionEvent.getChild("locality", nsTaxonx);
    Element elType = elCollectionEvent.getChild("type", nsTaxonx);
    Element elTypeLoc = elCollectionEvent.getChild("type_loc", nsTaxonx);
    // locality
    SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
    String locality = elLocality.getTextNormalize();
    if (!"".equals(locality)) {
        simpleSpecimen.setLocality(locality);
    }
    // type
    String[] type = elType.getTextNormalize().split(" ");
    if (type.length != 2) {
        logger.warn("<collecion_even><type> is of unsupported format: " + elType.getTextNormalize());
    } else {
        AgentBase collector = Person.NewTitledInstance(type[0]);
        simpleSpecimen.setCollector(collector);
        String collectorNumber = type[1];
        simpleSpecimen.setCollectorsNumber(collectorNumber);
    }
    // typeLoc
    String typeLocFullString = elTypeLoc.getTextTrim();
    typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
    String[] typeLocStatusList = typeLocFullString.split(";");
    DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
    for (String typeLocStatus : typeLocStatusList) {
        typeLocStatus = typeLocStatus.trim();
        int pos = typeLocStatus.indexOf(" ");
        if (pos == -1) {
            logger.warn("Unknown format: " + typeLocStatus);
        } else {
            String statusString = typeLocStatus.substring(0, pos);
            SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);
            String[] collectionStrings = typeLocStatus.substring(pos).split(",");
            for (String collectionString : collectionStrings) {
                if (taxonBase != null) {
                    TaxonName taxonName = taxonBase.getName();
                    if (taxonName != null) {
                        Reference citation = null;
                        String citationMicroReference = null;
                        String originalNameString = null;
                        boolean isNotDesignated = true;
                        boolean addToAllHomotypicNames = true;
                        DerivedUnit specimen = (DerivedUnit) originalSpecimen.clone();
                        unlazyTypeDesignation(config, taxonName);
                        taxonName.addSpecimenTypeDesignation(specimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
                        result = true;
                    }
                }
            }
        }
    }
    return result;
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) Reference(eu.etaxonomy.cdm.model.reference.Reference) Element(org.jdom.Element) SpecimenTypeDesignationStatus(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 5 with AgentBase

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

the class SpecimenSythesysExcelImport method prepareCollectors.

/**
 * @param unitsList
 * @param state
 */
private void prepareCollectors(List<Map<String, String>> unitsList, SpecimenSynthesysExcelImportState state) {
    System.out.println("PREPARE COLLECTORS");
    List<String> collectors = new ArrayList<>();
    List<String> teams = new ArrayList<>();
    List<List<String>> collectorinteams = new ArrayList<>();
    String tmp;
    for (Map<String, String> unit : unitsList) {
        tmp = null;
        tmp = unit.get("collector");
        if (tmp != null && !tmp.isEmpty()) {
            if (tmp.indexOf("et al.") != -1 || tmp.indexOf(" al. ") != -1 || tmp.indexOf("& al.") != -1) {
                if (!tmp.trim().isEmpty()) {
                    teams.add(tmp.trim());
                }
            } else {
                if (tmp.indexOf(" et ") != -1 || tmp.indexOf("&") != -1 || tmp.indexOf(";") != -1) {
                    List<String> collteam = new ArrayList<String>();
                    String[] tmp1 = tmp.split(" et ");
                    for (String elt : tmp1) {
                        String[] tmp2 = elt.split("&");
                        for (String elt2 : tmp2) {
                            if (!elt2.trim().isEmpty()) {
                                String[] tmp3 = elt.split(";");
                                for (String elt3 : tmp3) {
                                    if (!elt3.isEmpty()) {
                                        collectors.add(elt3.trim());
                                        collteam.add(elt3.trim());
                                    }
                                }
                            }
                        }
                    }
                    if (collteam.size() > 0) {
                        collectorinteams.add(new ArrayList<String>(new HashSet<>(collteam)));
                    }
                } else if (!tmp.trim().isEmpty() && !tmp.toString().trim().equalsIgnoreCase("none")) {
                    collectors.add(tmp.trim());
                }
            }
        }
    }
    List<String> collectorsU = new ArrayList<String>(new HashSet<>(collectors));
    List<String> teamsU = new ArrayList<String>(new HashSet<>(teams));
    // existing teams in DB
    Map<String, Team> titleCacheTeam = new HashMap<>();
    List<UuidAndTitleCache<Team>> hiberTeam = getAgentService().getUuidAndTitleCache(Team.class, null, null);
    Set<UUID> uuids = new HashSet<>();
    for (UuidAndTitleCache<Team> hibernateT : hiberTeam) {
        uuids.add(hibernateT.getUuid());
    }
    if (!uuids.isEmpty()) {
        List<AgentBase> existingTeams = getAgentService().find(uuids);
        for (AgentBase<?> existingP : existingTeams) {
            titleCacheTeam.put(existingP.getTitleCache(), (Team) existingP);
        }
    }
    Map<String, UUID> teamMap = new HashMap<>();
    for (UuidAndTitleCache<Team> uuidt : hiberTeam) {
        teamMap.put(uuidt.getTitleCache(), uuidt.getUuid());
    }
    // existing persons in DB
    List<UuidAndTitleCache<Person>> hiberPersons = getAgentService().getUuidAndTitleCache(Person.class, null, null);
    Map<String, Person> titleCachePerson = new HashMap<>();
    uuids = new HashSet<UUID>();
    for (UuidAndTitleCache<Person> hibernateP : hiberPersons) {
        uuids.add(hibernateP.getUuid());
    }
    if (!uuids.isEmpty()) {
        List<AgentBase> existingPersons = getAgentService().find(uuids);
        for (AgentBase<?> existingP : existingPersons) {
            titleCachePerson.put(existingP.getTitleCache(), CdmBase.deproxy(existingP, Person.class));
        }
    }
    Map<String, UUID> personMap = new HashMap<String, UUID>();
    for (UuidAndTitleCache<Person> person : hiberPersons) {
        personMap.put(person.getTitleCache(), person.getUuid());
    }
    java.util.Collection<AgentBase> personsToAdd = new ArrayList<>();
    java.util.Collection<AgentBase> teamsToAdd = new ArrayList<>();
    for (String collector : collectorsU) {
        Person p = Person.NewInstance();
        p.setTitleCache(collector, true);
        if (!personMap.containsKey(p.getTitleCache())) {
            personsToAdd.add(p);
        }
    }
    for (String team : teamsU) {
        Team p = Team.NewInstance();
        p.setTitleCache(team, true);
        if (!teamMap.containsKey(p.getTitleCache())) {
            teamsToAdd.add(p);
        }
    }
    Map<UUID, AgentBase> uuuidPerson = getAgentService().save(personsToAdd);
    for (UUID u : uuuidPerson.keySet()) {
        titleCachePerson.put(uuuidPerson.get(u).getTitleCache(), CdmBase.deproxy(uuuidPerson.get(u), Person.class));
    }
    Person ptmp;
    Map<String, Integer> teamdone = new HashMap<String, Integer>();
    for (List<String> collteam : collectorinteams) {
        if (!teamdone.containsKey(StringUtils.join(collteam.toArray(), "-"))) {
            Team team = new Team();
            boolean em = true;
            for (String collector : collteam) {
                ptmp = Person.NewInstance();
                ptmp.setTitleCache(collector, true);
                Person p2 = titleCachePerson.get(ptmp.getTitleCache());
                team.addTeamMember(p2);
                em = false;
            }
            if (!em) {
                teamsToAdd.add(team);
            }
            teamdone.put(StringUtils.join(collteam.toArray(), "-"), 0);
        }
    }
    Map<UUID, AgentBase> uuuidTeam = getAgentService().save(teamsToAdd);
    for (UUID u : uuuidTeam.keySet()) {
        titleCacheTeam.put(uuuidTeam.get(u).getTitleCache(), (Team) uuuidTeam.get(u));
    }
    state.getConfig().setTeams(titleCacheTeam);
    state.getConfig().setPersons(titleCachePerson);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) List(java.util.List) ArrayList(java.util.ArrayList) Team(eu.etaxonomy.cdm.model.agent.Team) UUID(java.util.UUID) HashSet(java.util.HashSet) Person(eu.etaxonomy.cdm.model.agent.Person)

Aggregations

AgentBase (eu.etaxonomy.cdm.model.agent.AgentBase)9 ArrayList (java.util.ArrayList)5 Person (eu.etaxonomy.cdm.model.agent.Person)4 HashMap (java.util.HashMap)3 Team (eu.etaxonomy.cdm.model.agent.Team)2 Reference (eu.etaxonomy.cdm.model.reference.Reference)2 UuidAndTitleCache (eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)2 HashSet (java.util.HashSet)2 List (java.util.List)2 UUID (java.util.UUID)2 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)1 Marker (eu.etaxonomy.cdm.model.common.Marker)1 NomenclaturalStatus (eu.etaxonomy.cdm.model.name.NomenclaturalStatus)1 SpecimenTypeDesignationStatus (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus)1 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)1 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)1 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)1 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)1 DefinedTermBase (eu.etaxonomy.cdm.model.term.DefinedTermBase)1 Representation (eu.etaxonomy.cdm.model.term.Representation)1