Java Code Examples for org.apache.commons.collections4.CollectionUtils#size()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpstreamJob.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public synchronized void onFinished(boolean success) {
    LOGGER.debug("job.onFinished({}), job={}", success, this);
    for (int i = jobFinishedCallbacks.size() - 1; i >= 0; i--) {
        try {
            jobFinishedCallbacks.get(i).callback(this, success);
        } catch (Throwable t) {
            LOGGER.error("Job.Finish callback.i=" + i + info(), t);
        }
    }
    resultCallBack.setResult(success);
    if (actionIndex < CollectionUtils.size(getActions())) {
        MetricUtils.put(this.getGroupId(), this.getTopic(), MetricUtils.IneffectiveMessage);
        if (!success) {
            DROP_LOGGER.info("[job:{},msg:{}]", this.info(), StringUtils.newString(this.getCommonMessage().getValue()));
        }
    } else {
        MetricUtils.put(this.getGroupId(), this.getTopic(), MetricUtils.EffectiveMessage);
    }
}
 
Example 2
Source File: UpstreamJob.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public int nextRetryDelay() {
    List<Integer> retryIntervals = upstreamTopic.getRetryIntervals();
    retryIdx++;
    if (retryIdx < CollectionUtils.size(retryIntervals)) {
        int interval = retryIntervals.get(retryIdx);
        if (interval == -1) {
            retryIdx--;
            if (retryIdx >= 0) {
                return retryIntervals.get(retryIdx);
            }
        } else {
            return interval;
        }
    }
    return -1;
}
 
Example 3
Source File: ConfigManager.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private void handleGroupConfigChanged(GroupConfig newConf) {
    //过滤掉禁用的订阅
    newConf.getTopics().removeIf(upstreamTopic -> !upstreamTopic.isEnabled());
    if (CollectionUtils.size(newConf.getTopics()) == 0) {
        return;
    }

    //构造配置
    ConsumerGroupConfig config = new ConsumerGroupConfig();
    config.setInstance(instance);
    config.setGroup(newConf.getGroup());
    config.setBrokerCluster(MixAll.BROKER_CLUSTER_GENERAL_NAME);
    config.setGroupConfig(newConf);
    config.setcProxyConfig(curCproxyConfig);
    config.setDelayRequestHandlerThreads(newConf.getDelayRequestHandlerThreads());

    config.createIndex();

    if (!config.validate()) {
        LogUtils.logErrorInfo("config_error", "config error, group:{}, config:{}", config.getGroup(), config.toString());
        return;
    }
    ConsumerManager.getInstance().addOrUpdateConsumer(config);
}
 
Example 4
Source File: UpstreamJob.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public int nextRetryDelay() {
    List<Integer> retryIntervals = upstreamTopic.getRetryIntervals();
    retryIdx++;
    if (retryIdx < CollectionUtils.size(retryIntervals)) {
        int interval = retryIntervals.get(retryIdx);
        if (interval == -1) {
            retryIdx--;
            if (retryIdx >= 0) {
                return retryIntervals.get(retryIdx);
            }
        } else {
            return interval;
        }
    }
    return -1;
}
 
Example 5
Source File: UpstreamJob.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public synchronized void onFinished(boolean success) {
    LOGGER.debug("job.onFinished({}), job={}", success, this);
    for (int i = jobFinishedCallbacks.size() - 1; i >= 0; i--) {
        try {
            jobFinishedCallbacks.get(i).callback(this, success);
        } catch (Throwable t) {
            LOGGER.error("Job.Finish callback.i=" + i + info(), t);
        }
    }
    resultCallBack.setResult(success);
    if (actionIndex < CollectionUtils.size(getActions())) {
        MetricUtils.put(this.getGroupId(), this.getTopic(), MetricUtils.IneffectiveMessage);
        if (!success) {
            DROP_LOGGER.info("[job:{},msg:{}]", this.info(), StringUtils.newString(this.getCommonMessage().getValue()));
        }
    } else {
        MetricUtils.put(this.getGroupId(), this.getTopic(), MetricUtils.EffectiveMessage);
    }
}
 
