Example usage for org.apache.commons.collections4 CollectionUtils isEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is empty.

Usage

From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java

@Override
public CompositionEntityValidationData updateComponent(ComponentEntity component, String user) {
    Version activeVersion = getVersionInfo(component.getVspId(), VersionableEntityAction.Write, user)
            .getActiveVersion();//from   w  w w.ja  v  a  2s  .  com
    component.setVersion(activeVersion);
    ComponentEntity retrieved = getComponent(component.getVspId(), activeVersion, component.getId());

    ComponentCompositionSchemaInput schemaInput = new ComponentCompositionSchemaInput();
    schemaInput.setManual(isManual(component.getVspId(), activeVersion));
    schemaInput.setComponent(retrieved.getComponentCompositionData());

    CompositionEntityValidationData validationData = CompositionEntityDataManager.validateEntity(component,
            SchemaTemplateContext.composition, schemaInput);
    if (CollectionUtils.isEmpty(validationData.getErrors())) {
        vendorSoftwareProductDao.updateComponent(component);
    }

    vendorSoftwareProductDao.updateVspLatestModificationTime(component.getVspId(), activeVersion);

    return validationData;
}

From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java

@Override
public CompositionEntityValidationData updateNic(org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic,
        String user) {/*  w  ww .  j  a  v a  2 s. c  om*/
    Version activeVersion = getVersionInfo(nic.getVspId(), VersionableEntityAction.Write, user)
            .getActiveVersion();
    nic.setVersion(activeVersion);
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity retrieved = getNic(nic.getVspId(), activeVersion,
            nic.getComponentId(), nic.getId());

    NicCompositionSchemaInput schemaInput = new NicCompositionSchemaInput();
    schemaInput.setManual(isManual(nic.getVspId(), activeVersion));
    schemaInput.setNic(retrieved.getNicCompositionData());

    CompositionEntityValidationData validationData = CompositionEntityDataManager.validateEntity(nic,
            SchemaTemplateContext.composition, schemaInput);
    if (CollectionUtils.isEmpty(validationData.getErrors())) {
        vendorSoftwareProductDao.updateNic(nic);
    }

    vendorSoftwareProductDao.updateVspLatestModificationTime(nic.getVspId(), activeVersion);
    return validationData;
}

From source file:org.openecomp.sdc.vendorsoftwareproduct.services.CompositionDataExtractor.java

private static void handleSubstitutableNodeTemplate(ServiceTemplate serviceTemplate,
        ToscaServiceModel toscaServiceModel, String substitutableNodeTemplateId,
        NodeTemplate substitutableNodeTemplate, ExtractCompositionDataContext context) {
    ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
    Optional<String> substituteServiceTemplateFileName = toscaAnalyzerService
            .getSubstituteServiceTemplateName(substitutableNodeTemplateId, substitutableNodeTemplate);
    if (!substituteServiceTemplateFileName.isPresent()) {
        throw new CoreException(
                new ToscaInvalidSubstituteNodeTemplateErrorBuilder(substitutableNodeTemplateId).build());
    }/*from www.ja  v  a  2 s  .c o  m*/
    if (context.getHandledServiceTemplates().contains(substituteServiceTemplateFileName.get())) {
        return;
    }

    ServiceTemplate substituteServiceTemplate = toscaServiceModel.getServiceTemplates()
            .get(substituteServiceTemplateFileName.get());
    extractServiceCompositionData(substituteServiceTemplateFileName.get(), substituteServiceTemplate,
            toscaServiceModel, context);

    List<Map<String, RequirementAssignment>> substitutableRequirements = substitutableNodeTemplate
            .getRequirements();

    if (CollectionUtils.isEmpty(substitutableRequirements)) {
        return;
    }

    for (Map<String, RequirementAssignment> substitutableReq : substitutableRequirements) {
        substitutableReq.keySet().stream().filter(reqId -> {
            RequirementAssignment reqAssignment = toscaExtensionYamlUtil.yamlToObject(
                    toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)),
                    RequirementAssignment.class);
            return isLinkToNetworkRequirementAssignment(reqAssignment);
        }).forEach(reqId -> {
            RequirementAssignment linkToNetworkRequirement = toscaExtensionYamlUtil.yamlToObject(
                    toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)),
                    RequirementAssignment.class);
            String connectedNodeId = linkToNetworkRequirement.getNode();
            Optional<NodeTemplate> connectedNodeTemplate = toscaAnalyzerService
                    .getNodeTemplateById(serviceTemplate, connectedNodeId);

            if (connectedNodeTemplate.isPresent() && toscaAnalyzerService.isTypeOf(connectedNodeTemplate.get(),
                    ToscaNodeType.NETWORK.getDisplayName(), serviceTemplate, toscaServiceModel)) {
                Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService
                        .getSubstitutionMappedNodeTemplateByExposedReq(substituteServiceTemplateFileName.get(),
                                substituteServiceTemplate, reqId);
                if (!mappedNodeTemplate.isPresent()) {
                    throw new CoreException(new ToscaMissingSubstitutionMappingForReqCapErrorBuilder(
                            ToscaMissingSubstitutionMappingForReqCapErrorBuilder.MappingExposedEntry.REQUIREMENT,
                            connectedNodeId).build());
                }

                if (toscaAnalyzerService.isTypeOf(mappedNodeTemplate.get().getValue(),
                        ToscaNodeType.NETWORK_PORT.getDisplayName(), serviceTemplate, toscaServiceModel)) {
                    Nic port = context.getNics().get(mappedNodeTemplate.get().getKey());
                    if (port != null) {
                        port.setNetworkName(connectedNodeId);
                    } else {
                        logger.warn("Different ports define for the same component which is used in different "
                                + "substitution service templates.");
                    }
                }
            } else if (!connectedNodeTemplate.isPresent()) {
                throw new CoreException(
                        new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", connectedNodeId).build());
            }
        });
    }
}

