Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:org.pentaho.big.data.kettle.plugins.sqoop.SqoopUtils.java

private static void appendCustomArgument(List<String> args, PropertyEntry arg, VariableSpace variableSpace,
        boolean quote) {
    String key = arg.getKey();/*from   w  w  w.j  a  v  a 2  s.c  o  m*/
    String value = arg.getValue();

    // ignore if both key and value are blank
    if (StringUtils.isBlank(key) && StringUtils.isBlank(value)) {
        return;
    }

    key = StringUtils.defaultIfBlank(arg.getKey(), "null");
    value = StringUtils.defaultIfBlank(arg.getValue(), "null");

    if (variableSpace != null) {
        key = variableSpace.environmentSubstitute(key);
        value = variableSpace.environmentSubstitute(value);
    }

    if (quote) {
        value = quote(escapeBackslash(value));
    }

    args.add(ARG_D);
    args.add(key + EQUALS + value);
}

From source file:org.pentaho.di.job.entries.build.JobEntryBuildModel.java

/**
 * Searches for tags on output steps to determine physical layer. Then, auto-models to generate the logical layer.
 * This method can be called during design time or run time.
 * //  w w w . jav  a  2  s .c  om
 * @param jobMeta
 * @return
 * @throws KettleException
 */
public String buildXmi(JobMeta jobMeta, String outputStep, final String modelName) throws KettleException {

    if (StringUtils.isEmpty(outputStep)) {
        throw new KettleException(this.getMsg("BuildModelJob.Missing.OutputStep"));
    }

    if (StringUtils.isEmpty(modelName)) {
        throw new KettleException(this.getMsg("BuildModelJob.Missing.ModelName"));
    }

    DatabaseMeta dbMeta = getConnectionInfo().getDatabaseMeta();
    String schemaName = StringUtils.defaultIfBlank(environmentSubstitute(getConnectionInfo().getSchemaName()),
            "");
    String tableName = environmentSubstitute(getConnectionInfo().getTableName());

    TableModelerSource source = new TableModelerSource(dbMeta, tableName, schemaName); //$NON-NLS-1$
    source.setSchemaName(StringUtils.defaultIfBlank(source.getSchemaName(), ""));
    try {
        Domain modeledDomain;
        PhysicalTableImporter.ImportStrategy importStrategy = getImportStrategy();

        final ModelAnnotationGroup modelAnnotations = getModelAnnotations();

        if (useExistingModel()) {
            String existingModelId = environmentSubstitute(getSelectedModel());
            ModelServerFetcher fetcher = getModelServerFetcher();
            // model can be created/deleted in between checking and fetching, but there is no sure way to tell
            // if a model doesn't exist or some other error occurred
            if (!modelExists(existingModelId, fetcher)) {
                if (isCreateOnPublish()) {
                    logBasic(getMsg("BuildModelJob.Info.ModelNotFound", existingModelId));
                    modeledDomain = getDswModeler().createModel(modelName, source, dbMeta, importStrategy,
                            modelAnnotations, getMetaStore());
                } else {
                    if (Const.isEmpty(existingModelId)) {
                        throw new KettleException(getMsg("BuildModelJob.Error.ModelNullNotFound", getName()));
                    } else {
                        throw new KettleException(getMsg("BuildModelJob.Error.ModelNotFound", existingModelId));
                    }
                }
            } else {
                final Domain templateModel = fetcher.downloadDswFile(existingModelId);
                modeledDomain = getDswModeler().updateModel(modelName, templateModel, dbMeta, schemaName,
                        tableName);
            }
        } else {
            modeledDomain = getDswModeler().createModel(modelName, source, dbMeta, importStrategy,
                    modelAnnotations, getMetaStore());
        }
        XmiParser parser = new XmiParser();
        String localXmi = parser.generateXmi(modeledDomain);
        return localXmi;
    } catch (AuthorizationException e) {
        throw new KettleException(getMsg("BuildModelJob.Error.Authorization"));
    } catch (ServerException e) {
        throw new KettleException(getMsg("BuildModelJob.Error.ErrorFetchingModel"));
    } catch (ColumnMismatchException e) {
        throw new KettleException(getMsg("BuildModelJob.Error.CannotUpdateModel",
                getMsg("BuildModelJob.Error.UnmatchedColumn", e.getColumnName(), e.getDataType())));
    } catch (UnsupportedModelException e) {
        throw new KettleException(getMsg("BuildModelJob.Error.CannotUpdateModel",
                getMsg("BuildModelJob.Error.UnsupportedModel")));
    } catch (Exception e) {
        throw new KettleException(e);
    }
}