Example 6
Source File: OperationTagsSizeEqValidator.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location,
  Operation oasObject) {

  List<String> tags = oasObject.getTags();
  if (CollectionUtils.size(tags) != expectedSize) {
    return singletonList(new OasViolation(location.property("tags"), ERROR + expectedSize));
  }
  return emptyList();
}
 
Example 7
Source File: BusinessObjectDataHelper.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Validates a list of sub-partition values. This method also trims the sub-partition values.
 *
 * @param subPartitionValues the list of sub-partition values
 *
 * @throws IllegalArgumentException if a sub-partition value is missing or not valid
 */
public void validateSubPartitionValues(List<String> subPartitionValues) throws IllegalArgumentException
{
    int subPartitionValuesCount = CollectionUtils.size(subPartitionValues);

    Assert.isTrue(subPartitionValuesCount <= BusinessObjectDataEntity.MAX_SUBPARTITIONS,
        String.format("Exceeded maximum number of allowed subpartitions: %d.", BusinessObjectDataEntity.MAX_SUBPARTITIONS));

    for (int i = 0; i < subPartitionValuesCount; i++)
    {
        subPartitionValues.set(i, alternateKeyHelper.validateStringParameter("subpartition value", subPartitionValues.get(i)));
    }
}
 
Example 8
Source File: RetentionExpirationExporterController.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Writes business object data to the CSV file.
 *
 * @param localOutputFile the file to write
 * @param namespace the namespace of business object definition
 * @param businessObjectDefinitionName the name of the business object definition
 * @param businessObjectDefinitionDisplayName the display name of the business object definition
 * @param udcServerHost the hostname of the UDC application server
 * @param businessObjectDataList the list of business object data
 *
 * @throws IOException if any problems were encountered
 */
private void writeToCsvFile(File localOutputFile, String namespace, String businessObjectDefinitionName, String businessObjectDefinitionDisplayName,
    String udcServerHost, List<BusinessObjectData> businessObjectDataList) throws IOException, URISyntaxException
{
    // Create business object definition URI.
    String businessObjectDefinitionUdcUri = getBusinessObjectDefinitionUdcUri(udcServerHost, namespace, businessObjectDefinitionName);

    // Create the local output file.
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(localOutputFile), StandardCharsets.UTF_8))
    {
        // Write csv file header.
        writeLine(writer, Arrays.asList("Namespace", "Business Object Definition Name", "Business Object Format Usage", "Business Object Format File Type",
            "Business Object Format Version", "Primary Partition Value", "Sub-Partition Value 1", "Sub-Partition Value 2", "Sub-Partition Value 3",
            "Sub-Partition Value 4", "Business Object Data Version", "Business Object Definition Display Name", "Business Object Definition URI"));

        for (BusinessObjectData businessObjectData : businessObjectDataList)
        {
            int subPartitionsCount = CollectionUtils.size(businessObjectData.getSubPartitionValues());
            List<String> businessObjectDataRecords = Arrays.asList(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(),
                businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(),
                Integer.toString(businessObjectData.getBusinessObjectFormatVersion()), businessObjectData.getPartitionValue(),
                subPartitionsCount > 0 ? businessObjectData.getSubPartitionValues().get(0) : "",
                subPartitionsCount > 1 ? businessObjectData.getSubPartitionValues().get(1) : "",
                subPartitionsCount > 2 ? businessObjectData.getSubPartitionValues().get(2) : "",
                subPartitionsCount > 3 ? businessObjectData.getSubPartitionValues().get(3) : "", Integer.toString(businessObjectData.getVersion()),
                businessObjectDefinitionDisplayName, businessObjectDefinitionUdcUri);
            writeLine(writer, businessObjectDataRecords);
        }
    }
}
 
