Search in sources :

Example 66 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project nifi-registry by apache.

the class RegistryService method getFlows.

public List<VersionedFlow> getFlows(final String bucketId) {
    if (StringUtils.isBlank(bucketId)) {
        throw new IllegalArgumentException("Bucket identifier cannot be null");
    }
    readLock.lock();
    try {
        final BucketEntity existingBucket = metadataService.getBucketById(bucketId);
        if (existingBucket == null) {
            LOGGER.warn("The specified bucket id [{}] does not exist.", bucketId);
            throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
        }
        // return non-verbose set of flows for the given bucket
        final List<FlowEntity> flows = metadataService.getFlowsByBucket(existingBucket.getId());
        return flows.stream().map(f -> DataModelMapper.map(existingBucket, f)).collect(Collectors.toList());
    } finally {
        readLock.unlock();
    }
}
Also used : SortedSet(java.util.SortedSet) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) LoggerFactory(org.slf4j.LoggerFactory) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) ConstraintViolation(javax.validation.ConstraintViolation) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Validator(javax.validation.Validator) Set(java.util.Set) FlowSnapshotContext(org.apache.nifi.registry.flow.FlowSnapshotContext) UUID(java.util.UUID) Serializer(org.apache.nifi.registry.serialization.Serializer) Collectors(java.util.stream.Collectors) BucketItem(org.apache.nifi.registry.bucket.BucketItem) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) List(java.util.List) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) Bucket(org.apache.nifi.registry.bucket.Bucket) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashMap(java.util.HashMap) ConciseEvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) ObjectUtils(org.apache.commons.lang3.ObjectUtils) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) Service(org.springframework.stereotype.Service) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) Logger(org.slf4j.Logger) StandardFlowSnapshotContext(org.apache.nifi.registry.provider.flow.StandardFlowSnapshotContext) FlowPersistenceProvider(org.apache.nifi.registry.flow.FlowPersistenceProvider) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) Lock(java.util.concurrent.locks.Lock) Validate(org.apache.commons.lang3.Validate) ConstraintViolationException(javax.validation.ConstraintViolationException) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 67 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project sponge by softelnet.

the class StandaloneEngineBuilder method build.

/**
 * Returns a new StandaloneEngine or {@code null} if help or version option is specified so the application should exit.
 */
