Search in sources :

Example 16 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project DiscordSRV by Scarsz.

the class AccountLinkManager method unlink.

public void unlink(UUID uuid) {
    Map.Entry<String, UUID> linkedAccount = linkedAccounts.entrySet().stream().filter(entry -> entry.getValue().equals(uuid)).findAny().orElse(null);
    if (linkedAccount == null)
        return;
    synchronized (linkedAccounts) {
        if (DiscordSRV.config().getBoolean("GroupRoleSynchronizationRemoveRolesOnUnlink")) {
            GroupSynchronizationUtil.reSyncGroups(Bukkit.getPlayer(uuid), true);
        }
        List<Map.Entry<String, UUID>> entriesToRemove = linkedAccounts.entrySet().stream().filter(entry -> entry.getValue().equals(uuid)).collect(Collectors.toList());
        entriesToRemove.forEach(entry -> linkedAccounts.remove(entry.getKey()));
    }
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
    for (String command : DiscordSRV.config().getStringList("MinecraftDiscordAccountUnlinkedConsoleCommands")) {
        if (offlinePlayer == null)
            continue;
        command = command.replace("%minecraftplayername%", offlinePlayer.getName()).replace("%minecraftdisplayname%", offlinePlayer.getPlayer() == null ? offlinePlayer.getName() : offlinePlayer.getPlayer().getDisplayName()).replace("%minecraftuuid%", uuid.toString()).replace("%discordid%", linkedAccount.getKey()).replace("%discordname%", DiscordUtil.getUserById(linkedAccount.getKey()).getName()).replace("%discorddisplayname%", DiscordSRV.getPlugin().getMainGuild().getMember(DiscordUtil.getUserById(linkedAccount.getKey())).getEffectiveName());
        if (StringUtils.isBlank(command))
            continue;
        String finalCommand = command;
        Bukkit.getScheduler().scheduleSyncDelayedTask(DiscordSRV.getPlugin(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand));
    }
}
Also used : LangUtil(github.scarsz.discordsrv.util.LangUtil) Role(net.dv8tion.jda.core.entities.Role) JsonObject(com.google.gson.JsonObject) Getter(lombok.Getter) GroupSynchronizationUtil(github.scarsz.discordsrv.util.GroupSynchronizationUtil) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) HashMap(java.util.HashMap) DiscordUtil(github.scarsz.discordsrv.util.DiscordUtil) UUID(java.util.UUID) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) List(java.util.List) User(net.dv8tion.jda.core.entities.User) Charset(java.nio.charset.Charset) DiscordSRV(github.scarsz.discordsrv.DiscordSRV) Map(java.util.Map) AccountLinkedEvent(github.scarsz.discordsrv.api.events.AccountLinkedEvent) Bukkit(org.bukkit.Bukkit) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project workbench by all-of-us.

the class CohortReviewServiceImpl method validateParticipantCohortAnnotation.

/**
 * Helper method to validate that requested annotations are proper.
 *
 * @param participantCohortAnnotation
 */
