0

I have a project that reads from mongodb and sends that information to the queue. my listener picks up the queue message from cloud. I am able to create a .txt file that inputs all the information inside from the queue. My problem that I have been searching for is: How can I sort through a specific field inside the POJO (IBusiness1,IBusiness2,IBusiness3)and create the file for each? The following code allows me to create only 1 txt file and it does not sort the field:

    public static void main(String[] args) {
        SpringApplication.run(PaymentPortalBatchListenerApplication.class, args);
    }

    private class MessageHandler implements IMessageHandler {
        private final Logger logger = LoggerFactory.getLogger(MessageHandler.class);

        public CompletableFuture<Void> onMessageAsync(IMessage message) {
            System.out.println("received "+message.getBody());
            ObjectMapper om = new ObjectMapper();
            PortalList auditList = null;

            try {
                auditList = om.readValue( message.getBody(), PortalList.class );
                System.out.println( "**Audit Message   " + auditList );
                logger.info( "Creating file");
                String exportFilePath = "C:\\filewriter\\IBusiness1 " + 
                LocalDateTime.now().format(formatter) + ".txt";
                File file = new File(exportFilePath);
                FileWriter writeToFile = new FileWriter(file);
                String exportFileHeader = "CREATE_DTTM|FNAME|LNAME|IBusiness";
                StringHeaderWriter headerWriter = new 
                StringHeaderWriter(exportFileHeader);
                writeToFile.write(exportFileHeader);
                writeToFile.write( String.valueOf( headerWriter));
                writeToFile.write( String.valueOf(auditList));
                writeToFile.flush();

            } catch (IOException e) {
                e.printStackTrace();
            }

//          System.out.println(auditList);
            return CompletableFuture.completedFuture(null);
        }

1 Answer 1

0

Here is what I did:

PaymentPortalBean = POJO auditlist =on-prem copy of PPB

PortalList =

    import lombok.Data;

import java.util.List;

@Data
public class PortalList{

    private List<PaymentPortalBean> portalList;
}

answer to creating files:

         for(PaymentPortalBean bean: auditList.getPortalList()) {
                if(bean.RxBusiness().contains( "IBusiness")){
                    File file = new File( exportFilePath );
                    FileWriter writeToFile = new FileWriter( file );
                    String exportFileHeader = CREATE_DTTM|FNAME|LNAME|IBusiness";
                    writeToFile.write( exportFileHeader );
                    writeToFile.write( String.valueOf(bean));
                    writeToFile.flush();
                }

that worked to to find IBusiness, I created two more conditional statements for the types I needed. runs fine. Mongo db was able to separate the fields I needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.