Skip to content

Commit

Permalink
Updated HDFC creditcard statement reader to support statement with re…
Browse files Browse the repository at this point in the history
…ward points

Added BooleanResult which is error aware,also used it for loading statement feature
Minor changes in MailConnection and Categorizer
  • Loading branch information
Jayeshecs committed Aug 31, 2021
1 parent 84d8d59 commit d1ff2c8
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
*
*/
package domainapp.modules.base.result;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

/**
* Boolean result which is {@link IErrorAware}
*
* @author jayesh.prajapati
*/
@Builder
public class BooleanResult implements IErrorAware {

@Getter
@Setter
private Boolean success;

@Getter
@Setter
private String error;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
*
*/
package domainapp.modules.base.result;

import lombok.Getter;
import lombok.Setter;

/**
* Adapter implementation of {@link IErrorAware}
*
* @author jayesh.prajapati
*/
public abstract class ErrorAwareAdapter implements IErrorAware {

@Getter
@Setter
private String error;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
*
*/
package domainapp.modules.base.result;

/**
* Specification for beans or POJO that are aware of contained error.
*
* @author jayesh.prajapati
*/
public interface IErrorAware {

String getError();

void setError(String error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Categorizer(ICategorizerDataHandler<R, L> labelProvider, TokenPreProcess

// initialize tokenizer factory
tokenizerFactory = new DefaultTokenizerFactory();
tokenizerFactory.setTokenPreProcessor(tokenPreProcessor);
tokenizerFactory.setTokenPreProcessor(this.tokenPreProcessor);
}

public Word2Vec train(Collection<R> listAllCategorized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ protected void read(IStatementReaderContext context, File inputFile, Properties
String regexTransaction = "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d.*";
int indexStartOfTransactions = content.indexOf("Date Transaction Description Amount");
log.info("content.indexOf(\"Date Transaction Description Amount\") = " + indexStartOfTransactions);
if (indexStartOfTransactions == -1) {
indexStartOfTransactions = content.indexOf("Date Transaction Description");
log.info("content.indexOf(\"Date Transaction Description Amount\") = " + indexStartOfTransactions);
}
log.info("content.substring(indexStartOfTransactions).length() = " + content.substring(indexStartOfTransactions).length());
BufferedReader reader = new BufferedReader(new StringReader(content.substring(indexStartOfTransactions)));
Collection<IStatementRecord> batch = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package domainapp.modules.rdr.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
Expand Down Expand Up @@ -68,10 +70,24 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
}

public Folder getOrCreateFolder(Store store, String folderName) {
try {
Folder folder = store.getFolder(folderName);
if (!folder.exists()) {
if (!folder.create(Folder.HOLDS_MESSAGES)) {
throw new IllegalStateException("Unable to create IMAP folder - " + folderName);
}
}
return getFolder(store, folderName);
} catch (MessagingException e) {
throw new IllegalStateException("Failed to get folder - " + e.getMessage(), e);
}
}

public Folder getFolder(Store store, String folderName) {
try {
Folder folder = store.getFolder(folderName);
folder.open(Folder.READ_ONLY);
folder.open(Folder.READ_WRITE);
openedFolder.add(folder);
return folder;
} catch (MessagingException e) {
Expand Down Expand Up @@ -149,4 +165,33 @@ public Message[] search(String folderName, String subjectWords, String sender, B
throw new IllegalStateException("Fail to access mailbox - " + e.getMessage(), e);
}
}

public void move(String uniqueId, String fromFolder, String toFolder) {
try {
Store store = connectStore();
Folder from = getFolder(store, fromFolder);
Folder to = getOrCreateFolder(store, toFolder);
for (Message message : from.getMessages())
{
String messageId = Arrays.asList(message.getHeader("Message-ID")).toString();
if (messageId.equals(uniqueId))
{
move(message, from, to);
break;
}
}
} catch (MessagingException e) {
throw new IllegalStateException("Fail to move message - " + e.getMessage(), e);
}
}

public void move(Message message, Folder fromFolder, Folder toFolder) {
try {
fromFolder.copyMessages(new Message[]{message}, toFolder);
message.setFlag(Flags.Flag.DELETED, true);
fromFolder.expunge();
} catch (MessagingException e) {
throw new IllegalStateException("Fail to move message - " + e.getMessage(), e);
}
}
}
12 changes: 12 additions & 0 deletions module-txn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@
<type>test-jar</type>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statements-module-dl4j</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statements-module-dl4j</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.incode.module.fixturesupport</groupId>
<artifactId>incode-module-fixturesupport-dom</artifactId>
Expand Down

0 comments on commit d1ff2c8

Please sign in to comment.