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

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

Introduction

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

Prototype

public static String stripToNull(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

This is similar to #trimToNull(String) but removes whitespace.

Usage

From source file:org.drombler.commons.client.util.ResourceBundleUtils.java

/**
 *
 * @param resourceKey// w  ww .  ja  v a2  s. c  om
 * @param resourceBundle
 * @exception NullPointerException if the key is null
 * @exception MissingResourceException if no value for the specified key can be found
 * @exception ClassCastException if the value is not a {@link String}
 * @return
 */
public static String getResourceStringPrefixed(String resourceKey, ResourceBundle resourceBundle) {
    String strippedResourceKey = StringUtils.stripToNull(resourceKey);
    if (isPrefixedResourceString(strippedResourceKey)) {
        strippedResourceKey = strippedResourceKey.substring(KEY_PREFIX.length());
        //            if (rb.containsKey(resourceKey)) {
        return resourceBundle.getString(strippedResourceKey);
        //            }
    }
    return resourceKey;
}

From source file:org.imsglobal.lti.BasicLTIUtil.java

/**
 * @deprecated See: {@link #parseDescriptor(Map, Map, String)}
 * @param launch_info Variable is mutated by this method.
 * @param postProp Variable is mutated by this method.
 * @param descriptor//from  w w w  . j ava  2s  .com
 * @return
 */
public static boolean parseDescriptor(Properties launch_info, Properties postProp, String descriptor) {
    // this is an ugly copy/paste of the non-@deprecated method
    // could not convert data types as they variables get mutated (ugh)
    Map<String, Object> tm = null;
    try {
        tm = XMLMap.getFullMap(descriptor.trim());
    } catch (Exception e) {
        M_log.warning("BasicLTIUtil exception parsing BasicLTI descriptor: " + e.getMessage());
        return false;
    }
    if (tm == null) {
        M_log.warning("Unable to parse XML in parseDescriptor");
        return false;
    }

    String launch_url = StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/launch_url"));
    String secure_launch_url = StringUtils
            .stripToNull(XMLMap.getString(tm, "/basic_lti_link/secure_launch_url"));
    if (launch_url == null && secure_launch_url == null) {
        return false;
    }

    setProperty(launch_info, "launch_url", launch_url);
    setProperty(launch_info, "secure_launch_url", secure_launch_url);

    // Extensions for hand-authored placements - The export process should scrub these
    setProperty(launch_info, "key",
            StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_key")));
    setProperty(launch_info, "secret",
            StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_secret")));

    List<Map<String, Object>> theList = XMLMap.getList(tm, "/basic_lti_link/custom/parameter");
    for (Map<String, Object> setting : theList) {
        dPrint("Setting=" + setting);
        String key = XMLMap.getString(setting, "/!key"); // Get the key attribute
        String value = XMLMap.getString(setting, "/"); // Get the value
        if (key == null || value == null) {
            continue;
        }
        key = "custom_" + mapKeyName(key);
        dPrint("key=" + key + " val=" + value);
        postProp.setProperty(key, value);
    }
    return true;
}

From source file:org.imsglobal.lti.BasicLTIUtil.java

/**
 *
 * @param launch_info Variable is mutated by this method.
 * @param postProp Variable is mutated by this method.
 * @param descriptor/* ww  w .ja  v  a 2 s  .  co  m*/
 * @return
 */
public static boolean parseDescriptor(Map<String, String> launch_info, Map<String, String> postProp,
        String descriptor) {
    Map<String, Object> tm = null;
    try {
        tm = XMLMap.getFullMap(descriptor.trim());
    } catch (Exception e) {
        M_log.warning("BasicLTIUtil exception parsing BasicLTI descriptor: " + e.getMessage());
        return false;
    }
    if (tm == null) {
        M_log.warning("Unable to parse XML in parseDescriptor");
        return false;
    }

    String launch_url = StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/launch_url"));
    String secure_launch_url = StringUtils
            .stripToNull(XMLMap.getString(tm, "/basic_lti_link/secure_launch_url"));
    if (launch_url == null && secure_launch_url == null) {
        return false;
    }

    setProperty(launch_info, "launch_url", launch_url);
    setProperty(launch_info, "secure_launch_url", secure_launch_url);

    // Extensions for hand-authored placements - The export process should scrub
    // these
    setProperty(launch_info, "key",
            StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_key")));
    setProperty(launch_info, "secret",
            StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_secret")));

    List<Map<String, Object>> theList = XMLMap.getList(tm, "/basic_lti_link/custom/parameter");
    for (Map<String, Object> setting : theList) {
        dPrint("Setting=" + setting);
        String key = XMLMap.getString(setting, "/!key"); // Get the key attribute
        String value = XMLMap.getString(setting, "/"); // Get the value
        if (key == null || value == null) {
            continue;
        }
        key = "custom_" + mapKeyName(key);
        dPrint("key=" + key + " val=" + value);
        postProp.put(key, value);
    }
    return true;
}

From source file:org.rippleosi.patient.details.search.LegacyPatientSearch.java

private BooleanBuilder generateAdvancedSearchPredicate(PatientQueryParams params) {
    QPatientEntity blueprint = QPatientEntity.patientEntity;
    BooleanBuilder predicate = new BooleanBuilder();

    String nhsNumber = params.getNhsNumber();

    if (nhsNumber != null) {
        predicate.and(blueprint.nhsNumber.eq(nhsNumber));
    } else {/*w  ww . jav a2  s.co  m*/
        String surname = StringUtils.stripToNull(params.getSurname());
        String forename = StringUtils.stripToNull(params.getForename());
        Date dateOfBirth = params.getDateOfBirth();
        String gender = StringUtils.stripToNull(params.getGender());

        if (surname != null) {
            predicate.and(blueprint.lastName.like(surname));
        }
        if (forename != null) {
            predicate.and(blueprint.firstName.like(forename));
        }
        if (dateOfBirth != null) {
            Date truncatedDateOfBirth = DateUtils.truncate(dateOfBirth, Calendar.DATE);

            predicate.and(blueprint.dateOfBirth.eq(truncatedDateOfBirth));
        }
        if (gender != null) {
            predicate.and(blueprint.gender.eq(gender));
        }
    }

    return predicate;
}

From source file:rapture.dp.invocable.calendar.steps.CalendarLookupStep.java

@Override
public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    try {/*w ww  . jav  a2  s.  co m*/
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

        String dateStr = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DATE"));
        String calendar = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "CALENDAR"));
        String translator = StringUtils
                .stripToNull(decision.getContextValue(ctx, getWorkerURI(), "TRANSLATOR"));
        if (translator == null)
            translator = StringUtils
                    .stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DEFAULT_TRANSLATOR"));
        LocalDate date = (dateStr == null) ? LocalDate.now() : LocalDate.parse(dateStr);

        // Translate the date to a name - eg Good Friday, Yom Kippur, Thanksgiving
        // Expected format is a map of dates (with or without years) to names or lists of names
        // Example:
        // {
        // "31Dec" : ["New Tear's Eve", "Hogmanay"] ,
        // "05Sep2016" : "Labor Day",
        // "04Sep2017" : "Labor Day"
        // "2015-01-01" : "New Year's Day"
        // }

        Map<String, Object> calendarTable = new HashMap<>();
        if (calendar != null) {
            String calendarJson = StringUtils.stripToNull(Kernel.getDoc().getDoc(ctx, calendar));
            if (calendarJson != null) {
                calendarTable = JacksonUtil.getMapFromJson(calendarJson);
            }
        }

        // Translate the date to a name - eg Good Friday, Yom Kippur, Thanksgiving
        Map<String, Object> translationTable = new HashMap<>();
        if (translator != null) {
            String translationJson = StringUtils.stripToNull(Kernel.getDoc().getDoc(ctx, translator));
            if (translationJson != null) {
                translationTable = JacksonUtil.getMapFromJson(translationJson);
            }
        }

        List<String> lookup = new ArrayList<>();

        String languageTag = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "LOCALE"));
        Locale locale = (languageTag == null) ? Locale.getDefault() : Locale.forLanguageTag(languageTag);

        for (DateTimeFormatter formatter : ImmutableList.of(DateTimeFormatter.ISO_LOCAL_DATE,
                DateTimeFormatter.ofPattern("ddMMMuuuu", locale), DateTimeFormatter.ofPattern("ddMMM", locale),
                DateTimeFormatter.ofPattern("MMMdduuuu", locale), DateTimeFormatter.ofPattern("MMMdd", locale),
                DateTimeFormatter.ofPattern("uuuuMMMdd", locale))) {

            String formattedDate = date.format(formatter);
            Object transList = translationTable.get(formattedDate);
            if (transList != null) {
                if (transList instanceof Iterable) {
                    for (Object o : (Iterable) transList) {
                        lookup.add(o.toString());
                    }
                } else
                    lookup.add(transList.toString());
            }
            lookup.add(formattedDate);
        }
        lookup.add(DayOfWeek.from(date).getDisplayName(TextStyle.FULL, locale));

        decision.setContextLiteral(ctx, getWorkerURI(), "DATE_TRANSLATIONS",
                JacksonUtil.jsonFromObject(lookup));

        // Calendar table defines the priority. getMapFromJson returns a LinkedHashMap so order is preserved.
        for (Entry<String, Object> calEntry : calendarTable.entrySet()) {
            if (lookup.contains(calEntry.getKey())) {
                decision.setContextLiteral(ctx, getWorkerURI(), "CALENDAR_LOOKUP_ENTRY",
                        JacksonUtil.jsonFromObject(calEntry));
                decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                        calEntry.getKey() + " matched as " + calEntry.getValue().toString(), false);
                return calEntry.getValue().toString();
            }
        }
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), getStepName() + ": No matches for "
                + DateTimeFormatter.ISO_LOCAL_DATE.format(date) + " found in calendar", false);
        return getNextTransition();
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Unable to access the calendar : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName() + "Error", ExceptionToString.summary(e));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}

