-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix : quicken up loading 31stJan2018 NAV
- Loading branch information
1 parent
faf9b27
commit ac2c5da
Showing
8 changed files
with
6,073 additions
and
6,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/learning/mfscreener/repository/MFSchemeNavEntityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.learning.mfscreener.repository; | ||
|
||
import com.learning.mfscreener.entities.MFSchemeNavEntity; | ||
import java.time.LocalDate; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MFSchemeNavEntityRepository extends JpaRepository<MFSchemeNavEntity, Long> { | ||
|
||
long countByNavDate(LocalDate navDate); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/learning/mfscreener/service/MFSchemeNavService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.learning.mfscreener.service; | ||
|
||
import com.learning.mfscreener.entities.MFSchemeNavEntity; | ||
import com.learning.mfscreener.repository.MFSchemeNavEntityRepository; | ||
import com.learning.mfscreener.repository.MFSchemeRepository; | ||
import com.learning.mfscreener.utils.AppConstants; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class MFSchemeNavService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MFSchemeNavService.class); | ||
|
||
private final MFSchemeNavEntityRepository mfSchemeNavEntityRepository; | ||
private final MFSchemeRepository mfSchemeRepository; | ||
private final ResourceLoader resourceLoader; | ||
|
||
public MFSchemeNavService( | ||
MFSchemeNavEntityRepository mfSchemeNavEntityRepository, | ||
MFSchemeRepository mfSchemeRepository, | ||
ResourceLoader resourceLoader) { | ||
this.mfSchemeNavEntityRepository = mfSchemeNavEntityRepository; | ||
this.mfSchemeRepository = mfSchemeRepository; | ||
this.resourceLoader = resourceLoader; | ||
} | ||
|
||
public void loadHistoricalNavOn31Jan2018ForExistingSchemes() { | ||
|
||
Resource resource = resourceLoader.getResource("classpath:/nav/31Jan2018Navdata.csv"); | ||
try { | ||
Path path = resource.getFile().toPath(); | ||
List<String> lines = Files.lines(path).parallel().toList(); | ||
List<MFSchemeNavEntity> mfSchemeNavEntities = lines.stream() | ||
.skip(1) | ||
.map(csvRow -> { | ||
// Split the row | ||
String[] fields = csvRow.split(","); | ||
|
||
// Trim and remove quotes | ||
for (int i = 0; i < fields.length; i++) { | ||
fields[i] = fields[i].trim().replaceAll("^\"+|\"+$", ""); | ||
} | ||
MFSchemeNavEntity mfSchemeNavEntity = new MFSchemeNavEntity(); | ||
mfSchemeNavEntity.setNav(Float.valueOf(fields[0])); | ||
mfSchemeNavEntity.setNavDate(AppConstants.GRAND_FATHERED_DATE); | ||
mfSchemeNavEntity.setMfSchemeEntity( | ||
mfSchemeRepository.getReferenceById(Long.valueOf(fields[2].replace("\"\"", "")))); | ||
return mfSchemeNavEntity; | ||
}) | ||
.toList(); | ||
List<MFSchemeNavEntity> persistedEntities = mfSchemeNavEntityRepository.saveAll(mfSchemeNavEntities); | ||
LOGGER.info("Persisted : {} rows", persistedEntities.size()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public boolean navLoadedFor31Jan2018ForExistingSchemes() { | ||
return mfSchemeNavEntityRepository.countByNavDate(AppConstants.GRAND_FATHERED_DATE) >= 5908; | ||
} | ||
|
||
@Transactional | ||
public boolean navLoadedForClosedOrMergedSchemes() { | ||
return mfSchemeNavEntityRepository.countByNavDate(AppConstants.GRAND_FATHERED_DATE) >= 9000; | ||
} | ||
} |
Oops, something went wrong.