From source file:org.openepics.discs.ccdb.core.ejb.ApplicationService.java

/**
 * Initializes the database with the bundled initial data on the first run of the application.
 *///www . j  a  v  a 2 s  . c o  m
@PostConstruct
public void init() {
    final List<Config> confList = em.createQuery("SELECT c from Config c WHERE c.name = :name", Config.class)
            .setParameter("name", "schema_version").getResultList();
    if (CollectionUtils.isEmpty(confList)) {
        initDB.initialPopulation();
        em.persist(new Config("schema_version", "1"));
    }
    checkDevicesTable();
    checkSlotsTable();
    checkUnitsTable();
}

From source file:org.openscore.lang.cli.utils.CompilerHelperImpl.java

@Override
public Map<String, ? extends Serializable> loadSystemProperties(List<String> systemPropertyFiles) {
    if (CollectionUtils.isEmpty(systemPropertyFiles))
        return null;
    SlangSource[] sources = new SlangSource[systemPropertyFiles.size()];
    for (int i = 0; i < systemPropertyFiles.size(); i++) {
        sources[i] = SlangSource.fromFile(new File(systemPropertyFiles.get(i)));
    }//from  w  w  w.  j a va2  s .c  o m
    return slang.loadSystemProperties(sources);
}

From source file:org.openscore.lang.compiler.modeller.ExecutableBuilder.java

