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

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

Introduction

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

Prototype

public static String left(String str, int len) 

Source Link

Document

Gets the leftmost len characters of a String.

Usage

From source file:org.jahia.admin.sites.ManageSites.java

/**
 * Process Edit Site form/*  w w w .j ava2 s .c o m*/
 *
 * @param request  Servlet request.
 * @param response Servlet response.
 * @param session  HttpSession object.
 */
private void processEdit(HttpServletRequest request, HttpServletResponse response, HttpSession session)
        throws IOException, ServletException {
    logger.debug(" process edit site started ");

    boolean processError = false;

    // get form values...
    String siteTitle = StringUtils.left(StringUtils.defaultString(request.getParameter("siteTitle")).trim(),
            100);
    String siteServerName = StringUtils
            .left(StringUtils.defaultString(request.getParameter("siteServerName")).trim(), 200);
    //      String  siteKey             = StringUtils.defaultIfEmpty(request.getParameter("siteKey"),"").toLowerCase().trim();
    String siteDescr = StringUtils.left(StringUtils.defaultString(request.getParameter("siteDescr")).trim(),
            250);

    String warningMsg = "";
    boolean defaultSite = (request.getParameter("defaultSite") != null);

    boolean versioningEnabled = (request.getParameter("versioningEnabled") != null);
    boolean stagingEnabled = (request.getParameter("stagingEnabled") != null);

    // set request attributes...
    request.setAttribute("siteTitle", siteTitle);
    request.setAttribute("siteServerName", siteServerName);
    request.setAttribute("siteDescr", siteDescr);
    request.setAttribute("defaultSite", Boolean.valueOf(defaultSite));
    request.setAttribute("versioningEnabled", Boolean.valueOf(versioningEnabled));
    request.setAttribute("stagingEnabled", Boolean.valueOf(stagingEnabled));

    try {
        // get site...
        String site_id = StringUtils.defaultString(request.getParameter("siteid")).trim();
        Integer siteID = new Integer(site_id);
        JahiaSite site = sMgr.getSite(siteID.intValue());

        // check validity...
        if (siteTitle != null && (siteTitle.trim().length() > 0) && siteServerName != null
                && (siteServerName.trim().length() > 0)) {
            if (!isServerNameValid(siteServerName)) {
                warningMsg = getMessage("org.jahia.admin.warningMsg.invalidServerName.label");
                processError = true;
            } else if (!site.getServerName().equals(siteServerName)) {
                if (!Url.isLocalhost(siteServerName) && sMgr.getSite(siteServerName) != null) {
                    warningMsg = getMessage("org.jahia.admin.warningMsg.chooseAnotherServerName.label");
                    processError = true;
                }
            }
        } else {
            warningMsg = getMessage("org.jahia.admin.warningMsg.completeRequestInfo.label");
        }

        if (!processError) {
            // save modified informations...
            site.setTitle(siteTitle);
            site.setServerName(siteServerName);
            site.setDescr(siteDescr);

            sMgr.updateSite(site);

            JahiaSite defSite = getDefaultSite();
            if (defaultSite) {
                if (defSite == null) {
                    changeDefaultSite(site);
                } else if (!defSite.getSiteKey().equals(site.getSiteKey())) {
                    changeDefaultSite(site);
                }
            } else {
                if (defSite != null && defSite.getSiteKey().equals(site.getSiteKey())) {
                    changeDefaultSite(null);
                }
            }

            // set message default values...
            session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", Jahia.COPYRIGHT);

            // redirect...
            displayList(request, response, session);
        } else {
            request.setAttribute("warningMsg", warningMsg);
            displayEdit(request, response, session);
        }
    } catch (JahiaException ex) {
        logger.warn("Error while processing site edition", ex);
        warningMsg = getMessage("label.error.processingRequestError");
        request.setAttribute("warningMsg", warningMsg);
        displayEdit(request, response, session);
    }
}

From source file:org.jahia.admin.sites.ManageSites.java