private void validateParticipantCohortAnnotation(ParticipantCohortAnnotation participantCohortAnnotation, CohortAnnotationDefinition cohortAnnotationDefinition) {
    if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.BOOLEAN)) {
        if (participantCohortAnnotation.getAnnotationValueBoolean() == null) {
            throw createBadRequestException(AnnotationType.BOOLEAN.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.STRING)) {
        if (StringUtils.isBlank(participantCohortAnnotation.getAnnotationValueString())) {
            throw createBadRequestException(AnnotationType.STRING.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.DATE)) {
        if (StringUtils.isBlank(participantCohortAnnotation.getAnnotationValueDateString())) {
            throw createBadRequestException(AnnotationType.DATE.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = new Date(sdf.parse(participantCohortAnnotation.getAnnotationValueDateString()).getTime());
            participantCohortAnnotation.setAnnotationValueDate(date);
        } catch (ParseException e) {
            throw new BadRequestException(String.format("Invalid Request: Please provide a valid %s value (%s) for annotation defintion id: %s", AnnotationType.DATE.name(), sdf.toPattern(), participantCohortAnnotation.getCohortAnnotationDefinitionId()));
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.INTEGER)) {
        if (participantCohortAnnotation.getAnnotationValueInteger() == null) {
            throw createBadRequestException(AnnotationType.INTEGER.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.ENUM)) {
        if (StringUtils.isBlank(participantCohortAnnotation.getAnnotationValueEnum())) {
            throw createBadRequestException(AnnotationType.ENUM.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
        List<CohortAnnotationEnumValue> enumValues = cohortAnnotationDefinition.getEnumValues().stream().filter(enumValue -> participantCohortAnnotation.getAnnotationValueEnum().equals(enumValue.getName())).collect(Collectors.toList());
        if (enumValues.isEmpty()) {
            throw createBadRequestException(AnnotationType.ENUM.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
        participantCohortAnnotation.setCohortAnnotationEnumValue(enumValues.get(0));
    }
}
Also used : AnnotationType(org.pmiops.workbench.model.AnnotationType) CohortReview(org.pmiops.workbench.db.model.CohortReview) PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Provider(javax.inject.Provider) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) StringUtils(org.apache.commons.lang3.StringUtils) CohortReviewDao(org.pmiops.workbench.db.dao.CohortReviewDao) CohortAnnotationDefinitionDao(org.pmiops.workbench.db.dao.CohortAnnotationDefinitionDao) GenderRaceEthnicityConcept(org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept) ParticipantCohortAnnotationDao(org.pmiops.workbench.db.dao.ParticipantCohortAnnotationDao) Service(org.springframework.stereotype.Service) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Workspace(org.pmiops.workbench.db.model.Workspace) ParseException(java.text.ParseException) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) WorkspaceService(org.pmiops.workbench.db.dao.WorkspaceService) ParticipantCohortStatusDao(org.pmiops.workbench.db.dao.ParticipantCohortStatusDao) Cohort(org.pmiops.workbench.db.model.Cohort) CohortDao(org.pmiops.workbench.db.dao.CohortDao) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Date(java.sql.Date) Filter(org.pmiops.workbench.model.Filter) List(java.util.List) CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) Transactional(org.springframework.transaction.annotation.Transactional) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.sql.Date) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue)

Example 18 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project Gemma by PavlidisLab.

the class ArrayDesignControllerImpl method filter.

@Override
@RequestMapping("/filterArrayDesigns.html")
public ModelAndView filter(HttpServletRequest request, HttpServletResponse response) {
    StopWatch overallWatch = new StopWatch();
    overallWatch.start();
    String filter = request.getParameter("filter");
    // Validate the filtering search criteria.
    if (StringUtils.isBlank(filter)) {
        return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("message", "No search criteria provided");
    }
    Collection<SearchResult> searchResults = searchService.search(SearchSettingsImpl.arrayDesignSearch(filter)).get(ArrayDesign.class);
    if ((searchResults == null) || (searchResults.size() == 0)) {
        return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("message", "No search criteria provided");
    }
    StringBuilder list = new StringBuilder();
    if (searchResults.size() == 1) {
        ArrayDesign arrayDesign = arrayDesignService.load(searchResults.iterator().next().getId());
        return new ModelAndView(new RedirectView("/arrays/showArrayDesign.html?id=" + arrayDesign.getId(), true)).addObject("message", "Matched one : " + arrayDesign.getName() + "(" + arrayDesign.getShortName() + ")");
    }
    for (SearchResult ad : searchResults) {
        list.append(ad.getId()).append(",");
    }
    overallWatch.stop();
    Long overallElapsed = overallWatch.getTime();
    log.info("Generating the AD list:  (" + list + ") took: " + overallElapsed / 1000 + "s ");
    return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html?id=" + list, true)).addObject("message", searchResults.size() + " Platforms matched your search.");
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) SearchResult(ubic.gemma.core.search.SearchResult) StopWatch(org.apache.commons.lang3.time.StopWatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project alien4cloud by alien4cloud.

the class VariableExpressionService method getInEnvironmentScope.

public List<ScopeVariableExpressionDTO> getInEnvironmentScope(String varName, String applicationId, String topologyVersion, String envId) {
    Application application = applicationService.getOrFail(applicationId);
    if (StringUtils.isBlank(envId)) {
        return Arrays.stream(applicationEnvironmentService.getAuthorizedByApplicationId(applicationId)).map(env -> getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env)).collect(Collectors.toList());
    } else {
        ApplicationEnvironment env = applicationEnvironmentService.getOrFail(envId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, env);
        return Lists.newArrayList(getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env));
    }
}
Also used : Arrays(java.util.Arrays) Setter(lombok.Setter) Getter(lombok.Getter) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) EditorFileService(org.alien4cloud.tosca.editor.EditorFileService) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) YamlParserUtil(alien4cloud.utils.YamlParserUtil) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Collection(java.util.Collection) ScopeVariableExpressionDTO(org.alien4cloud.tosca.variable.ScopeVariableExpressionDTO) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) AuthorizationUtil(alien4cloud.security.AuthorizationUtil) List(java.util.List) EnvironmentType(alien4cloud.model.application.EnvironmentType) Variable(org.alien4cloud.tosca.variable.model.Variable) QuickFileStorageService(org.alien4cloud.tosca.variable.QuickFileStorageService) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 20 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project Gemma by PavlidisLab.

