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