use of org.apache.commons.lang3.StringUtils.isEmpty in project cuba by cuba-platform.
the class ScreenNavigationHandler method doHandle.
@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState) || !isScreenChanged(requestedState, ui)) {
return false;
}
String requestedRoute = requestedState.getNestedRoute();
if (StringUtils.isEmpty(requestedRoute)) {
log.info("Unable to handle state with empty route '{}'", requestedState);
urlChangeHandler.revertNavigationState();
return true;
}
String[] routeParts = { requestedRoute };
if (windowConfig.findWindowInfoByRoute(requestedRoute) == null) {
routeParts = requestedRoute.split("/");
}
if (routeParts.length > MAX_SUB_ROUTES) {
log.info("Unable to perform navigation to requested state '{}'. Only {} sub routes are supported", requestedRoute, MAX_SUB_ROUTES);
urlChangeHandler.revertNavigationState();
return true;
}
List<Pair<String, WindowInfo>> routeWindowInfos = Arrays.stream(routeParts).map(subRoute -> new Pair<>(subRoute, windowConfig.findWindowInfoByRoute(subRoute))).collect(Collectors.toList());
for (Pair<String, WindowInfo> entry : routeWindowInfos) {
WindowInfo routeWindowInfo = entry.getSecond();
if (routeWindowInfo == null) {
log.info("No registered screen found for route: '{}'", entry.getFirst());
urlChangeHandler.revertNavigationState();
handle404(entry.getFirst(), ui);
return true;
}
if (urlChangeHandler.shouldRedirect(routeWindowInfo)) {
urlChangeHandler.redirect(requestedState);
return true;
}
if (urlChangeHandler.isRootRoute(routeWindowInfo)) {
log.info("Unable navigate to '{}' as nested screen", routeWindowInfo.getId());
urlChangeHandler.revertNavigationState();
return true;
}
}
return navigate(requestedState, ui, routeWindowInfos);
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project mxisd by kamax-io.
the class ExecAuthStore method authenticate.
@Override
public ExecAuthResult authenticate(_MatrixID uId, String password) {
Objects.requireNonNull(uId);
Objects.requireNonNull(password);
log.info("Performing authentication for {}", uId.getId());
ExecAuthResult result = new ExecAuthResult();
result.setId(new UserID(UserIdType.Localpart, uId.getLocalPart()));
Processor<ExecAuthResult> p = new Processor<>(cfg);
p.addTokenMapper(cfg.getToken().getLocalpart(), uId::getLocalPart);
p.addTokenMapper(cfg.getToken().getDomain(), uId::getDomain);
p.addTokenMapper(cfg.getToken().getMxid(), uId::getId);
p.addTokenMapper(cfg.getToken().getPassword(), () -> password);
p.addJsonInputTemplate(tokens -> {
RestAuthRequestJson json = new RestAuthRequestJson();
json.setLocalpart(tokens.getLocalpart());
json.setDomain(tokens.getDomain());
json.setMxid(tokens.getMxid());
json.setPassword(tokens.getPassword());
return json;
});
p.addInputTemplate(PlainType, tokens -> tokens.getLocalpart() + System.lineSeparator() + tokens.getDomain() + System.lineSeparator() + tokens.getMxid() + System.lineSeparator() + tokens.getPassword() + System.lineSeparator());
p.withExitHandler(pr -> result.setExitStatus(pr.getExitValue()));
p.withSuccessHandler(pr -> result.setSuccess(true));
p.withSuccessDefault(o -> result);
p.addSuccessMapper(JsonType, output -> {
JsonObject data = GsonUtil.getObj(GsonUtil.parseObj(output), "auth");
GsonUtil.findPrimitive(data, "success").map(JsonPrimitive::getAsBoolean).ifPresent(result::setSuccess);
GsonUtil.findObj(data, "profile").flatMap(profile -> GsonUtil.findString(profile, "display_name")).ifPresent(v -> result.getProfile().setDisplayName(v));
return result;
});
p.addSuccessMapper(PlainType, output -> {
String[] lines = output.split("\\R");
if (lines.length > 2) {
throw new InternalServerError("Exec auth command returned more than 2 lines (" + lines.length + ")");
}
result.setSuccess(Optional.ofNullable(StringUtils.isEmpty(lines[0]) ? null : lines[0]).map(v -> StringUtils.equalsAnyIgnoreCase(v, "true", "1")).orElse(result.isSuccess()));
if (lines.length == 2) {
Optional.ofNullable(StringUtils.isEmpty(lines[1]) ? null : lines[1]).ifPresent(v -> result.getProfile().setDisplayName(v));
}
return result;
});
p.withFailureHandler(pr -> result.setSuccess(false));
p.withFailureDefault(o -> result);
return p.execute();
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project data-prep by Talend.
the class ResourceLoaderContentCache method getResource.
private DeletableResource getResource(ContentCacheKey key) {
try {
final DeletableResource[] patternMatches = resolver.getResources(CACHE_PREFIX + key.getKey() + "*");
final DeletableResource[] directMatches = resolver.getResources(CACHE_PREFIX + key.getKey());
final DeletableResource[] resources = new DeletableResource[patternMatches.length + directMatches.length];
System.arraycopy(patternMatches, 0, resources, 0, patternMatches.length);
System.arraycopy(directMatches, 0, resources, patternMatches.length, directMatches.length);
if (resources.length <= 0) {
return null;
} else {
// resources.length > 0
final Optional<DeletableResource> reduce = stream(resources).reduce(maxBy((r1, r2) -> {
final String suffix1 = substringAfterLast(r1.getFilename(), ".");
final String suffix2 = substringAfterLast(r2.getFilename(), ".");
if (StringUtils.isEmpty(suffix1) || StringUtils.isEmpty(suffix2)) {
return 0;
}
final long i1 = parseLong(suffix1);
final long i2 = parseLong(suffix2);
return Long.compare(i1, i2);
}));
return reduce.filter(r -> {
if (!r.exists()) {
return false;
}
final String suffix = StringUtils.substringAfterLast(r.getFilename(), ".");
if (NumberUtils.isCreatable(suffix)) {
final long time = parseLong(suffix);
return time > System.currentTimeMillis();
} else {
return true;
}
}).orElse(null);
}
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project data-prep by Talend.
the class DataSetService method preview.
/**
* Returns preview of the the data set content for given id (first 100 rows). Service might return
* {@link org.apache.http.HttpStatus#SC_ACCEPTED} if the data set exists but analysis is not yet fully
* completed so content is not yet ready to be served.
*
* @param metadata If <code>true</code>, includes data set metadata information.
* @param sheetName the sheet name to preview
* @param dataSetId A data set id.
*/
@RequestMapping(value = "/datasets/{id}/preview", method = RequestMethod.GET)
@ApiOperation(value = "Get a data preview set by id", notes = "Get a data set preview content based on provided id. Not valid or non existing data set id returns empty content. Data set not in drat status will return a redirect 301")
@Timed
@ResponseBody
public DataSet preview(@RequestParam(defaultValue = "true") @ApiParam(name = "metadata", value = "Include metadata information in the response") boolean metadata, @RequestParam(defaultValue = "") @ApiParam(name = "sheetName", value = "Sheet name to preview") String sheetName, @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the requested data set") String dataSetId) {
DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);
if (dataSetMetadata == null) {
HttpResponseContext.status(HttpStatus.NO_CONTENT);
// No data set, returns empty content.
return DataSet.empty();
}
if (!dataSetMetadata.isDraft()) {
// Moved to get data set content operation
HttpResponseContext.status(HttpStatus.MOVED_PERMANENTLY);
HttpResponseContext.header("Location", "/datasets/" + dataSetId + "/content");
// dataset not anymore a draft so preview doesn't make sense.
return DataSet.empty();
}
if (StringUtils.isNotEmpty(sheetName)) {
dataSetMetadata.setSheetName(sheetName);
}
// take care of previous data without schema parser result
if (dataSetMetadata.getSchemaParserResult() != null) {
// sheet not yet set correctly so use the first one
if (StringUtils.isEmpty(dataSetMetadata.getSheetName())) {
String theSheetName = dataSetMetadata.getSchemaParserResult().getSheetContents().get(0).getName();
LOG.debug("preview for dataSetMetadata: {} with sheetName: {}", dataSetId, theSheetName);
dataSetMetadata.setSheetName(theSheetName);
}
String theSheetName = dataSetMetadata.getSheetName();
Optional<Schema.SheetContent> sheetContentFound = dataSetMetadata.getSchemaParserResult().getSheetContents().stream().filter(//
sheetContent -> theSheetName.equals(sheetContent.getName())).findFirst();
if (!sheetContentFound.isPresent()) {
HttpResponseContext.status(HttpStatus.NO_CONTENT);
// No sheet found, returns empty content.
return DataSet.empty();
}
List<ColumnMetadata> columnMetadatas = sheetContentFound.get().getColumnMetadatas();
if (dataSetMetadata.getRowMetadata() == null) {
dataSetMetadata.setRowMetadata(new RowMetadata(emptyList()));
}
dataSetMetadata.getRowMetadata().setColumns(columnMetadatas);
} else {
LOG.warn("dataset#{} has draft status but any SchemaParserResult", dataSetId);
}
// Build the result
DataSet dataSet = new DataSet();
if (metadata) {
dataSet.setMetadata(conversionService.convert(dataSetMetadata, UserDataSetMetadata.class));
}
dataSet.setRecords(contentStore.stream(dataSetMetadata).limit(100));
return dataSet;
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project iaf by ibissource.
the class FileSystemUtils method getFilteredStream.
public static <F> Stream<F> getFilteredStream(IBasicFileSystem<F> fileSystem, String folder, String wildCard, String excludeWildCard) throws FileSystemException, IOException {
DirectoryStream<F> ds = fileSystem.listFiles(folder);
if (ds == null) {
return null;
}
Iterator<F> it = ds.iterator();
if (it == null) {
return null;
}
WildCardFilter wildcardfilter = StringUtils.isEmpty(wildCard) ? null : new WildCardFilter(wildCard);
WildCardFilter excludeFilter = StringUtils.isEmpty(excludeWildCard) ? null : new WildCardFilter(excludeWildCard);
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false).filter(F -> (wildcardfilter == null || wildcardfilter.accept(null, fileSystem.getName((F) F))) && (excludeFilter == null || !excludeFilter.accept(null, fileSystem.getName((F) F)))).onClose(() -> {
try {
ds.close();
} catch (IOException e) {
throw Lombok.sneakyThrow(e);
}
});
}
Aggregations