List of usage examples for org.apache.commons.lang3 BooleanUtils isNotTrue
public static boolean isNotTrue(final Boolean bool)
Checks if a Boolean value is not true , handling null by returning true .
BooleanUtils.isNotTrue(Boolean.TRUE) = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null) = true
From source file:com.base2.kagura.core.report.freemarker.FreemarkerWhereClause.java
/** * Looks for a render option, to determine if it should be run. This is supposed to encapsulate a single SQL where * clause. Such as "name IS NOT NULL" or "id > ${method.value(param.lowLimit)}". This should be encapsulated within * a where tag. If this doesn't have an render attribute it will run regardless. When this is successful it will * populate the parent where clause with the contents. * * {@inheritDoc}/* w ww . ja v a 2s . c o m*/ */ @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { if (params.size() > 1) { String message = "This directive doesn't allow multiple parameters."; errors.add(message); throw new TemplateModelException(message); } if (params.size() != 0 && !((Map.Entry) params.entrySet().toArray()[0]).getKey().equals("render")) { String message = "This directive only takes 'render'."; errors.add(message); throw new TemplateModelException(message); } Object renderParam = params.get("render"); if (renderParam == null && params.size() != 0) return; if (params.size() == 0) { } else if (renderParam instanceof TemplateBooleanModel) { TemplateBooleanModel render = (TemplateBooleanModel) renderParam; if (BooleanUtils.isNotTrue(render.getAsBoolean())) return; } else { String message = "This directive only accepts boolean values for 'render'."; errors.add(message); throw new TemplateModelException(message); } if (loopVars.length != 0) { String message = "This directive doesn't allow loop variables."; errors.add(message); throw new TemplateModelException(message); } WhereContext whereContext = (WhereContext) env.getCustomAttribute("whereTag"); if (whereContext == null) { String message = "Can not find parent where clause."; errors.add(message); throw new TemplateModelException(message); } StringWriter stringWriter = new StringWriter(); body.render(stringWriter); outputBody = stringWriter.toString(); whereContext.addWhereClause(this); }
From source file:com.romeikat.datamessie.core.statistics.task.StatisticsToBeRebuilt.java
synchronized void toBeRebuilt(final StatisticsRebuildingSparseTable statisticsToBeRebuilt) { final Collection<Cell<Long, LocalDate, Boolean>> cells = statisticsToBeRebuilt.getCells(); for (final Cell<Long, LocalDate, Boolean> cell : cells) { final Boolean toBeRebuilt = cell.getValue(); if (BooleanUtils.isNotTrue(toBeRebuilt)) { continue; }/*www. j a va2s . co m*/ final Long sourceId = cell.getRowHeader(); final LocalDate publishedDate = cell.getColumnHeader(); toBeRebuilt(sourceId, publishedDate); } }
From source file:com.joyent.manta.config.AuthAwareConfigContext.java
/** * Check the configuration for authentication-related changes. Clean up old authentication objects which might * still exist and load new instances./* ww w . ja v a 2 s. co m*/ * * @return this after reload */ @SuppressWarnings("unchecked") public AuthAwareConfigContext reload() { synchronized (lock) { final int newParamsFingerprint = calculateAuthParamsFingerprint(this); if (authContext != null) { if (authContext.paramsFingerprint == newParamsFingerprint) { return this; } else { authContext.signer.clearAll(); authContext = null; } } if (BooleanUtils.isNotTrue(noAuth())) { authContext = doLoad(newParamsFingerprint); } } return this; }
From source file:com.romeikat.datamessie.core.rss.init.RssCrawlingInitializer.java
private void scheduleCrawling(final long projectId) { synchronized (crawlingProjectIds) { // Only add project if not yet added if (crawlingProjectIds.contains(projectId)) { LOG.debug("Not adding project {} as a crawling has already scheduled for that project", projectId); return; }/*from w w w .j a v a2 s .com*/ // Add crawling LOG.debug("Adding project {}", projectId); crawlingProjectIds.add(projectId); // Schedule crawlings new IntervalTaskSchedulingThread() { private final HibernateSessionProvider sessionProvider = new HibernateSessionProvider( sessionFactory); private Project getProject() { final Project project = projectDao.getEntity(sessionProvider.getStatelessSession(), projectId); sessionProvider.closeStatelessSession(); return project; } @Override protected Task getTask() { final Project project = getProject(); if (project == null) { return null; } final RssCrawlingTask task = (RssCrawlingTask) ctx.getBean(RssCrawlingTask.BEAN_NAME, project); return task; } @Override protected String getTaskName() { return "RSS crawling for project " + projectId; } @Override protected Integer getTaskExecutionInterval() { // Project final Project project = getProject(); if (project == null) { return null; } // Crawling interval final Integer crawlingIntervalInMins = project.getCrawlingInterval(); if (crawlingIntervalInMins == null) { return null; } final int crawlingIntervalInMillis = crawlingIntervalInMins * 60 * 1000; return crawlingIntervalInMillis; } @Override protected LocalDateTime getActualStartOfLatestCompletedTask() { final Project project = getProject(); if (project == null) { return null; } final LocalDateTime latestCrawlingStart = crawlingDao.getStartOfLatestCompletedCrawling( sessionProvider.getStatelessSession(), project.getId()); sessionProvider.closeStatelessSession(); return latestCrawlingStart; } @Override protected boolean shouldSkipTaskExecution() { final Project project = getProject(); if (project == null) { return true; } final Boolean isCrawlingEnabled = project.getCrawlingEnabled(); return BooleanUtils.isNotTrue(isCrawlingEnabled); } @Override protected TaskManager getTaskManager() { return taskManager; } }.start(); } }
From source file:com.joyent.manta.config.ConfigContext.java
/** * Utility method for validating that the configuration has been instantiated * with valid settings./* w ww. j a va2s .com*/ * * @param config configuration to test * @throws ConfigurationException thrown when validation fails */ static void validate(final ConfigContext config) { List<String> failureMessages = new ArrayList<>(); if (StringUtils.isBlank(config.getMantaUser())) { failureMessages.add("Manta account name must be specified"); } if (StringUtils.isBlank(config.getMantaURL())) { failureMessages.add("Manta URL must be specified"); } else { try { new URI(config.getMantaURL()); } catch (URISyntaxException e) { final String msg = String.format("%s - invalid Manta URL: %s", e.getMessage(), config.getMantaURL()); failureMessages.add(msg); } } if (config.getTimeout() != null && config.getTimeout() < 0) { failureMessages.add("Manta timeout must be 0 or greater"); } if (config.getTcpSocketTimeout() != null && config.getTcpSocketTimeout() < 0) { failureMessages.add("Manta tcp socket timeout must be 0 or greater"); } if (config.getConnectionRequestTimeout() != null && config.getConnectionRequestTimeout() < 0) { failureMessages.add("Manta connection request timeout must be 0 or greater"); } if (config.getExpectContinueTimeout() != null && config.getExpectContinueTimeout() < 1) { failureMessages.add("Manta Expect 100-continue timeout must be 1 or greater"); } final boolean authenticationEnabled = BooleanUtils.isNotTrue(config.noAuth()); if (authenticationEnabled) { if (config.getMantaKeyId() == null) { failureMessages.add("Manta key id must be specified"); } if (config.getMantaKeyPath() == null && config.getPrivateKeyContent() == null) { failureMessages.add("Either the Manta key path must be set or the private " + "key content must be set. Both can't be null."); } if (config.getMantaKeyPath() != null && StringUtils.isBlank(config.getMantaKeyPath())) { failureMessages.add("Manta key path must not be blank"); } if (config.getPrivateKeyContent() != null && StringUtils.isBlank(config.getPrivateKeyContent())) { failureMessages.add("Manta private key content must not be blank"); } } if (config.getSkipDirectoryDepth() != null && config.getSkipDirectoryDepth() < 0) { failureMessages.add("Manta skip directory depth must be 0 or greater"); } if (config.getMetricReporterMode() != null) { if (MetricReporterMode.SLF4J.equals(config.getMetricReporterMode())) { if (config.getMetricReporterOutputInterval() == null) { failureMessages.add("SLF4J metric reporter selected but no output interval was provided"); } else if (config.getMetricReporterOutputInterval() < 1) { failureMessages.add("Metric reporter output interval (ms) must be 1 or greater"); } } } if (BooleanUtils.isTrue(config.isClientEncryptionEnabled())) { encryptionSettings(config, failureMessages); } if (!failureMessages.isEmpty()) { String messages = StringUtils.join(failureMessages, System.lineSeparator()); ConfigurationException e = new ConfigurationException( "Errors when loading Manta SDK configuration:" + System.lineSeparator() + messages); // We don't dump all of the configuration settings, just the important ones e.setContextValue(MapConfigContext.MANTA_URL_KEY, config.getMantaURL()); e.setContextValue(MapConfigContext.MANTA_USER_KEY, config.getMantaUser()); e.setContextValue(MapConfigContext.MANTA_KEY_ID_KEY, config.getMantaKeyId()); e.setContextValue(MapConfigContext.MANTA_NO_AUTH_KEY, config.noAuth()); e.setContextValue(MapConfigContext.MANTA_KEY_PATH_KEY, config.getMantaKeyPath()); final String redactedPrivateKeyContent; if (config.getPrivateKeyContent() == null) { redactedPrivateKeyContent = "null"; } else { redactedPrivateKeyContent = "non-null"; } e.setContextValue(MapConfigContext.MANTA_PRIVATE_KEY_CONTENT_KEY, redactedPrivateKeyContent); e.setContextValue(MapConfigContext.MANTA_CLIENT_ENCRYPTION_ENABLED_KEY, config.isClientEncryptionEnabled()); if (BooleanUtils.isTrue(config.isClientEncryptionEnabled())) { e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_KEY_ID_KEY, config.getEncryptionKeyId()); e.setContextValue(MapConfigContext.MANTA_PERMIT_UNENCRYPTED_DOWNLOADS_KEY, config.permitUnencryptedDownloads()); e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_ALGORITHM_KEY, config.getEncryptionAlgorithm()); e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_PATH_KEY, config.getEncryptionPrivateKeyPath()); e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_BYTES_KEY + "_size", ArrayUtils.getLength(config.getEncryptionPrivateKeyBytes())); } throw e; } }
From source file:org.brekka.pegasus.core.services.impl.CertificateAuthenticationServiceImpl.java
@Override @Transactional()//from www .j av a2 s.c o m public DigitalCertificate authenticate(X509Certificate certificate) throws BadCredentialsException, DisabledException { byte[] signature = certificate.getSignature(); String subjectDN = certificate.getSubjectDN().getName(); String commonName = null; Matcher matcher = matchAllowedSubjectDN(subjectDN, allowedSubjectDistinguishedNamePatterns); if (matcher.groupCount() > 0) { commonName = matcher.group(1); } byte[] subjectDNBytes = subjectDN.getBytes(Charset.forName("UTF-8")); SystemDerivedKeySpecType spec = config.getSubjectDerivedKeySpec(); DerivedKey derivedKey = derivedKeyCryptoService.apply(subjectDNBytes, spec.getSalt(), null, CryptoProfile.Static.of(spec.getCryptoProfile())); byte[] distinguishedNameDigest = derivedKey.getDerivedKey(); CertificateSubject certificateSubject = certificateSubjectDAO .retrieveByDistinguishedNameDigest(distinguishedNameDigest); if (certificateSubject == null) { // Create it certificateSubject = new CertificateSubject(); certificateSubject.setDistinguishedNameDigest(distinguishedNameDigest); certificateSubjectDAO.create(certificateSubject); } DigitalCertificate digitalCertificate = digitalCertificateDAO .retrieveBySubjectAndSignature(certificateSubject, signature); if (digitalCertificate == null) { digitalCertificate = new DigitalCertificate(); digitalCertificate.setActive(Boolean.TRUE); digitalCertificate.setCertificateSubject(certificateSubject); digitalCertificate.setCreated(certificate.getNotBefore()); digitalCertificate.setExpires(certificate.getNotAfter()); digitalCertificate.setSignature(signature); digitalCertificateDAO.create(digitalCertificate); } // Perform some checks if (BooleanUtils.isNotTrue(digitalCertificate.getActive())) { throw new DisabledException( String.format("The certficate with id '%s' has been disabled", digitalCertificate.getId())); } if (digitalCertificate.getExpires().before(new Date())) { throw new CredentialsExpiredException(String.format("The certficate with id '%s' expired %tF", digitalCertificate.getId(), digitalCertificate.getExpires())); } // Both of these are transient certificateSubject.setCommonName(commonName); certificateSubject.setDistinguishedName(subjectDN); return digitalCertificate; }
From source file:org.broadleafcommerce.openadmin.server.security.service.AdminSecurityServiceImpl.java
protected void checkUser(AdminUser user, GenericResponse response) { if (user == null) { response.addErrorCode("invalidUser"); } else if (StringUtils.isBlank(user.getEmail())) { response.addErrorCode("emailNotFound"); } else if (BooleanUtils.isNotTrue(user.getActiveStatusFlag())) { response.addErrorCode("inactiveUser"); }/*from w ww . j ava 2 s .c o m*/ }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
@Override public void restoreObjects(final S3FileTransferRequestParamsDto params, int expirationInDays, String archiveRetrievalOption) { LOGGER.info("Restoring a list of objects in S3... s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={}", params.getS3KeyPrefix(), params.getS3BucketName(), params.getFiles().size()); if (!CollectionUtils.isEmpty(params.getFiles())) { // Initialize a key value pair for the error message in the catch block. String key = params.getFiles().get(0).getPath().replaceAll("\\\\", "/"); try {//from w w w .j a v a 2s . c o m // Create an S3 client. AmazonS3Client s3Client = getAmazonS3(params); // Create a restore object request. RestoreObjectRequest requestRestore = new RestoreObjectRequest(params.getS3BucketName(), null, expirationInDays); // Make Bulk the default archive retrieval option if the option is not provided requestRestore.setGlacierJobParameters(new GlacierJobParameters() .withTier(StringUtils.isNotEmpty(archiveRetrievalOption) ? archiveRetrievalOption : Tier.Bulk.toString())); try { for (File file : params.getFiles()) { key = file.getPath().replaceAll("\\\\", "/"); ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(params.getS3BucketName(), key, s3Client); // Request a restore for objects that are not already being restored. if (BooleanUtils.isNotTrue(objectMetadata.getOngoingRestore())) { requestRestore.setKey(key); s3Operations.restoreObject(requestRestore, s3Client); } } } finally { s3Client.shutdown(); } } catch (Exception e) { throw new IllegalStateException(String.format( "Failed to initiate a restore request for \"%s\" key in \"%s\" bucket. Reason: %s", key, params.getS3BucketName(), e.getMessage()), e); } } }
From source file:org.finra.herd.service.helper.UserNamespaceAuthorizationHelper.java
/** * Builds a set of namespace authorizations per specified user and adds them to the application user. * * @param applicationUser the application user *///w ww .j ava 2 s . c o m public void buildNamespaceAuthorizations(ApplicationUser applicationUser) { // Get the user id from the application user. String userId = applicationUser.getUserId(); // Check if user namespace authorization is not enabled or this user is a namespace authorization administrator. if (BooleanUtils.isNotTrue( configurationHelper.getBooleanProperty(ConfigurationValue.USER_NAMESPACE_AUTHORIZATION_ENABLED)) || isNamespaceAuthorizationAdmin(userId)) { // Assign all permissions for all namespaces configured in the system. applicationUser.setNamespaceAuthorizations(getAllNamespaceAuthorizations()); } else { // Assign a set of namespace authorizations per specified user. Set<NamespaceAuthorization> namespaceAuthorizations = new HashSet<>(); applicationUser.setNamespaceAuthorizations(namespaceAuthorizations); for (UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity : userNamespaceAuthorizationDao .getUserNamespaceAuthorizationsByUserId(userId)) { namespaceAuthorizations.add(toNamespaceAuthorization(userNamespaceAuthorizationEntity)); } // Search authorizations by wildcard token for (UserNamespaceAuthorizationEntity wildcardEntity : userNamespaceAuthorizationDao .getUserNamespaceAuthorizationsByUserIdStartsWith(WildcardHelper.WILDCARD_TOKEN)) { if (wildcardHelper.matches(userId.toUpperCase(), wildcardEntity.getUserId().toUpperCase())) { namespaceAuthorizations.add(toNamespaceAuthorization(wildcardEntity)); } } } }
From source file:org.finra.herd.service.impl.BusinessObjectDataServiceImpl.java
@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override/*from www . j a va 2s . co m*/ public BusinessObjectData updateBusinessObjectDataParents(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest) { // Validate and trim the business object data key. businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true); // Validate the update request. Assert.notNull(businessObjectDataParentsUpdateRequest, "A business object data parents update request must be specified."); // Validate and trim the parents' keys. businessObjectDataDaoHelper.validateBusinessObjectDataKeys( businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents()); // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper .getBusinessObjectDataEntity(businessObjectDataKey); // Fail if this business object data is not in a pre-registration status. if (BooleanUtils.isNotTrue(businessObjectDataEntity.getStatus().getPreRegistrationStatus())) { throw new IllegalArgumentException(String.format( "Unable to update parents for business object data because it has \"%s\" status, which is not one of pre-registration statuses.", businessObjectDataEntity.getStatus().getCode())); } // Update parents. List<BusinessObjectDataEntity> businessObjectDataParents = businessObjectDataEntity .getBusinessObjectDataParents(); // Remove all existing parents. businessObjectDataParents.clear(); // Loop through all business object data parents specified in the request and add them one by one. if (CollectionUtils.isNotEmpty(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents())) { for (BusinessObjectDataKey businessObjectDataParentKey : businessObjectDataParentsUpdateRequest .getBusinessObjectDataParents()) { // Look up parent business object data. BusinessObjectDataEntity businessObjectDataParentEntity = businessObjectDataDaoHelper .getBusinessObjectDataEntity(businessObjectDataParentKey); // Add business object data entity being updated as a dependent (i.e. child) of the looked up parent. businessObjectDataParentEntity.getBusinessObjectDataChildren().add(businessObjectDataEntity); // Add the looked up parent as a parent of the business object data entity being updated. businessObjectDataParents.add(businessObjectDataParentEntity); } } // Persist and refresh the entity. businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity); // Create and return the business object data object from the persisted entity. return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity); }