private void processFileImport(HttpServletRequest request, HttpServletResponse response, HttpSession session)
        throws IOException, ServletException {
    @SuppressWarnings("unchecked")
    List<Map<Object, Object>> importsInfos = (List<Map<Object, Object>>) session.getAttribute("importsInfos");
    Map<Object, Object> siteKeyMapping = new HashMap<Object, Object>();
    boolean stillBad = false;
    JahiaSitesService jahiaSitesService = ServicesRegistry.getInstance().getJahiaSitesService();
    for (Map<Object, Object> infos : importsInfos) {
        File file = (File) infos.get("importFile");
        infos.put("sitekey", StringUtils.left(request.getParameter(file.getName() + "siteKey") == null ? null
                : request.getParameter(file.getName() + "siteKey").trim(), 50));
        infos.put("oldsitekey", request.getParameter(file.getName() + "oldSiteKey") == null ? null
                : request.getParameter(file.getName() + "oldSiteKey").trim());
        if (infos.get("sitekey") != null && !infos.get("sitekey").equals(infos.get("oldsitekey"))) {
            siteKeyMapping.put(infos.get("oldsitekey"), infos.get("sitekey"));
        }//from ww w .jav a  2  s  . c om
        infos.put("siteservername",
                StringUtils.left(request.getParameter(file.getName() + "siteServerName") == null ? null
                        : request.getParameter(file.getName() + "siteServerName").trim(), 200));
        infos.put("sitetitle",
                StringUtils.left(request.getParameter(file.getName() + "siteTitle") == null ? null
                        : request.getParameter(file.getName() + "siteTitle").trim(), 100));
        infos.put("selected", request.getParameter(file.getName() + "selected"));
        infos.put("templates", request.getParameter(file.getName() + "templates"));
        infos.put("legacyMapping", request.getParameter(file.getName() + "legacyMapping"));
        infos.put("legacyDefinitions", request.getParameter(file.getName() + "legacyDefinitions"));
        if (request.getParameter(file.getName() + "selected") != null) {
            try {
                if (NON_SITE_IMPORTS.contains(infos.get("importFileName"))) {

                } else {
                    infos.put("siteTitleInvalid", StringUtils.isEmpty((String) infos.get("sitetitle")));

                    String siteKey = (String) infos.get("sitekey");
                    boolean valid = isSiteKeyValid(siteKey);
                    infos.put("siteKeyInvalid", !valid);
                    infos.put("siteKeyExists", valid && jahiaSitesService.getSiteByKey(siteKey) != null);

                    String serverName = (String) infos.get("siteservername");
                    valid = isServerNameValid(serverName);
                    infos.put("siteServerNameInvalid", !valid);
                    infos.put("siteServerNameExists", valid && !Url.isLocalhost(serverName)
                            && jahiaSitesService.getSite(serverName) != null);

                    stillBad = (Boolean) infos.get("siteKeyInvalid") || (Boolean) infos.get("siteKeyExists")
                            || (Boolean) infos.get("siteServerNameInvalid")
                            || (Boolean) infos.get("siteServerNameExists");
                }
            } catch (JahiaException e) {
                logger.error("Error while processing file import", e);
            }
        } else {
            infos.put("siteKeyInvalid", Boolean.FALSE);
            infos.put("siteKeyExists", Boolean.FALSE);
            infos.put("siteServerNameInvalid", Boolean.FALSE);
            infos.put("siteServerNameExists", Boolean.FALSE);

        }
    }
    if (stillBad) {
        try {
            TreeMap<String, JCRNodeWrapper> orderedTemplateSets = getTemplatesSets();

            request.setAttribute("tmplSets", new ArrayList<JCRNodeWrapper>(orderedTemplateSets.values()));
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
        }

        JahiaAdministration.doRedirect(request, response, session, JSP_PATH + "import_choose.jsp");
    } else {

        boolean doImportServerPermissions = false;
        for (Map<Object, Object> infos : importsInfos) {
            File file = (File) infos.get("importFile");
            if (request.getParameter(file.getName() + "selected") != null
                    && infos.get("importFileName").equals("serverPermissions.xml")) {
                doImportServerPermissions = true;
                break;
            }
        }

        request.setAttribute("doImportServerPermissions", Boolean.valueOf(doImportServerPermissions));

        for (Map<Object, Object> infos : importsInfos) {
            File file = (File) infos.get("importFile");
            if (request.getParameter(file.getName() + "selected") != null
                    && infos.get("importFileName").equals("users.xml")) {
                try {
                    ImportExportBaseService.getInstance().importUsers(file);
                } finally {
                    file.delete();
                }
                break;
            }
        }

        try {
            for (Map<Object, Object> infos : importsInfos) {
                File file = (File) infos.get("importFile");
                if (request.getParameter(file.getName() + "selected") != null) {
                    if (infos.get("type").equals("files")) {
                        try {
                            JahiaSite system = ServicesRegistry.getInstance().getJahiaSitesService()
                                    .getSiteByKey(JahiaSitesBaseService.SYSTEM_SITE_KEY);

                            Map<String, String> pathMapping = JCRSessionFactory.getInstance()
                                    .getCurrentUserSession().getPathMapping();
                            pathMapping.put("/shared/files/", "/sites/" + system.getSiteKey() + "/files/");
                            pathMapping.put("/shared/mashups/", "/sites/" + system.getSiteKey() + "/portlets/");

                            ImportExportBaseService.getInstance().importSiteZip(file, system, infos);
                        } catch (Exception e) {
                            logger.error("Error when getting templates", e);
                        }
                    } else if (infos.get("type").equals("xml")
                            && (infos.get("importFileName").equals("serverPermissions.xml")
                                    || infos.get("importFileName").equals("users.xml"))) {

                    } else if (infos.get("type").equals("site")) {
                        // site import
                        String tpl = (String) infos.get("templates");
                        if ("".equals(tpl)) {
                            tpl = null;
                        }
                        Object legacyImport = infos.get("legacyImport");
                        String legacyImportFilePath = null;
                        String legacyDefinitionsFilePath = null;
                        if (legacyImport != null && (Boolean) legacyImport) {
                            legacyImportFilePath = (String) infos.get("legacyMapping");
                            if (legacyImportFilePath != null && "".equals(legacyImportFilePath.trim())) {
                                legacyImportFilePath = null;
                            }
                            legacyDefinitionsFilePath = (String) infos.get("legacyDefinitions");
                            if (legacyDefinitionsFilePath != null
                                    && "".equals(legacyDefinitionsFilePath.trim())) {
                                legacyDefinitionsFilePath = null;
                            }
                        }
                        Locale defaultLocale = determineDefaultLocale(jParams, infos);
                        try {
                            JahiaSite site = jahiaSitesService.addSite(jParams.getUser(),
                                    (String) infos.get("sitetitle"), (String) infos.get("siteservername"),
                                    (String) infos.get("sitekey"), "", defaultLocale, tpl, null, "fileImport",
                                    file, (String) infos.get("importFileName"), false, false,
                                    (String) infos.get("originatingJahiaRelease"), legacyImportFilePath,
                                    legacyDefinitionsFilePath);
                            session.setAttribute(ProcessingContext.SESSION_SITE, site);
                            jParams.setSite(site);
                            jParams.setSiteID(site.getID());
                            jParams.setSiteKey(site.getSiteKey());
                            jParams.setCurrentLocale(defaultLocale);

                        } catch (Exception e) {
                            logger.error("Cannot create site " + infos.get("sitetitle"), e);
                        }
                    }
                }
            }
        } finally {
            for (Map<Object, Object> infos : importsInfos) {
                FileUtils.deleteQuietly((File) infos.get("importFile"));
            }
        }

        CompositeSpellChecker.updateSpellCheckerIndex();

        redirectAfterAdd(request, response, session);
    }
}

