test_class.declarator: awsHelper
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private AwsHelper awsHelper;
test_class.type: AwsHelper
test_class.var_name: awsHelper
test_class.declarator: businessObjectDataDao
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private BusinessObjectDataDao businessObjectDataDao;
test_class.type: BusinessObjectDataDao
test_class.var_name: businessObjectDataDao
test_class.declarator: businessObjectDataHelper
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private BusinessObjectDataHelper businessObjectDataHelper;
test_class.type: BusinessObjectDataHelper
test_class.var_name: businessObjectDataHelper
test_class.declarator: herdDao
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private HerdDaoImpl herdDao;
test_class.type: HerdDaoImpl
test_class.var_name: herdDao
test_class.declarator: herdStringHelper
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private HerdStringHelper herdStringHelper;
test_class.type: HerdStringHelper
test_class.var_name: herdStringHelper
test_class.declarator: jsonHelper
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private JsonHelper jsonHelper;
test_class.type: JsonHelper
test_class.var_name: jsonHelper
test_class.declarator: sqsDao
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private SqsDao sqsDao;
test_class.type: SqsDao
test_class.var_name: sqsDao
test_class.declarator: storagePolicySelectorServiceImpl
test_class.modifier: @InjectMocks
      private
test_class.original_string: @InjectMocks
      private StoragePolicySelectorServiceImpl storagePolicySelectorServiceImpl;
test_class.type: StoragePolicySelectorServiceImpl
test_class.var_name: storagePolicySelectorServiceImpl
test_class.file: herd-code/herd-service/src/test/java/org/finra/herd/service/impl/StoragePolicySelectorServiceImplTest.java
test_class.identifier: StoragePolicySelectorServiceImplTest
test_class.superclass: extends AbstractServiceTest
test_case.body: @Test
      public void testCompleteStoragePolicyTransitionImpl()
      {
          // Create a current timestamp.
          Timestamp currentTimestamp = new Timestamp(LONG_VALUE);
  
          // Set a number of maximum results.
          Integer maxResults = 10;
  
          // Create configuration values required for testing.
          Integer updatedOnThresholdInDays = 90;
          Integer storagePolicyTransitionMaxAllowedAttempts = 3;
  
          // Create an empty mapping of matched business object data entities.
          Map<BusinessObjectDataEntity, StoragePolicyEntity> noMatchingBusinessObjectDataEntities = new HashMap<>();
  
          // Create an empty list of storage policy selections.
          List<StoragePolicySelection> storagePolicySelections = new ArrayList<>();
  
          // Mock the external calls.
          when(herdDao.getCurrentTimestamp()).thenReturn(currentTimestamp);
          when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS))
              .thenReturn(updatedOnThresholdInDays);
          when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(0),
              StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults))
              .thenReturn(noMatchingBusinessObjectDataEntities);
          when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(1),
              StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults))
              .thenReturn(noMatchingBusinessObjectDataEntities);
          when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(2),
              StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults))
              .thenReturn(noMatchingBusinessObjectDataEntities);
          when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(3),
              StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults))
              .thenReturn(noMatchingBusinessObjectDataEntities);
          when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS))
              .thenReturn(storagePolicyTransitionMaxAllowedAttempts);
  
          // Call the method under test.
          List<StoragePolicySelection> result = storagePolicySelectorServiceImpl.execute(AWS_SQS_QUEUE_NAME, maxResults);
  
          // Verify the external calls.
          verify(herdDao).getCurrentTimestamp();
          verify(herdStringHelper).getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS);
          verify(herdStringHelper).getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS);
          verify(businessObjectDataDao)
              .getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(0),
                  StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
          verify(businessObjectDataDao)
              .getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(1),
                  StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
          verify(businessObjectDataDao)
              .getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(2),
                  StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
          verify(businessObjectDataDao)
              .getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(3),
                  StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
          verifyNoMoreInteractionsHelper();
  
          // Validate the results.
          assertEquals(storagePolicySelections, result);
      }