@Override
public StandaloneSpongeEngine build() {
    try {
        if (commandLineArgs == null) {
            return super.build();
        }
        CommandLineParser parser = new DefaultParser();
        CommandLine commandLine = parser.parse(options, commandLineArgs);
        if (commandLine.hasOption(OPTION_HELP)) {
            printHelp();
            return null;
        }
        if (commandLine.hasOption(OPTION_VERSION)) {
            System.out.println(getDescription());
            return null;
        }
        if (commandLine.hasOption(OPTION_CONFIG)) {
            config(commandLine.getOptionValue(OPTION_CONFIG));
        }
        if (Stream.of(commandLine.getOptions()).filter(option -> option.getOpt().equals(OPTION_CONFIG)).count() > 1) {
            throw new StandaloneInitializationException("Only one Sponge XML configuration file may be provided.");
        }
        Stream.of(commandLine.getOptions()).filter(option -> option.getOpt().equals(OPTION_KNOWLEDGE_BASE)).forEachOrdered(option -> {
            String value = option.getValue();
            if (value == null || StringUtils.isBlank(value)) {
                throw new StandaloneInitializationException("Empty knowledge base specification.");
            }
            String[] values = StringUtils.split(value, ARGUMENT_VALUE_SEPARATOR);
            String kbName = values.length == 2 ? values[0] : DEFAULT_KNOWLEDGE_BASE_NAME;
            String kbFilesString = values.length == 2 ? values[1] : values[0];
            if (StringUtils.isBlank(kbName)) {
                throw new StandaloneInitializationException("Empty knowledge base name.");
            }
            List<String> kbFiles = SpongeUtils.split(kbFilesString, KB_FILES_SEPARATOR);
            knowledgeBase(kbName, kbFiles.toArray(new String[kbFiles.size()]));
        });
        if (!commandLine.hasOption(OPTION_CONFIG) && !commandLine.hasOption(OPTION_KNOWLEDGE_BASE)) {
            throw new StandaloneInitializationException("An Sponge XML configuration file or a knowledge base file(s) should be provided.");
        }
        // Apply standard parameters.
        super.build();
        applyDefaultParameters();
        if (commandLine.hasOption(OPTION_INTERACTIVE)) {
            InteractiveMode interactiveMode = new DefaultInteractiveMode(engine, commandLine.getOptionValue(OPTION_INTERACTIVE), interactiveModeConsoleSupplier);
            ExceptionHandler interactiveExceptionHandler = new SystemErrExceptionHandler();
            interactiveMode.setExceptionHandler(interactiveExceptionHandler);
            engine.setInteractiveMode(interactiveMode);
            if (commandLine.hasOption(OPTION_PRINT_ALL_EXCEPTIONS)) {
                engine.setExceptionHandler(new CombinedExceptionHandler(interactiveExceptionHandler, new LoggingExceptionHandler()));
            } else {
                LoggingUtils.logToConsole(false);
            }
        } else {
            if (commandLine.hasOption(OPTION_PRINT_ALL_EXCEPTIONS)) {
                throw new StandaloneInitializationException("'" + OPTION_PRINT_ALL_EXCEPTIONS + "' option may be used only if '" + OPTION_INTERACTIVE + "' is also used.");
            }
        }
        StandaloneEngineListener standaloneListener = new StandaloneEngineListener(engine);
        List<String> springConfigurationFiles = Stream.of(commandLine.getOptions()).filter(option -> option.getOpt().equals(OPTION_SPRING)).map(option -> {
            String[] values = option.getValues();
            if (values == null || values.length == 0) {
                throw new StandaloneInitializationException("No Spring configuration file provided.");
            }
            return option.getValue(0);
        }).collect(Collectors.toList());
        if (!springConfigurationFiles.isEmpty()) {
            standaloneListener.setSpringConfigurations(springConfigurationFiles);
        }
        if (commandLine.hasOption(OPTION_CAMEL)) {
            standaloneListener.setCamel(true);
        }
        engine.addOnStartupListener(standaloneListener);
        engine.addOnShutdownListener(standaloneListener);
    } catch (ParseException e) {
        throw new StandaloneInitializationException(e.getMessage(), e);
    }
    return engine;
}
Also used : VersionInfo(org.openksavi.sponge.core.VersionInfo) LoggingExceptionHandler(org.openksavi.sponge.core.engine.LoggingExceptionHandler) JLineInteractiveModeConsole(org.openksavi.sponge.standalone.interactive.JLineInteractiveModeConsole) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) HelpFormatter(org.apache.commons.cli.HelpFormatter) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) DefaultParser(org.apache.commons.cli.DefaultParser) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) InteractiveModeConsole(org.openksavi.sponge.engine.interactive.InteractiveModeConsole) Logger(org.slf4j.Logger) CommandLineParser(org.apache.commons.cli.CommandLineParser) InteractiveModeConstants(org.openksavi.sponge.core.engine.interactive.InteractiveModeConstants) ExceptionHandler(org.openksavi.sponge.engine.ExceptionHandler) CombinedExceptionHandler(org.openksavi.sponge.core.engine.CombinedExceptionHandler) Collectors(java.util.stream.Collectors) InteractiveMode(org.openksavi.sponge.engine.interactive.InteractiveMode) List(java.util.List) Stream(java.util.stream.Stream) ParseException(org.apache.commons.cli.ParseException) StringsCompleter(org.jline.reader.impl.completer.StringsCompleter) SpongeUtils(org.openksavi.sponge.core.util.SpongeUtils) EngineBuilder(org.openksavi.sponge.core.engine.EngineBuilder) LoggingUtils(org.openksavi.sponge.logging.LoggingUtils) DefaultInteractiveMode(org.openksavi.sponge.core.engine.interactive.DefaultInteractiveMode) LoggingExceptionHandler(org.openksavi.sponge.core.engine.LoggingExceptionHandler) LoggingExceptionHandler(org.openksavi.sponge.core.engine.LoggingExceptionHandler) ExceptionHandler(org.openksavi.sponge.engine.ExceptionHandler) CombinedExceptionHandler(org.openksavi.sponge.core.engine.CombinedExceptionHandler) CommandLine(org.apache.commons.cli.CommandLine) CombinedExceptionHandler(org.openksavi.sponge.core.engine.CombinedExceptionHandler) DefaultInteractiveMode(org.openksavi.sponge.core.engine.interactive.DefaultInteractiveMode) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) InteractiveMode(org.openksavi.sponge.engine.interactive.InteractiveMode) DefaultInteractiveMode(org.openksavi.sponge.core.engine.interactive.DefaultInteractiveMode) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 68 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project timbuctoo by HuygensING.

the class RdfUpload method upload.