From source file:org.jahia.modules.defaultmodule.actions.admin.AdminCreateSiteAction.java

@Override
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource,
        JCRSessionWrapper session, Map<String, List<String>> parameters, URLResolver urlResolver)
        throws Exception {
    JCRNodeWrapper node = resource.getNode();

    if (!node.isNodeType("jnt:virtualsitesFolder") || !node.getPath().equals("/sites")) {
        return ActionResult.BAD_REQUEST;
    }//from   www.  j a va2  s  .c o  m

    logger.debug("started");

    // get form values...
    String siteTitle = StringUtils.left(StringUtils.defaultString(getParameter(parameters, "siteTitle")).trim(),
            100);
    String siteServerName = StringUtils
            .left(StringUtils.defaultString(getParameter(parameters, "siteServerName")).trim(), 200);
    String siteKey = StringUtils.left(StringUtils.defaultString(getParameter(parameters, "siteKey")).trim(),
            50);
    String siteDescr = StringUtils.left(StringUtils.defaultString(getParameter(parameters, "siteDescr")).trim(),
            250);

    Map<String, String> result = new HashMap<String, String>();

    JahiaSite site = null;
    // create jahia site object if checks are in green light...
    try {
        // check validity...
        if (siteTitle != null && (siteTitle.length() > 0) && siteServerName != null
                && (siteServerName.length() > 0) && siteKey != null && (siteKey.length() > 0)) {
            if (!sitesService.isSiteKeyValid(siteKey)) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.onlyLettersDigitsUnderscore"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            } else if (siteKey.equals("site")) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.chooseAnotherSiteKey"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            } else if (!sitesService.isServerNameValid(siteServerName)) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.invalidServerName"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            } else if (siteServerName.equals("default")) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.chooseAnotherServerName"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            } else if (!Url.isLocalhost(siteServerName) && sitesService.getSite(siteServerName) != null) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.chooseAnotherServerName"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            } else if (sitesService.getSiteByKey(siteKey) != null) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.chooseAnotherSiteKey"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            }
        } else {
            result.put("warn", getMessage(renderContext.getUILocale(),
                    "serverSettings.manageWebProjects.warningMsg.completeRequestInfo"));
            return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
        }

        Locale selectedLocale = resource.getLocale();
        String lang = getParameter(parameters, "language");
        if (lang != null) {
            selectedLocale = LanguageCodeConverters.getLocaleFromCode(lang);
        }

        // add the site in siteManager...
        site = sitesService.addSite(session.getUser(), siteTitle, siteServerName, siteKey, siteDescr,
                selectedLocale, getParameter(parameters, "templatesSet"), null, null, null, null, false, null,
                null, null, null, session);

        if (getParameter(parameters, "mixLanguage", "false").equals("true")
                || getParameter(parameters, "allowsUnlistedLanguages", "false").equals("true")) {
            site.setMixLanguagesActive(getParameter(parameters, "mixLanguage", "false").equals("true"));
            site.setAllowsUnlistedLanguages(
                    getParameter(parameters, "allowsUnlistedLanguages", "false").equals("true"));
            sitesService.updateSystemSitePermissions(site);
        }

        if (site != null) {
            JahiaSite systemSite = sitesService.getSiteByKey(JahiaSitesService.SYSTEM_SITE_KEY);
            // update the system site only if it does not yet contain at least one of the site languages
            if (!systemSite.getLanguages().containsAll(site.getLanguages())) {
                systemSite.getLanguages().addAll(site.getLanguages());
                sitesService.updateSystemSitePermissions(systemSite);
            }
            session.save();
            configureSite(site, req, renderContext, resource, session, parameters, urlResolver);
        } else {
            result.put("warn", getMessage(renderContext.getUILocale(), "label.error.processingRequestError"));
            return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
        }
    } catch (JahiaException ex) {
        try {
            if (site != null) {
                sitesService.removeSite(site);
            }
        } catch (Exception t) {
            logger.error("Error while cleaning site", t);
        }

        logger.error("Error while adding site", ex);

        result.put("warn", getMessage(renderContext.getUILocale(), "label.error.processingRequestError"));
        return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
    }

    return ActionResult.OK_JSON;
}

