Example usage for org.apache.commons.lang3 StringUtils upperCase

List of usage examples for org.apache.commons.lang3 StringUtils upperCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils upperCase.

Prototype

public static String upperCase(final String str) 

Source Link

Document

Converts a String to upper case as per String#toUpperCase() .

A null input String returns null .

 StringUtils.upperCase(null)  = null StringUtils.upperCase("")    = "" StringUtils.upperCase("aBc") = "ABC" 

Note: As described in the documentation for String#toUpperCase() , the result of this method is affected by the current locale.

Usage

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

/** Gets a PipelineDefinition by name (case-insensitive). */
@Override//from   w w w.  j  a  v a2  s . c  om
public PipelineDefinition getPipeline(String name) {
    return pipelines.get(StringUtils.upperCase(name));
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

private void addAlgorithm(AlgorithmDefinition algorithm) {
    setAlgorithmDefaultValues(algorithm);

    validateAlgorithm(algorithm);/*from  w w  w. ja  v  a  2s.  c  om*/
    log.debug("{}: Adding algorithm", StringUtils.upperCase(algorithm.getName()));
    algorithms.put(StringUtils.upperCase(algorithm.getName()), algorithm);
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

private void addAction(ActionDefinition actionNode) {
    validateAction(actionNode);/*  ww  w .j ava  2s. co  m*/
    log.debug("{}: Adding action", StringUtils.upperCase(actionNode.getName()));
    actions.put(StringUtils.upperCase(actionNode.getName()), actionNode);
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

private void addTask(TaskDefinition task) {
    validateTask(task);//from  w  ww . jav a2 s . c om

    log.debug("{}: Adding task", StringUtils.upperCase(task.getName()));
    tasks.put(StringUtils.upperCase(task.getName()), task);
    for (ActionDefinitionRef actionRef : task.getActions()) {
        AlgorithmDefinition algorithm = getAlgorithm(actionRef);
        String taskName = StringUtils.upperCase(task.getName());

        if (algorithm.getProvidesCollection() != null
                && algorithm.getProvidesCollection().getStates() != null) {
            providedTaskStates.put(taskName, algorithm.getProvidesCollection().getStates());
        } else {
            providedTaskStates.put(taskName, Collections.emptySet());
        }

        if (algorithm.getRequiresCollection() != null
                && algorithm.getRequiresCollection().getStateRefs() != null) {
            requiredTaskStates.put(taskName, algorithm.getRequiresCollection().getStateRefs());
        } else {
            requiredTaskStates.put(taskName, Collections.emptySet());
        }
    }
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

private void addPipeline(PipelineDefinition pipeline) {
    validatePipeline(pipeline);// w ww .j a  v a2  s. c  o m
    log.debug("{}: Adding pipeline", StringUtils.upperCase(pipeline.getName()));
    pipelines.put(StringUtils.upperCase(pipeline.getName()), pipeline);
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

/** Check that the algorithm is not null, is valid, and has a name which has not already been added to the PipelineManager instance. Returns false if the algorithm is not valid.*/
private void validateAlgorithm(AlgorithmDefinition algorithm) {
    if (algorithm == null) {
        throw new CannotBeNullWfmProcessingException("Algorithm cannot be null.");
    } else if (!algorithm.isValid()) {
        throw new InvalidPipelineObjectWfmProcessingException("Algorithm is not valid.");
    } else if (getAlgorithm(algorithm.getName()) != null) {
        throw new DuplicateNameWfmProcessingException(
                StringUtils.upperCase(algorithm.getName()) + ": algorithm name is already in use.");
    }//from w w  w.  j  ava2 s  . com
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

/** Check that the task is not null, is valid, references an algorithm which already exists in the PipelineManager, has a name which has not already been added to the PipelineManager instance, and has properties associated with it which are valid for the referenced algorithm. Returns false if the action is invalid. */
private void validateAction(ActionDefinition actionDefinition) {
    if (actionDefinition == null) {
        throw new CannotBeNullWfmProcessingException("Action cannot be null.");
    } else if (!actionDefinition.isValid()) {
        throw new InvalidPipelineObjectWfmProcessingException("Action is not valid.");
    } else if (getAlgorithm(actionDefinition) == null) {
        throw new InvalidPropertyWfmProcessingException(StringUtils.upperCase(actionDefinition.getName())
                + ": referenced algorithm " + actionDefinition.getAlgorithmRef() + " does not exist.");
    } else if (getAction(actionDefinition.getName()) != null) {
        throw new DuplicateNameWfmProcessingException(
                StringUtils.upperCase(actionDefinition.getName()) + ": action name is already in use.");
    } else {/*from ww  w  .j  av  a  2s.co m*/
        // If this action provided any properties...
        if (actionDefinition.getProperties() != null) {
            AlgorithmDefinition algorithm = getAlgorithm(actionDefinition);

            // For each property (we've already verified the completeness of this set)...
            for (PropertyDefinitionRef propertyValue : actionDefinition.getProperties()) {

                if (!algorithm.getProvidesCollection().getAlgorithmProperties().contains(propertyValue)) {
                    // If the referenced property in the action doesn't exist in the algorithm's definition...
                    log.error("{}: The referenced algorithm ({}) does not expose the property {}.",
                            actionDefinition.getName(), actionDefinition.getAlgorithmRef(),
                            propertyValue.getName());
                    throw new InvalidPropertyWfmProcessingException(new StringBuilder()
                            .append(actionDefinition.getName()).append(": The referenced algorithm (")
                            .append(actionDefinition.getAlgorithmRef())
                            .append(") does not expose the property ").append(propertyValue.getName())
                            .append(".").toString());
                } else if (!isValidValueForType(propertyValue.getValue(), algorithm.getProvidesCollection()
                        .getAlgorithmProperty(propertyValue.getName()).getType())) {
                    // Otherwise, if the provided value for the property is not acceptable given the property's defined type...
                    log.error("{}.{}: The provided value of '{}' cannot be converted to type {}.",
                            actionDefinition.getName(), propertyValue.getName(), propertyValue.getValue(),
                            algorithm.getProvidesCollection().getAlgorithmProperty(propertyValue.getName())
                                    .getType());
                    throw new InvalidPropertyWfmProcessingException(
                            new StringBuilder().append(actionDefinition.getName()).append(".")
                                    .append(propertyValue.getName()).append(": The provided value of '")
                                    .append(propertyValue.getValue()).append("' cannot be converted to type ")
                                    .append(algorithm.getProvidesCollection()
                                            .getAlgorithmProperty(propertyValue.getName()).getType())
                                    .append(".").toString());
                }
            }
        } else {
            log.debug("{}: no properties were provided", actionDefinition.getName());
        }
    }
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

/** Check that the task is not null, is valid, has a name which has not already been added to the PipelineManager,
 *  references only actions which have already been added to the PipelineManager,
 *  all actions support either batch or streaming, and if more than one action is specified,
 *  check that all referenced actions are of the same Operation.
 *//*from w w  w .  jav  a  2 s . c  om*/
private void validateTask(TaskDefinition task) {
    if (task == null) {
        throw new CannotBeNullWfmProcessingException("Task cannot be null.");
    } else if (!task.isValid()) {
        throw new InvalidPipelineObjectWfmProcessingException("Task is not valid.");
    } else if (getTask(task.getName()) != null) {
        throw new DuplicateNameWfmProcessingException(
                StringUtils.upperCase(task.getName()) + ": task name is already in use.");
    } else {
        ActionType actionType = null;

        for (ActionDefinitionRef actionRef : task.getActions()) {
            if (getAction(actionRef) == null) {
                log.error("{}: The referenced action ({}) does not exist",
                        StringUtils.upperCase(task.getName()), StringUtils.upperCase(actionRef.getName()));
                throw new InvalidActionWfmProcessingException(
                        new StringBuilder().append(task.getName()).append(": The referenced action (")
                                .append(actionRef.getName()).append(") does not exist.").toString());
            } else if (actionType == null) {
                // First time through - set the action type. Remember, algorithms MUST have an ActionType associated with them, so this is okay.
                actionType = getAlgorithm(actionRef).getActionType();
            } else {
                // Not first time through - check that the current action uses the same action type as the first action in the task.
                ActionType otherActionType = null;
                if (actionType != (otherActionType = getAlgorithm(actionRef).getActionType())) {
                    log.error(
                            "{}: task cannot contain actions which have different ActionTypes. The first ActionType for this task was {}, but {} has an ActionType of {}.",
                            task.getName(), actionType, actionRef.getName(), otherActionType);
                    throw new InvalidActionWfmProcessingException(new StringBuilder().append(task.getName())
                            .append(": task cannot contain actions which have different ActionTypes. The first ActionType for this task was ")
                            .append(actionType).append(", but ").append(actionRef.getName())
                            .append(" has an ActionType of ").append(otherActionType).append(".").toString());
                }
            }
        }

        boolean supportsBatch = task.getActions().stream().allMatch(adr -> actionSupportsBatch(adr.getName()));
        if (!supportsBatch) {
            boolean supportsStreaming = task.getActions().stream()
                    .allMatch(adr -> actionSupportsStreaming(adr.getName()));
            if (!supportsStreaming) {
                throw new InvalidTaskWfmProcessingException(String.format(
                        "The %s task does not fully support batch or stream processing", task.getName()));
            }
        }
    }
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

/** Check that the pipeline is not null, is valid, has a name which is unique in the PipelineManager,
 *  references valid tasks, that the states (using provides/requires) are valid for the proposed sequence of
 *  tasks, and all of the tasks support either batch or streaming.
 *//*w w  w . j a  v a 2  s  .  c  o m*/
private void validatePipeline(PipelineDefinition pipeline) {
    if (pipeline == null) {
        throw new CannotBeNullWfmProcessingException("Pipeline cannot be null.");
    } else if (!pipeline.isValid()) {
        throw new InvalidPipelineObjectWfmProcessingException("Pipeline is not valid.");
    } else if (getPipeline(pipeline.getName()) != null) {
        throw new DuplicateNameWfmProcessingException(
                StringUtils.upperCase(pipeline.getName()) + ": pipeline name is already in use.");
    }
    validateTasks(StringUtils.upperCase(pipeline.getName()), pipeline.getTaskRefs());

    boolean supportsBatch = pipeline.getTaskRefs().stream().allMatch(tdr -> taskSupportsBatch(tdr.getName()));
    if (!supportsBatch) {
        boolean supportsStreaming = pipeline.getTaskRefs().stream()
                .allMatch(tdr -> taskSupportsStreaming(tdr.getName()));

        if (!supportsStreaming) {
            throw new InvalidPipelineObjectWfmProcessingException(
                    String.format("The %s pipeline does not full support batch processing or stream processing",
                            pipeline.getName()));
        }
    }
}

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

private void validateDetectionPipeline(String pipelineName, List<TaskDefinitionRef> taskDefinitions,
        Set<StateDefinition> currentStates) {
    if (taskDefinitions.size() == 1) {
        // There's only one task in the pipeline, and we know it to be detection.
        boolean rValue = true;
        Set<StateDefinitionRef> requiredStates = requiredTaskStates
                .get(StringUtils.upperCase(taskDefinitions.get(0).getName()));
        if (!currentStates.containsAll(requiredStates)) {
            log.error("{}: The states for {} are not satisfied. Current: {}. Required: {}.", pipelineName,
                    taskDefinitions.get(0).getName(), currentStates, requiredStates);
            throw new InvalidTaskWfmProcessingException(new StringBuilder().append(pipelineName)
                    .append(": The states for ").append(taskDefinitions.get(0).getName())
                    .append(" are not satisfied. Current: ").append(currentStates).append(". Required: ")
                    .append(requiredStates).append(".").toString());
        }/* w w w. j  a v  a2  s  . c o  m*/
    } else if (getTask(taskDefinitions.get(0)).getActions().size() > 1) {
        // There's more than one task, and the number of actions in the first task exceeds 1.
        log.error("{}: No tasks may follow the multi-detection task of {}.", pipelineName,
                taskDefinitions.get(0).getName());
        throw new InvalidTaskWfmProcessingException(new StringBuilder().append(pipelineName)
                .append(": No tasks may follow the multi-detection task of ")
                .append(taskDefinitions.get(0).getName()).append(".").toString());
    } else if (getTask(taskDefinitions.get(1)) == null) {
        // At this point, we've determined there's at least one more task. The next task name must exist.
        log.error("{}: Task with name {} does not exist.", pipelineName, taskDefinitions.get(1).getName());
        throw new InvalidTaskWfmProcessingException(
                new StringBuilder().append(pipelineName).append(": Task with name ")
                        .append(taskDefinitions.get(1).getName()).append(" does not exist.").toString());
    } else {
        currentStates.addAll(providedTaskStates.get(StringUtils.upperCase(taskDefinitions.get(0).getName())));
        ActionType nextTaskType = getTaskType(taskDefinitions.get(1));
        switch (nextTaskType) {
        case DETECTION:
            currentStates.clear(); // If the next task is detection-based, we should disregard the current states as we're downselecting.
            validateDetectionPipeline(pipelineName, taskDefinitions.subList(1, taskDefinitions.size()),
                    currentStates);
            return;
        case MARKUP:
            validateMarkupPipeline(pipelineName, taskDefinitions.subList(1, taskDefinitions.size()),
                    currentStates);
            return;
        default:
            log.error("{}: {} is a detection task and may not be followed by {}.", pipelineName,
                    taskDefinitions.get(0).getName(), taskDefinitions.get(1).getName());
            throw new InvalidTaskWfmProcessingException(new StringBuilder().append(pipelineName).append(": ")
                    .append(taskDefinitions.get(0).getName())
                    .append(" is a detection task and may not be followed by ")
                    .append(taskDefinitions.get(1).getName()).append(".").toString());
        }
    }
}