@Consumes(MediaType.MULTIPART_FORM_DATA)
@POST
public Response upload(@FormDataParam("file") final InputStream rdfInputStream, @FormDataParam("file") final FormDataBodyPart body, @FormDataParam("fileMimeTypeOverride") final MediaType mimeTypeOverride, @FormDataParam("encoding") final String encoding, @FormDataParam("baseUri") final URI baseUri, @FormDataParam("defaultGraph") final URI defaultGraph, @HeaderParam("authorization") final String authHeader, @PathParam("userId") final String userId, @PathParam("dataSet") final String dataSetId, @QueryParam("forceCreation") boolean forceCreation, @QueryParam("async") final boolean async) throws ExecutionException, InterruptedException, LogStorageFailedException, DataStoreCreationException {
    final Either<Response, Response> result = authCheck.getOrCreate(authHeader, userId, dataSetId, forceCreation).flatMap(userAndDs -> authCheck.hasAdminAccess(userAndDs.getLeft(), userAndDs.getRight())).map((Tuple<User, DataSet> userDataSetTuple) -> {
        final MediaType mediaType = mimeTypeOverride == null ? body.getMediaType() : mimeTypeOverride;
        final DataSet dataSet = userDataSetTuple.getRight();
        ImportManager importManager = dataSet.getImportManager();
        if (mediaType == null || !importManager.isRdfTypeSupported(mediaType)) {
            return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity("{\"error\": \"We do not support the mediatype '" + mediaType + "'. Make sure to add the correct " + "mediatype to the file parameter. In curl you'd use `-F \"file=@<filename>;type=<mediatype>\"`. In a " + "webbrowser you probably have no way of setting the correct mimetype. So you can use a special " + "parameter " + "to override it: `formData.append(\"fileMimeTypeOverride\", \"<mimetype>\");`\"}").build();
        }
        if (StringUtils.isBlank(encoding)) {
            return Response.status(Response.Status.BAD_REQUEST).entity("Please provide an 'encoding' parameter").build();
        }
        if (StringUtils.isBlank(body.getContentDisposition().getFileName())) {
            return Response.status(400).entity("filename cannot be empty.").build();
        }
        Future<ImportStatus> promise = null;
        try {
            promise = importManager.addLog(baseUri == null ? dataSet.getMetadata().getBaseUri() : baseUri.toString(), defaultGraph == null ? dataSet.getMetadata().getBaseUri() : defaultGraph.toString(), body.getContentDisposition().getFileName(), rdfInputStream, Optional.of(Charset.forName(encoding)), mediaType);
        } catch (LogStorageFailedException e) {
            return Response.serverError().build();
        }
        if (!async) {
            return handleImportManagerResult(promise);
        }
        return Response.accepted().build();
    });
    if (result.isLeft()) {
        return result.getLeft();
    } else {
        return result.get();
    }
}
Also used : Response(javax.ws.rs.core.Response) PathParam(javax.ws.rs.PathParam) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) Path(javax.ws.rs.Path) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) StringUtils(org.apache.commons.lang3.StringUtils) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) MediaType(javax.ws.rs.core.MediaType) Future(java.util.concurrent.Future) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Charset(java.nio.charset.Charset) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) HeaderParam(javax.ws.rs.HeaderParam) URI(java.net.URI) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) AuthCheck(nl.knaw.huygens.timbuctoo.v5.dropwizard.endpoints.auth.AuthCheck) Either(javaslang.control.Either) POST(javax.ws.rs.POST) ImportManager(nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) ErrorResponseHelper.handleImportManagerResult(nl.knaw.huygens.timbuctoo.v5.dropwizard.endpoints.ErrorResponseHelper.handleImportManagerResult) ExecutionException(java.util.concurrent.ExecutionException) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) InputStream(java.io.InputStream) ImportManager(nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) MediaType(javax.ws.rs.core.MediaType) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) Consumes(javax.ws.rs.Consumes) POST(javax.ws.rs.POST)

Example 69 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project dwoss by gg-net.

the class GenerateOnePriceAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Ui.exec(() -> {
        Ui.build().title("Bitte SopoNr eingeben :").dialog().eval(() -> {
            TextInputDialog dialog = new TextInputDialog();
            dialog.setContentText("Bitte SopoNr eingeben :");
            return dialog;
        }).opt().filter(s -> !StringUtils.isBlank(s)).map(r -> ReplyUtil.wrap(() -> Dl.remote().lookup(Exporter.class).onePrice(r))).filter(Ui.failure()::handle).map(Reply::getPayload).ifPresent(p -> Ui.build().modality(WINDOW_MODAL).title("SopoNr").fx().show(() -> Css.toHtml5WithStyle(PriceEngineResultFormater.toSimpleHtml(p)), () -> new HtmlPane()));
    });
}
Also used : Css(eu.ggnet.dwoss.rules.Css) AccessableAction(eu.ggnet.saft.core.auth.AccessableAction) CREATE_ONE_PRICE(eu.ggnet.dwoss.rights.api.AtomicRight.CREATE_ONE_PRICE) Ui(eu.ggnet.saft.Ui) ActionEvent(java.awt.event.ActionEvent) StringUtils(org.apache.commons.lang3.StringUtils) Dl(eu.ggnet.saft.Dl) ReplyUtil(eu.ggnet.dwoss.common.ReplyUtil) TextInputDialog(javafx.scene.control.TextInputDialog) Reply(eu.ggnet.saft.api.Reply) WINDOW_MODAL(javafx.stage.Modality.WINDOW_MODAL) HtmlPane(eu.ggnet.dwoss.util.HtmlPane) PriceEngineResultFormater(eu.ggnet.dwoss.price.engine.support.PriceEngineResultFormater) HtmlPane(eu.ggnet.dwoss.util.HtmlPane) TextInputDialog(javafx.scene.control.TextInputDialog)