From source file:rapture.dp.invocable.calendar.steps.GetDayOfWeekStep.java

@Override
public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    try {/*from ww w . ja v  a 2 s. c  o m*/
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());
        String dateStr = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DATE"));
        String languageTag = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "LOCALE"));
        LocalDateTime date = (dateStr == null) ? LocalDateTime.now() : LocalDateTime.parse(dateStr);
        Locale locale = (languageTag == null) ? Locale.getDefault() : Locale.forLanguageTag(languageTag);
        String day = DayOfWeek.from(date).getDisplayName(TextStyle.FULL, locale);
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), "Day of week is " + day, false);
        return day;
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Exception in workflow : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}

From source file:rapture.dp.invocable.configuration.steps.ConfigurationStep.java

@Override
public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    String workOrderUri = new RaptureURI(getWorkerURI(), Scheme.WORKORDER).toShortString();
    decision.setContextLiteral(ctx, workOrderUri, "WORKORDER", new RaptureURI(workOrderUri).getLeafName());
    String config = StringUtils.stripToNull(decision.getContextValue(ctx, workOrderUri, "CONFIGURATION"));

    try {/*from  w  ww.j a v  a  2s.  c o m*/
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

        String docPath = new RaptureURI(workOrderUri).getDocPath();
        int lio = docPath.lastIndexOf('/');
        if (lio < 0)
            lio = 0;

        StringBuilder externalUrl = new StringBuilder();
        String host = System.getenv("HOST");
        String port = System.getenv("PORT");
        externalUrl.append("http://").append((host != null) ? host : LOCALHOST).append(":")
                .append((port != null) ? port : DEFAULT_RIM_PORT).append("/process/")
                .append(docPath.substring(0, lio)).append(WORKORDER_DELIMETER)
                .append(docPath.substring(lio + 1));
        decision.setContextLiteral(ctx, workOrderUri, EXTERNAL_RIM_WORKORDER_URL, externalUrl.toString());

        Map<String, String> view = new HashMap<>();
        DocApi docApi = Kernel.getDoc();

        if (config == null) {
            decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), "No configuration document specified", false);
            return this.getNextTransition();
        }
        List<String> configs;
        try {
            // Could be a list or a single entry.
            configs = JacksonUtil.objectFromJson(config, ArrayList.class);
        } catch (Exception e) {
            configs = ImmutableList.of(config);
        }

        for (String conf : configs) {
            if (docApi.docExists(ctx, conf)) {
                String doc = docApi.getDoc(ctx, conf);
                Map<String, Object> map = JacksonUtil.getMapFromJson(doc);
                for (Entry<String, Object> entry : map.entrySet()) {
                    String key = entry.getKey();
                    String value = StringUtils.stripToNull(entry.getValue().toString());
                    ContextValueType type = ContextValueType.getContextValueType(value.charAt(0));
                    if (type == ContextValueType.NULL) {
                        type = ContextValueType.LITERAL;
                    } else
                        value = value.substring(1);
                    ExecutionContextUtil.setValueECF(ctx, workOrderUri, view, key, type, value);
                    decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                            getStepName() + ": Read configuration data from " + conf, false);
                }
            } else {
                decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                        getStepName() + ": Cannot locate configuration document " + conf, true);
            }
        }
        return Steps.NEXT.toString();
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Exception in workflow : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e));
        log.error(ExceptionToString.format(ExceptionToString.getRootCause(e)));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": unable to read the configuration document " + config, true);
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(), true);

        return getErrorTransition();
    }
}