Example 9
Source File: SavedQueryController.java    From find with MIT License 5 votes vote down vote up
private Collection<S> convertEmbeddableIndexes(final Iterable<EmbeddableIndex> embeddableIndexes) {
    final Collection<S> indexes = new ArrayList<>(CollectionUtils.size(embeddableIndexes));
    if(embeddableIndexes != null) {
        for(final EmbeddableIndex embeddableIndex : embeddableIndexes) {
            indexes.add(convertEmbeddableIndex(embeddableIndex));
        }
    }

    return indexes;
}
 
Example 10
Source File: BusinessObjectDataInitiateDestroyHelperServiceImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves and validates storage unit for the specified business object data. The method makes sure that there is one and only one S3 storage unit.
 *
 * @param businessObjectDataEntity the business object data entity
 * @param businessObjectDataKey the business object data key
 *
 * @return the storage unit entity
 */
StorageUnitEntity getAndValidateStorageUnit(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey)
{
    // Retrieve all S3 storage units for this business object data.
    List<StorageUnitEntity> s3StorageUnitEntities =
        storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);

    // Validate that business object data has at least one S3 storage unit.
    if (CollectionUtils.isEmpty(s3StorageUnitEntities))
    {
        throw new IllegalArgumentException(String.format("Business object data has no S3 storage unit. Business object data: {%s}",
            businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }

    // Validate that this business object data has no multiple S3 storage units.
    if (CollectionUtils.size(s3StorageUnitEntities) > 1)
    {
        throw new IllegalArgumentException(String
            .format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", s3StorageUnitEntities.size(),
                StoragePlatformEntity.S3, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }

    // Get the S3 storage unit.
    StorageUnitEntity storageUnitEntity = s3StorageUnitEntities.get(0);

    // Get the storage unit status code.
    String storageUnitStatus = storageUnitEntity.getStatus().getCode();

    // Validate storage unit status.
    if (!BusinessObjectDataInitiateDestroyHelperServiceImpl.SUPPORTED_STORAGE_UNIT_STATUSES.contains(storageUnitStatus))
    {
        throw new IllegalArgumentException(String
            .format("Storage unit status \"%s\" is not supported by the business object data destroy feature. Storage: {%s}, business object data: {%s}",
                storageUnitStatus, storageUnitEntity.getStorage().getName(),
                businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }

    return storageUnitEntity;
}
 
Example 11
Source File: Plan.java    From DataDefender with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Class of the first function's dynamic argument if one is set,
 * or null otherwise.
 *
 * @return
 */
public Class<?> getDynamicArgumentType() {
    if (CollectionUtils.size(functions) > 0) {
        return CollectionUtils.emptyIfNull(functions.get(0).getArguments())
            .stream()
            .filter((a) -> Objects.equals(Boolean.TRUE, a.getIsDynamicValue()))
            .map((a) -> a.getType())
            .findFirst()
            .orElse(null);
    }
    return null;
}
 
Example 12
Source File: SizeSeverityAlertGroupFilter.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isQualified(GroupedAnomalyResultsDTO groupedAnomaly) {
  Set<String> dimensionNames = new HashSet<>();
  dimensionNames.addAll(groupedAnomaly.getDimensions().keySet());
  int threshold = this.threshold;
  if (overrideThreshold.containsKey(dimensionNames)) {
    threshold = overrideThreshold.get(dimensionNames);
  }
  return CollectionUtils.size(groupedAnomaly.getAnomalyResults()) > threshold;
}
 
Example 13
Source File: OpenApiTagsSizeGteValidator.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) {

  if (CollectionUtils.size(openAPI.getTags()) < expectedSize) {
    return singletonList(new OasViolation(location.property("tags", OasObjectType.TAG), ERROR + expectedSize));
  }
  return emptyList();

}
 
Example 14
Source File: OperationServersSizeEqValidator.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location,
  Operation oasObject) {

  if (CollectionUtils.size(oasObject.getServers()) != expectedSize) {
    return singletonList(new OasViolation(location.property("servers", SERVER), ERROR + expectedSize));
  }
  return emptyList();
}
 
Example 15
Source File: UpstreamJob.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public void execute() {
    if (!upstreamTopic.isPressureTraffic() && isPressureTrafficMessage()) {
        onFinished(true);
        LOGGER.debug("pressure traffic message, do not send, group:{}, topic:{}, key:{}", getGroupId(), getTopic(), message.getKey());
        return;
    }
    if (actionIndex == CollectionUtils.size(getActions())) {
        onFinished(true);
        return;
    }
    String actionName = getActions().get(actionIndex++);
    state = actionName;
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("job executing... {} actionIndex={}, act={}, thread={}", info(), actionIndex - 1, actionName, Thread.currentThread());
    }

    Action action = actionMap.get(actionName);
    if (action == null) {
        LOGGER.error("wrong act: {}", actionName);
        onFinished(false);
        return;
    }

    if (isTerminated) {
        LOGGER.info("job is terminated! job={}", info());
        terminate();
        return;
    }

    Action.Status status;
    try {
        status = action.act(this);
    } catch (Throwable e) {
        LOGGER.error("unexpected err, job=" + info(), e);
        onFinished(false);
        return;
    }
    switch (status) {
        case FAIL:
            LOGGER.error("execute error,job={}", info());
            onFinished(false);
            break;
        case FINISH:
            onFinished(true);
            break;
        case ASYNCHRONIZED:
            break;
        case CONTINUE:
            execute();
    }
}
 
Example 16
Source File: ApacheCommonsUtils.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public int collectionSize(Collection collection) {
	return CollectionUtils.size(collection);
}
 
Example 17
Source File: BusinessObjectDataDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getBusinessObjectDataLimitedCountBySearchKey(BusinessObjectDataSearchKey businessObjectDataSearchKey, Integer recordCountLimit)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);

    // The criteria root is the business object data.
    Root<BusinessObjectDataEntity> businessObjectDataEntityRoot = criteria.from(BusinessObjectDataEntity.class);

    // Namespace and business object definition are required parameters, so fetch the relative business object definition entity to optimize the main query.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(
        new BusinessObjectDefinitionKey(businessObjectDataSearchKey.getNamespace(), businessObjectDataSearchKey.getBusinessObjectDefinitionName()));

    // If specified business object definition does not exist, then return a zero record count.
    if (businessObjectDefinitionEntity == null)
    {
        return 0;
    }

    // If file type is specified, fetch the relative entity to optimize the main query.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatFileType()))
    {
        fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectDataSearchKey.getBusinessObjectFormatFileType());

        // If specified file type does not exist, then return a zero record count.
        if (fileTypeEntity == null)
        {
            return 0;
        }
    }

    // Join to the other tables we can filter on.
    Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin =
        businessObjectDataEntityRoot.join(BusinessObjectDataEntity_.businessObjectFormat);

    // Add select clause to the query. We use business object data partition value column for select, since this is enough to check the record count.
    criteria.select(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue));

    // Add standard restrictions to the query. (i.e. the standard where clauses).
    try
    {
        criteria.where(getQueryPredicateBySearchKey(builder, businessObjectDataEntityRoot, businessObjectFormatEntityJoin, businessObjectDataSearchKey,
            businessObjectDefinitionEntity, fileTypeEntity));
    }
    catch (IllegalArgumentException ex)
    {
        // This exception means that there are no records found for the query, thus return 0 record count.
        return 0;
    }


    // If latest valid version filter is specified, ignore business object format and business object data versions when counting search results.
    // In order to do that, we group by all elements of business object data alternate key, except for the versions.  Please note that we need to apply
    // upper() call on business object format usage, since it is not a dictionary value (does not have the relative lookup table).
    if (BooleanUtils.isTrue(businessObjectDataSearchKey.isFilterOnLatestValidVersion()))
    {
        List<Expression<?>> groupBy = new ArrayList<>();
        groupBy.add(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.businessObjectDefinitionId));
        groupBy.add(builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)));
        groupBy.add(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.fileTypeCode));
        groupBy.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue));
        groupBy.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue2));
        groupBy.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue3));
        groupBy.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue4));
        groupBy.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue5));
        criteria.groupBy(groupBy);
    }

    // Execute the query.
    List<String> businessObjectDataPartitionValues = entityManager.createQuery(criteria).setMaxResults(recordCountLimit).getResultList();

    // Return the size of the result list.
    return CollectionUtils.size(businessObjectDataPartitionValues);
}
 
