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);
}
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);
}
}
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;
}
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");
}
Aggregations