use of java.util.function.Consumer in project pact-jvm by DiUS.
the class HttpTarget method getProviderInfo.
protected ProviderInfo getProviderInfo() {
Provider provider = testClass.getAnnotation(Provider.class);
final ProviderInfo providerInfo = new ProviderInfo(provider.value());
providerInfo.setPort(port);
providerInfo.setHost(host);
providerInfo.setProtocol(protocol);
providerInfo.setPath(path);
providerInfo.setInsecure(insecure);
if (testClass != null) {
final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
if (!methods.isEmpty()) {
providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
try {
method.invokeExplosively(testTarget, httpRequest);
} catch (Throwable t) {
throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
}
}));
}
}
return providerInfo;
}
use of java.util.function.Consumer in project pact-jvm by DiUS.
the class MockMvcTarget method getProviderInfo.
@Override
protected ProviderInfo getProviderInfo() {
Provider provider = testClass.getAnnotation(Provider.class);
final ProviderInfo providerInfo = new ProviderInfo(provider.value());
if (testClass != null) {
final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
if (!methods.isEmpty()) {
providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
try {
method.invokeExplosively(testTarget, httpRequest);
} catch (Throwable t) {
throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
}
}));
}
}
return providerInfo;
}
use of java.util.function.Consumer in project Gargoyle by callakrsos.
the class CrudBaseGridView method saveBtnClickHandler.
/**
* 저장버튼 클릭 핸들러
*
* @param saveClickCallbackProperty2
*
* @Date 2015. 10. 10.
* @return
* @User KYJ
*/
private EventHandler<MouseEvent> saveBtnClickHandler(ObjectProperty<Consumer<List<T>>> saveClickCallbackProperty) {
return new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
try {
Consumer<List<T>> callback = saveClickCallbackProperty.get();
if (callback == null) {
errorMsgCallback.accept("saveClickCallback 함수에 에러메세지 콜백을 등록하세요.");
return;
}
gridview.fireEvent(event);
List<T> items = getItems();
//필수값 검증로직 추가. 2016.12.08
AbstractVoNullChecker<T> nullCheckHandler = new DefaultVoNullChecker<>(CrudBaseGridView.this);
nullCheckHandler.setList(items);
Optional<Field> findFirst = nullCheckHandler.findFirst();
boolean present = findFirst.isPresent();
if (present) {
String msgFieldName = nullCheckHandler.getMsgNameByfield();
// String message = ValueUtil.getMessage("MSG_W_000001", msgFieldName);
int emptyIndex = nullCheckHandler.getEmptyIndex();
Set<Node> findAllByNodes = CrudBaseGridView.this.lookupAll("TableRow");
findAllByNodes.stream().map(n -> (TableRow) n).filter(r -> {
return emptyIndex == r.getIndex();
}).findFirst().ifPresent(n -> {
Timeline timeline = new Timeline();
timeline.setCycleCount(10);
timeline.setAutoReverse(true);
KeyFrame keyFrame = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px"));
KeyFrame keyFrame2 = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), ""));
KeyValue keyValueX = new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px");
KeyValue keyValueY = new KeyValue(n.styleProperty(), "");
KeyFrame keyFrame3 = new KeyFrame(Duration.seconds(2), "", keyValueX, keyValueY);
timeline.getKeyFrames().add(keyFrame3);
timeline.play();
});
getSelectionModel().select(emptyIndex);
// DialogUtil.showMessageDialog(SharedMemory.getPrimaryStage(), msgFieldName + " Field is empty.");
return;
}
List<T> arrayList = new ArrayList<T>(items);
arrayList.addAll(deleteItems);
callback.accept(arrayList);
// 사용자 정의 로직이 이상없으면 deleteItems 항목도 비운다.
deleteItems.clear();
} catch (Exception e) {
throw e;
}
}
};
}
use of java.util.function.Consumer in project Gargoyle by callakrsos.
the class CommonsSqllPan method queryAll.
/**
* @inheritDoc
*/
@Override
public void queryAll(List<String> queryArray, Consumer<Integer> onSuccess, BiConsumer<Exception, Boolean> exceptionHandler) {
int result = -1;
Connection con = null;
try {
con = connectionSupplier.get();
// List<List<String>> collect = Stream.of(queryArray).filter(str ->
// ValueUtil.isNotEmpty(str)).map(str ->
// str).collect(Collectors.toList());
result = DbUtil.getTransactionedScope(con, queryArray, arr -> {
List<String> collect = arr.stream().filter(str -> ValueUtil.isNotEmpty(str)).collect(Collectors.toList());
return collect;
}, ex -> {
LOGGER.error(ValueUtil.toString(ex));
exceptionHandler.accept(ex, true);
});
onSuccess.accept(result);
} catch (SQLException e) {
boolean showDialog = true;
// 사용자가 SQL을 잘못입력한경우 처리할 내용. [크리틱컬하지않는 에러... 처리.]
if ("42P01".equals(e.getSQLState())) {
LOGGER.error(ValueUtil.toString(e));
showDialog = false;
} else if ("42S02".equals(e.getSQLState())) {
LOGGER.error(ValueUtil.toString(e));
showDialog = false;
} else /* Postgre sql */
if ("42601".equals(e.getSQLState())) {
LOGGER.error(ValueUtil.toString(e));
showDialog = false;
}
exceptionHandler.accept(e, showDialog);
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
exceptionHandler.accept(e, true);
} finally /* 2015.11.12 finnaly문 추가. */
{
try {
if (con != null)
con.close();
} catch (SQLException e) {
LOGGER.error(ValueUtil.toString(e));
}
}
}
use of java.util.function.Consumer in project Gargoyle by callakrsos.
the class DbUtil method getTransactionedScope.
public static <T> int getTransactionedScope(Connection con, T userObj, Function<T, List<String>> sqlConverter, Consumer<Exception> exceptionHandler) throws Exception {
int result = -1;
try {
LOGGER.debug("is AutoCommit ? : {}", con.getAutoCommit());
con.setAutoCommit(false);
List<String> apply = sqlConverter.apply(userObj);
Statement createStatement = con.createStatement();
for (String sql : apply) {
/*
* sqlite에서 공백이 포함된 sql은 add한경우 에러.
* 확인해보니 isEmpty함수에 이상이 있는듯하여 수정.
*/
if (ValueUtil.isEmpty(sql))
continue;
LOGGER.debug(sql);
createStatement.addBatch(sql);
}
int[] executeBatch = createStatement.executeBatch();
con.commit();
result = (int) IntStream.of(executeBatch).filter(v -> v == 0).count();
} catch (Exception e) {
con.rollback();
exceptionHandler.accept(e);
result = -1;
} finally {
con.commit();
close(con);
}
return result;
}
Aggregations