From source file:rapture.dp.invocable.ftp.steps.CheckFileExistsStep.java

/**
 * FTP_CONFIGURATION is optional. If not set the arguments are assumed to be local EXIST_FILENAMES is a map of file names to Booleans, indicating whether
 * the file is expected or not/*from  w w w  . j  av  a 2 s  .  c  om*/
 */
@Override
public String invoke(CallingContext ctx) {
    String workerUri = getWorkerURI();
    String workOrderUri = new RaptureURI(workerUri).toShortString();
    try {
        decision.setContextLiteral(ctx, workOrderUri, "STEPNAME", getStepName());

        String configUri = StringUtils
                .stripToNull(decision.getContextValue(ctx, workOrderUri, "FTP_CONFIGURATION"));
        String filename = StringUtils
                .stripToNull(decision.getContextValue(ctx, workOrderUri, "EXIST_FILENAMES"));
        if (filename == null) {
            decision.setContextLiteral(ctx, workOrderUri, getStepName(), "No files to check");
            decision.setContextLiteral(ctx, workOrderUri, getErrName(), "");
            return getNextTransition();
        }

        Map<String, Object> files = JacksonUtil.objectFromJson(
                ExecutionContextUtil.evalTemplateECF(ctx, workOrderUri, filename, null), Map.class);

        FTPConnection connection = new SFTPConnection(configUri).setContext(ctx);
        String retval = getNextTransition();
        List<FTPRequest> requests = new ArrayList<>();
        int existsCount = 0;
        int failCount = 0;
        StringBuilder error = new StringBuilder();
        for (Entry<String, Object> e : files.entrySet()) {
            FTPRequest request = new FTPRequest(Action.EXISTS).setRemoteName(e.getKey());
            boolean exists = connection.doAction(request);
            if (!exists == ((Boolean) e.getValue())) {
                retval = getFailTransition();
                String target = e.getKey();
                boolean plural = false;
                if (exists) {
                    List l = (List) request.getResult();
                    if (l != null) {
                        if (l.size() > 1) {
                            target = l.size() + " files or directories matching " + e.getKey();
                            plural = true;
                        } else {
                            target = l.get(0).toString();
                        }
                    }
                }
                if (error.length() > 0)
                    error.append("\n");
                error.append(target).append((plural) ? wereNotWere(exists) : wasNotWas(exists))
                        .append("found but").append(plural ? wereNotWere((Boolean) e.getValue())
                                : wasNotWas((Boolean) e.getValue()))
                        .append("expected");
                failCount++;
            }
            requests.add(request);
        }
        decision.setContextLiteral(ctx, workOrderUri, getStepName(),
                "Located " + existsCount + " of " + files.size() + " files");
        String errMsg = error.toString();
        String audit_quiet = decision.getContextValue(ctx, workOrderUri, "AUDIT_QUIET");
        if (!StringUtils.isEmpty(errMsg)) {
            log.error(errMsg);
            if (audit_quiet == null)
                decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), getStepName() + ": " + errMsg, true);
        } else {
            if (audit_quiet == null)
                decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                        getStepName() + ": all files successfully matched", false);
        }
        decision.setContextLiteral(ctx, workOrderUri, getErrName(), errMsg);
        return retval;
    } catch (Exception e) {
        decision.setContextLiteral(ctx, workOrderUri, getStepName(),
                "Unable to determine if files exist : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, workOrderUri, getErrName(), ExceptionToString.summary(e));
        log.error(ExceptionToString.format(ExceptionToString.getRootCause(e)));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}

From source file:rapture.dp.invocable.ftp.steps.CopyFileStep.java

@Override
public String invoke(CallingContext ctx) {
    try {//w  ww . ja va2s.  com
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());
        this.context = ctx;
        String copy = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "COPY_FILES"));
        if (copy == null) {
            decision.setContextLiteral(ctx, getWorkerURI(), getStepName(), "No files to copy");
            decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), "No files to copy");
            decision.writeWorkflowAuditEntry(context, getWorkerURI(), getStepName() + ": No files to copy",
                    false);
            return getNextTransition();
        }

        Map<String, Object> map = JacksonUtil.getMapFromJson(renderTemplate(ctx, copy));

        String retval = getNextTransition();
        int failCount = 0;
        StringBuilder sb = new StringBuilder();
        List<Entry<String, Object>> list = new ArrayList<>();
        for (Entry<String, Object> e : map.entrySet()) {
            Object value = e.getValue();
            List<String> targets;
            if (value instanceof List) {
                targets = (List<String>) value;
            } else {
                targets = ImmutableList.of(value.toString());
            }
            for (String target : targets) {
                if (!copy(e.getKey(), target)) {
                    sb.append("Unable to copy ").append(e.getKey()).append(" to ").append(target).append("\n");
                    retval = getFailTransition();
                    failCount++;
                    list.add(e);
                }
            }
        }

        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                (failCount > 0) ? "Unable to copy " + failCount + " files" : "All files copied");

        String err = sb.toString();
        if (!StringUtils.isEmpty(err)) {
            log.error(err);
            decision.writeWorkflowAuditEntry(context, getWorkerURI(), getStepName() + ": " + err, true);
        } else {
            decision.writeWorkflowAuditEntry(context, getWorkerURI(), getStepName() + ": All files copied",
                    false);

        }
        decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), err);
        return retval;
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Unable to copy files : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e));
        log.error(ExceptionToString.format(ExceptionToString.getRootCause(e)));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}