From source file:org.jahia.modules.defaultmodule.actions.admin.AdminEditSiteAction.java

@Override
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, JahiaSite site,
        JCRSessionWrapper session, Map<String, List<String>> parameters) throws Exception {
    logger.debug(" process edit site started ");

    // get form values...
    String siteTitle = StringUtils.left(StringUtils.defaultString(getParameter(parameters, "siteTitle")).trim(),
            100);/*from   w ww .ja  va2  s .  c  o  m*/
    String siteServerName = StringUtils
            .left(StringUtils.defaultString(getParameter(parameters, "siteServerName")).trim(), 200);
    String siteDescr = StringUtils.left(StringUtils.defaultString(getParameter(parameters, "siteDescr")).trim(),
            250);

    boolean defaultSite = (getParameter(parameters, "defaultSite") != null);

    Map<String, String> result = new HashMap<String, String>();

    try {
        session.checkout((Node) site);
        // check validity...
        if (siteTitle != null && (siteTitle.trim().length() > 0) && siteServerName != null
                && (siteServerName.trim().length() > 0)) {
            if (!sitesService.isServerNameValid(siteServerName)) {
                result.put("warn", getMessage(renderContext.getUILocale(),
                        "serverSettings.manageWebProjects.warningMsg.invalidServerName"));
                return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
            } else if (!site.getServerName().equals(siteServerName)) {
                if (!Url.isLocalhost(siteServerName) && sitesService.getSite(siteServerName) != null) {
                    result.put("warn", getMessage(renderContext.getUILocale(),
                            "serverSettings.manageWebProjects.warningMsg.chooseAnotherServerName"));
                    return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
                }
            }
        } else {
            result.put("warn", getMessage(renderContext.getUILocale(),
                    "serverSettings.manageWebProjects.warningMsg.completeRequestInfo"));
            return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
        }

        // save modified informations...
        site.setTitle(siteTitle);
        site.setServerName(siteServerName);
        site.setDescription(siteDescr);

        sitesService.updateSystemSitePermissions(site);

        JahiaSite defSite = sitesService.getDefaultSite();
        if (defaultSite) {
            if (defSite == null) {
                sitesService.setDefaultSite(site);
            } else if (!defSite.getSiteKey().equals(site.getSiteKey())) {
                sitesService.setDefaultSite(site);
            }
        } else {
            if (defSite != null && defSite.getSiteKey().equals(site.getSiteKey())) {
                sitesService.setDefaultSite(null);
            }
        }
        session.save();
        // redirect...
        return ActionResult.OK_JSON;
    } catch (JahiaException ex) {
        logger.warn("Error while processing site edition", ex);
        result.put("warn", getMessage(renderContext.getUILocale(), "label.error.processingRequestError"));
        return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject(result));
    }
}