test_case.class_method_signature: StoragePolicySelectorServiceImplTest.testCompleteStoragePolicyTransitionImpl()
test_case.full_signature: @Test public void testCompleteStoragePolicyTransitionImpl()
test_case.identifier: testCompleteStoragePolicyTransitionImpl
test_case.invocations: thenReturn when getCurrentTimestamp thenReturn when getConfigurationValueAsInteger thenReturn when getBusinessObjectDataEntitiesMatchingStoragePolicies get thenReturn when getBusinessObjectDataEntitiesMatchingStoragePolicies get thenReturn when getBusinessObjectDataEntitiesMatchingStoragePolicies get thenReturn when getBusinessObjectDataEntitiesMatchingStoragePolicies get thenReturn when getConfigurationValueAsInteger execute getCurrentTimestamp verify getConfigurationValueAsInteger verify getConfigurationValueAsInteger verify getBusinessObjectDataEntitiesMatchingStoragePolicies verify get getBusinessObjectDataEntitiesMatchingStoragePolicies verify get getBusinessObjectDataEntitiesMatchingStoragePolicies verify get getBusinessObjectDataEntitiesMatchingStoragePolicies verify get verifyNoMoreInteractionsHelper assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCompleteStoragePolicyTransitionImpl()
focal_class.declarator: STORAGE_POLICY_PRIORITY_LEVELS = Collections.unmodifiableList(Arrays
          .asList(new StoragePolicyPriorityLevel(false, false, false), new StoragePolicyPriorityLevel(false, true, true),
              new StoragePolicyPriorityLevel(true, false, false), new StoragePolicyPriorityLevel(true, true, true)))
focal_class.modifier: public static final
focal_class.original_string: public static final List<StoragePolicyPriorityLevel> STORAGE_POLICY_PRIORITY_LEVELS = Collections.unmodifiableList(Arrays
          .asList(new StoragePolicyPriorityLevel(false, false, false), new StoragePolicyPriorityLevel(false, true, true),
              new StoragePolicyPriorityLevel(true, false, false), new StoragePolicyPriorityLevel(true, true, true)));
focal_class.type: List<StoragePolicyPriorityLevel>
focal_class.var_name: STORAGE_POLICY_PRIORITY_LEVELS
focal_class.declarator: SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES = Collections
          .unmodifiableList(Arrays.asList(BusinessObjectDataStatusEntity.VALID, BusinessObjectDataStatusEntity.INVALID, BusinessObjectDataStatusEntity.EXPIRED))
focal_class.modifier: public static final
focal_class.original_string: public static final List<String> SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES = Collections
          .unmodifiableList(Arrays.asList(BusinessObjectDataStatusEntity.VALID, BusinessObjectDataStatusEntity.INVALID, BusinessObjectDataStatusEntity.EXPIRED));
