use of org.apache.commons.lang3.StringUtils.startsWith in project alf.io by alfio-event.
the class MvcConfiguration method getDefaultTemplateObjectsFiller.
@Bean
public HandlerInterceptorAdapter getDefaultTemplateObjectsFiller() {
return new HandlerInterceptorAdapter() {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
Optional.ofNullable(modelAndView).filter(mv -> !StringUtils.startsWith(mv.getViewName(), "redirect:")).ifPresent(mv -> {
mv.addObject("request", request);
final ModelMap modelMap = mv.getModelMap();
boolean demoModeEnabled = environment.acceptsProfiles(Initializer.PROFILE_DEMO);
modelMap.put("demoModeEnabled", demoModeEnabled);
Optional.ofNullable(request.getAttribute("ALFIO_EVENT_NAME")).map(Object::toString).ifPresent(eventName -> {
List<?> availableLanguages = i18nManager.getEventLanguages(eventName);
modelMap.put("showAvailableLanguagesInPageTop", availableLanguages.size() > 1);
modelMap.put("availableLanguages", availableLanguages);
});
modelMap.putIfAbsent("event", null);
modelMap.putIfAbsent("pageTitle", "empty");
Event event = modelMap.get("event") == null ? null : modelMap.get("event") instanceof Event ? (Event) modelMap.get("event") : ((EventDescriptor) modelMap.get("event")).getEvent();
ConfigurationPathKey googleAnalyticsKey = Optional.ofNullable(event).map(e -> alfio.model.system.Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_KEY)).orElseGet(() -> alfio.model.system.Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_KEY));
modelMap.putIfAbsent("analyticsEnabled", StringUtils.isNotBlank(configurationManager.getStringConfigValue(googleAnalyticsKey, "")));
if (demoModeEnabled) {
modelMap.putIfAbsent("paypalTestUsername", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_USERNAME), "<missing>"));
modelMap.putIfAbsent("paypalTestPassword", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_PASSWORD), "<missing>"));
}
});
}
};
}
use of org.apache.commons.lang3.StringUtils.startsWith in project eol-globi-data by jhpoelen.
the class StudyImporterForSaproxylic method importStudy.
@Override
public void importStudy() throws StudyImporterException {
try {
final Model model = ModelFactory.createDefaultModel();
NavigableSet<Triple<String, String, String>> triples = DBMaker.newTempTreeSet();
Tripler add = triple -> {
Resource resource = model.createResource("sx:" + triple.getLeft());
Property property = model.createProperty("sx:" + triple.getMiddle());
String obj = triple.getRight();
if (StringUtils.startsWith(obj, "{")) {
Resource food = model.createResource("sx:" + obj);
model.add(resource, property, food);
} else if (StringUtils.startsWith(obj, "http")) {
model.add(resource, property, model.createResource(obj));
} else if (StringUtils.isNotBlank(obj)) {
model.add(resource, property, obj);
}
};
parseReferences(add, getDataset().getResource("sx_txt/Reference.txt"));
parseLocalities(add, getDataset().getResource("sx_txt/Locality.txt"));
parseTaxa(add, getDataset().getResource("sx_txt/Taxon.txt"));
parseTaxonRanks(add, getDataset().getResource("sx_txt/TaxonRank.txt"));
parseOccurrences(add, getDataset().getResource("sx_txt/Occurrence.txt"));
parseAssociations(add, getDataset().getResource("sx_txt/SX_Association.txt"));
parseInteractionTypeMap(add, getDataset().getResource("interaction_type_map.tsv"));
// associations -> occurrences, taxa, reference
String queryString = "SELECT ?sourceTaxonName ?sourceLifeStage ?interactionTypeId ?targetTaxonName ?targetLifeStage ?referenceCitation ?localityName ?studyTitle " + "WHERE {" + " ?interaction <sx:mentioned_by> ?studyTitle . " + " ?studyTitle <sx:hasName> ?referenceCitation . " + " ?sourceSpecimen <sx:participates_in> ?interaction . " + " ?targetSpecimen <sx:participates_in> ?interaction . " + " ?sourceSpecimen ?inter ?targetSpecimen . " + " ?inter <sx:equivalentTo> ?interactionTypeId . " + " ?sourceSpecimen <sx:classifiedAs> ?sourceTaxon . " + " ?sourceTaxon <sx:hasName> ?sourceTaxonName . " + " ?targetSpecimen <sx:classifiedAs> ?targetTaxon . " + " ?targetTaxon <sx:hasName> ?targetTaxonName . " + " ?sourceSpecimen <sx:inStage> ?sourceLifeStage . " + " ?targetSpecimen <sx:inStage> ?targetLifeStage . " + " ?targetSpecimen <sx:foundAt> ?locality . " + " ?locality <sx:hasName> ?localityName . " + "}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
toInteractions(results);
qe.close();
} catch (IOException e) {
throw new StudyImporterException("failed to access resource", e);
}
}
use of org.apache.commons.lang3.StringUtils.startsWith in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class Utils method getWrappedImageResourceWithInheritance.
/**
* Wraps an image resource with the properties and child resources of the inherited featured image of either
* the linked page or the page containing the resource.
*
* @param resource The image resource
* @param linkHandler The link handler
* @param currentStyle The style of the image resource
* @param currentPage The page containing the image resource
* @return The wrapped image resource augmented with inherited properties and child resource if inheritance is enabled, the plain image resource otherwise.
*/
public static Resource getWrappedImageResourceWithInheritance(Resource resource, LinkHandler linkHandler, Style currentStyle, Page currentPage) {
if (resource == null) {
LOGGER.error("The resource is not defined");
return null;
}
if (linkHandler == null) {
LOGGER.error("The link handler is not defined");
return null;
}
ValueMap properties = resource.getValueMap();
String fileReference = properties.get(DownloadResource.PN_REFERENCE, String.class);
Resource fileResource = resource.getChild(DownloadResource.NN_FILE);
boolean imageFromPageImage = properties.get(PN_IMAGE_FROM_PAGE_IMAGE, StringUtils.isEmpty(fileReference) && fileResource == null);
boolean altValueFromPageImage = properties.get(PN_ALT_VALUE_FROM_PAGE_IMAGE, imageFromPageImage);
if (imageFromPageImage) {
Resource inheritedResource = null;
String linkURL = properties.get(ImageResource.PN_LINK_URL, String.class);
boolean actionsEnabled = (currentStyle != null) ? !currentStyle.get(Teaser.PN_ACTIONS_DISABLED, !properties.get(Teaser.PN_ACTIONS_ENABLED, true)) : properties.get(Teaser.PN_ACTIONS_ENABLED, true);
Resource firstAction = Optional.of(resource).map(res -> res.getChild(Teaser.NN_ACTIONS)).map(actions -> actions.getChildren().iterator().next()).orElse(null);
if (StringUtils.isNotEmpty(linkURL)) {
// the inherited resource is the featured image of the linked page
Optional<Link> link = linkHandler.getLink(resource);
inheritedResource = link.map(link1 -> (Page) link1.getReference()).map(ComponentUtils::getFeaturedImage).orElse(null);
} else if (actionsEnabled && firstAction != null) {
// the inherited resource is the featured image of the first action's page (the resource is assumed to be a teaser)
inheritedResource = Optional.of(linkHandler.getLink(firstAction, Teaser.PN_ACTION_LINK)).map(link1 -> {
if (link1.isPresent()) {
Page linkedPage = (Page) link1.get().getReference();
return Optional.ofNullable(linkedPage).map(ComponentUtils::getFeaturedImage).orElse(null);
}
return null;
}).orElse(null);
} else {
// the inherited resource is the featured image of the current page
inheritedResource = Optional.ofNullable(currentPage).map(page -> {
Template template = page.getTemplate();
// make sure the resource is part of the currentPage or of its template
if (StringUtils.startsWith(resource.getPath(), currentPage.getPath()) || (template != null && StringUtils.startsWith(resource.getPath(), template.getPath()))) {
return ComponentUtils.getFeaturedImage(currentPage);
}
return null;
}).orElse(null);
}
Map<String, String> overriddenProperties = new HashMap<>();
Map<String, Resource> overriddenChildren = new HashMap<>();
String inheritedFileReference = null;
Resource inheritedFileResource = null;
String inheritedAlt = null;
String inheritedAltValueFromDAM = null;
if (inheritedResource != null) {
// Define the inherited properties
ValueMap inheritedProperties = inheritedResource.getValueMap();
inheritedFileReference = inheritedProperties.get(DownloadResource.PN_REFERENCE, String.class);
inheritedFileResource = inheritedResource.getChild(DownloadResource.NN_FILE);
inheritedAlt = inheritedProperties.get(ImageResource.PN_ALT, String.class);
inheritedAltValueFromDAM = inheritedProperties.get(PN_ALT_VALUE_FROM_DAM, String.class);
}
overriddenProperties.put(DownloadResource.PN_REFERENCE, inheritedFileReference);
overriddenChildren.put(DownloadResource.NN_FILE, inheritedFileResource);
// don't inherit the image title from the page image
overriddenProperties.put(PN_TITLE_VALUE_FROM_DAM, "false");
if (altValueFromPageImage) {
overriddenProperties.put(ImageResource.PN_ALT, inheritedAlt);
overriddenProperties.put(PN_ALT_VALUE_FROM_DAM, inheritedAltValueFromDAM);
} else {
overriddenProperties.put(PN_ALT_VALUE_FROM_DAM, "false");
}
return new CoreResourceWrapper(resource, resource.getResourceType(), null, overriddenProperties, overriddenChildren);
}
return resource;
}
use of org.apache.commons.lang3.StringUtils.startsWith in project GDSC-SMLM by aherbert.
the class ResultsManager method run.
@Override
public void run(String arg) {
extraOptions = ImageJUtils.isExtraOptions();
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if ("load".equals(arg)) {
batchLoad();
return;
}
if ("save".equals(arg)) {
batchSave();
return;
}
if (StringUtils.startsWith(arg, "clear")) {
runClearMemory(arg);
return;
}
if (!showDialog()) {
return;
}
final MemoryPeakResults results = loadResults(settings.inputOption);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return;
}
IJ.showStatus("Loaded " + TextUtils.pleural(results.size(), "result"));
boolean saved = false;
if (resultsSettings.getResultsInMemorySettings().getInMemory() && fileInput) {
if (!addResultsToMemory(results, settings.inputFilename)) {
IJ.showStatus("");
return;
}
saved = true;
}
if (resultsSettings.getResultsTableSettings().getResultsTableFormatValue() <= 0 && resultsSettings.getResultsImageSettings().getImageTypeValue() <= 0 && TextUtils.isNullOrEmpty(resultsSettings.getResultsFileSettings().getResultsFilename())) {
// No outputs. Error if results were not saved to memory
if (!saved) {
IJ.error(TITLE, "No output selected");
}
return;
}
final Rectangle bounds = results.getBounds(true);
final boolean showDeviations = resultsSettings.getShowDeviations() && canShowDeviations(results);
final boolean showEndFrame = canShowEndFrame(results);
final boolean showId = canShowId(results);
final boolean showCategory = canShowCategory(results);
// Display the configured output
final PeakResultsList outputList = new PeakResultsList();
outputList.copySettings(results);
final int tableFormat = resultsSettings.getResultsTableSettings().getResultsTableFormatValue();
if (tableFormat == ResultsTableFormat.IMAGEJ_VALUE) {
addImageJTableResults(outputList, resultsSettings.getResultsTableSettings(), showDeviations, showEndFrame, results.is3D(), showId, showCategory);
} else if (tableFormat == ResultsTableFormat.INTERACTIVE_VALUE) {
showInteractiveTable(results, resultsSettings.getResultsTableSettings());
}
addImageResults(outputList, resultsSettings.getResultsImageSettings(), bounds, (extraOptions) ? FLAG_EXTRA_OPTIONS : 0);
addFileResults(outputList, showDeviations, showEndFrame, showId, showCategory);
if (outputList.numberOfOutputs() == 0) {
// This occurs when only using the interactive table
IJ.showStatus("Processed " + TextUtils.pleural(results.size(), "result"));
return;
}
IJ.showStatus("Processing outputs ...");
// Reduce to single object for speed
final PeakResults output = (outputList.numberOfOutputs() == 1) ? outputList.toArray()[0] : outputList;
output.begin();
// Note: We could add a batch iterator to the MemoryPeakResults.
// However the speed increase will be marginal as the main time
// taken is in processing the outputs.
// Process in batches to provide progress
final Counter progress = new Counter();
final int totalProgress = results.size();
final int batchSize = Math.max(100, totalProgress / 10);
final FixedPeakResultList batch = new FixedPeakResultList(batchSize);
IJ.showProgress(0);
results.forEach((PeakResultProcedureX) result -> {
batch.add(result);
if (batch.size == batchSize) {
if (IJ.escapePressed()) {
batch.clear();
return true;
}
output.addAll(batch.results);
batch.clear();
IJ.showProgress(progress.incrementAndGet(batchSize), totalProgress);
}
return false;
});
// Will be empty if interrupted
if (batch.isNotEmpty()) {
output.addAll(batch.toArray());
}
IJ.showProgress(1);
output.end();
if (output.size() == results.size()) {
IJ.showStatus("Processed " + TextUtils.pleural(results.size(), "result"));
} else {
IJ.showStatus(String.format("A %d/%s", output.size(), TextUtils.pleural(results.size(), "result")));
}
}
Aggregations