From source file:org.jason.mapmaker.server.actionHandler.shapefile.DeleteSingleShapefileHandler.java

@Override
public DeleteSingleShapefileResult execute(DeleteSingleShapefileAction action,
        ExecutionContext executionContext) throws ActionException {

    ShapefileMetadata sm = action.getShapefileMetadata();
    int affectedRows;

    try {/*ww  w. ja  va 2  s. co  m*/
        // delete the borderpoints
        String stateGeoId = StringUtils.left(sm.getGeoId(), 2); // get the state portion of the geoid
        affectedRows = locationService.removeByStateGeoIdAndMtfcc(stateGeoId, sm.getMtfccCode());
        //shapefileService.deleteByShapefileMetadata(sm);

        // update the sm object status
        sm.setCurrentStatus(GeographyUtils.Status.NOT_IMPORTED);
        shapefileMetadataService.update(sm);

    } catch (ServiceException e) {
        throw new ActionException(e);
    }

    return new DeleteSingleShapefileResult(affectedRows);
}

From source file:org.jason.mapmaker.server.service.FeatureServiceImpl.java

public void deleteByFeaturesMetadata(FeaturesMetadata fm) throws ServiceException {

    String validatedGeoId = StringUtils.left(fm.getStateGeoId(), 2);
    try {/* w  w  w.ja v a  2s  .c o m*/
        featureRepository.deleteByStateGeoId(validatedGeoId);
    } catch (RepositoryException e) {
        throw new ServiceException(e);
    }

    fm.setCurrentStatus(GeographyUtils.Status.NOT_IMPORTED);
    featuresMetadataService.update(fm);

}

From source file:org.jason.mapmaker.server.service.FeatureServiceImpl.java

