List of usage examples for org.apache.commons.lang3 StringUtils trimToNull
public static String trimToNull(final String str)
Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .
From source file:org.ligoj.app.plugin.id.resource.batch.GroupFullTask.java
@Override protected void doBatch(final GroupImportEntry entry, final boolean quiet) { // Copy the group information final GroupEditionVo edition = new GroupEditionVo(); edition.setName(entry.getName());//from ww w . j a va2 s . co m edition.setParent(StringUtils.trimToNull(entry.getParent())); edition.setScope(containerScopeResource.findByName(entry.getScope()).getId()); // Split muti-valued data edition.setAssistants(toList(entry.getAssistant())); edition.setDepartments(toList(entry.getDepartment())); edition.setOwners(toList(entry.getOwner())); // Create the user resource.create(edition); }
From source file:org.ligoj.app.plugin.id.resource.ContainerScopeResource.java
/** * Validate and clean the type.//w ww . j ava 2 s . c o m * * @param entity * The entity to check. * @return The given parameter. */ protected ContainerScope check(final ContainerScope entity) { entity.setDn(StringUtils.trimToNull(entity.getDn())); entity.setName(StringUtils.trimToNull(entity.getName())); return entity; }
From source file:org.ligoj.app.plugin.id.resource.GroupResource.java
@Override protected String toDn(final GroupEditionVo container, final ContainerScope scope) { String parentDn = scope.getDn(); container.setParent(StringUtils.trimToNull(Normalizer.normalize(container.getParent()))); if (container.getParent() != null) { // Check the parent is also inside the type, a new DN will be built final GroupOrg parent = findByIdExpected(container.getParent()); if (!DnUtils.equalsOrParentOf(scope.getDn(), parent.getDn())) { throw new ValidationJsonException("parent", "container-parent-type-match", TYPE_ATTRIBUTE, this.type, "provided", scope.getType()); }//from w w w . ja v a2 s . c o m parentDn = parent.getDn(); } return "cn=" + container.getName() + "," + parentDn; }
From source file:org.ligoj.app.plugin.id.resource.UserOrgResource.java
/** * Return users matching the given criteria. The visible groups, trees and companies are checked. The returned * groups of each user depends on the groups the user can see and are in normalized CN form. The result is not * secured, it contains DN./* w ww . j av a2s. c o m*/ * * @param visibleGroups * The visible groups by the principal user. * @param company * the optional company name to match. Will be normalized. * @param group * the optional group name to match. May be <code>null</code>. * @param criteria * the optional criteria to match. * @param uriInfo * filter data. * @return found users. */ private Page<UserOrg> findAllNotSecure(final Set<GroupOrg> visibleGroups, final String company, final String group, final String criteria, @Context final UriInfo uriInfo) { final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, ORDERED_COLUMNS); final Collection<String> visibleCompanies = companyResource.getContainers().stream().map(CompanyOrg::getId) .collect(Collectors.toSet()); final Map<String, GroupOrg> allGroups = getGroup().findAll(); // The companies to use final Set<String> filteredCompanies = computeFilteredCompanies(Normalizer.normalize(company), visibleCompanies); // The groups to use final Collection<GroupOrg> filteredGroups = group == null ? null : computeFilteredGroups(group, visibleGroups, allGroups); // Search the users return getUser().findAll(filteredGroups, filteredCompanies, StringUtils.trimToNull(criteria), pageRequest); }
From source file:org.ligoj.app.plugin.id.resource.UserOrgResource.java
/** * Normalize the entry : capitalize and trimming. *///from www. j av a 2 s . c o m private void normalize(final UserOrgEditionVo importEntry) { // Normalize the identifiers importEntry.setCompany(Normalizer.normalize(importEntry.getCompany())); importEntry.setId(StringUtils.trimToNull(Normalizer.normalize(importEntry.getId()))); importEntry.setGroups(new ArrayList<>(Normalizer.normalize(importEntry.getGroups()))); // Fix the names of user importEntry.setDepartment(StringUtils.trimToNull(importEntry.getDepartment())); importEntry.setLocalId(StringUtils.trimToNull(importEntry.getLocalId())); importEntry.setLastName(WordUtils.capitalizeFully(StringUtils.trimToNull(importEntry.getLastName()))); importEntry.setFirstName(WordUtils.capitalizeFully(StringUtils.trimToNull(importEntry.getFirstName()))); }
From source file:org.ligoj.app.plugin.km.confluence.ConfluencePluginResource.java
@Override public String getVersion(final Map<String, String> parameters) { final String page = StringUtils .trimToEmpty(getConfluencePublicResource(parameters, "/forgotuserpassword.action")); final String ajsMeta = "ajs-version-number\" content="; final int versionIndex = Math.min(page.length(), page.indexOf(ajsMeta) + ajsMeta.length() + 1); return StringUtils .trimToNull(page.substring(versionIndex, Math.max(versionIndex, page.indexOf('\"', versionIndex)))); }
From source file:org.ligoj.app.plugin.prov.aws.in.ProvAwsPriceImportResource.java
/** * Install or update a EC2 price/* w ww . j av a 2 s . co m*/ */ private ProvInstancePrice newInstancePrice(final UpdateContext context, final AwsEc2Price csv, final ProvLocation region) { final VmOs os = VmOs.valueOf(csv.getOs().toUpperCase(Locale.ENGLISH)); final ProvInstanceType instance = installInstanceType(context, csv); final String license = StringUtils.trimToNull(StringUtils.remove( csv.getLicenseModel().replace("License Included", StringUtils.defaultString(csv.getSoftware(), "")) .replace("NA", "License Included"), "No License required")); final ProvTenancy tenancy = ProvTenancy.valueOf(StringUtils.upperCase(csv.getTenancy())); final ProvInstancePriceTerm term = context.getPriceTypes().computeIfAbsent(csv.getOfferTermCode(), k -> newInstancePriceTerm(context, csv)); final String code = toCode(csv); return context.getPrevious().computeIfAbsent(code, c -> { final ProvInstancePrice p = new ProvInstancePrice(); p.setLocation(region); p.setCode(code); p.setOs(os); p.setTenancy(tenancy); p.setLicense(license); p.setType(instance); p.setTerm(term); return p; }); }
From source file:org.ligoj.app.plugin.prov.aws.in.ProvAwsPriceImportResource.java
/** * Build a new instance price type from the CSV line. *//*from w ww . j a va2s. c o m*/ private ProvInstancePriceTerm newInstancePriceTerm(final UpdateContext context, final AwsEc2Price csvPrice) { final ProvInstancePriceTerm term = new ProvInstancePriceTerm(); term.setNode(context.getNode()); term.setCode(csvPrice.getOfferTermCode()); // Build the name from the leasing, purchase option and offering class final String name = StringUtils.trimToNull(StringUtils.removeAll( StringUtils.replaceAll(csvPrice.getPurchaseOption(), "([a-z])Upfront", "$1 Upfront"), "No\\s*Upfront")); term.setName(Arrays .stream(new String[] { csvPrice.getTermType(), StringUtils.replace(csvPrice.getLeaseContractLength(), " ", ""), name, StringUtils.trimToNull(StringUtils.remove(csvPrice.getOfferingClass(), "standard")) }) .filter(Objects::nonNull).collect(Collectors.joining(", "))); // Handle leasing final Matcher matcher = LEASING_TIME .matcher(StringUtils.defaultIfBlank(csvPrice.getLeaseContractLength(), "")); if (matcher.find()) { // Convert years to months term.setPeriod(Integer.parseInt(matcher.group(1)) * 12); } iptRepository.saveAndFlush(term); return term; }
From source file:org.ligoj.app.plugin.vm.aws.VmAwsSnapshotResource.java
/** * Convert a XML AMI node to a {@link Snapshot} instance. *//* w w w . ja v a 2 s . c o m*/ private Snapshot toAmi(final Element element) { final Snapshot snapshot = new Snapshot(); snapshot.setId(xml.getTagText(element, "imageId")); snapshot.setName(xml.getTagText(element, "name")); snapshot.setDescription(StringUtils.trimToNull(xml.getTagText(element, "description"))); snapshot.setStatusText(xml.getTagText(element, "imageState")); snapshot.setAvailable("available".equals(snapshot.getStatusText())); snapshot.setPending("pending".equals(snapshot.getStatusText())); final String date = xml.getTagText(element, "creationDate"); final XPath xPath = xml.xpathFactory.newXPath(); try { // Author final NodeList tags = (NodeList) xPath.compile("tagSet/item").evaluate(element, XPathConstants.NODESET); snapshot.setAuthor(IntStream.range(0, tags.getLength()).mapToObj(tags::item) .filter(t -> TAG_AUDIT.equals(xml.getTagText((Element) t, "key"))) .map(t -> xml.getTagText((Element) t, "value")).map(this::getUser).findAny().orElse(null)); // Volumes final NodeList volumes = (NodeList) xPath.compile("blockDeviceMapping/item").evaluate(element, XPathConstants.NODESET); snapshot.setVolumes(IntStream.range(0, volumes.getLength()).mapToObj(volumes::item) .map(v -> toVolume((Element) v)).filter(v -> v.getId() != null).collect(Collectors.toList())); // Creation date snapshot.setDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse(date)); } catch (final Exception pe) { // Invalid of not correctly managed XML content snapshot.setVolumes(ListUtils.emptyIfNull(snapshot.getVolumes())); snapshot.setDate(new Date(0)); log.info("Details of AMI {} cannot be fully parsed", snapshot.getId(), pe); } return snapshot; }
From source file:org.mitre.mpf.wfm.businessrules.impl.StreamingJobRequestBoImpl.java
/** * Create and initialize a JSON representation of a streaming job request given the raw parameters. * This version of the method allows for callbacks to be defined, use null to disable. This method also * does value checks, and sets additional parameters for the streaming job given the current state of streaming * job request parameters.// w w w .java2 s . c o m * * @param externalId * @param pipelineName * @param stream * @param algorithmProperties * @param jobProperties * @param buildOutput if true, output objects will be stored and this method will assign the output object directory * @param priority * @param stallTimeout * @param healthReportCallbackUri callback for health reports to be sent using HTTP method POST, pass null to disable health reports * @param summaryReportCallbackUri callback for summary reports to be sent using HTTP method POST, pass null to disable summary reports * @return JSON representation of the streaming job request */ @Override public JsonStreamingJobRequest createRequest(String externalId, String pipelineName, JsonStreamingInputObject stream, Map<String, Map<String, String>> algorithmProperties, Map<String, String> jobProperties, boolean buildOutput, int priority, long stallTimeout, String healthReportCallbackUri, String summaryReportCallbackUri) { log.debug("[streaming createRequest] externalId:" + externalId + ", pipeline:" + pipelineName + ", buildOutput:" + buildOutput + ", priority:" + priority + ", healthReportCallbackUri:" + healthReportCallbackUri + ", summaryReportCallbackUri:" + summaryReportCallbackUri); String jsonHealthReportCallbackUri = StringUtils.trimToNull(healthReportCallbackUri); String jsonSummaryReportCallbackUri = StringUtils.trimToNull(summaryReportCallbackUri); String outputObjectPath = ""; // initialize output output object to empty string, the path will be set after the streaming job is submitted JsonStreamingJobRequest jsonStreamingJobRequest = new JsonStreamingJobRequest(TextUtils.trim(externalId), buildOutput, outputObjectPath, pipelineService.createJsonPipeline(pipelineName), priority, stream, stallTimeout, jsonHealthReportCallbackUri, jsonSummaryReportCallbackUri, algorithmProperties, jobProperties); return jsonStreamingJobRequest; }