From source file:org.pentaho.di.ui.trans.steps.annotation.BaseAnnotationStepDialog.java

protected Control createDescription(Control topWidget) {
    Label wlDescription = new Label(shell, SWT.LEFT);
    wlDescription.setText(BaseMessages.getString(PKG, "SharedDimension.Dialog.Description.Label"));
    props.setLook(wlDescription);//from  w  w w. ja va2 s  .  c  o  m

    FormData fdlDescription = new FormData();
    fdlDescription.top = new FormAttachment(topWidget, 10);
    fdlDescription.left = new FormAttachment(0, LEFT_MARGIN_OFFSET);
    fdlDescription.right = new FormAttachment(100, RIGHT_MARGIN_OFFSET);
    wlDescription.setLayoutData(fdlDescription);

    wDescription = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP);
    props.setLook(wDescription);

    FormData fdDescription = new FormData();
    fdDescription.height = 50;
    fdDescription.top = new FormAttachment(wlDescription, 5);
    fdDescription.left = new FormAttachment(0, LEFT_MARGIN_OFFSET);
    fdDescription.right = new FormAttachment(100, RIGHT_MARGIN_OFFSET);
    wDescription.setLayoutData(fdDescription);

    // Add Listener
    wDescription.addListener(SWT.FocusOut, new Listener() {
        @Override
        public void handleEvent(Event event) {
            if (input.getModelAnnotations() != null && textChanged(wDescription,
                    StringUtils.defaultIfBlank(input.getModelAnnotations().getDescription(), ""))) {
                modelAnnotationDirty = true;
                onModelAnnotationDirty();
            }
        }
    });

    return wDescription;
}

From source file:org.pentaho.di.ui.trans.steps.annotation.BaseAnnotationStepDialog.java

protected void populateTable(final ModelAnnotationGroup modelAnnotations) {
    getTableComposite().populateTable(modelAnnotations, transMeta, stepname, shell);
    if (wDescription != null && modelAnnotations != null) {
        wDescription.setText(StringUtils.defaultIfBlank(modelAnnotations.getDescription(), ""));
    }//from www  .  ja v a2 s.  c  o m
}

From source file:org.pentaho.di.ui.trans.steps.annotation.BaseAnnotationStepDialog.java

protected void linkAnnotations(final ComboVar combo, final String groupName, final String description) {
    removeItem(combo, groupName);/*from   w w  w.j  a v  a 2  s  . c  o  m*/
    combo.add(groupName);
    combo.select(combo.getItemCount() - 1);
    if (wDescription != null) {
        wDescription.setText(StringUtils.defaultIfBlank(description, ""));
    }
    (getTableComposite().getData()).setDescription(description);
    (getTableComposite().getData()).setName(groupName);
    modelAnnotationDirty = true;
    onLinkAnnotations();
}

From source file:org.pentaho.di.ui.trans.steps.annotation.ModelAnnotationActionPropertiesDialog.java