Example 18
Source File: UpstreamJob.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public void execute() {
    if (!upstreamTopic.isPressureTraffic() && isPressureTrafficMessage()) {
        onFinished(true);
        LOGGER.debug("pressure traffic message, do not send, group:{}, topic:{}, key:{}", getGroupId(), getTopic(), message.getKey());
        return;
    }
    if (actionIndex == CollectionUtils.size(getActions())) {
        onFinished(true);
        return;
    }
    String actionName = getActions().get(actionIndex++);
    state = actionName;
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("job executing... {} actionIndex={}, act={}, thread={}", info(), actionIndex - 1, actionName, Thread.currentThread());
    }

    Action action = actionMap.get(actionName);
    if (action == null) {
        LOGGER.error("wrong act: {}", actionName);
        onFinished(false);
        return;
    }

    if (isTerminated) {
        LOGGER.info("job is terminated! job={}", info());
        terminate();
        return;
    }

    Action.Status status;
    try {
        status = action.act(this);
    } catch (Throwable e) {
        LOGGER.error("unexpected err, job=" + info(), e);
        onFinished(false);
        return;
    }
    switch (status) {
        case FAIL:
            LOGGER.error("execute error,job={}", info());
            onFinished(false);
            break;
        case FINISH:
            onFinished(true);
            break;
        case ASYNCHRONIZED:
            break;
        case CONTINUE:
            execute();
    }
}
 