the class SearchServiceImpl method characteristicSearchWithChildren.

/**
 * Search for the query in ontologies, including items that are associated with children of matching query terms.
 * That is, 'brain' should return entities tagged as 'hippocampus'. This method will return results only up to
 * MAX_CHARACTERISTIC_SEARCH_RESULTS. It can handle AND in searches, so Parkinson's AND neuron finds items tagged
 * with both of those terms. The use of OR is handled by the caller.
 *
 * @param classes Classes of characteristic-bound entities. For example, to get matching characteristics of
 *                ExpressionExperiments, pass ExpressionExperiments.class in this collection parameter.
 * @return SearchResults of CharacteristicObjects. Typically to be useful one needs to retrieve the 'parents'
 * (entities which have been 'tagged' with the term) of those Characteristics
 */
private Collection<SearchResult> characteristicSearchWithChildren(Collection<Class<?>> classes, String query) {
    StopWatch timer = this.startTiming();
    /*
         * The tricky part here is if the user has entered a boolean query. If they put in Parkinson's disease AND neuron,
         * then we want to eventually return entities that are associated with both. We don't expect to find single
         * characteristics that match both.
         *
         * But if they put in Parkinson's disease we don't want to do two queries.
         */
    List<String> subparts = Arrays.asList(query.split(" AND "));
    // we would have to first deal with the separate queries, and then apply the logic.
    Collection<SearchResult> allResults = new HashSet<>();
    SearchServiceImpl.log.info("Starting characteristic search: " + query + " for type=" + StringUtils.join(classes, ","));
    for (String rawTerm : subparts) {
        String trimmed = StringUtils.strip(rawTerm);
        if (StringUtils.isBlank(trimmed)) {
            continue;
        }
        Collection<SearchResult> subqueryResults = this.characteristicSearchTerm(classes, trimmed);
        if (allResults.isEmpty()) {
            allResults.addAll(subqueryResults);
        } else {
            // this is our Intersection operation.
            allResults.retainAll(subqueryResults);
            // aggregate the highlighted text.
            Map<SearchResult, String> highlights = new HashMap<>();
            for (SearchResult sqr : subqueryResults) {
                highlights.put(sqr, sqr.getHighlightedText());
            }
            for (SearchResult ar : allResults) {
                String k = highlights.get(ar);
                if (StringUtils.isNotBlank(k)) {
                    String highlightedText = ar.getHighlightedText();
                    if (StringUtils.isBlank(highlightedText)) {
                        ar.setHighlightedText(k);
                    } else {
                        ar.setHighlightedText(highlightedText + "," + k);
                    }
                }
            }
        }
        if (timer.getTime() > 1000) {
            SearchServiceImpl.log.info("Characteristic search for '" + rawTerm + "': " + allResults.size() + " hits retained so far; " + timer.getTime() + "ms");
            timer.reset();
            timer.start();
        }
    }
    return allResults;
}
Also used : 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