use of org.apache.commons.lang3.StringUtils.isNotEmpty in project nifi by apache.
the class Notify method onTrigger.
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
final ComponentLog logger = getLogger();
final PropertyValue signalIdProperty = context.getProperty(RELEASE_SIGNAL_IDENTIFIER);
final PropertyValue counterNameProperty = context.getProperty(SIGNAL_COUNTER_NAME);
final PropertyValue deltaProperty = context.getProperty(SIGNAL_COUNTER_DELTA);
final String attributeCacheRegex = context.getProperty(ATTRIBUTE_CACHE_REGEX).getValue();
final Integer bufferCount = context.getProperty(SIGNAL_BUFFER_COUNT).asInteger();
// the cache client used to interact with the distributed cache.
final AtomicDistributedMapCacheClient cache = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(AtomicDistributedMapCacheClient.class);
final WaitNotifyProtocol protocol = new WaitNotifyProtocol(cache);
final Map<String, SignalBuffer> signalBuffers = new HashMap<>();
for (int i = 0; i < bufferCount; i++) {
final FlowFile flowFile = session.get();
if (flowFile == null) {
break;
}
// Signal id is computed from attribute 'RELEASE_SIGNAL_IDENTIFIER' with expression language support
final String signalId = signalIdProperty.evaluateAttributeExpressions(flowFile).getValue();
// if the computed value is null, or empty, we transfer the flow file to failure relationship
if (StringUtils.isBlank(signalId)) {
logger.error("FlowFile {} has no attribute for given Release Signal Identifier", new Object[] { flowFile });
// set 'notified' attribute
session.transfer(session.putAttribute(flowFile, NOTIFIED_ATTRIBUTE_NAME, String.valueOf(false)), REL_FAILURE);
continue;
}
String counterName = counterNameProperty.evaluateAttributeExpressions(flowFile).getValue();
if (StringUtils.isEmpty(counterName)) {
counterName = WaitNotifyProtocol.DEFAULT_COUNT_NAME;
}
int delta = 1;
if (deltaProperty.isSet()) {
final String deltaStr = deltaProperty.evaluateAttributeExpressions(flowFile).getValue();
try {
delta = Integer.parseInt(deltaStr);
} catch (final NumberFormatException e) {
logger.error("Failed to calculate delta for FlowFile {} due to {}", new Object[] { flowFile, e }, e);
session.transfer(session.putAttribute(flowFile, NOTIFIED_ATTRIBUTE_NAME, String.valueOf(false)), REL_FAILURE);
continue;
}
}
if (!signalBuffers.containsKey(signalId)) {
signalBuffers.put(signalId, new SignalBuffer());
}
final SignalBuffer signalBuffer = signalBuffers.get(signalId);
if (StringUtils.isNotEmpty(attributeCacheRegex)) {
flowFile.getAttributes().entrySet().stream().filter(e -> (!e.getKey().equals("uuid") && e.getKey().matches(attributeCacheRegex))).forEach(e -> signalBuffer.attributesToCache.put(e.getKey(), e.getValue()));
}
signalBuffer.incrementDelta(counterName, delta);
signalBuffer.flowFiles.add(flowFile);
if (logger.isDebugEnabled()) {
logger.debug("Cached release signal identifier {} counterName {} from FlowFile {}", new Object[] { signalId, counterName, flowFile });
}
}
signalBuffers.forEach((signalId, signalBuffer) -> {
// retry after yielding for a while.
try {
protocol.notify(signalId, signalBuffer.deltas, signalBuffer.attributesToCache);
signalBuffer.flowFiles.forEach(flowFile -> session.transfer(session.putAttribute(flowFile, NOTIFIED_ATTRIBUTE_NAME, String.valueOf(true)), REL_SUCCESS));
} catch (IOException e) {
throw new RuntimeException(String.format("Unable to communicate with cache when processing %s due to %s", signalId, e), e);
}
});
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project flow by vaadin.
the class ComponentGenerator method generateClassSource.
/*
* Gets the JavaClassSource object (note, the license is added externally to
* the source, since JavaClassSource doesn't support adding a comment to the
* beginning of the file).
*/
private JavaClassSource generateClassSource(ComponentMetadata metadata, String basePackage) {
String targetPackage = basePackage;
String baseUrl = metadata.getBaseUrl();
if (StringUtils.isNotBlank(baseUrl)) {
// this is a fugly way to remove that
if (baseUrl.contains("/src/")) {
baseUrl = baseUrl.replace("/src/", "/");
}
String subPackage = ComponentGeneratorUtils.convertFilePathToPackage(baseUrl);
if (StringUtils.isNotBlank(subPackage)) {
int firstDot = subPackage.indexOf('.');
if (firstDot > 0) {
String firstSegment = subPackage.substring(0, firstDot);
String lastSegment = subPackage.substring(firstDot + 1);
subPackage = lastSegment.replace(".", "");
if (!"vaadin".equals(firstSegment)) {
subPackage = firstSegment + "." + subPackage;
}
}
targetPackage += "." + subPackage;
}
}
JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.setPackage(targetPackage).setPublic().setAbstract(abstractClass).setName(getGeneratedClassName(metadata.getTag()));
if (metadata.getParentTagName() != null) {
javaClass.setSuperType(getGeneratedClassName(metadata.getParentTagName()) + GENERIC_TYPE_DECLARATION);
} else {
javaClass.setSuperType(Component.class);
addInterfaces(metadata, javaClass);
}
javaClass.addTypeVariable().setName(GENERIC_TYPE).setBounds(javaClass.getName() + GENERIC_TYPE_DECLARATION);
addClassAnnotations(metadata, javaClass);
Map<String, MethodSource<JavaClassSource>> propertyToGetterMap = new HashMap<String, MethodSource<JavaClassSource>>();
if (metadata.getProperties() != null) {
generateEventsForPropertiesWithNotify(metadata);
generateGettersAndSetters(metadata, javaClass, propertyToGetterMap);
}
if (metadata.getMethods() != null) {
metadata.getMethods().stream().filter(function -> !ExclusionRegistry.isMethodExcluded(metadata.getTag(), function.getName())).forEach(function -> generateMethodFor(javaClass, function));
}
if (metadata.getEvents() != null) {
metadata.getEvents().stream().filter(event -> !ExclusionRegistry.isEventExcluded(metadata.getTag(), event.getName())).forEach(event -> generateEventListenerFor(javaClass, metadata, event, propertyToGetterMap));
}
if (metadata.getSlots() != null && !metadata.getSlots().isEmpty()) {
generateAdders(metadata, javaClass);
}
if (StringUtils.isNotEmpty(metadata.getDescription())) {
addMarkdownJavaDoc(metadata.getDescription(), javaClass.getJavaDoc());
}
generateConstructors(javaClass);
return javaClass;
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project pentaho-platform by pentaho.
the class PentahoWebContextFilter method getActiveThemeVar.
// region get Environment Variables
private String getActiveThemeVar(HttpServletRequest request) {
IPentahoSession session = getSession();
String activeTheme = (String) session.getAttribute("pentaho-user-theme");
String ua = request.getHeader("User-Agent");
// check if we're coming from a mobile device, if so, lock to system default (ruby)
if (StringUtils.isNotEmpty(ua) && ua.matches(".*(?i)(iPad|iPod|iPhone|Android).*")) {
activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
}
if (activeTheme == null) {
IUserSettingService settingsService = getUserSettingsService();
try {
activeTheme = settingsService.getUserSetting("pentaho-user-theme", null).getSettingValue();
} catch (Exception ignored) {
// the user settings service is not valid in the agile-bi deployment of the server
}
if (activeTheme == null) {
activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
}
}
return activeTheme;
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty 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");
}
// 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.isNotEmpty in project okta-sdk-java by okta.
the class AbstractOktaJavaClientCodegen method fromModel.
@Override
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
// super add these imports, and we don't want that dependency
codegenModel.imports.remove("ApiModel");
if (model.getVendorExtensions().containsKey("x-baseType")) {
String baseType = (String) model.getVendorExtensions().get("x-baseType");
codegenModel.vendorExtensions.put("baseType", toModelName(baseType));
codegenModel.imports.add(toModelName(baseType));
}
Collection<CodegenOperation> operations = (Collection<CodegenOperation>) codegenModel.vendorExtensions.get("operations");
if (operations != null) {
operations.forEach(op -> {
if (op.returnType != null) {
codegenModel.imports.add(op.returnType);
}
if (op.allParams != null) {
op.allParams.stream().filter(param -> needToImport(param.dataType)).forEach(param -> codegenModel.imports.add(param.dataType));
}
});
}
// force alias == false (likely only relevant for Lists, but something changed in swagger 2.2.3 to require this)
codegenModel.isAlias = false;
String parent = (String) model.getVendorExtensions().get("x-okta-parent");
if (StringUtils.isNotEmpty(parent)) {
codegenModel.parent = toApiName(parent.substring(parent.lastIndexOf("/")));
// figure out the resourceClass if this model has a parent
String discriminatorRoot = getRootDiscriminator(name);
if (discriminatorRoot != null) {
model.getVendorExtensions().put("discriminatorRoot", discriminatorRoot);
}
}
// We use '$ref' attributes with siblings, which isn't valid JSON schema (or swagger), so we need process
// additional attributes from the raw schema
Map<String, Object> modelDef = getRawSwaggerDefinition(name);
codegenModel.vars.forEach(codegenProperty -> {
Map<String, Object> rawPropertyMap = getRawSwaggerProperty(modelDef, codegenProperty.baseName);
codegenProperty.isReadOnly = Boolean.TRUE.equals(rawPropertyMap.get("readOnly"));
});
return codegenModel;
}
Aggregations