Example 19
Source File: BusinessObjectDataInitiateRestoreHelperServiceImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves storage unit for the business object data. The method validates that there one and only one storage unit for this business object data in
 * "ARCHIVED" state.
 *
 * @param businessObjectDataEntity the business object data entity
 *
 * @return the archived storage unit entity
 */
protected StorageUnitEntity getStorageUnit(BusinessObjectDataEntity businessObjectDataEntity)
{
    // Retrieve all S3 storage units for this business object data.
    List<StorageUnitEntity> s3StorageUnitEntities =
        storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);

    // Validate that business object data has at least one S3 storage unit.
    if (CollectionUtils.isEmpty(s3StorageUnitEntities))
    {
        throw new IllegalArgumentException(String.format("Business object data has no S3 storage unit. Business object data: {%s}",
            businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
    }

    // Validate that this business object data has no multiple S3 storage units.
    if (CollectionUtils.size(s3StorageUnitEntities) > 1)
    {
        throw new IllegalArgumentException(String
            .format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", s3StorageUnitEntities.size(),
                StoragePlatformEntity.S3, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
    }

    // Get the S3 storage unit.
    StorageUnitEntity storageUnitEntity = s3StorageUnitEntities.get(0);

    // Get the storage unit status code.
    String storageUnitStatus = storageUnitEntity.getStatus().getCode();

    // Validate that this business object data has its S3 storage unit in "ARCHIVED" state.
    if (!StorageUnitStatusEntity.ARCHIVED.equals(storageUnitStatus))
    {
        // Get the storage name.
        String storageName = storageUnitEntity.getStorage().getName();

        // Fail with a custom error message if the S3 storage unit is already enabled.
        if (StorageUnitStatusEntity.ENABLED.equals(storageUnitStatus))
        {
            throw new IllegalArgumentException(String
                .format("Business object data is already available in \"%s\" S3 storage. Business object data: {%s}", storageName,
                    businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData())));
        }
        // Fail with a custom error message if this business object data is already marked as being restored.
        else if (StorageUnitStatusEntity.RESTORING.equals(storageUnitStatus))
        {
            throw new IllegalArgumentException(String
                .format("Business object data is already being restored in \"%s\" S3 storage. Business object data: {%s}", storageName,
                    businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData())));
        }
        // Else, fail and report the actual S3 storage unit status.
        else
        {
            throw new IllegalArgumentException(String.format("Business object data is not archived. " +
                    "S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName,
                StorageUnitStatusEntity.ARCHIVED, storageUnitStatus,
                businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData())));
        }
    }

    return storageUnitEntity;
}
 
