Search in sources :

Example 56 with StringUtils.isBlank

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);
}
Also used : SalesForceManager(org.orcid.core.manager.SalesForceManager) SalesForceConnectionDao(org.orcid.persistence.dao.SalesForceConnectionDao) URL(java.net.URL) Date(java.util.Date) Member(org.orcid.core.salesforce.model.Member) GenericCacheManager(org.orcid.core.cache.GenericCacheManager) EmailManager(org.orcid.core.manager.EmailManager) ContactPermission(org.orcid.core.salesforce.model.ContactPermission) DateUtils(org.orcid.utils.DateUtils) MemberDetailsCacheKey(org.orcid.core.salesforce.cache.MemberDetailsCacheKey) StringUtils(org.apache.commons.lang3.StringUtils) ManagerReadOnlyBaseImpl(org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl) ArrayList(java.util.ArrayList) SalesForceConnectionEntity(org.orcid.persistence.jpa.entities.SalesForceConnectionEntity) Map(java.util.Map) ContactRole(org.orcid.core.salesforce.model.ContactRole) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Collection(java.util.Collection) Resource(javax.annotation.Resource) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) Opportunity(org.orcid.core.salesforce.model.Opportunity) SlugUtils(org.orcid.core.salesforce.model.SlugUtils) Collectors(java.util.stream.Collectors) ObjectUtils(org.apache.commons.lang.ObjectUtils) Objects(java.util.Objects) List(java.util.List) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) OrcidString(org.orcid.core.cache.OrcidString) SourceManager(org.orcid.core.manager.SourceManager) Consortium(org.orcid.core.salesforce.model.Consortium) Optional(java.util.Optional) Contact(org.orcid.core.salesforce.model.Contact) OrgId(org.orcid.core.salesforce.model.OrgId) OpportunityContactRole(org.orcid.core.salesforce.model.OpportunityContactRole) Email(org.orcid.jaxb.model.record_v2.Email) Pattern(java.util.regex.Pattern) ContactRoleType(org.orcid.core.salesforce.model.ContactRoleType) SubMember(org.orcid.core.salesforce.model.SubMember) ReleaseNameUtils(org.orcid.utils.ReleaseNameUtils) Collections(java.util.Collections) SalesForceDao(org.orcid.core.salesforce.dao.SalesForceDao) Email(org.orcid.jaxb.model.record_v2.Email) OrcidString(org.orcid.core.cache.OrcidString) ContactRole(org.orcid.core.salesforce.model.ContactRole) OpportunityContactRole(org.orcid.core.salesforce.model.OpportunityContactRole) Contact(org.orcid.core.salesforce.model.Contact)

Example 57 with StringUtils.isBlank

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;
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 58 with StringUtils.isBlank

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;
    }
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 59 with StringUtils.isBlank

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;
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) ConcurrentHashSet(org.compass.core.util.concurrent.ConcurrentHashSet)

Example 60 with StringUtils.isBlank

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);
}
Also used : SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)54 List (java.util.List)33 Collectors (java.util.stream.Collectors)29 Map (java.util.Map)28 Set (java.util.Set)27 ArrayList (java.util.ArrayList)23 Optional (java.util.Optional)22 Collections (java.util.Collections)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 IOException (java.io.IOException)18 HashSet (java.util.HashSet)18 Collection (java.util.Collection)16 HashMap (java.util.HashMap)16 StopWatch (org.apache.commons.lang3.time.StopWatch)13 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Slf4j (lombok.extern.slf4j.Slf4j)10 InputStream (java.io.InputStream)9 Inject (javax.inject.Inject)8 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)7