public Executable transformToExecutable(ParsedSlang parsedSlang, String execName,
        Map<String, Object> executableRawData) {

    Validate.notEmpty(executableRawData, "Error compiling " + parsedSlang.getName()
            + ". Executable data for: \'" + execName + "\' is empty");
    Validate.notNull(parsedSlang, "Slang source for: \'" + execName + "\' is null");

    Map<String, Serializable> preExecutableActionData = new HashMap<>();
    Map<String, Serializable> postExecutableActionData = new HashMap<>();

    transformersHandler.validateKeyWords(execName, executableRawData,
            ListUtils.union(preExecTransformers, postExecTransformers), execAdditionalKeywords, null);

    preExecutableActionData.putAll(transformersHandler.runTransformers(executableRawData, preExecTransformers));
    postExecutableActionData//from   ww  w  .j  ava  2  s .c o m
            .putAll(transformersHandler.runTransformers(executableRawData, postExecTransformers));

    @SuppressWarnings("unchecked")
    List<Input> inputs = (List<Input>) preExecutableActionData.remove(INPUTS_KEY);
    @SuppressWarnings("unchecked")
    List<Output> outputs = (List<Output>) postExecutableActionData.remove(OUTPUTS_KEY);
    @SuppressWarnings("unchecked")
    List<Result> results = (List<Result>) postExecutableActionData.remove(RESULTS_KEY);

    String namespace = parsedSlang.getNamespace();
    Map<String, String> imports = parsedSlang.getImports();
    Set<String> dependencies;
    switch (parsedSlang.getType()) {
    case FLOW:

        if (!executableRawData.containsKey(WORKFLOW_KEY)) {
            throw new RuntimeException("Error compiling " + parsedSlang.getName() + ". Flow: " + execName
                    + " has no workflow property");
        }
        List<Map<String, Map<String, Object>>> workFlowRawData;
        try {
            workFlowRawData = (List) executableRawData.get(WORKFLOW_KEY);
        } catch (ClassCastException ex) {
            throw new RuntimeException("Flow: '" + execName
                    + "' syntax is illegal.\nBelow 'workflow' property there should be a list of tasks and not a map");
        }
        if (CollectionUtils.isEmpty(workFlowRawData)) {
            throw new RuntimeException("Error compiling " + parsedSlang.getName() + ". Flow: " + execName
                    + " has no workflow data");
        }

        Workflow onFailureWorkFlow = null;
        List<Map<String, Map<String, Object>>> onFailureData;
        Iterator<Map<String, Map<String, Object>>> tasksIterator = workFlowRawData.iterator();
        while (tasksIterator.hasNext()) {
            Map<String, Map<String, Object>> taskData = tasksIterator.next();
            String taskName = taskData.keySet().iterator().next();
            if (taskName.equals(ON_FAILURE_KEY)) {
                try {
                    onFailureData = (List<Map<String, Map<String, Object>>>) taskData.values().iterator()
                            .next();
                } catch (ClassCastException ex) {
                    throw new RuntimeException("Flow: '" + execName
                            + "' syntax is illegal.\nBelow 'on_failure' property there should be a list of tasks and not a map");
                }
                if (CollectionUtils.isNotEmpty(onFailureData)) {
                    onFailureWorkFlow = compileWorkFlow(onFailureData, imports, null, true);
                }
                tasksIterator.remove();
                break;
            }
        }

        Workflow workflow = compileWorkFlow(workFlowRawData, imports, onFailureWorkFlow, false);
        dependencies = fetchDirectTasksDependencies(workflow);
        return new Flow(preExecutableActionData, postExecutableActionData, workflow, namespace, execName,
                inputs, outputs, results, dependencies);

    case OPERATION:
        Map<String, Object> actionRawData;
        try {
            actionRawData = (Map<String, Object>) executableRawData.get(ACTION_KEY);
        } catch (ClassCastException ex) {
            throw new RuntimeException("Operation: '" + execName
                    + "' syntax is illegal.\nBelow 'action' property there should be a map of values such as: 'python_script:' or 'java_action:'");
        }

        if (MapUtils.isEmpty(actionRawData)) {
            throw new RuntimeException("Error compiling " + parsedSlang.getName() + ". Operation: " + execName
                    + " has no action data");
        }
        Action action = compileAction(actionRawData);
        dependencies = new HashSet<>();
        return new Operation(preExecutableActionData, postExecutableActionData, action, namespace, execName,
                inputs, outputs, results, dependencies);
    default:
        throw new RuntimeException(
                "Error compiling " + parsedSlang.getName() + ". It is not of flow or operations type");
    }
}

From source file:org.openscore.lang.compiler.modeller.transformers.AbstractOutputsTransformer.java

public List<Output> transform(List<Object> rawData) {

    List<Output> outputs = new ArrayList<>();
    if (CollectionUtils.isEmpty(rawData)) {
        return outputs;
    }// ww  w .j  a va  2 s  . com
    for (Object rawOutput : rawData) {
        if (rawOutput instanceof Map) {
            @SuppressWarnings("unchecked")
            Map.Entry<String, ?> entry = (Map.Entry<String, ?>) (((Map) rawOutput).entrySet()).iterator()
                    .next();
            // - some_output: some_expression
            // the value of the input is an expression we need to evaluate at runtime
            if (entry.getValue() instanceof String) {
                outputs.add(createExpressionOutput(entry.getKey(), (String) entry.getValue()));
            } else {
                throw new RuntimeException(
                        "The value of outputs and publish parameters must be an expression. For: "
                                + entry.getKey() + " the value: " + entry.getValue() + " is not supported");
            }
        } else {
            //- some_output
            //this is our default behavior that if the user specifies only a key, the key is also the ref we look for
            outputs.add(createRefOutput((String) rawOutput));
        }
    }
    return outputs;
}

