List of usage examples for java.util.function Supplier get
T get();
From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java
public <ElementData extends GraphNode> void validateElementExistInGraph(String elementUniqueId, NodeTypeEnum elementNodeType, Supplier<Class<ElementData>> elementClassGen, Wrapper<ElementData> elementDataWrapper, Wrapper<TitanOperationStatus> errorWrapper) { Either<ElementData, TitanOperationStatus> findResInstanceRes = titanGenericDao .getNode(UniqueIdBuilder.getKeyByNodeType(elementNodeType), elementUniqueId, elementClassGen.get()); if (findResInstanceRes.isRight()) { TitanOperationStatus status = findResInstanceRes.right().value(); if (status == TitanOperationStatus.NOT_FOUND) { status = TitanOperationStatus.INVALID_ID; }//from ww w . j a va 2 s . c om errorWrapper.setInnerElement(status); } else { if (elementDataWrapper != null) { elementDataWrapper.setInnerElement(findResInstanceRes.left().value()); } } }
From source file:org.openecomp.sdc.be.servlets.AbstractValidationsServlet.java
protected <T> void validateClassParse(String data, Wrapper<T> parsedClassWrapper, Supplier<Class<T>> classGen, Wrapper<ResponseFormat> errorWrapper) { try {/*w w w . j a va 2 s.c o m*/ T parsedClass = gson.fromJson(data, classGen.get()); if (parsedClass == null) { errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)); } else { parsedClassWrapper.setInnerElement(parsedClass); } } catch (JsonSyntaxException e) { log.debug("Failed to decode received {} {} to object.", classGen.get().getName(), data, e); errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)); } }
From source file:org.openecomp.sdc.be.servlets.TypesUploadServlet.java
private <T> void createElementsType(Wrapper<Response> responseWrapper, Supplier<Either<T, ResponseFormat>> elementsCreater) { Either<T, ResponseFormat> eitherResult = elementsCreater.get(); if (eitherResult.isRight()) { Response response = buildErrorResponse(eitherResult.right().value()); responseWrapper.setInnerElement(response); } else {//from w w w . ja v a 2s.c om Response response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), eitherResult.left().value()); responseWrapper.setInnerElement(response); } }
From source file:org.openecomp.sdc.be.servlets.TypesUploadServlet.java
private <ElementTypeDefinition> void buildStatusForElementTypeCreate(Wrapper<Response> responseWrapper, Supplier<Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml, ActionStatus alreadyExistStatus, String elementTypeName) { Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml .get();//from w w w . j a v a2 s . c o m if (eitherResult.isRight()) { Response response = buildErrorResponse(eitherResult.right().value()); responseWrapper.setInnerElement(response); } else { Object representation; try { List<ImmutablePair<ElementTypeDefinition, Boolean>> list = eitherResult.left().value(); ActionStatus status = ActionStatus.OK; if (list != null) { // Group result by the right value - true or false. // I.e., get the number of data types which are new and // which are old. Map<Boolean, List<ImmutablePair<ElementTypeDefinition, Boolean>>> collect = list.stream() .collect( Collectors.groupingBy(ImmutablePair<ElementTypeDefinition, Boolean>::getRight)); if (collect != null) { Set<Boolean> keySet = collect.keySet(); if (keySet.size() == 1) { Boolean isNew = keySet.iterator().next(); if (isNew.booleanValue() == true) { // all data types created at the first time status = ActionStatus.CREATED; } else { // All data types already exists status = alreadyExistStatus; } } } } representation = RepresentationUtils.toRepresentation(eitherResult.left().value()); Response response = buildOkResponse(getComponentsUtils().getResponseFormat(status), representation); responseWrapper.setInnerElement(response); } catch (IOException e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create " + elementTypeName); log.debug("failed to convert {} to json", elementTypeName, e); Response response = buildErrorResponse( getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); responseWrapper.setInnerElement(response); } } }
From source file:org.openecomp.sdc.be.servlets.TypesUploadServlet.java
private <T> T initElementTypeImportManager(ServletContext context, Supplier<Class<T>> classGetter) { WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context .getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); T elementTypeImortManager = webApplicationContext.getBean(classGetter.get()); return elementTypeImortManager; }
From source file:org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.java
public static void errorMessagePopupHandle(@SuppressWarnings("rawtypes") Supplier func) throws Exception { try {/*from ww w. j a v a 2 s . co m*/ WebElement errorMessagePopupHeader = getDriver().findElement(By.className("w-sdc-modal-head-text")); if (errorMessagePopupHeader.getText().equals("Error")) { WebElement okButton = getWebButton("OK"); if (okButton.isDisplayed()) { okButton.click(); func.get(); } } } catch (Exception e) { throw new Exception("something went wrong, can't do anything"); } }
From source file:org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.java
public static <R> R retryMethodOnException(Supplier<R> supplier) { boolean stopSearch = false; R ret = null;//from w w w .ja v a2s . co m Exception throwMe = null; int timeElapsed = 0; while (!stopSearch) { try { ret = supplier.get(); } catch (Exception e) { throwMe = e; GeneralUIUtils.sleep(250); timeElapsed += 250; if (timeElapsed > 5000) { stopSearch = true; } } finally { if (ret != null) { stopSearch = true; } } } if (ret == null) { throw new RuntimeException(throwMe); } else { return ret; } }
From source file:org.opensingular.form.SType.java
public final <T extends SView> SType<I> withView(Supplier<T> factory) { withView(factory.get()); return this; }
From source file:org.opensingular.form.SType.java
public final <T extends SView> T setView(Supplier<T> factory) { T v = factory.get(); setView(v);/*from w ww .j a va2s . c o m*/ return v; }
From source file:org.opensingular.form.SType.java
/** * Run initialization code for new created instance. Recebe uma referncia que * pode ser de inicializao lazy.//from w w w .j ava 2 s . co m */ @SuppressWarnings("unchecked") void init(Supplier<I> instanceRef) { IConsumer<I> initListener = asAtr().getAttributeValue(SPackageBasic.ATR_INIT_LISTENER); if (initListener != null) { initListener.accept(instanceRef.get()); } }