@Override
protected void initializeListeners() {

    super.initializeListeners();

    comboValuesSelectionListener = new ComboValuesSelectionListener() {
        @Override//  w ww .j  a v a2s.c o  m
        public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
            try {

                String name = tableItem.getText(1);

                if (StringUtils.isNotBlank(name)) {

                    // Use currently loaded model in the table
                    final AnnotationType at = annotationType;
                    final Class propertyClassType = at.getModelPropertyNameClassType(name);

                    // Parent options
                    if (name.equals(CreateAttribute.PARENT_ATTRIBUTE_NAME)) {
                        List<String> names = new ArrayList<String>();
                        for (ModelAnnotation m : getModifiedModelAnnotations()) {
                            if (ModelAnnotation.Type.CREATE_ATTRIBUTE.equals(m.getType())) {
                                if (StringUtils.isNotBlank(m.getAnnotation().getName())) {
                                    // Do not include self
                                    if (!StringUtils.equals(at.getName(), m.getAnnotation().getName())) {
                                        names.add(m.getAnnotation().getName()); // return display names
                                    }
                                }
                            }
                        }
                        return names.toArray(new String[names.size()]);
                    }

                    // Dimension options
                    if (name.equals(CreateAttribute.DIMENSION_NAME)) {
                        LinkedHashSet<String> names = new LinkedHashSet<String>();
                        for (ModelAnnotation<?> m : getModifiedModelAnnotations()) {
                            // Do not include self
                            if (m.getAnnotation() != null && StringUtils.isNotBlank(m.getAnnotation().getName())
                                    && !at.equals(m.getAnnotation())) {
                                // return dimension names
                                if (ModelAnnotation.Type.CREATE_ATTRIBUTE.equals(m.getType())) {
                                    names.add(((CreateAttribute) m.getAnnotation()).getDimension());
                                } else if (ModelAnnotation.Type.CREATE_DIMENSION_KEY.equals(m.getType())) {
                                    names.add(((CreateDimensionKey) m.getAnnotation()).getDimension());
                                }
                            }
                        }
                        return names.toArray(new String[names.size()]);
                    }

                    // Hierarchy options
                    if (name.equals(CreateAttribute.HIERARCHY_NAME)) {
                        LinkedHashSet<String> names = new LinkedHashSet<String>();
                        for (ModelAnnotation m : getModifiedModelAnnotations()) {
                            if (ModelAnnotation.Type.CREATE_ATTRIBUTE.equals(m.getType())) {
                                if (StringUtils.isNotBlank(m.getAnnotation().getName())) {
                                    // Do not include self
                                    if (!StringUtils.equals(at.getName(), m.getAnnotation().getName())) {
                                        String hierarchy = ((CreateAttribute) m.getAnnotation()).getHierarchy();
                                        if (StringUtils.isNotBlank(hierarchy)) {
                                            names.add(hierarchy);
                                        }
                                    }
                                }
                            }
                        }
                        return names.toArray(new String[names.size()]);
                    }

                    // Time Type options
                    if (name.equals(CreateAttribute.TIME_TYPE_NAME) && (propertyClassType != null)
                            && propertyClassType.equals(ModelAnnotation.TimeType.class)) {
                        return ModelAnnotation.TimeType.names();
                    }

                    // GeoType options
                    if (name.equals(CreateAttribute.GEO_TYPE_NAME) && (propertyClassType != null)
                            && propertyClassType.equals(ModelAnnotation.GeoType.class)) {
                        return ModelAnnotation.GeoType.names();
                    }

                    // Time Format String options
                    if (name.equals(CreateAttribute.TIME_FORMAT_NAME)) {
                        String timeType = StringUtils
                                .defaultIfBlank(findTableItemValue(CreateAttribute.TIME_TYPE_NAME), "");
                        return optionsResolver.resolveTimeSourceFormatOptions(timeType);
                    }

                    // Ordinal Field options
                    if (name.equals(CreateAttribute.ORDINAL_FIELD_NAME)) {
                        return optionsResolver.resolveOrdinalFieldOptions(transMeta, stepname,
                                getModelAnnotation());
                    }

                    // Measure Format String options
                    if (name.equals(CreateMeasure.FORMAT_STRING_NAME)) {
                        return optionsResolver.resolveMeasureFormatOptions();
                    }

                    // AggregationType options
                    if (name.equals(CreateMeasure.AGGREGATE_TYPE_NAME) && (propertyClassType != null)
                            && propertyClassType.equals(AggregationType.class)) {
                        return optionsResolver.resolveAggregationTypeOptions(getValueMeta(), at);
                    }

                    // Boolean Type options
                    if (propertyClassType != null && (propertyClassType.equals(Boolean.class)
                            || propertyClassType.equals(boolean.class))) {
                        return optionsResolver.resolveBooleanOptions();
                    }

                    if (name.equals(LinkDimension.SHARED_DIMENSION_NAME)) {
                        return optionsResolver.resolveSharedDimensions(new ModelAnnotationManager(true),
                                getMetaStore());
                    }
                }

            } catch (Exception e) {
                logError(e.getMessage());
            }

            return new String[0];
        }
    };
}

