List of usage examples for org.springframework.util Assert isNull
public static void isNull(@Nullable Object object, Supplier<String> messageSupplier)
From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java
public static AnnotationConfigApplicationContext debugOnlyCreateKurentoApplicationContext() { Assert.isNull(kurentoApplicationContextInternalReference, "Pre-existing Kurento ApplicationContext found. Cannot create a new instance."); kurentoApplicationContextInternalReference = new AnnotationConfigApplicationContext(); // Add or remove packages when required kurentoApplicationContextInternalReference.scan("com.kurento.kmf"); kurentoApplicationContextInternalReference.refresh(); return kurentoApplicationContextInternalReference; }
From source file:com.jaxio.celerio.model.Entity.java
public void setEntityConfig(EntityConfig config) { Assert.isNull(this.entityConfig, "entityConfig can be set only once"); Assert.notNull(config);/* ww w. j a va 2s. c om*/ this.entityConfig = config; }
From source file:com.jaxio.celerio.model.Entity.java
public void setParent(Entity parent) { Assert.isNull(this.parent, "parent can be set only once"); this.parent = parent; parent.addChild(this); }
From source file:org.kurento.rabbitmq.RabbitTemplate.java
protected Message doSendAndReceiveWithTemporary(final String exchange, final String routingKey, final Message message) { return this.execute(new ChannelCallback<Message>() { @Override//w ww . j av a 2s . c o m public Message doInRabbit(Channel channel) throws Exception { final ArrayBlockingQueue<Message> replyHandoff = new ArrayBlockingQueue<Message>(1); Assert.isNull(message.getMessageProperties().getReplyTo(), "Send-and-receive methods can only be used if the Message does not already have a replyTo property."); DeclareOk queueDeclaration = channel.queueDeclare(); String replyTo = queueDeclaration.getQueue(); message.getMessageProperties().setReplyTo(replyTo); String consumerTag = UUID.randomUUID().toString(); DefaultConsumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { MessageProperties messageProperties = messagePropertiesConverter .toMessageProperties(properties, envelope, encoding); Message reply = new Message(body, messageProperties); if (logger.isTraceEnabled()) { logger.trace("Message received " + reply); } try { replyHandoff.put(reply); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }; channel.basicConsume(replyTo, true, consumerTag, true, true, null, consumer); doSend(channel, exchange, routingKey, message, null); Message reply = (replyTimeout < 0) ? replyHandoff.take() : replyHandoff.poll(replyTimeout, TimeUnit.MILLISECONDS); channel.basicCancel(consumerTag); return reply; } }); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientImpl.java
private void createUserProvidedServiceDelegate(CloudService service, Map<String, Object> credentials, String syslogDrainUrl) {/* www . ja v a 2 s . c o m*/ assertSpaceProvided("create service"); Assert.notNull(credentials, "Service credentials must not be null"); Assert.notNull(service, "Service must not be null"); Assert.notNull(service.getName(), "Service name must not be null"); Assert.isNull(service.getLabel(), "Service label is not valid for user-provided services"); Assert.isNull(service.getProvider(), "Service provider is not valid for user-provided services"); Assert.isNull(service.getVersion(), "Service version is not valid for user-provided services"); Assert.isNull(service.getPlan(), "Service plan is not valid for user-provided services"); HashMap<String, Object> serviceRequest = new HashMap<>(); serviceRequest.put("space_guid", sessionSpace.getMeta().getGuid()); serviceRequest.put("name", service.getName()); serviceRequest.put("credentials", credentials); if (syslogDrainUrl != null && !syslogDrainUrl.equals("")) { serviceRequest.put("syslog_drain_url", syslogDrainUrl); } getRestTemplate().postForObject(getUrl("/v2/user_provided_service_instances"), serviceRequest, String.class); }
From source file:org.finra.dm.service.helper.DmHelper.java
/** * Validates the given instance definition. Generates an appropriate error message using the given name. The name specified is one of "master", "core", or * "task"./* w w w. j av a2s. c om*/ * * @param name name of instance group * @param instanceDefinition the instance definition to validate * * @throws IllegalArgumentException when any validation error occurs */ private void validateInstanceDefinition(String name, InstanceDefinition instanceDefinition) { String capitalizedName = StringUtils.capitalize(name); Assert.isTrue(instanceDefinition.getInstanceCount() >= 1, "At least 1 " + name + " instance must be specified."); Assert.hasText(instanceDefinition.getInstanceType(), "An instance type for " + name + " instances must be specified."); if (instanceDefinition.getInstanceSpotPrice() != null) { Assert.isNull(instanceDefinition.getInstanceMaxSearchPrice(), capitalizedName + " instance max search price must not be specified when instance spot price is specified."); Assert.isTrue(instanceDefinition.getInstanceSpotPrice().compareTo(BigDecimal.ZERO) > 0, capitalizedName + " instance spot price must be greater than 0"); } if (instanceDefinition.getInstanceMaxSearchPrice() != null) { Assert.isNull(instanceDefinition.getInstanceSpotPrice(), capitalizedName + " instance spot price must not be specified when max search price is specified."); Assert.isTrue(instanceDefinition.getInstanceMaxSearchPrice().compareTo(BigDecimal.ZERO) > 0, capitalizedName + " instance max search price must be greater than 0"); if (instanceDefinition.getInstanceOnDemandThreshold() != null) { Assert.isTrue(instanceDefinition.getInstanceOnDemandThreshold().compareTo(BigDecimal.ZERO) > 0, capitalizedName + " instance on-demand threshold must be greater than 0"); } } else { Assert.isNull(instanceDefinition.getInstanceOnDemandThreshold(), capitalizedName + " instance on-demand threshold must not be specified when instance max search price is not specified."); } }
From source file:org.finra.herd.service.helper.EmrClusterDefinitionHelper.java
/** * Validates the given instance definition. Generates an appropriate error message using the given name. The name specified is one of "master", "core", or * "task"./* ww w. ja v a 2 s . c om*/ * * @param name name of instance group * @param instanceDefinition the instance definition to validate * @param minimumInstanceCount The minimum instance count. * * @throws IllegalArgumentException when any validation error occurs */ private void validateInstanceDefinition(String name, InstanceDefinition instanceDefinition, Integer minimumInstanceCount) { String capitalizedName = StringUtils.capitalize(name); Assert.isTrue(instanceDefinition.getInstanceCount() >= minimumInstanceCount, String.format("At least %d %s instance must be specified.", minimumInstanceCount, name)); Assert.hasText(instanceDefinition.getInstanceType(), "An instance type for " + name + " instances must be specified."); if (instanceDefinition.getInstanceSpotPrice() != null) { Assert.isNull(instanceDefinition.getInstanceMaxSearchPrice(), capitalizedName + " instance max search price must not be specified when instance spot price is specified."); Assert.isTrue(instanceDefinition.getInstanceSpotPrice().compareTo(BigDecimal.ZERO) > 0, capitalizedName + " instance spot price must be greater than 0"); } if (instanceDefinition.getInstanceMaxSearchPrice() != null) { Assert.isNull(instanceDefinition.getInstanceSpotPrice(), capitalizedName + " instance spot price must not be specified when max search price is specified."); Assert.isTrue(instanceDefinition.getInstanceMaxSearchPrice().compareTo(BigDecimal.ZERO) > 0, capitalizedName + " instance max search price must be greater than 0"); if (instanceDefinition.getInstanceOnDemandThreshold() != null) { Assert.isTrue(instanceDefinition.getInstanceOnDemandThreshold().compareTo(BigDecimal.ZERO) > 0, capitalizedName + " instance on-demand threshold must be greater than 0"); } } else { Assert.isNull(instanceDefinition.getInstanceOnDemandThreshold(), capitalizedName + " instance on-demand threshold must not be specified when instance max search price is not specified."); } }
From source file:org.finra.herd.service.impl.BusinessObjectDataInitiateDestroyHelperServiceImpl.java
/** * Validate that business object data is supported by the business object data destroy feature. * * @param businessObjectDataEntity the business object data entity * @param businessObjectDataKey the business object data key *//* w ww . j a v a2 s. c o m*/ void validateBusinessObjectData(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) { // Get business object format for this business object data. BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat(); // Create a version-less key for the business object format. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey( businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), null); // Get the latest version of the format to retrieve retention information. BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatEntity .getLatestVersion() ? businessObjectFormatEntity : businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); // Get retention information. String retentionType = latestVersionBusinessObjectFormatEntity.getRetentionType() != null ? latestVersionBusinessObjectFormatEntity.getRetentionType().getCode() : null; Integer retentionPeriodInDays = latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays(); // Get the current timestamp from the database. Timestamp currentTimestamp = herdDao.getCurrentTimestamp(); // Validate that retention information is specified for this business object format. if (retentionType != null) { switch (retentionType) { case RetentionTypeEntity.PARTITION_VALUE: Assert.notNull(retentionPeriodInDays, String.format("Retention period in days must be specified for %s retention type.", RetentionTypeEntity.PARTITION_VALUE)); Assert.isTrue(retentionPeriodInDays > 0, String.format( "A positive retention period in days must be specified for %s retention type.", RetentionTypeEntity.PARTITION_VALUE)); // Try to convert business object data primary partition value to a timestamp. // If conversion is not successful, the method returns a null value. Date primaryPartitionValue = businessObjectDataHelper .getDateFromString(businessObjectDataEntity.getPartitionValue()); // If primary partition values is not a date, this business object data is not supported by the business object data destroy feature. if (primaryPartitionValue == null) { throw new IllegalArgumentException(String.format( "Primary partition value \"%s\" cannot get converted to a valid date. Business object data: {%s}", businessObjectDataEntity.getPartitionValue(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } // Compute the relative primary partition value threshold date based on the current timestamp and retention period value. Date primaryPartitionValueThreshold = new Date( HerdDateUtils.addDays(currentTimestamp, -retentionPeriodInDays).getTime()); // Validate that this business object data has it's primary partition value before or equal to the threshold date. if (primaryPartitionValue.compareTo(primaryPartitionValueThreshold) > 0) { throw new IllegalArgumentException(String.format( "Business object data fails retention threshold check for retention type \"%s\" with retention period of %d days. " + "Business object data: {%s}", retentionType, retentionPeriodInDays, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } break; case RetentionTypeEntity.BDATA_RETENTION_DATE: // Retention period in days value must only be specified for PARTITION_VALUE retention type. Assert.isNull(retentionPeriodInDays, String.format( "A retention period in days cannot be specified for %s retention type.", retentionType)); // Validate that the retention information is specified for business object data with retention type as BDATA_RETENTION_DATE. Assert.notNull(businessObjectDataEntity.getRetentionExpiration(), String.format( "Retention information with retention type %s must be specified for the Business Object Data: {%s}", retentionType, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Validate that the business object data retention expiration date is in the past. if (!(businessObjectDataEntity.getRetentionExpiration().before(currentTimestamp))) { throw new IllegalArgumentException(String.format( "Business object data fails retention threshold check for retention type \"%s\" with retention expiration date %s. " + "Business object data: {%s}", retentionType, businessObjectDataEntity.getRetentionExpiration(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } break; default: throw new IllegalArgumentException(String.format( "Retention type \"%s\" is not supported by the business object data destroy feature. Business object format: {%s}", retentionType, businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey))); } } else { throw new IllegalArgumentException(String.format( "Retention information is not configured for the business object format. Business object format: {%s}", businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey))); } }
From source file:org.finra.herd.service.impl.BusinessObjectFormatServiceImpl.java
@NamespacePermissions({ @NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", permissions = NamespacePermissionEnum.READ) }) @Override// ww w .ja v a 2 s . c o m public BusinessObjectFormat updateBusinessObjectFormatParents(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatParentsUpdateRequest businessObjectFormatParentsUpdateRequest) { Assert.notNull(businessObjectFormatParentsUpdateRequest, "A Business Object Format Parents Update Request is required."); // Perform validation and trim the alternate key parameters. businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false); Assert.isNull(businessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified."); // Perform validation and trim for the business object format parents validateBusinessObjectFormatParents( businessObjectFormatParentsUpdateRequest.getBusinessObjectFormatParents()); // Retrieve and ensure that a business object format exists. BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper .getBusinessObjectFormatEntity(businessObjectFormatKey); // Retrieve and ensure that business object format parents exist. A set is used to ignore duplicate business object format parents. Set<BusinessObjectFormatEntity> businessObjectFormatParents = new HashSet<>(); for (BusinessObjectFormatKey businessObjectFormatParent : businessObjectFormatParentsUpdateRequest .getBusinessObjectFormatParents()) { // Retrieve and ensure that a business object format exists. BusinessObjectFormatEntity businessObjectFormatEntityParent = businessObjectFormatDaoHelper .getBusinessObjectFormatEntity(businessObjectFormatParent); businessObjectFormatParents.add(businessObjectFormatEntityParent); } // Set the business object format parents. businessObjectFormatEntity.setBusinessObjectFormatParents(new ArrayList<>(businessObjectFormatParents)); // Persist and refresh the entity. businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity); // Notify the search index that a business object definition must be updated. LOGGER.info( "Modify the business object definition in the search index associated with the business object definition format being updated." + " businessObjectDefinitionId=\"{}\", searchIndexUpdateType=\"{}\"", businessObjectFormatEntity.getBusinessObjectDefinition().getId(), SEARCH_INDEX_UPDATE_TYPE_UPDATE); searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex( businessObjectFormatEntity.getBusinessObjectDefinition(), SEARCH_INDEX_UPDATE_TYPE_UPDATE); // Create and return the business object format object from the persisted entity. return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity); }