@Override
public void importFromUrl(String url, FeaturesMetadata fm) throws ServiceException {

    URL u;//w  ww  . j  a  v  a  2  s  .  c  o  m
    try {
        u = new URL(url);
    } catch (MalformedURLException ex) {
        log.debug("Exception thrown:", ex.getMessage());
        throw new ServiceException(ex);
    }

    List<File> fileList;
    try {
        fileList = ZipUtil.decompress(u);
    } catch (Exception e) {
        log.debug("Exception thrown:", e.getMessage());
        throw new ServiceException(e);
    }

    if (fileList == null || fileList.size() == 0) {
        log.debug("File list is null or zero!");
        throw new ServiceException("File List contains no files!");
    }

    File file = fileList.get(0); // get the txt file handler
    try {

        BufferedReader reader = new BufferedReader(new FileReader(file));
        reader.readLine(); // ignore header line

        String line = reader.readLine();
        List<Feature> featureList = new ArrayList<Feature>(); // arraylist may not be the best choice since I don't know how many features I'm importing
        int counter = 1;
        while (line != null) {
            String[] splitLine = split(line, "|"); // static import of StringUtils because I don't like regex's
            if (!NumberUtils.isNumber(splitLine[0]) || !NumberUtils.isNumber(splitLine[9])
                    || !NumberUtils.isNumber(splitLine[10])) {
                System.out.println("Feature ID#" + splitLine[0] + " fails isNumeric() test. Skipping.");
                line = reader.readLine();
                continue; // "silently" die
            }

            // only import the manmade features
            if (FeatureUtil.isManmadeFeature(splitLine[2])) {
                // setting this to variables and using the non-default Feature constructor means this is
                // easier to debug. Yay.

                // sometimes the USGS state file isn't limited to a single state... god only knows what the problem is
                String stateGeoId = splitLine[4];
                if (fm.getStateGeoId().equals(stateGeoId)) {

                    int id = Integer.parseInt(splitLine[0]);
                    String featureName = StringUtils.left(splitLine[1], 99);
                    String featureClass = StringUtils.left(splitLine[2], 99);
                    double lat = Double.parseDouble(splitLine[9]);
                    double lng = Double.parseDouble(splitLine[10]);

                    Feature feature = new Feature(id, featureName, featureClass, lat, lng, fm);
                    feature.setFeatureSource("usgs");

                    featureList.add(feature);

                    counter++;
                }
            }

            if (counter % 100000 == 0) {
                System.out.println("Processed " + counter + " items");
                try {
                    saveList(featureList);
                    featureList.clear();
                } catch (ServiceException e) {
                    log.debug("Exception thrown: ", e.getMessage());
                    break;
                }
            }
            line = reader.readLine();
        }

        saveList(featureList);

        reader.close();

    } catch (IOException e) {
        log.debug("Exception thrown:", e);
        throw new ServiceException(e);
    }

    file.delete();
}

From source file:org.jason.mapmaker.server.service.LocationServiceImpl.java

public int removeByStateGeoIdAndMtfcc(String stateGeoId, String mtfcc) throws ServiceException {

    MTFCC m = mtfccService.get(mtfcc);//from w  w w  .jav a  2 s.co  m
    Location example = new Location();
    example.setGeoId(StringUtils.left(stateGeoId, 2)); // the first two digits are always equal to the state's geoid
    example.setMtfcc(m);

    List<Location> resultList = locationRepository.getByExample(example);
    int affectedRows = resultList.size();
    for (Location l : resultList) {
        locationRepository.delete(l);
    }

    return affectedRows;
}

From source file:org.jason.mapmaker.service.FeatureServiceImpl.java

public void deleteByFeaturesMetadata(FeaturesMetadata fm) throws ServiceException {

    String validatedGeoId = StringUtils.left(fm.getStateGeoId(), 2);
    featureRepository.deleteByStateGeoId(validatedGeoId);

    fm.setCurrentStatus(GeographyUtils.Status.NOT_IMPORTED);
    featuresMetadataService.update(fm);/*  w  w  w  . j ava2  s  . c  o  m*/

}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.snapshot.SaveSnapshotWizardPageModel.java

public SaveSnapshotWizardPageModel(SaveSnapshotWizardModel wizardModel) {
    this.wizardModel = wizardModel;
    String filepath = wizardModel.getFilepath();
    if (filepath != null) {
        this.directory = StringUtils.left(filepath,
                filepath.length() - FilenameUtils.getName(filepath).length());
    }/*  w  w w .jav  a2  s  .  com*/

}