class BusinessObjectFormatServiceImpl implements BusinessObjectFormatService {

    @NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE)
    @Override
    public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(BusinessObjectFormatKey businessObjectFormatKey,
        BusinessObjectFormatRetentionInformationUpdateRequest updateRequest)
    {
        // Validate and trim the business object format retention information update request update request.
        Assert.notNull(updateRequest, "A business object format retention information update request must be specified.");
        Assert.notNull(updateRequest.isRecordFlag(), "A record flag in business object format retention information update request must be specified.");
        businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false);
        Assert.isNull(businessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified.");

        // Validate business object format retention information.
        RetentionTypeEntity recordRetentionTypeEntity = null;
        if (updateRequest.getRetentionType() != null)
        {
            // Trim the business object format retention in update request.
            updateRequest.setRetentionType(updateRequest.getRetentionType().trim());

            // Retrieve and ensure that a retention type exists.
            recordRetentionTypeEntity = businessObjectFormatDaoHelper.getRecordRetentionTypeEntity(updateRequest.getRetentionType());

            if (recordRetentionTypeEntity.getCode().equals(RetentionTypeEntity.PARTITION_VALUE))
            {
                Assert.notNull(updateRequest.getRetentionPeriodInDays(),
                    String.format("A retention period in days must be specified for %s retention type.", RetentionTypeEntity.PARTITION_VALUE));
                Assert.isTrue(updateRequest.getRetentionPeriodInDays() > 0,
                    String.format("A positive retention period in days must be specified for %s retention type.", RetentionTypeEntity.PARTITION_VALUE));
            }
            else
            {
                Assert.isNull(updateRequest.getRetentionPeriodInDays(),
                    String.format("A retention period in days cannot be specified for %s retention type.", recordRetentionTypeEntity.getCode()));
            }
        }
        else
        {
            // Do not allow retention period to be specified without retention type.
            Assert.isNull(updateRequest.getRetentionPeriodInDays(), "A retention period in days cannot be specified without retention type.");
        }

        // Retrieve and ensure that a business object format exists.
        BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
        businessObjectFormatEntity.setRecordFlag(BooleanUtils.isTrue(updateRequest.isRecordFlag()));
        businessObjectFormatEntity.setRetentionPeriodInDays(updateRequest.getRetentionPeriodInDays());
        businessObjectFormatEntity.setRetentionType(recordRetentionTypeEntity);

        // Persist and refresh the entity.
        businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);

        // Create and return the business object format object from the persisted entity.
        return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
    }

}