Example 70 with StringUtils.isBlank

use of org.apache.commons.lang3.StringUtils.isBlank in project dwoss by gg-net.

the class ScrapUnitAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Ui.exec(() -> {
        Ui.build().title("SopoNr die verschrottet werden soll").dialog().eval(() -> {
            TextInputDialog dialog = new TextInputDialog();
            dialog.setContentText("SopoNr die verschrottet werden soll:");
            return dialog;
        }).opt().filter(s -> !StringUtils.isBlank(s)).ifPresent(r -> {
            Ui.build().dialog().eval(() -> new Alert(CONFIRMATION, "SopoNr " + r + " wirklich verschrotten ?")).opt().filter(b -> b == OK).map(u -> ReplyUtil.wrap(() -> Dl.remote().lookup(UnitDestroyer.class).verifyScarpOrDeleteAble(r))).filter(Ui.failure()::handle).map(Reply::getPayload).ifPresent(u -> {
                Ui.build().title("Bitte Grund angeben").dialog().eval(() -> {
                    TextInputDialog dialog = new TextInputDialog();
                    dialog.setContentText("Bitte Grund angeben");
                    dialog.getDialogPane().lookupButton(OK).disableProperty().bind(Bindings.createBooleanBinding(() -> dialog.getEditor().getText().trim().isEmpty(), dialog.getEditor().textProperty()));
                    return dialog;
                }).opt().filter(s -> !StringUtils.isBlank(s)).ifPresent(c -> {
                    Dl.remote().lookup(UnitDestroyer.class).scrap(u, c, Dl.local().lookup(Guardian.class).getUsername());
                    Ui.build().alert().message("SopoNr " + r + " ist verschrottet.").show(AlertType.INFO);
                });
            });
        });
    });
}
Also used : Alert(javafx.scene.control.Alert) UPDATE_UNIQUE_UNIT_TO_SCRAP_UNIT(eu.ggnet.dwoss.rights.api.AtomicRight.UPDATE_UNIQUE_UNIT_TO_SCRAP_UNIT) AccessableAction(eu.ggnet.saft.core.auth.AccessableAction) Ui(eu.ggnet.saft.Ui) ActionEvent(java.awt.event.ActionEvent) Bindings(javafx.beans.binding.Bindings) StringUtils(org.apache.commons.lang3.StringUtils) Dl(eu.ggnet.saft.Dl) CONFIRMATION(javafx.scene.control.Alert.AlertType.CONFIRMATION) Guardian(eu.ggnet.saft.core.auth.Guardian) AlertType(eu.ggnet.saft.core.ui.AlertType) ReplyUtil(eu.ggnet.dwoss.common.ReplyUtil) TextInputDialog(javafx.scene.control.TextInputDialog) Reply(eu.ggnet.saft.api.Reply) UnitDestroyer(eu.ggnet.dwoss.receipt.ee.UnitDestroyer) OK(javafx.scene.control.ButtonType.OK) Alert(javafx.scene.control.Alert) UnitDestroyer(eu.ggnet.dwoss.receipt.ee.UnitDestroyer) TextInputDialog(javafx.scene.control.TextInputDialog)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)54 List (java.util.List)33 Collectors (java.util.stream.Collectors)29 Map (java.util.Map)28 Set (java.util.Set)27 ArrayList (java.util.ArrayList)23 Optional (java.util.Optional)22 Collections (java.util.Collections)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 IOException (java.io.IOException)18 HashSet (java.util.HashSet)18 Collection (java.util.Collection)16 HashMap (java.util.HashMap)16 StopWatch (org.apache.commons.lang3.time.StopWatch)13 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Slf4j (lombok.extern.slf4j.Slf4j)10 InputStream (java.io.InputStream)9 Inject (javax.inject.Inject)8 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)7