List of usage examples for org.apache.commons.lang ObjectUtils defaultIfNull
public static <T> T defaultIfNull(T object, T defaultValue)
Returns a default value if the object passed is null
.
ObjectUtils.defaultIfNull(null, null) = null ObjectUtils.defaultIfNull(null, "") = "" ObjectUtils.defaultIfNull(null, "zz") = "zz" ObjectUtils.defaultIfNull("abc", *) = "abc" ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
From source file:org.sipfoundry.sipxconfig.admin.dialplan.config.MappingRules.java
protected final void generateRule(IDialingRule rule, Element hostMatch) { Element userMatch = hostMatch.addElement("userMatch"); addRuleNameComment(userMatch, rule); addRuleDescription(userMatch, rule); CallTag callTag = (CallTag) ObjectUtils.defaultIfNull(rule.getCallTag(), CallTag.UNK); userMatch.addElement("callTag").setText(callTag.toString()); String[] patterns = rule.getPatterns(); for (int i = 0; i < patterns.length; i++) { String pattern = patterns[i]; Element userPattern = userMatch.addElement("userPattern"); userPattern.setText(pattern);/*w w w . ja va 2 s . c om*/ } addTransforms(rule, userMatch); }
From source file:org.sipfoundry.sipxconfig.site.user.ConfirmPassword.java
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) { if (!cycle.isRewinding()) { // If the password is null, then init both password and confirmPassword to the empty string if (getPassword() == null) { setPassword(StringUtils.EMPTY); setConfirmPassword(StringUtils.EMPTY); }/*from w ww . ja va2 s. co m*/ // If the confirmPassword is null, then init it to be the same as the password setConfirmPassword((String) ObjectUtils.defaultIfNull(getConfirmPassword(), getPassword())); } super.renderComponent(writer, cycle); // At rewind time, after the user has filled in the form, do any validation that spans // multiple fields. Such validation cannot simply use a validator bound to a single field. if (cycle.isRewinding()) { // The user typed in the password twice. Make sure that it was the same both times. IValidationDelegate delegate = TapestryUtils.getValidator(cycle.getPage()); String password = StringUtils.defaultIfEmpty(getPassword(), StringUtils.EMPTY); String confirmPassword = StringUtils.defaultIfEmpty(getConfirmPassword(), StringUtils.EMPTY); if (!password.equals(confirmPassword)) { delegate.record(getPasswordMismatchMessage(), ValidationConstraint.CONSISTENCY); return; } } }
From source file:org.sipfoundry.sipxconfig.site.user_portal.ChangePin.java
/** * Listeners/* w w w . j av a 2s. c om*/ */ public void changePin() { // Proceed only if Tapestry validation succeeded if (!TapestryUtils.isValid(this)) { return; } // Get the userId. Note that the Border component of the page ensures // that the user is logged in and therefore that userId is non-null. Integer userId = getUserSession().getUserId(); // Validate the current PIN. // Note that the ConfirmPassword component ensures that the new PIN and // confirm new PIN fields match, so we don't have to worry about that here. CoreContext coreContext = getCoreContext(); User user = coreContext.loadUser(userId); LoginContext loginContext = getLoginContext(); // If the currentPin is null, then make it the empty string String currentPin = (String) ObjectUtils.defaultIfNull(getCurrentPin(), StringUtils.EMPTY); user = loginContext.checkCredentials(user.getUserName(), currentPin); if (user == null) { IValidationDelegate delegate = TapestryUtils.getValidator(this); delegate.record(getMessages().getMessage("error.badCurrentPin"), ValidationConstraint.CONSISTENCY); return; } // Change the PIN user.setPin(getNewPin()); coreContext.saveUser(user); // Scrub the PIN fields, for security setCurrentPin(null); setNewPin(null); }
From source file:org.sonar.api.batch.rule.internal.NewRule.java
public NewRule setStatus(@Nullable RuleStatus s) { this.status = (RuleStatus) ObjectUtils.defaultIfNull(s, RuleStatus.defaultStatus()); return this; }
From source file:org.sonar.batch.components.PastMeasuresLoader.java
public List<Object[]> getPastMeasures(String resourceKey, Snapshot projectPastSnapshot) { String sql = "select m.metric_id, m.characteristic_id, m.person_id, m.rule_id, m.value from project_measures m, snapshots s" + " where m.snapshot_id=s.id and m.metric_id in (:metricIds) " + " and (s.root_snapshot_id=:rootSnapshotId or s.id=:rootSnapshotId) " + " and s.status=:status and s.project_id=(select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib)"; return session.createNativeQuery(sql).setParameter("metricIds", metricByIds.keySet()) .setParameter("rootSnapshotId", ObjectUtils.defaultIfNull(projectPastSnapshot.getRootId(), projectPastSnapshot.getId())) .setParameter("resourceKey", resourceKey).setParameter("lib", Qualifiers.LIBRARY) .setParameter("status", Snapshot.STATUS_PROCESSED).getResultList(); }
From source file:org.sonar.batch.compute.AbstractNewCoverageFileAnalyzer.java
private boolean parse(DecoratorContext context) { BatchReportReader reader = new BatchReportReader(publishReportJob.getReportDir()); BatchReport.Changesets componentScm = reader .readChangesets(resourceCache.get(context.getResource()).batchId()); Measure hitsByLineMeasure = context.getMeasure(getCoverageLineHitsDataMetric()); if (componentScm != null && hitsByLineMeasure != null && hitsByLineMeasure.hasData()) { Map<Integer, Integer> hitsByLine = parseCountByLine(hitsByLineMeasure); Map<Integer, Integer> conditionsByLine = parseCountByLine( context.getMeasure(getConditionsByLineMetric())); Map<Integer, Integer> coveredConditionsByLine = parseCountByLine( context.getMeasure(getCoveredConditionsByLineMetric())); reset();// w w w . j av a 2 s . co m for (Map.Entry<Integer, Integer> entry : hitsByLine.entrySet()) { int lineId = entry.getKey(); int hits = entry.getValue(); int conditions = (Integer) ObjectUtils.defaultIfNull(conditionsByLine.get(lineId), 0); int coveredConditions = (Integer) ObjectUtils.defaultIfNull(coveredConditionsByLine.get(lineId), 0); Changeset changeset = componentScm.getChangeset(componentScm.getChangesetIndexByLine(lineId - 1)); Date date = changeset.hasDate() ? new Date(changeset.getDate()) : null; for (PeriodStruct struct : structs) { struct.analyze(date, hits, conditions, coveredConditions); } } return true; } return false; }
From source file:org.sonar.batch.index.DefaultIndex.java
private Bucket doIndex(Resource resource, Resource parentReference) { Bucket bucket = buckets.get(resource); if (bucket != null) { return bucket; }//from w w w . j a va2 s . com checkLock(resource); Resource parent = null; if (!ResourceUtils.isLibrary(resource)) { // a library has no parent parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject); } Bucket parentBucket = getBucket(parent, true); if (parentBucket == null && parent != null) { LOG.warn("Resource ignored, parent is not indexed: " + resource); return null; } resource.setEffectiveKey(createUID(currentProject, resource)); bucket = new Bucket(resource).setParent(parentBucket); buckets.put(resource, bucket); boolean excluded = checkExclusion(resource, parentBucket); if (!excluded) { Snapshot snapshot = persistence.saveResource(currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null)); if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) { graph.addComponent(resource, snapshot); } } return bucket; }
From source file:org.sonar.batch.index.DefaultResourcePersister.java
private Snapshot persistProject(Project project, Project parent) { // temporary hack project.setEffectiveKey(project.getKey()); ResourceModel model = findOrCreateModel(project); model.setLanguageKey(project.getLanguageKey());// ugly, only for projects Snapshot parentSnapshot = null;// www . j a v a 2 s .co m if (parent != null) { // assume that the parent project has already been saved parentSnapshot = snapshotsByResource.get(project.getParent()); model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId())); } else { model.setRootId(null); } model = session.save(model); project.setId(model.getId()); Snapshot snapshot = new Snapshot(model, parentSnapshot); snapshot.setVersion(project.getAnalysisVersion()); snapshot.setCreatedAt(project.getAnalysisDate()); snapshot.setBuildDate(new Date()); snapshot = session.save(snapshot); session.commit(); if (!permissions.hasRoles(project)) { permissions.grantDefaultRoles(project); } return snapshot; }
From source file:org.sonar.batch.index.DefaultResourcePersister.java
/** * Everything except project and library *///from w w w. j a va2 s .co m private Snapshot persistFileOrDirectory(Project project, Resource resource, Resource parentReference) { ResourceModel model = findOrCreateModel(resource); Snapshot projectSnapshot = snapshotsByResource.get(project); model.setRootId(projectSnapshot.getResourceId()); model = session.save(model); resource.setId(model.getId()); Snapshot parentSnapshot = (Snapshot) ObjectUtils.defaultIfNull(getSnapshot(parentReference), projectSnapshot); Snapshot snapshot = new Snapshot(model, parentSnapshot); snapshot.setBuildDate(new Date()); snapshot = session.save(snapshot); session.commit(); return snapshot; }
From source file:org.sonar.batch.index.ResourcePersister.java
private Snapshot persistProject(Project project, @Nullable Project parent) { ResourceModel model = findOrCreateModel(project, parent); // Used by ResourceKeyMigration in order to know that a project has already being migrated model.setDeprecatedKey(project.getKey()); // language is null for project since multi-language support model.setLanguageKey(null);/*w w w .ja va 2s . co m*/ // For views if (project instanceof ResourceCopy) { model.setCopyResourceId(((ResourceCopy) project).getCopyResourceId()); } Snapshot parentSnapshot = null; if (parent != null) { // assume that the parent project has already been saved parentSnapshot = resourceCache.get(parent.getEffectiveKey()).snapshot(); model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId())); } else { model.setRootId(null); } model = session.save(model); project.setId(model.getId()); project.setUuid(model.getUuid()); Snapshot snapshot = new Snapshot(model, parentSnapshot); snapshot.setVersion(project.getAnalysisVersion()); snapshot.setCreatedAtMs(dateToLong(project.getAnalysisDate())); snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot = session.save(snapshot); session.commit(); if (parent == null && !permissions.hasRoles(project)) { permissions.grantDefaultRoles(project); } return snapshot; }