test_class.declarator: sampleDataJmsMessageListener
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private SampleDataJmsMessageListener sampleDataJmsMessageListener;
test_class.type: SampleDataJmsMessageListener
test_class.var_name: sampleDataJmsMessageListener
test_class.file: herd-code/herd-service/src/test/java/org/finra/herd/service/helper/SampleDataJmsMessageListenerTest.java
test_class.identifier: SampleDataJmsMessageListenerTest
test_class.superclass: extends AbstractServiceTest
test_case.body: @Test
      public void testS3Message() throws Exception
      {
          // Create and persist database entities required for testing.
          businessObjectDefinitionServiceTestHelper.createDatabaseEntitiesForBusinessObjectDefinitionTesting();
  
          storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE,
              Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME)));
  
          // Create a business object definition.
          BusinessObjectDefinitionCreateRequest request =
              new BusinessObjectDefinitionCreateRequest(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME,
                  businessObjectDefinitionServiceTestHelper.getNewAttributes());
          businessObjectDefinitionService.createBusinessObjectDefinition(request);
  
          // Get the business object definition entity.
          BusinessObjectDefinitionEntity businessObjectDefinitionEntity =
              businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
          assertNotNull(businessObjectDefinitionEntity);
  
          String fileName = "test1.csv";
          String filePath = NAMESPACE + "/" + BDEF_NAME + "/" + fileName;
          long fileSize = 1024L;
          S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, fileSize, null, null), null);
  
          List<S3EventNotificationRecord> records = new ArrayList<>();
          records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null));
  
          S3EventNotification s3EventNotification = new S3EventNotification(records);
  
          sampleDataJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
          BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
          BusinessObjectDefinition updatedBusinessObjectDefinition =
              businessObjectDefinitionService.getBusinessObjectDefinition(businessObjectDefinitionKey, false);
  
          List<SampleDataFile> sampleDataFiles = Arrays.asList(new SampleDataFile(NAMESPACE + "/" + BDEF_NAME + "/", fileName));
  
          // Validate the returned object.
          assertEquals(new BusinessObjectDefinition(updatedBusinessObjectDefinition.getId(), NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION,
              NO_BDEF_SHORT_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes(), NO_DESCRIPTIVE_BUSINESS_OBJECT_FORMAT,
              sampleDataFiles, businessObjectDefinitionEntity.getCreatedBy(), businessObjectDefinitionEntity.getUpdatedBy(),
                  HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionEntity.getUpdatedOn()), NO_BUSINESS_OBJECT_DEFINITION_CHANGE_EVENTS),
              updatedBusinessObjectDefinition);
      }