Example 20
Source File: BusinessObjectDataDaoHelper.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new business object data entity from the request information.
 *
 * @param request the request.
 * @param businessObjectFormatEntity the business object format entity.
 * @param businessObjectDataVersion the business object data version.
 *
 * @return the newly created business object data entity.
 */
private BusinessObjectDataEntity createBusinessObjectDataEntity(BusinessObjectDataCreateRequest request,
    BusinessObjectFormatEntity businessObjectFormatEntity, Integer businessObjectDataVersion, BusinessObjectDataStatusEntity businessObjectDataStatusEntity)
{
    // Create a new entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setPartitionValue(request.getPartitionValue());
    int subPartitionValuesCount = CollectionUtils.size(request.getSubPartitionValues());
    businessObjectDataEntity.setPartitionValue2(subPartitionValuesCount > 0 ? request.getSubPartitionValues().get(0) : null);
    businessObjectDataEntity.setPartitionValue3(subPartitionValuesCount > 1 ? request.getSubPartitionValues().get(1) : null);
    businessObjectDataEntity.setPartitionValue4(subPartitionValuesCount > 2 ? request.getSubPartitionValues().get(2) : null);
    businessObjectDataEntity.setPartitionValue5(subPartitionValuesCount > 3 ? request.getSubPartitionValues().get(3) : null);
    businessObjectDataEntity.setVersion(businessObjectDataVersion);
    businessObjectDataEntity.setLatestVersion(true);
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);

    // Create the storage unit entities.
    businessObjectDataEntity.setStorageUnits(createStorageUnitEntitiesFromStorageUnits(request.getStorageUnits(), businessObjectDataEntity));

    // Create the attributes.
    List<BusinessObjectDataAttributeEntity> attributeEntities = new ArrayList<>();
    businessObjectDataEntity.setAttributes(attributeEntities);

    if (CollectionUtils.isNotEmpty(request.getAttributes()))
    {
        for (Attribute attribute : request.getAttributes())
        {
            BusinessObjectDataAttributeEntity attributeEntity = new BusinessObjectDataAttributeEntity();
            attributeEntities.add(attributeEntity);
            attributeEntity.setBusinessObjectData(businessObjectDataEntity);
            attributeEntity.setName(attribute.getName());
            attributeEntity.setValue(attribute.getValue());
        }
    }

    // Create the parents.
    List<BusinessObjectDataEntity> businessObjectDataParents = new ArrayList<>();
    businessObjectDataEntity.setBusinessObjectDataParents(businessObjectDataParents);

    // Loop through all the business object data parents.
    if (request.getBusinessObjectDataParents() != null)
    {
        for (BusinessObjectDataKey businessObjectDataKey : request.getBusinessObjectDataParents())
        {
            // Look up the business object data for each parent.
            BusinessObjectDataEntity businessObjectDataParent = getBusinessObjectDataEntity(businessObjectDataKey);

            // Add our newly created entity as a dependent (i.e. child) of the looked up parent.
            businessObjectDataParent.getBusinessObjectDataChildren().add(businessObjectDataEntity);

            // Add the looked up parent as a parent of our newly created entity.
            businessObjectDataParents.add(businessObjectDataParent);
        }
    }

    // Return the newly created entity.
    return businessObjectDataEntity;
}