Search in sources :

Example 6 with AgentBase

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

the class TaxonXExtractor method prepareCollectors.

protected void prepareCollectors(TaxonXImportState state, IAgentService agentService) {
    // logger.info("PREPARE COLLECTORS");
    List<String> collectors = new ArrayList<>();
    String tmp;
    List<String> collectorsU = new ArrayList<>(new HashSet<>(collectors));
    Set<UUID> uuids = new HashSet<UUID>();
    // existing persons in DB
    List<UuidAndTitleCache<Person>> hiberPersons = agentService.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 = agentService.find(uuids);
        for (AgentBase existingP : existingPersons) {
            titleCachePerson.put(existingP.getTitleCache(), CdmBase.deproxy(existingP, Person.class));
        }
    }
    Map<String, UUID> personMap = new HashMap<>();
    for (UuidAndTitleCache<Person> person : hiberPersons) {
        personMap.put(person.getTitleCache(), person.getUuid());
    }
    java.util.Collection<AgentBase> personToadd = new ArrayList<>();
    for (String collector : collectorsU) {
        Person p = Person.NewInstance();
        p.setTitleCache(collector, true);
        if (!personMap.containsKey(p.getTitleCache())) {
            personToadd.add(p);
        }
    }
    if (!personToadd.isEmpty()) {
        Map<UUID, AgentBase> uuuidPerson = agentService.save(personToadd);
        for (UUID u : uuuidPerson.keySet()) {
            titleCachePerson.put(uuuidPerson.get(u).getTitleCache(), CdmBase.deproxy(uuuidPerson.get(u), Person.class));
        }
    }
    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) UUID(java.util.UUID) Person(eu.etaxonomy.cdm.model.agent.Person) HashSet(java.util.HashSet)

Example 7 with AgentBase

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

the class SDDDocumentBuilder method buildAgents.

/**
 * Builds Agents associated with the Dataset
 */
public void buildAgents(ElementImpl dataset) throws ParseException {
    if (cdmSource.getAgents() != null) {
        ElementImpl elAgents = new ElementImpl(document, AGENTS);
        for (int i = 0; i < cdmSource.getAgents().size(); i++) {
            ElementImpl elAgent = new ElementImpl(document, AGENT);
            AgentBase personagent = cdmSource.getAgents().get(i);
            if (personagent instanceof Person) {
                if (personagent.getMarkers() != null) {
                    Set<Marker> markers = personagent.getMarkers();
                    for (Iterator<Marker> m = markers.iterator(); m.hasNext(); ) {
                        Marker marker = m.next();
                        if (marker.getMarkerType().getLabel().equals("editor")) {
                            agentsCount = buildReference(personagent, agents, ID, elAgent, "a", agentsCount);
                        }
                    }
                }
                agentsCount = buildReference(personagent, agents, ID, elAgent, "a", agentsCount);
                buildRepresentation(elAgent, personagent);
                elAgents.appendChild(elAgent);
            }
        }
        dataset.appendChild(elAgents);
    }
}
Also used : ElementImpl(org.apache.xerces.dom.ElementImpl) AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) Marker(eu.etaxonomy.cdm.model.common.Marker) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 8 with AgentBase

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

the class AbcdPersonParser method parse.

public AgentBase<?> parse(Element item) {
    AgentBase<?> agentBase = null;
    NodeList fullNameList = item.getElementsByTagName(prefix + "FullName");
    String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);
    if (fullName != null) {
        List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitleWithRestrictions(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();
        if (matchingAgents.size() == 1) {
            agentBase = matchingAgents.iterator().next();
        } else {
            agentBase = Person.NewTitledInstance(fullName);
        }
    }
    return agentBase;
}
Also used : AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) NodeList(org.w3c.dom.NodeList)

Example 9 with AgentBase

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

the class AgentDaoImplTest method testSortingListInPreviousView.

@Test
@DataSet("AgentDaoImplTest.testExists.xml")
public void testSortingListInPreviousView() {
    AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
    List<OrderHint> orderHints = new ArrayList<OrderHint>();
    orderHints.add(new OrderHint("titleCache", SortOrder.ASCENDING));
    List<AgentBase> result = agentDao.list((Class) null, null, null, orderHints, null);
    Assert.assertNotNull("list() should return a list", result);
    Assert.assertEquals("list() should return nine agents in the current view", result.size(), 9);
    Assert.assertEquals(result.get(0).getTitleCache(), "B.R. Clark");
    Assert.assertEquals(result.get(8).getTitleCache(), "University of Oxford");
}
Also used : OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) ArrayList(java.util.ArrayList) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

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