use of org.apache.commons.lang3.StringUtils.isBlank in project ORCID-Source by ORCID.
the class SalesForceManagerImpl method createContact.
@Override
public void createContact(Contact contact) {
String accountId = contact.getAccountId();
if (StringUtils.isBlank(contact.getEmail())) {
String contactOrcid = contact.getOrcid();
Email primaryEmail = emailManager.getEmails(contactOrcid).getEmails().stream().filter(e -> e.isPrimary()).findFirst().get();
contact.setEmail(primaryEmail.getEmail());
}
List<Contact> existingContacts = salesForceDao.retrieveAllContactsByAccountId(accountId);
Optional<Contact> existingContact = existingContacts.stream().filter(c -> {
if ((contact.getOrcid() != null && contact.getOrcid().equals(c.getOrcid())) || (contact.getEmail() != null && contact.getEmail().equals(c.getEmail()))) {
return true;
}
return false;
}).findFirst();
String contactId = existingContact.isPresent() ? existingContact.get().getId() : salesForceDao.createContact(contact);
List<Contact> existingContactsWithRoles = salesForceDao.retrieveContactsWithRolesByAccountId(accountId, true);
Optional<ContactRole> existingContactRole = existingContactsWithRoles.stream().filter(c -> contactId.equals(c.getId()) && ContactRoleType.OTHER_CONTACT.equals(c.getRole().getRoleType())).map(c -> c.getRole()).findFirst();
if (existingContactRole.isPresent()) {
ContactRole contactRole = existingContactRole.get();
if (!contactRole.isCurrent()) {
contactRole.setCurrent(true);
salesForceDao.updateContactRole(contactRole);
}
} else {
ContactRole contactRole = new ContactRole();
contactRole.setContactId(contactId);
contactRole.setRoleType(ContactRoleType.OTHER_CONTACT);
contactRole.setAccountId(contact.getAccountId());
salesForceDao.createContactRole(contactRole);
}
addSalesForceConnection(accountId, contact);
salesForceContactsCache.remove(accountId);
}
use of org.apache.commons.lang3.StringUtils.isBlank in project Gemma by PavlidisLab.
the class GeneSetDaoImpl method findByName.
@Override
public Collection<GeneSet> findByName(String name, Taxon taxon) {
StopWatch timer = new StopWatch();
timer.start();
if (StringUtils.isBlank(name))
return new HashSet<>();
assert taxon != null;
// slow? would it be faster to just findByName and then restrict taxon?
List result = this.getSessionFactory().getCurrentSession().createQuery("select gs from GeneSet gs join gs.members gm join gm.gene g where g.taxon = :taxon and gs.name like :query order by gs.name").setParameter("query", name + "%").setParameter("taxon", taxon).list();
if (timer.getTime() > 500)
AbstractDao.log.info("Find geneSets by name took " + timer.getTime() + "ms query=" + name + " taxon=" + taxon);
// noinspection unchecked
return (Collection<GeneSet>) result;
}
use of org.apache.commons.lang3.StringUtils.isBlank in project Gemma by PavlidisLab.
the class ArrayDesignSequenceProcessingServiceImpl method parseAccessionFile.
/**
* @param sequenceIdentifierFile with two columns: first is probe id, second is genbank accession.
*/
private Map<String, String> parseAccessionFile(InputStream sequenceIdentifierFile) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(sequenceIdentifierFile))) {
String line;
StopWatch timer = new StopWatch();
timer.start();
Map<String, String> probe2acc = new HashMap<>();
int count = 0;
int totalLines = 0;
while ((line = br.readLine()) != null) {
String[] fields = line.split("\t");
++totalLines;
if (fields.length < 2) {
continue;
}
String probeName = fields[0];
String seqAcc = fields[1];
if (StringUtils.isBlank(seqAcc)) {
continue;
}
probe2acc.put(probeName, seqAcc);
if (++count % 2000 == 0 && timer.getTime() > 10000) {
ArrayDesignSequenceProcessingServiceImpl.log.info(count + " / " + totalLines + " probes read so far have identifiers");
}
}
ArrayDesignSequenceProcessingServiceImpl.log.info(count + " / " + totalLines + " probes have accessions");
return probe2acc;
}
}
use of org.apache.commons.lang3.StringUtils.isBlank in project Gemma by PavlidisLab.
the class OntologyServiceImpl method findTermsInexact.
@Override
public Collection<CharacteristicValueObject> findTermsInexact(String givenQueryString, Taxon taxon) {
if (StringUtils.isBlank(givenQueryString))
return null;
StopWatch watch = new StopWatch();
watch.start();
String queryString = OntologySearch.stripInvalidCharacters(givenQueryString);
if (StringUtils.isBlank(queryString)) {
OntologyServiceImpl.log.warn("The query was not valid (ended up being empty): " + givenQueryString);
return new HashSet<>();
}
if (OntologyServiceImpl.log.isDebugEnabled()) {
OntologyServiceImpl.log.debug("starting findExactTerm for " + queryString + ". Timing information begins from here");
}
Collection<? extends OntologyResource> results;
Collection<CharacteristicValueObject> searchResults = new HashSet<>();
Map<String, CharacteristicValueObject> previouslyUsedInSystem = new HashMap<>();
this.countOccurrences(queryString, previouslyUsedInSystem);
this.searchForGenes(queryString, taxon, searchResults);
for (AbstractOntologyService service : this.ontologyServices) {
if (!service.isOntologyLoaded())
continue;
results = service.findResources(queryString);
if (results.isEmpty())
continue;
if (OntologyServiceImpl.log.isDebugEnabled())
OntologyServiceImpl.log.debug("found " + results.size() + " from " + service.getClass().getSimpleName() + " in " + watch.getTime() + " ms");
searchResults.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(this.termsToCharacteristics(results)));
if (searchResults.size() > OntologyServiceImpl.MAX_TERMS_TO_FETCH) {
break;
}
}
this.countOccurrences(searchResults, previouslyUsedInSystem);
// get GO terms, if we don't already have a lot of possibilities. (might have to adjust this)
if (searchResults.size() < OntologyServiceImpl.MAX_TERMS_TO_FETCH && geneOntologyService.isReady()) {
searchResults.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(this.termsToCharacteristics(geneOntologyService.findTerm(queryString))));
}
// Sort the results rather elaborately.
Collection<CharacteristicValueObject> sortedResults = this.sort(previouslyUsedInSystem, searchResults, queryString);
if (watch.getTime() > 1000) {
OntologyServiceImpl.log.info("Ontology term query for: " + givenQueryString + ": " + watch.getTime() + "ms");
}
return sortedResults;
}
use of org.apache.commons.lang3.StringUtils.isBlank in project Gemma by PavlidisLab.
the class GeneralSearchControllerImpl method ajaxSearch.
@Override
public JsonReaderResponse<SearchResult> ajaxSearch(SearchSettingsValueObject settingsValueObject) {
SearchSettings settings = SearchSettingsValueObject.toEntity(settingsValueObject);
List<SearchResult> finalResults = new ArrayList<>();
if (settings == null || StringUtils.isBlank(settings.getQuery()) || StringUtils.isBlank(settings.getQuery().replaceAll("\\*", ""))) {
// FIXME validate input better, and return error.
BaseFormController.log.info("No query or invalid.");
// return new ListRange( finalResults );
throw new IllegalArgumentException("Query '" + settings + "' was invalid");
}
StopWatch watch = new StopWatch();
watch.start();
((SearchSettingsImpl) settings).setDoHighlighting(true);
Map<Class<?>, List<SearchResult>> searchResults = searchService.search(settings);
watch.stop();
if (watch.getTime() > 500) {
BaseFormController.log.info("Search service work on: " + settings + " took " + watch.getTime() + " ms");
}
/*
* FIXME sort by the number of hits per class, so smallest number of hits is at the top.
*/
watch.reset();
watch.start();
if (searchResults != null) {
for (Class<?> clazz : searchResults.keySet()) {
List<SearchResult> results = searchResults.get(clazz);
if (results.size() == 0)
continue;
BaseFormController.log.info("Search for: " + settings + "; result: " + results.size() + " " + clazz.getSimpleName() + "s");
/*
* Now put the valueObjects inside the SearchResults in score order.
*/
Collections.sort(results);
this.fillValueObjects(clazz, results, settings);
finalResults.addAll(results);
}
}
if (watch.getTime() > 500) {
BaseFormController.log.info("Final unpacking of results for query:" + settings + " took " + watch.getTime() + " ms");
}
return new JsonReaderResponse<>(finalResults);
}
Aggregations