From source file:rapture.dp.invocable.ftp.steps.GetFileStep.java

@Override
public String invoke(CallingContext ctx) {
    try {//from w  ww. ja v  a  2s .co  m
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

        String copy = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "FETCH_FILES"));
        if (copy == null) {
            decision.setContextLiteral(ctx, getWorkerURI(), getStepName(), "No files to copy");
            return getNextTransition();
        }

        String workOrder = new RaptureURI(getWorkerURI()).toShortString();
        String json = ExecutionContextUtil.evalTemplateECF(ctx, workOrder, copy, new HashMap<>());
        Map<String, Object> map = JacksonUtil.getMapFromJson(json);

        String configUri = decision.getContextValue(ctx, getWorkerURI(), "FTP_CONFIGURATION");
        if (configUri == null) {
            decision.setContextLiteral(ctx, getWorkerURI(), getStepName(), "FTP_CONFIGURATION not set");
            decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                    "Problem in " + getStepName() + " - parameter FTP_CONFIGURATION is not set", true);
            return getErrorTransition();
        }

        if (!Kernel.getDoc().docExists(ctx, configUri)) {
            decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                    "Cannot load FTP_CONFIGURATION from " + configUri);
            decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                    "Problem in " + getStepName() + " - Cannot load FTP_CONFIGURATION from " + configUri, true);
            return getErrorTransition();
        }

        String retval = getNextTransition();
        int failCount = 0;
        StringBuilder sb = new StringBuilder();
        List<FTPRequest> requests = new ArrayList<>();
        Connection connection = new SFTPConnection(configUri).setContext(ctx);
        for (Entry<String, Object> e : map.entrySet()) {
            FTPRequest request = new FTPRequest(Action.READ).setRemoteName(e.getKey())
                    .setLocalName(e.getValue().toString());
            connection.doAction(request);
            if (!request.getStatus().equals(Status.SUCCESS)) {
                retval = getFailTransition();
                sb.append("Unable to retrieve ").append(e.getKey()).append(" as ")
                        .append(e.getValue().toString()).append("\n");
                log.warn("Unable to retrieve " + e.getKey());
                failCount++;
            }
            requests.add(request);
        }
        if (failCount > 0)
            decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                    "Unable to retrieve " + failCount + " files");
        else
            decision.setContextLiteral(ctx, getWorkerURI(), getStepName(), "All files retrieved");

        String err = sb.toString();
        if (!StringUtils.isEmpty(err)) {
            log.error(err);
            decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), getStepName() + ": " + err, true);
        } else {
            decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), getStepName() + ": All files retrieved",
                    false);
        }
        decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), err);
        return retval;
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Unable to retrieve files : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e));
        log.error(ExceptionToString.format(ExceptionToString.getRootCause(e)));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}