Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Added code to set parentNumber to numeric value of longest numeric su…
Browse files Browse the repository at this point in the history
…bstring of parent corp name if parent number is not already set. Fixes issue where preassigned corporate IDs loaded via SDF Bulk Loader do not get parent numbers properly assigned, and thus cannot be searched on by raw numbers in Compound Reg Search.
  • Loading branch information
bffrost committed Jan 10, 2018
1 parent 8f7a098 commit f37c1d3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/labsynch/cmpdreg/domain/CorpName.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ public static String convertLotToSaltFormCorpName(String corpName) {
Matcher matcher = pattern.matcher(corpName);
return (matcher.replaceFirst("$1"));
}

/**
* Takes a string and returns the numeric value of the longest numeric substring, or 0 if the string has no numerals
* @param corpName The corporate ID string
* @return the Long value of the corp number parsed
*/
public static Long parseParentNumber(String corpName){
//Returns the numeric value of the largest numeric substring of the input string, or 0 if one cannot be parsed
String longestSub = "";
for (String sub : corpName.split("[^0-9]")){
if (sub.length() > longestSub.length()){
longestSub = sub;
}
}
if (longestSub.length() > 0){
return Long.parseLong(longestSub);
}else {
return 0L;
}
}

public static Long parseCorpNumber(String corpName) {
corpName = corpName.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ public MetalotReturn processAndSave(Metalot metaLot, MetalotReturn mr, ArrayList
generateAndSetCorpName(parent);
corpNameAlreadyExists = checkCorpNameAlreadyExists(parent.getCorpName());
}
//try to set the parentNumber if it is not set already
if (parent.getParentNumber() < 1){
parent.setParentNumber(CorpName.parseParentNumber(parent.getCorpName()));
}
logger.debug("Saving new parent with corp name "+parent.getCorpName()+" and parent number "+parent.getParentNumber());
parent.persist();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPDATE parent SET parent_number = new_parent_number FROM (
SELECT corp_name, parent_number, ordered_nums[1]::bigint as new_parent_number FROM (
SELECT corp_name, parent_number, array_agg(parsed_corp_number order by length(parsed_corp_number) DESC) as ordered_nums from (
select corp_name, parent_number, regexp_split_to_table(corp_name, '[^0-9]') as parsed_corp_number
from parent) a
group by corp_name, parent_number) b) c
WHERE c.corp_name = parent.corp_name AND parent.parent_number = 0;
20 changes: 17 additions & 3 deletions src/test/java/com/labsynch/cmpdreg/service/CustomCorpNameTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.labsynch.cmpdreg.service;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
Expand All @@ -18,8 +19,6 @@
import com.labsynch.cmpdreg.domain.CorpName;
import com.labsynch.cmpdreg.domain.Lot;

import org.junit.Assert;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext*.xml")
@Configurable
Expand Down Expand Up @@ -108,4 +107,19 @@ public void testLicensePlateNameFull(){
logger.info("custom license plate: " + output);

}

@Test
public void parseCorpNameTest(){
Map<String, Long> corpNames = new HashMap<String, Long>();
corpNames.put("CMPD-0001234", 1234L);
corpNames.put("CMPD-0001", 1L);
corpNames.put("CMPD0001234", 1234L);
corpNames.put("CMP1-001234", 1234L);
corpNames.put("CMP1-001234-001A", 1234L);
corpNames.put("CMPDTHEBESTNONUMBERS", 0L);
for(String corpName : corpNames.keySet()){
Long parentNumber = CorpName.parseParentNumber(corpName);
Assert.assertEquals(corpNames.get(corpName), parentNumber);
}
}
}

0 comments on commit f37c1d3

Please sign in to comment.