focal_class.type: List<String>
focal_class.var_name: SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES
focal_class.declarator: LOGGER = LoggerFactory.getLogger(StoragePolicySelectorServiceImpl.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(StoragePolicySelectorServiceImpl.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: awsHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private AwsHelper awsHelper;
focal_class.type: AwsHelper
focal_class.var_name: awsHelper
focal_class.declarator: businessObjectDataDao
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private BusinessObjectDataDao businessObjectDataDao;
focal_class.type: BusinessObjectDataDao
focal_class.var_name: businessObjectDataDao
focal_class.declarator: businessObjectDataHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private BusinessObjectDataHelper businessObjectDataHelper;
focal_class.type: BusinessObjectDataHelper
focal_class.var_name: businessObjectDataHelper
focal_class.declarator: herdDao
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private HerdDao herdDao;
focal_class.type: HerdDao
focal_class.var_name: herdDao
focal_class.declarator: herdStringHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private HerdStringHelper herdStringHelper;
focal_class.type: HerdStringHelper
focal_class.var_name: herdStringHelper
focal_class.declarator: jsonHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private JsonHelper jsonHelper;
focal_class.type: JsonHelper
focal_class.var_name: jsonHelper
focal_class.declarator: sqsDao
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private SqsDao sqsDao;
focal_class.type: SqsDao
focal_class.var_name: sqsDao
focal_class.file: herd-code/herd-service/src/main/java/org/finra/herd/service/impl/StoragePolicySelectorServiceImpl.java
focal_class.identifier: StoragePolicySelectorServiceImpl
focal_class.interfaces: implements StoragePolicySelectorService
focal_class.class_method_signature: StoragePolicySelectorServiceImpl.execute(String sqsQueueName, int maxResult)
focal_class.full_signature: @Override public List<StoragePolicySelection> execute(String sqsQueueName, int maxResult)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (String sqsQueueName, int maxResult)
focal_class.return: List<StoragePolicySelection>
focal_class.signature: List<StoragePolicySelection> execute(String sqsQueueName, int maxResult)
focal_class.class_method_signature: StoragePolicySelectorServiceImpl.sendStoragePolicySelectionToSqsQueue(String sqsQueueName, List<StoragePolicySelection> storagePolicySelections)
focal_class.full_signature: private void sendStoragePolicySelectionToSqsQueue(String sqsQueueName, List<StoragePolicySelection> storagePolicySelections)
focal_class.identifier: sendStoragePolicySelectionToSqsQueue
focal_class.modifiers: private
focal_class.parameters: (String sqsQueueName, List<StoragePolicySelection> storagePolicySelections)
focal_class.return: void
focal_class.signature: void sendStoragePolicySelectionToSqsQueue(String sqsQueueName, List<StoragePolicySelection> storagePolicySelections)
focal_method.body: @Override
      public List<StoragePolicySelection> execute(String sqsQueueName, int maxResult)
      {
          // Create a result list.
          List<StoragePolicySelection> storagePolicySelections = new ArrayList<>();
  
          // Get the current timestamp from the database.
          Timestamp currentTimestamp = herdDao.getCurrentTimestamp();
  
          // Get the threshold in days since business object data registration update for business object data to be selectable
          // by a storage policy with DAYS_SINCE_BDATA_PRIMARY_PARTITION_VALUE storage policy rule type.
          int updatedOnThresholdInDays =
              herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS);
  
          // Get the maximum number of failed storage policy transition attempts before the relative storage unit gets excluded from
          // being selected per storage policies by the storage policy selector system job. 0 means the maximum is not set.
          int maxAllowedTransitionAttempts = herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS);
  
          LOGGER.info("{}={} {}={}", ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS.getKey(), updatedOnThresholdInDays,
              ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS.getKey(), maxAllowedTransitionAttempts);
  
          // Compute business object data "updated on" threshold timestamp based on
          // the current database timestamp and the threshold value configured in the system.
          Timestamp updatedOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -updatedOnThresholdInDays);
  
          // Keep track of all business object data entities selected per storage policies. This is need to avoid a lower priority selection policy
          // to be executed ahead of a higher priority one.
          Set<BusinessObjectDataEntity> selectedBusinessObjectDataEntities = new LinkedHashSet<>();
  
          // Separately process all possible storage policy priority levels in order of priorities. This is done to assure that higher priority level storage
          // policies will be listed earlier in the final result map.
          for (StoragePolicyPriorityLevel storagePolicyPriorityLevel : STORAGE_POLICY_PRIORITY_LEVELS)
          {
              // Until we reach maximum number of results or run out of entities to select, retrieve and process business object data entities mapped to their
              // corresponding storage policy entities, where the business object data status is supported by the storage policy feature and the business object
              // data alternate key values match storage policy's filter and transition (not taking into account storage policy rules).
              int startPosition = 0;
              while (true)
              {
                  Map<BusinessObjectDataEntity, StoragePolicyEntity> map = businessObjectDataDao
                      .getBusinessObjectDataEntitiesMatchingStoragePolicies(storagePolicyPriorityLevel, SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES,
                          maxAllowedTransitionAttempts, startPosition, maxResult);
  
                  for (Map.Entry<BusinessObjectDataEntity, StoragePolicyEntity> entry : map.entrySet())
                  {
                      BusinessObjectDataEntity businessObjectDataEntity = entry.getKey();
  
                      // Process this storage policy selection, only if this business object data has not been selected earlier.
                      if (!selectedBusinessObjectDataEntities.contains(businessObjectDataEntity))
                      {
                          boolean createStoragePolicySelection = false;
  
                          // Remember that we got this business object data entity as matching to a storage policy.
                          // This is done so we would not try to select this business object data again later by a lower level storage policy.
                          selectedBusinessObjectDataEntities.add(businessObjectDataEntity);
  
                          // Get the storage policy entity, so we can validate the storage policy rule against this business object data.
                          StoragePolicyEntity storagePolicyEntity = entry.getValue();
  
                          // Get a storage policy rule type and value.
                          String storagePolicyRuleType = storagePolicyEntity.getStoragePolicyRuleType().getCode();
                          Integer storagePolicyRuleValue = storagePolicyEntity.getStoragePolicyRuleValue();
  
                          // For DAYS_SINCE_BDATA_REGISTERED storage policy rule type, select business object data based on it's "created on" timestamp.
                          if (StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_REGISTERED.equals(storagePolicyRuleType))
                          {
                              // Compute "created on" threshold timestamp based on the current timestamp and storage policy rule value.
                              Timestamp createdOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue);
  
                              // Select this business object data if it has "created on" timestamp before or equal to the threshold timestamp.
                              createStoragePolicySelection = (businessObjectDataEntity.getCreatedOn().compareTo(createdOnThresholdTimestamp) <= 0);
                          }
                          // For DAYS_SINCE_BDATA_PRIMARY_PARTITION_VALUE storage policy rule type, select business object data based on both it's primary
                          // partition value compared against storage policy rule value and "updated on" timestamp being below the threshold.
                          else if (StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_PRIMARY_PARTITION_VALUE.equals(storagePolicyRuleType))
                          {
                              // For this storage policy rule, we ignore this business object data if it was updated earlier than the threshold value of days ago.
                              if (businessObjectDataEntity.getUpdatedOn().compareTo(updatedOnThresholdTimestamp) <= 0)
                              {
                                  // Try to convert business object data primary partition value to a timestamp.
                                  // If it is not a date, the storage policy rule is not matching this business object data.
                                  Date primaryPartitionValue = businessObjectDataHelper.getDateFromString(businessObjectDataEntity.getPartitionValue());
  
                                  // For this storage policy rule, we ignore this business data if primary partition value is not a date.
                                  if (primaryPartitionValue != null)
                                  {
                                      // Compute the relative primary partition value threshold date based on the current timestamp and storage policy rule value.
                                      Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue).getTime());
  
                                      // Select this business object data if it has it's primary partition value before or equal to the threshold date.
                                      createStoragePolicySelection = (primaryPartitionValue.compareTo(primaryPartitionValueThreshold) <= 0);
                                  }
                              }
                          }
                          // Fail on an un-supported storage policy rule type.
                          else
                          {
                              throw new IllegalStateException(String.format("Storage policy type \"%s\" is not supported.", storagePolicyRuleType));
                          }
  
                          // If this business object data got selected, create a storage policy selection and add it to the result list.
                          if (createStoragePolicySelection)
                          {
                              // Create business object data key and storage policy key per selected entities.
                              BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
                              StoragePolicyKey storagePolicyKey =
                                  new StoragePolicyKey(storagePolicyEntity.getNamespace().getCode(), storagePolicyEntity.getName());
  
                              // Create and add a storage policy selection to the result list.
                              storagePolicySelections.add(new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, storagePolicyEntity.getVersion()));
  
                              LOGGER.info("Selected business object data for storage policy processing: " +
                                  "businessObjectDataKey={} storagePolicyKey={} storagePolicyVersion={}", jsonHelper.objectToJson(businessObjectDataKey),
                                  jsonHelper.objectToJson(storagePolicyKey), storagePolicyEntity.getVersion());
  
                              // Stop adding storage policy selections to the result list if we reached the maximum results limit.
                              if (storagePolicySelections.size() >= maxResult)
                              {
                                  break;
                              }
                          }
                      }
                  }
  
                  // Stop processing storage policies if we reached the max result limit or there are no more business object data to select.
                  if (storagePolicySelections.size() >= maxResult || map.isEmpty())
                  {
                      break;
                  }
  
                  // Increment start position for the next select.
                  startPosition += maxResult;
              }
  
              // Stop processing storage policies if we reached the max result limit.
              if (storagePolicySelections.size() >= maxResult)
              {
                  break;
              }
          }
  
          // Send all storage policy selections to the specified SQS queue.
          sendStoragePolicySelectionToSqsQueue(sqsQueueName, storagePolicySelections);
  
          return storagePolicySelections;
      }
focal_method.class_method_signature: StoragePolicySelectorServiceImpl.execute(String sqsQueueName, int maxResult)
focal_method.full_signature: @Override public List<StoragePolicySelection> execute(String sqsQueueName, int maxResult)
focal_method.identifier: execute
focal_method.invocations: getCurrentTimestamp getConfigurationValueAsInteger getConfigurationValueAsInteger info getKey getKey addDays getBusinessObjectDataEntitiesMatchingStoragePolicies entrySet getKey contains add getValue getCode getStoragePolicyRuleType getStoragePolicyRuleValue equals addDays compareTo getCreatedOn equals compareTo getUpdatedOn getDateFromString getPartitionValue getTime addDays compareTo format getBusinessObjectDataKey getCode getNamespace getName add getVersion info objectToJson objectToJson getVersion size size isEmpty size sendStoragePolicySelectionToSqsQueue
focal_method.modifiers: @Override public
focal_method.parameters: (String sqsQueueName, int maxResult)
focal_method.return: List<StoragePolicySelection>
focal_method.signature: List<StoragePolicySelection> execute(String sqsQueueName, int maxResult)