use of org.apache.commons.lang3.StringUtils.isNotEmpty in project kylo by Teradata.
the class DefaultCatalogTableManager method describeTable.
@Nonnull
@Override
public CatalogTableSchema describeTable(@Nonnull final DataSource dataSource, @Nullable final String schemaName, @Nullable final String tableName) throws SQLException {
final DataSetTemplate template = DataSourceUtil.mergeTemplates(dataSource);
if (Objects.equals("hive", template.getFormat())) {
final TableSchema tableSchema = hiveMetastoreService.getTable(schemaName, tableName);
final CatalogTableSchema catalogTableSchema = new CatalogTableSchema(tableSchema);
// Get table metadata
if (StringUtils.isNotEmpty(tableSchema.getName())) {
final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(tableSchema.getName(), "TABLE");
jdbcTable.setCatalog(tableSchema.getDatabaseName());
jdbcTable.setCatalog(tableSchema.getDatabaseName());
jdbcTable.setRemarks(tableSchema.getDescription());
jdbcTable.setSchema(tableSchema.getSchemaName());
jdbcTable.setCatalogSeparator(".");
jdbcTable.setIdentifierQuoteString("`");
catalogTableSchema.setTable(createTable(jdbcTable));
}
return catalogTableSchema;
} else if (Objects.equals("jdbc", template.getFormat())) {
return isolatedFunction(template, schemaName, (connection, schemaParser) -> {
final javax.sql.DataSource ds = new SingleConnectionDataSource(connection, true);
final DBSchemaParser tableSchemaParser = new DBSchemaParser(ds, new KerberosTicketConfiguration());
final TableSchema tableSchema = tableSchemaParser.describeTable(schemaName, tableName);
if (tableSchema != null) {
// Get table metadata
final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(tableSchema.getName(), "TABLE");
jdbcTable.setCatalog(tableSchema.getDatabaseName());
jdbcTable.setCatalog(tableSchema.getDatabaseName());
jdbcTable.setRemarks(tableSchema.getDescription());
jdbcTable.setSchema(tableSchema.getSchemaName());
jdbcTable.setMetaData(connection.getMetaData());
// Return table schema
final CatalogTableSchema catalogTableSchema = new CatalogTableSchema(tableSchema);
catalogTableSchema.setTable(createTable(jdbcTable));
return catalogTableSchema;
} else {
return null;
}
});
} else {
throw new IllegalArgumentException("Unsupported format: " + template.getFormat());
}
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project cuba by cuba-platform.
the class MbeanInspectWindow method initOperationsLayout.
protected void initOperationsLayout(ManagedBeanInfo mbean) {
BoxLayout container = operations;
for (ManagedBeanOperation op : mbean.getOperations()) {
BoxLayout vl = uiComponents.create(VBoxLayout.class);
vl.setMargin(false, false, true, false);
vl.setSpacing(true);
vl.setStyleName("c-mbeans-operation-container");
Label<String> nameLbl = uiComponents.create(Label.TYPE_DEFAULT);
nameLbl.setValue(convertTypeToReadableName(op.getReturnType()) + " " + op.getName() + "()");
nameLbl.setStyleName("h2");
vl.add(nameLbl);
if (StringUtils.isNotEmpty(op.getDescription())) {
Label<String> descrLbl = uiComponents.create(Label.TYPE_DEFAULT);
descrLbl.setValue(op.getDescription());
vl.add(descrLbl);
}
List<AttributeEditor> attrProviders = new ArrayList<>();
if (!op.getParameters().isEmpty()) {
GridLayout grid = uiComponents.create(GridLayout.class);
grid.setSpacing(true);
grid.setColumns(3);
grid.setRows(op.getParameters().size());
int row = 0;
for (ManagedBeanOperationParameter param : op.getParameters()) {
Label<String> pnameLbl = uiComponents.create(Label.TYPE_DEFAULT);
pnameLbl.setValue(param.getName());
Label<String> ptypeLbl = uiComponents.create(Label.TYPE_DEFAULT);
ptypeLbl.setValue(convertTypeToReadableName(param.getType()));
AttributeEditor prov = new AttributeEditor(frame, param.getType());
attrProviders.add(prov);
Component editField = prov.getComponent();
Component editComposition = editField;
if (StringUtils.isNotBlank(param.getDescription())) {
Label<String> pdescrLbl = uiComponents.create(Label.TYPE_DEFAULT);
pdescrLbl.setValue(param.getDescription());
BoxLayout editorLayout = uiComponents.create(VBoxLayout.class);
editorLayout.add(editField);
editorLayout.add(pdescrLbl);
editComposition = editorLayout;
}
grid.add(pnameLbl, 0, row);
grid.add(ptypeLbl, 1, row);
grid.add(editComposition, 2, row);
row++;
}
vl.add(grid);
}
Button invokeBtn = uiComponents.create(Button.class);
invokeBtn.setAction(new BaseAction("invoke").withCaption(getMessage("mbean.operation.invoke")).withHandler(event -> invokeOperation(op, attrProviders)));
vl.add(invokeBtn);
container.add(vl);
}
if (mbean.getOperations().isEmpty()) {
Label<String> lbl = uiComponents.create(Label.TYPE_DEFAULT);
lbl.setValue(getMessage("mbean.operations.none"));
container.add(lbl);
}
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project data-prep by Talend.
the class SimpleManagedTaskExecutor method queue.
/**
* @see ManagedTaskExecutor#queue(ManagedTaskCallable, String, String, AsyncExecutionResult)
*/
@Override
public synchronized AsyncExecution queue(final ManagedTaskCallable task, String executionId, String groupId, AsyncExecutionResult resultUrl) {
// Create async execution
final AsyncExecution asyncExecution = ofNullable(groupId).map(s -> new AsyncExecution(groupId)).orElseGet(AsyncExecution::new);
if (StringUtils.isNotEmpty(executionId)) {
asyncExecution.setId(executionId);
}
asyncExecution.setUserId(security.getUserId());
asyncExecution.setTenantId(security.getTenantId());
repository.save(asyncExecution);
// Wrap callable to get the running status.
final Callable wrapper = wrapTaskWithProgressInformation(task, asyncExecution);
asyncExecution.setResult(resultUrl);
ListenableFuture future = delegate.submitListenable(wrapper);
future.addCallback(new AsyncListenableFutureCallback(asyncExecution));
futures.put(asyncExecution.getId(), future);
LOGGER.debug("Execution {} queued for execution.", asyncExecution.getId());
return asyncExecution;
}
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", 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.isNotEmpty in project cuba by cuba-platform.
the class EntityRestore method buildLayout.
protected void buildLayout() {
Object value = entities.getValue();
if (value != null) {
MetaClass metaClass = (MetaClass) value;
MetaProperty deleteTsMetaProperty = metaClass.getProperty("deleteTs");
if (deleteTsMetaProperty != null) {
if (entitiesTable != null) {
tablePanel.remove(entitiesTable);
}
if (filter != null) {
tablePanel.remove(filter);
}
entitiesTable = uiComponents.create(Table.NAME);
entitiesTable.setFrame(frame);
restoreButton = uiComponents.create(Button.class);
restoreButton.setId("restore");
restoreButton.setCaption(getMessage("entityRestore.restore"));
ButtonsPanel buttonsPanel = uiComponents.create(ButtonsPanel.class);
buttonsPanel.add(restoreButton);
entitiesTable.setButtonsPanel(buttonsPanel);
RowsCount rowsCount = uiComponents.create(RowsCount.class);
entitiesTable.setRowsCount(rowsCount);
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(getMessage("dateTimeFormat"));
Function<Object, String> dateTimeFormatter = propertyValue -> {
if (propertyValue == null) {
return StringUtils.EMPTY;
}
return dateTimeFormat.format(propertyValue);
};
// collect properties in order to add non-system columns first
LinkedList<Table.Column<Entity>> nonSystemPropertyColumns = new LinkedList<>();
LinkedList<Table.Column<Entity>> systemPropertyColumns = new LinkedList<>();
List<MetaProperty> metaProperties = new ArrayList<>();
for (MetaProperty metaProperty : metaClass.getProperties()) {
// don't show embedded, transient & multiple referred entities
Range range = metaProperty.getRange();
if (isEmbedded(metaProperty) || metadataTools.isNotPersistent(metaProperty) || range.getCardinality().isMany() || metadataTools.isSystemLevel(metaProperty) || (range.isClass() && metadataTools.isSystemLevel(range.asClass()))) {
continue;
}
metaProperties.add(metaProperty);
Table.Column<Entity> column = new Table.Column<>(metaClass.getPropertyPath(metaProperty.getName()));
if (!metadataTools.isSystem(metaProperty)) {
column.setCaption(getPropertyCaption(metaClass, metaProperty));
nonSystemPropertyColumns.add(column);
} else {
column.setCaption(metaProperty.getName());
column.setDescription(getSystemAttributeDescription(metaClass, metaProperty));
systemPropertyColumns.add(column);
}
if (range.isDatatype() && range.asDatatype().getJavaClass().equals(Date.class)) {
column.setFormatter(dateTimeFormatter);
}
}
for (Table.Column<Entity> column : nonSystemPropertyColumns) {
entitiesTable.addColumn(column);
}
for (Table.Column<Entity> column : systemPropertyColumns) {
entitiesTable.addColumn(column);
}
DsContext dsContext = getDsContext();
if (entitiesDs != null) {
((DsContextImplementation) dsContext).unregister(entitiesDs);
}
entitiesDs = DsBuilder.create(dsContext).setId("entitiesDs").setMetaClass(metaClass).setView(buildView(metaClass, metaProperties)).buildGroupDatasource();
entitiesDs.setQuery("select e from " + metaClass.getName() + " e " + "where e.deleteTs is not null order by e.deleteTs");
entitiesDs.setSoftDeletion(false);
entitiesDs.refresh();
entitiesTable.setDatasource(entitiesDs);
String filterId = metaClass.getName().replace("$", "") + "GenericFilter";
filter = uiComponents.create(Filter.class);
filter.setId(filterId);
filter.setFrame(getFrame());
StringBuilder sb = new StringBuilder();
for (MetaProperty property : metaClass.getProperties()) {
AnnotatedElement annotatedElement = property.getAnnotatedElement();
if (annotatedElement.getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class) != null) {
sb.append(property.getName()).append("|");
}
}
Element filterElement = dom4JTools.readDocument(String.format("<filter id=\"%s\">\n" + " <properties include=\".*\" exclude=\"\"/>\n" + "</filter>", filterId)).getRootElement();
String excludedProperties = sb.toString();
if (StringUtils.isNotEmpty(excludedProperties)) {
Element properties = filterElement.element("properties");
properties.attribute("exclude").setValue(excludedProperties.substring(0, excludedProperties.lastIndexOf("|")));
}
((HasXmlDescriptor) filter).setXmlDescriptor(filterElement);
filter.setUseMaxResults(true);
filter.setDatasource(entitiesDs);
entitiesTable.setSizeFull();
entitiesTable.setMultiSelect(true);
Action restoreAction = new ItemTrackingAction("restore").withCaption(getMessage("entityRestore.restore")).withPrimary(true).withHandler(event -> showRestoreDialog());
entitiesTable.addAction(restoreAction);
restoreButton.setAction(restoreAction);
tablePanel.add(filter);
tablePanel.add(entitiesTable);
tablePanel.expand(entitiesTable, "100%", "100%");
entitiesTable.refresh();
((FilterImplementation) filter).loadFiltersAndApplyDefault();
}
}
}
Aggregations