test_case.class_method_signature: SampleDataJmsMessageListenerTest.testS3Message()
test_case.full_signature: @Test public void testS3Message()
test_case.identifier: testS3Message
test_case.invocations: createDatabaseEntitiesForBusinessObjectDefinitionTesting createStorageEntity asList getProperty getNewAttributes createBusinessObjectDefinition getBusinessObjectDefinitionByKey assertNotNull add processMessage objectToJson getBusinessObjectDefinition asList assertEquals getId getNewAttributes getCreatedBy getUpdatedBy getXMLGregorianCalendarValue getUpdatedOn
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testS3Message()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(SampleDataJmsMessageListener.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(SampleDataJmsMessageListener.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: configurationHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private ConfigurationHelper configurationHelper;
focal_class.type: ConfigurationHelper
focal_class.var_name: configurationHelper
focal_class.declarator: businessObjectDefinitionService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private BusinessObjectDefinitionService businessObjectDefinitionService;
focal_class.type: BusinessObjectDefinitionService
focal_class.var_name: businessObjectDefinitionService
focal_class.file: herd-code/herd-service/src/main/java/org/finra/herd/service/helper/SampleDataJmsMessageListener.java
focal_class.identifier: SampleDataJmsMessageListener
focal_class.class_method_signature: SampleDataJmsMessageListener.controlSampleDataJmsMessageListener()
focal_class.full_signature: @Scheduled(fixedDelay = 60000) public void controlSampleDataJmsMessageListener()
focal_class.identifier: controlSampleDataJmsMessageListener
focal_class.modifiers: @Scheduled(fixedDelay = 60000) public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void controlSampleDataJmsMessageListener()
focal_class.class_method_signature: SampleDataJmsMessageListener.processMessage(String payload, @Headers Map<Object, Object> allHeaders)
focal_class.full_signature: @JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE) public void processMessage(String payload, @Headers Map<Object, Object> allHeaders)
focal_class.identifier: processMessage
focal_class.modifiers: @JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE) public
focal_class.parameters: (String payload, @Headers Map<Object, Object> allHeaders)
focal_class.return: void
focal_class.signature: void processMessage(String payload, @Headers Map<Object, Object> allHeaders)
focal_class.class_method_signature: SampleDataJmsMessageListener.convertS3KeyFormat(String string)
focal_class.full_signature: private String convertS3KeyFormat(String string)
focal_class.identifier: convertS3KeyFormat
focal_class.modifiers: private
focal_class.parameters: (String string)
focal_class.return: String
focal_class.signature: String convertS3KeyFormat(String string)
focal_method.body: @JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE,
          containerFactory = "jmsListenerContainerFactory",
          destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE)
      public void processMessage(String payload, @Headers Map<Object, Object> allHeaders)
      {
          LOGGER.info("Message received from the JMS queue. jmsQueueName=\"{}\" jmsMessageHeaders=\"{}\" jmsMessagePayload={}",
              HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, allHeaders, payload);
  
          try
          {
              // Process messages coming from S3 bucket.
              S3EventNotification s3EventNotification = S3EventNotification.parseJson(payload);
              String objectKey = URLDecoder.decode(s3EventNotification.getRecords().get(0).getS3().getObject().getKey(), CharEncoding.UTF_8);
              long fileSize = s3EventNotification.getRecords().get(0).getS3().getObject().getSizeAsLong();
              // parse the objectKey, it should be in the format of namespace/businessObjectDefinitionName/fileName
              String[] objectKeyArrays = objectKey.split("/");
              Assert.isTrue(objectKeyArrays.length == 3, String.format("S3 notification message %s is not in expected format", objectKey));
  
              String namespace = objectKeyArrays[0];
              String businessObjectDefinitionName = objectKeyArrays[1];
              String fileName = objectKeyArrays[2];
              String path = namespace + "/" + businessObjectDefinitionName + "/";
              BusinessObjectDefinitionSampleFileUpdateDto businessObjectDefinitionSampleFileUpdateDto =
                      new BusinessObjectDefinitionSampleFileUpdateDto(path, fileName, fileSize);
  
              String convertedNamespaece = convertS3KeyFormat(namespace);
              String convertedBusinessObjectDefinitionName = convertS3KeyFormat(businessObjectDefinitionName);
  
              BusinessObjectDefinitionKey businessObjectDefinitionKey =
                      new BusinessObjectDefinitionKey(convertedNamespaece, convertedBusinessObjectDefinitionName);
              try
              {
                  businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey,
                          businessObjectDefinitionSampleFileUpdateDto);
              }
              catch (ObjectNotFoundException ex)
              {
                  LOGGER.info("Failed to find the business object definition, next try the original namespace and business oject defination name " + ex);
                  // if Business object definition is not found, use the original name space and bdef name
                  businessObjectDefinitionKey = new BusinessObjectDefinitionKey(namespace, businessObjectDefinitionName);
                  businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey,
                          businessObjectDefinitionSampleFileUpdateDto);
              }
          }
          catch (RuntimeException | IOException e)
          {
              LOGGER.error("Failed to process message from the JMS queue. jmsQueueName=\"{}\" jmsMessagePayload={}",
                      HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, payload, e);
          }
      }
focal_method.class_method_signature: SampleDataJmsMessageListener.processMessage(String payload, @Headers Map<Object, Object> allHeaders)
focal_method.full_signature: @JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE) public void processMessage(String payload, @Headers Map<Object, Object> allHeaders)
focal_method.identifier: processMessage
focal_method.invocations: info parseJson decode getKey getObject getS3 get getRecords getSizeAsLong getObject getS3 get getRecords split isTrue format convertS3KeyFormat convertS3KeyFormat updateBusinessObjectDefinitionEntitySampleFile info updateBusinessObjectDefinitionEntitySampleFile error
focal_method.modifiers: @JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE) public
focal_method.parameters: (String payload, @Headers Map<Object, Object> allHeaders)
focal_method.return: void
focal_method.signature: void processMessage(String payload, @Headers Map<Object, Object> allHeaders)