From source file:org.openscore.lang.compiler.modeller.transformers.InputsTransformer.java

/**
 * Transforms a list of inputs in (raw data form) to Input objects.
 * @param rawData : inputs as described in Yaml source.
 * @return : list of inputs after transformation.
 *///from w  ww  . j  a v  a2 s  . c  o m
@Override
public List<Input> transform(List<Object> rawData) {
    List<Input> result = new ArrayList<>();
    if (CollectionUtils.isEmpty(rawData)) {
        return result;
    }
    for (Object rawInput : rawData) {
        Input input = transformSingleInput(rawInput);
        result.add(input);
    }
    return result;
}

From source file:org.openscore.lang.compiler.modeller.transformers.ResultsTransformer.java

@Override
public List<Result> transform(List rawData) {
    List<Result> results = new ArrayList<>();
    // If there are no results specified, add the default SUCCESS & FAILURE results
    if (CollectionUtils.isEmpty(rawData)) {
        results.add(createNoExpressionResult(ScoreLangConstants.SUCCESS_RESULT));
        results.add(createNoExpressionResult(ScoreLangConstants.FAILURE_RESULT));
        return results;
    }/* w w  w .j  av a2s .c  o m*/
    for (Object rawResult : rawData) {
        if (rawResult instanceof String) {
            //- some_result
            results.add(createNoExpressionResult((String) rawResult));
        } else if (rawResult instanceof Map) {
            // - some_result: some_expression
            // the value of the result is an expression we need to evaluate at runtime
            @SuppressWarnings("unchecked")
            Map.Entry<String, ?> entry = (Map.Entry<String, ?>) (((Map) rawResult).entrySet()).iterator()
                    .next();
            if (entry.getValue() instanceof Boolean) {
                results.add(createExpressionResult(entry.getKey(), String.valueOf(entry.getValue())));
            } else {
                results.add(createExpressionResult(entry.getKey(), (String) entry.getValue()));
            }
        }
    }
    return results;
}

From source file:org.openscore.lang.compiler.scorecompiler.ExecutionPlanBuilder.java

public ExecutionPlan createFlowExecutionPlan(Flow compiledFlow) {
    ExecutionPlan executionPlan = new ExecutionPlan();
    executionPlan.setName(compiledFlow.getName());
    executionPlan.setLanguage(SLANG_NAME);
    executionPlan.setFlowUuid(compiledFlow.getId());

    executionPlan.setBeginStep(FLOW_START_STEP_ID);
    //flow start step
    executionPlan.addStep(stepFactory.createStartStep(FLOW_START_STEP_ID, compiledFlow.getPreExecActionData(),
            compiledFlow.getInputs(), compiledFlow.getName()));
    //flow end step
    executionPlan.addStep(stepFactory.createEndStep(FLOW_END_STEP_ID, compiledFlow.getPostExecActionData(),
            compiledFlow.getOutputs(), compiledFlow.getResults(), compiledFlow.getName()));

    Map<String, Long> taskReferences = new HashMap<>();
    for (Result result : compiledFlow.getResults()) {
        taskReferences.put(result.getName(), FLOW_END_STEP_ID);
    }//w  ww  .j a  va2  s.  c o m

    Deque<Task> tasks = compiledFlow.getWorkflow().getTasks();

    if (CollectionUtils.isEmpty(tasks)) {
        throw new RuntimeException("Flow: " + compiledFlow.getName() + " has no tasks");
    }

    List<ExecutionStep> taskExecutionSteps = buildTaskExecutionSteps(tasks.getFirst(), taskReferences, tasks);
    executionPlan.addSteps(taskExecutionSteps);

    return executionPlan;
}