use of org.apache.commons.lang3.StringUtils.EMPTY in project data-prep by Talend.
the class DataSetService method updateDataSet.
/**
* Updates a data set metadata. If no data set exists for given id, a {@link TDPException} is thrown.
*
* @param dataSetId The id of data set to be updated.
* @param dataSetMetadata The new content for the data set. If empty, existing content will <b>not</b> be replaced.
* For delete operation, look at {@link #delete(String)}.
*/
@RequestMapping(value = "/datasets/{id}", method = PUT)
@ApiOperation(value = "Update a data set metadata by id", notes = "Update a data set metadata according to the content of the PUT body. Id should be a UUID returned by the list operation. Not valid or non existing data set id return an error response.")
@Timed
public void updateDataSet(@PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the data set to update") String dataSetId, @RequestBody DataSetMetadata dataSetMetadata) {
if (dataSetMetadata != null && dataSetMetadata.getName() != null) {
checkDataSetName(dataSetMetadata.getName());
}
final DistributedLock lock = dataSetMetadataRepository.createDatasetMetadataLock(dataSetId);
lock.lock();
try {
DataSetMetadata metadataForUpdate = dataSetMetadataRepository.get(dataSetId);
if (metadataForUpdate == null) {
// No need to silently create the data set metadata: associated content will most likely not exist.
throw new TDPException(DataSetErrorCodes.DATASET_DOES_NOT_EXIST, build().put("id", dataSetId));
}
LOG.debug("updateDataSet: {}", dataSetMetadata);
publisher.publishEvent(new DatasetUpdatedEvent(dataSetMetadata));
//
// Only part of the metadata can be updated, so the original dataset metadata is loaded and updated
//
DataSetMetadata original = metadataBuilder.metadata().copy(metadataForUpdate).build();
try {
// update the name
metadataForUpdate.setName(dataSetMetadata.getName());
// update the sheet content (in case of a multi-sheet excel file)
if (metadataForUpdate.getSchemaParserResult() != null) {
Optional<Schema.SheetContent> sheetContentFound = metadataForUpdate.getSchemaParserResult().getSheetContents().stream().filter(sheetContent -> dataSetMetadata.getSheetName().equals(sheetContent.getName())).findFirst();
if (sheetContentFound.isPresent()) {
List<ColumnMetadata> columnMetadatas = sheetContentFound.get().getColumnMetadatas();
if (metadataForUpdate.getRowMetadata() == null) {
metadataForUpdate.setRowMetadata(new RowMetadata(emptyList()));
}
metadataForUpdate.getRowMetadata().setColumns(columnMetadatas);
}
metadataForUpdate.setSheetName(dataSetMetadata.getSheetName());
metadataForUpdate.setSchemaParserResult(null);
}
// Location updates
metadataForUpdate.setLocation(dataSetMetadata.getLocation());
// update parameters & encoding (so that user can change import parameters for CSV)
metadataForUpdate.getContent().setParameters(dataSetMetadata.getContent().getParameters());
metadataForUpdate.setEncoding(dataSetMetadata.getEncoding());
// update limit
final Optional<Long> newLimit = dataSetMetadata.getContent().getLimit();
newLimit.ifPresent(limit -> metadataForUpdate.getContent().setLimit(limit));
// Validate that the new data set metadata and removes the draft status
final String formatFamilyId = dataSetMetadata.getContent().getFormatFamilyId();
if (formatFamilyFactory.hasFormatFamily(formatFamilyId)) {
FormatFamily format = formatFamilyFactory.getFormatFamily(formatFamilyId);
try {
DraftValidator draftValidator = format.getDraftValidator();
DraftValidator.Result result = draftValidator.validate(dataSetMetadata);
if (result.isDraft()) {
// This is not an exception case: data set may remain a draft after update (although rather
// unusual)
LOG.warn("Data set #{} is still a draft after update.", dataSetId);
return;
}
// Data set metadata to update is no longer a draft
metadataForUpdate.setDraft(false);
} catch (UnsupportedOperationException e) {
// no need to validate draft here
}
}
// update schema
formatAnalyzer.update(original, metadataForUpdate);
// save the result
dataSetMetadataRepository.save(metadataForUpdate);
// all good mate!! so send that to jms
// Asks for a in depth schema analysis (for column type information).
analyzeDataSet(dataSetId, true, singletonList(FormatAnalysis.class));
} catch (TDPException e) {
throw e;
} catch (Exception e) {
throw new TDPException(UNABLE_TO_CREATE_OR_UPDATE_DATASET, e);
}
} finally {
lock.unlock();
}
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project bisq-desktop by bisq-network.
the class WithdrawalView method setSelectColumnCellFactory.
private void setSelectColumnCellFactory() {
selectColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
selectColumn.setCellFactory(new Callback<TableColumn<WithdrawalListItem, WithdrawalListItem>, TableCell<WithdrawalListItem, WithdrawalListItem>>() {
@Override
public TableCell<WithdrawalListItem, WithdrawalListItem> call(TableColumn<WithdrawalListItem, WithdrawalListItem> column) {
return new TableCell<WithdrawalListItem, WithdrawalListItem>() {
CheckBox checkBox = new AutoTooltipCheckBox();
@Override
public void updateItem(final WithdrawalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
checkBox.setOnAction(e -> {
item.setSelected(checkBox.isSelected());
selectForWithdrawal(item);
// If all are selected we select useAllInputsRadioButton
if (observableList.size() == selectedItems.size()) {
inputsToggleGroup.selectToggle(useAllInputsRadioButton);
} else {
// We don't want to get deselected all when we activate the useCustomInputsRadioButton
// so we temporarily disable the listener
inputsToggleGroup.selectedToggleProperty().removeListener(inputsToggleGroupListener);
inputsToggleGroup.selectToggle(useCustomInputsRadioButton);
useAllInputs.set(false);
inputsToggleGroup.selectedToggleProperty().addListener(inputsToggleGroupListener);
}
});
setGraphic(checkBox);
checkBox.setSelected(item.isSelected());
} else {
checkBox.setOnAction(null);
setGraphic(null);
}
}
};
}
});
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project bisq-desktop by bisq-network.
the class PreferencesView method initializeDisplayCurrencies.
private void initializeDisplayCurrencies() {
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 3, Res.get("setting.preferences.currenciesInList"), Layout.GROUP_DISTANCE);
GridPane.setColumnSpan(titledGroupBg, 4);
// noinspection unchecked
preferredTradeCurrencyComboBox = addLabelComboBox(root, gridRow, Res.get("setting.preferences.prefCurrency"), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
preferredTradeCurrencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
@Override
public String toString(TradeCurrency tradeCurrency) {
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
return tradeCurrency.getDisplayPrefix() + tradeCurrency.getNameAndCode();
}
@Override
public TradeCurrency fromString(String s) {
return null;
}
});
Tuple2<Label, ListView> fiatTuple = addLabelListView(root, ++gridRow, Res.get("setting.preferences.displayFiat"));
GridPane.setValignment(fiatTuple.first, VPos.TOP);
// noinspection unchecked
fiatCurrenciesListView = fiatTuple.second;
fiatCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
fiatCurrenciesListView.setPrefHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
Label placeholder = new AutoTooltipLabel(Res.get("setting.preferences.noFiat"));
placeholder.setWrapText(true);
fiatCurrenciesListView.setPlaceholder(placeholder);
fiatCurrenciesListView.setCellFactory(new Callback<ListView<FiatCurrency>, ListCell<FiatCurrency>>() {
@Override
public ListCell<FiatCurrency> call(ListView<FiatCurrency> list) {
return new ListCell<FiatCurrency>() {
final Label label = new AutoTooltipLabel();
final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);
final Button removeButton = new AutoTooltipButton("", icon);
final AnchorPane pane = new AnchorPane(label, removeButton);
{
label.setLayoutY(5);
removeButton.setId("icon-button");
AnchorPane.setRightAnchor(removeButton, 0d);
}
@Override
public void updateItem(final FiatCurrency item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
label.setText(item.getNameAndCode());
removeButton.setOnAction(e -> {
if (item.equals(preferences.getPreferredTradeCurrency())) {
new Popup<>().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
} else {
preferences.removeFiatCurrency(item);
if (!allFiatCurrencies.contains(item))
allFiatCurrencies.add(item);
}
});
setGraphic(pane);
} else {
setGraphic(null);
removeButton.setOnAction(null);
}
}
};
}
});
Tuple2<Label, ListView> cryptoCurrenciesTuple = addLabelListView(root, gridRow, Res.get("setting.preferences.displayAltcoins"));
GridPane.setValignment(cryptoCurrenciesTuple.first, VPos.TOP);
GridPane.setMargin(cryptoCurrenciesTuple.first, new Insets(0, 0, 0, 20));
// noinspection unchecked
cryptoCurrenciesListView = cryptoCurrenciesTuple.second;
GridPane.setColumnIndex(cryptoCurrenciesTuple.first, 2);
GridPane.setColumnIndex(cryptoCurrenciesListView, 3);
cryptoCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
cryptoCurrenciesListView.setPrefHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
placeholder = new AutoTooltipLabel(Res.get("setting.preferences.noAltcoins"));
placeholder.setWrapText(true);
cryptoCurrenciesListView.setPlaceholder(placeholder);
cryptoCurrenciesListView.setCellFactory(new Callback<ListView<CryptoCurrency>, ListCell<CryptoCurrency>>() {
@Override
public ListCell<CryptoCurrency> call(ListView<CryptoCurrency> list) {
return new ListCell<CryptoCurrency>() {
final Label label = new AutoTooltipLabel();
final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);
final Button removeButton = new AutoTooltipButton("", icon);
final AnchorPane pane = new AnchorPane(label, removeButton);
{
label.setLayoutY(5);
removeButton.setId("icon-button");
AnchorPane.setRightAnchor(removeButton, 0d);
}
@Override
public void updateItem(final CryptoCurrency item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
label.setText(item.getNameAndCode());
removeButton.setOnAction(e -> {
if (item.equals(preferences.getPreferredTradeCurrency())) {
new Popup<>().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
} else {
preferences.removeCryptoCurrency(item);
if (!allCryptoCurrencies.contains(item))
allCryptoCurrencies.add(item);
}
});
setGraphic(pane);
} else {
setGraphic(null);
removeButton.setOnAction(null);
}
}
};
}
});
// noinspection unchecked
fiatCurrenciesComboBox = addLabelComboBox(root, ++gridRow).second;
fiatCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addFiat"));
fiatCurrenciesComboBox.setConverter(new StringConverter<FiatCurrency>() {
@Override
public String toString(FiatCurrency tradeCurrency) {
return tradeCurrency.getNameAndCode();
}
@Override
public FiatCurrency fromString(String s) {
return null;
}
});
Tuple2<Label, ComboBox> labelComboBoxTuple2 = addLabelComboBox(root, gridRow);
// noinspection unchecked
cryptoCurrenciesComboBox = labelComboBoxTuple2.second;
GridPane.setColumnIndex(cryptoCurrenciesComboBox, 3);
cryptoCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addAltcoin"));
cryptoCurrenciesComboBox.setConverter(new StringConverter<CryptoCurrency>() {
@Override
public String toString(CryptoCurrency tradeCurrency) {
return tradeCurrency.getNameAndCode();
}
@Override
public CryptoCurrency fromString(String s) {
return null;
}
});
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project syncope by apache.
the class GroupDataBinderImpl method update.
@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
// Re-merge any pending change from workflow tasks
Group group = groupDAO.save(toBeUpdated);
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
// fetch connObjectKeys before update
Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
// realm
setRealm(group, groupPatch);
// name
if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
group.setName(groupPatch.getName().getValue());
}
// owner
if (groupPatch.getUserOwner() != null) {
group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
}
if (groupPatch.getGroupOwner() != null) {
group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
}
// attributes and resources
propByRes.merge(fill(group, groupPatch, anyUtils, scce));
// check if some connObjectKey was changed by the update above
Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
propByRes.add(ResourceOperation.UPDATE, entry.getKey());
});
group = groupDAO.save(group);
// dynamic membership
if (groupPatch.getUDynMembershipCond() == null) {
if (group.getUDynMembership() != null) {
group.getUDynMembership().setGroup(null);
group.setUDynMembership(null);
groupDAO.clearUDynMembers(group);
}
} else {
setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
}
for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
ADynGroupMembership memb = itor.next();
memb.setGroup(null);
itor.remove();
}
groupDAO.clearADynMembers(group);
for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
AnyType anyType = anyTypeDAO.find(entry.getKey());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
} else {
setDynMembership(group, anyType, entry.getValue());
}
}
// type extensions
for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
if (typeExt == null) {
typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
}
// add all classes contained in the TO
for (String name : typeExtTO.getAuxClasses()) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
}
// remove all classes not contained in the TO
typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
// only consider non-empty type extensions
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
}
// remove all type extensions not contained in the TO
group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
return propByRes;
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project bullet-storm by yahoo.
the class JoinBoltTest method testGroupBy.
@Test
public void testGroupBy() {
final int entries = 16;
BulletConfig bulletConfig = GroupByTest.makeConfiguration(entries);
GroupBy groupBy = GroupByTest.makeGroupBy(bulletConfig, singletonMap("fieldA", "A"), entries, AggregationUtils.makeGroupOperation(COUNT, null, "cnt"), AggregationUtils.makeGroupOperation(SUM, "fieldB", "sumB"));
IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i % 16).add("fieldB", i / 16).getRecord()).forEach(groupBy::consume);
byte[] first = groupBy.getData();
groupBy = GroupByTest.makeGroupBy(bulletConfig, singletonMap("fieldA", "A"), entries, AggregationUtils.makeGroupOperation(COUNT, null, "cnt"), AggregationUtils.makeGroupOperation(SUM, "fieldB", "sumB"));
IntStream.range(256, 1024).mapToObj(i -> RecordBox.get().add("fieldA", i % 16).add("fieldB", i / 16).getRecord()).forEach(groupBy::consume);
byte[] second = groupBy.getData();
// Send generated data to JoinBolt
bolt = new DonableJoinBolt(config, 2, true);
setup(bolt);
List<GroupOperation> operations = asList(new GroupOperation(COUNT, null, "cnt"), new GroupOperation(SUM, "fieldB", "sumB"));
String queryString = makeGroupFilterQuery("ts", singletonList("1"), EQUALS, GROUP, entries, operations, Pair.of("fieldA", "A"));
Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", queryString, EMPTY);
bolt.execute(query);
sendRawByteTuplesTo(bolt, "42", asList(first, second));
Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
bolt.execute(tick);
for (int i = 0; i < BulletStormConfig.DEFAULT_JOIN_BOLT_QUERY_TICK_TIMEOUT - 1; ++i) {
bolt.execute(tick);
Assert.assertEquals(collector.getEmittedCount(), 0);
}
bolt.execute(tick);
Assert.assertEquals(collector.getEmittedCount(), 2);
String response = (String) collector.getMthElementFromNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1, 1).get();
JsonParser parser = new JsonParser();
JsonObject actual = parser.parse(response).getAsJsonObject();
JsonArray actualRecords = actual.get(Clip.RECORDS_KEY).getAsJsonArray();
Assert.assertEquals(actualRecords.size(), 16);
}
Aggregations