From source file:org.pentaho.di.ui.trans.steps.annotation.ModelAnnotationActionPropertiesDialog.java

public void populateDialog() {
    populateActionList();/*from   w w w . j ava 2 s .  co m*/
    if (getModelAnnotation() == null) {
        return;
    }

    wField.setText(StringUtils.defaultIfBlank(getModelAnnotation().getField(), ""));

    if (getModelAnnotation().getAnnotation() != null) {
        wActionList.setText(getModelAnnotation().getAnnotation().getType().description());
        if (wActionList.getData(wActionList.getText()) == null) {
            // invalid action
            wActionList.setText("");
        }
    } else {
        wActionList.setText("");
    }

    loadAnnotationProperties(getModelAnnotation().getAnnotation());
}

From source file:org.pentaho.di.ui.trans.steps.common.CalculatedMeasureComposite.java

public void load(ModelAnnotation<?> modelAnnotation) {

    if (modelAnnotation == null || modelAnnotation.getAnnotation() == null
            || !(modelAnnotation.getType() == ModelAnnotation.Type.CREATE_CALCULATED_MEMBER)) {
        return;//from  www  .  jav a 2s.c o m
    }

    CreateCalculatedMember calculatedMember = (CreateCalculatedMember) modelAnnotation.getAnnotation();
    wMeasureName.setText(StringUtils.defaultIfBlank(calculatedMember.getName(), ""));
    wFormat.setText(StringUtils.defaultIfBlank(calculatedMember.getFormatString(), ""));
    wFormula.setText(StringUtils.defaultIfBlank(calculatedMember.getFormula(), ""));
    wCalculateSubtotals.setSelection(calculatedMember.isCalculateSubtotals());
}

From source file:org.pentaho.di.ui.trans.steps.common.CalculatedMeasureComposite.java

public void save(AnnotationType annotationType) {

    if (annotationType == null
            || !(annotationType.getType() == ModelAnnotation.Type.CREATE_CALCULATED_MEMBER)) {
        return;//from   ww  w .ja va 2 s  . c o  m
    }

    CreateCalculatedMember calculatedMember = (CreateCalculatedMember) annotationType;

    calculatedMember.setName(StringUtils.defaultIfBlank(wMeasureName.getText(), null));
    calculatedMember.setFormatString(StringUtils.defaultIfBlank(wFormat.getText(), null));
    calculatedMember.setFormula(StringUtils.defaultIfBlank(wFormula.getText(), null));
    calculatedMember.setDimension(DEFAULT_DIMENSION);
    calculatedMember.setCalculateSubtotals(wCalculateSubtotals.getSelection());
}

From source file:org.quackbot.impl.HibernateMain.java

public void firstRun() {
    LocalSessionFactoryBean session = (LocalSessionFactoryBean) context.getBean("&sessionFactory");
    SchemaExport export = new SchemaExport(session.getConfiguration());
    export.drop(false, true);/*  w w  w.j a v  a 2 s  .  co m*/
    export.create(false, true);

    //Start prompting the user for info
    System.out.println();
    System.out.println("--------------------------");
    System.out.println("- Quackbot Initial Setup -");
    System.out.println("--------------------------");
    System.out.println();

    if (promptForInput("Do you wish to setup initial servers now? (Y/N)", false, "Y", "y", "N", "n")
            .equalsIgnoreCase("N")) {
        System.out.println("Skipping setup. Note: You will have to setup servers manually");
        return;
    }

    while (true) {
        String server = promptForInput("What is the address of the server?", false);
        String portString = promptForInput("What is the server port? [Default: 6667]", true);
        String password = promptForInput("What is the server password? [Default: none]", true);
        boolean ssl = promptForInput("Does the server use SSL? [Default: no] (Y/N)", false, "Y", "y", "N", "n")
                .equalsIgnoreCase("Y");

        //Store
        System.out.println("Storing server");
        int port = Integer.parseInt(StringUtils.defaultIfBlank(portString, "6667"));

        //TODO
    }
}