Skip to content

Commit

Permalink
GIAI / GRAI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jlcout committed Apr 1, 2019
1 parent 6a6c862 commit 1015684
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 139 deletions.
53 changes: 27 additions & 26 deletions epctagcoder/.classpath
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
12 changes: 12 additions & 0 deletions epctagcoder/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>ch.acanda.eclipse.pmd.builder.PMDBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
Expand All @@ -31,5 +41,7 @@
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>com.jaspersoft.studio.babel.editor.rbeNature</nature>
<nature>ch.acanda.eclipse.pmd.builder.PMDNature</nature>
<nature>net.sourceforge.pmd.eclipse.plugin.pmdNature</nature>
</natures>
</projectDescription>
1 change: 1 addition & 0 deletions epctagcoder/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
2 changes: 1 addition & 1 deletion epctagcoder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.epctagcoder</groupId>
<artifactId>epctagcoder</artifactId>
<version>0.0.5-SNAPSHOT</version>
<version>0.0.6-SNAPSHOT</version>
<packaging>jar</packaging>

<name>epctagcoder</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.LinkedHashMap;
import java.util.Map;



public enum CPIHeader {
HEADER_00111100("00111100") {
public Integer getTagSize() {
Expand Down Expand Up @@ -35,7 +37,13 @@ public String getValue() {
}

public static CPIHeader forCode(String code) {
return BY_CODE_MAP.get(code);
CPIHeader header = BY_CODE_MAP.get(code);

if (header==null) {
throw new IllegalArgumentException(String.format("CPI header [%s] is invalid. Allowed only 00111100 or 00111101", code));
}

return header;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.LinkedHashMap;
import java.util.Map;


public enum GDTIHeader {
HEADER_00101100("00101100") {
public Integer getTagSize() {
Expand Down Expand Up @@ -35,7 +36,13 @@ public String getValue() {
}

public static GDTIHeader forCode(String code) {
return BY_CODE_MAP.get(code);
GDTIHeader header = BY_CODE_MAP.get(code);

if (header==null) {
throw new IllegalArgumentException(String.format("GDTI header [%s] is invalid. Allowed only 00101100 or 00111110", code));
}

return header;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.LinkedHashMap;
import java.util.Map;


public enum GSRNHeader {
HEADER_00101101("00101101") {
public Integer getTagSize() {
Expand Down Expand Up @@ -30,7 +31,13 @@ public String getValue() {
}

public static GSRNHeader forCode(String code) {
return BY_CODE_MAP.get(code);
GSRNHeader header = BY_CODE_MAP.get(code);

if (header==null) {
throw new IllegalArgumentException(String.format("GSRN header [%s] is invalid. Allowed only 00101101", code));
}

return header;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static SGTINHeader forCode(String code) {
SGTINHeader header = BY_CODE_MAP.get(code);

if (header==null) {
throw new IllegalArgumentException(String.format("SGTIN header %s is invalid. Allowed only 00110000 and 00110110", code));
throw new IllegalArgumentException(String.format("SGTIN header [%s] is invalid. Allowed only 00110000 or 00110110", code));
}

return header;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public String getValue() {
}

public static SSCCHeader forCode(String code) {
return BY_CODE_MAP.get(code);
SSCCHeader header = BY_CODE_MAP.get(code);

if (header==null) {
throw new IllegalArgumentException(String.format("SSCC header [%s] is invalid. Allowed only 00110001", code));
}

return header;
}


Expand Down
92 changes: 7 additions & 85 deletions epctagcoder/src/main/java/org/epctagcoder/parse/CPI/ParseCPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ParseCPI {
private TableItem tableItem;
private int remainder;

public static ChoiceStep Builder() {
public static ChoiceStep Builder() throws Exception {
return new Steps();
}

Expand Down Expand Up @@ -70,92 +70,34 @@ private void parse() {
String serialBin = null;

if (tagSize.getValue()==0) { // variable
// System.out.println("inputBin.length() "+inputBin.length() );
// System.out.println("tableItem.getM() "+tableItem.getM() );
// System.out.println("tableItem.getN() "+tableItem.getN() );
// System.out.println("tableItem.getDigits() "+tableItem.getDigits() );
// System.out.println("tagSize.getSerialBitCount() "+tagSize.getSerialBitCount() );

String componentPartReferenceAndSerialBin = inputBin.substring(14+tableItem.getM() );

Pattern pattern = Pattern.compile("\\d{6}");
Matcher matcher = pattern.matcher(componentPartReferenceAndSerialBin);

System.out.println("lpadzero "+ Converter.lPadZero(123, 5) );
System.out.println("lpadzero "+ Converter.strZero("123", 5) );

// System.out.println( componentPartReferenceAndSerialBin );



StringBuilder decodeComponentPartReference = new StringBuilder();

List<String> aaa = Converter.splitEqually(componentPartReferenceAndSerialBin, 6);
for (String a : aaa) {
// System.out.println("* "+a);
if ( a.equals("000000") ) {
List<String> splitCPR = Converter.splitEqually(componentPartReferenceAndSerialBin, 6);
for (String item : splitCPR) {
if ( item.equals("000000") ) {
break;
}
decodeComponentPartReference.append( a );
decodeComponentPartReference.append(item);
}





// int mIdx = 0;
// boolean stop = false;
// while (matcher.find()) {
// for (int groupIdx = 0; groupIdx < matcher.groupCount() + 1; groupIdx++) {
// System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + matcher.group(groupIdx));
// if ( matcher.group(groupIdx).equals("000000") ) {
// stop = true;
// break;
// }
// decodeComponentPartReference.append( matcher.group(groupIdx) );
// }
// if (stop) {
// break;
// }
// mIdx++;
// }

// System.out.println("decodeComponentPartReference "+decodeComponentPartReference.toString());

componentPartReferenceBin = decodeComponentPartReference.toString();

int posSerial = 14+tableItem.getM()+componentPartReferenceBin.length()+6;
// System.out.println("pos "+pos );

// System.out.println("componentPartReferenceBin.length() "+ componentPartReferenceBin.length()+" * "+componentPartReferenceBin );

componentPartReferenceBin = Converter.convertBinToBit(componentPartReferenceBin, 6, 8);
// System.out.println("componentPartReferenceBin.convertBinToBit "+ componentPartReferenceBin.length()+" * "+componentPartReferenceBin );

componentPartReference = Converter.binToString(componentPartReferenceBin);

serialBin = inputBin.substring(posSerial, posSerial+tagSize.getSerialBitCount());
// System.out.println("*** "+serialBin);


} else if (tagSize.getValue()==96) {
componentPartReferenceBin = inputBin.substring(14+tableItem.getM(),14+tableItem.getM()+tableItem.getN());
componentPartReference = Converter.binToDec(componentPartReferenceBin);
serialBin = inputBin.substring(14+tableItem.getM()+tableItem.getN() );
}




String companyPrefixDec = Converter.binToDec(companyPrefixBin);




serial = Converter.binToDec(serialBin);
companyPrefix = Converter.strZero(companyPrefixDec, tableItem.getL()); // strzero aqui
filterValue = CPIFilterValue.forCode( Integer.parseInt(filterDec) );
prefixLength = PrefixLength.forCode(tableItem.getL());

} else {

if ( optionalCompanyPrefix.isPresent() ) {
Expand All @@ -172,8 +114,6 @@ private void parse() {
} else {

if ( optionalEpcTagURI.isPresent() ) {
//urn:epc:tag:cpi-var:0.0614141.23467890.1234567
// Pattern pattern = Pattern.compile("(urn:epc:tag:cpi-)(96|var)\\:([0-7])\\.(\\d+)\\.(\\d+)\\.(\\w+)");
Pattern pattern = Pattern.compile("(urn:epc:tag:cpi-)(96|var)\\:([0-7])\\.(\\d+)\\.(\\d+)\\.(\\w+)");

Matcher matcher = pattern.matcher(epcTagURI);
Expand Down Expand Up @@ -243,25 +183,17 @@ private String getBinary() {
bin.append( Converter.decToBin(tableItem.getPartitionValue(), 3) );
bin.append( Converter.decToBin(Integer.parseInt(companyPrefix), tableItem.getM()) );

// System.out.println("sem componentPartReference "+ bin.toString() );

if (tagSize.getValue()==0) { // variable
//bin.append( Converter.fill(Converter.StringtoBinary(componentPartReference, 6), tableItem.getDigits()) );
bin.append( Converter.StringtoBinary(componentPartReference, 6) );
bin.append("000000");
} else if (tagSize.getValue()==96) {
bin.append( Converter.decToBin(Integer.parseInt(componentPartReference), tableItem.getN()) );
}

// System.out.println("sem serial "+ bin.toString() );

bin.append( Converter.decToBin(serial, tagSize.getSerialBitCount() ) );
remainder = (int) (Math.ceil((bin.length()/16.0))*16)-bin.length();
bin.append( Converter.fill("0", remainder) );

// System.out.println("completo "+ bin.toString() );


return bin.toString();
}

Expand All @@ -284,17 +216,7 @@ private void validateCompanyPrefix() {
}
}

/*
The component/part reference is also limited to
values that are numeric-only, with no leading
zeros, and whose length is less than or equal to
15 minus the length of the GS1 Company Prefix
All values permitted by GS1 General
Specifications (up to 12 decimal digits, no
leading zeros).
*/



private void validateComponentPartReference() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ParseGDTI {
private TableItem tableItem;
private int remainder;

public static ChoiceStep Builder() {
public static ChoiceStep Builder() throws Exception {
return new Steps();
}

Expand Down Expand Up @@ -120,7 +120,7 @@ private void parse() {
if ( matcher.matches() ) {
companyPrefix = matcher.group(2);
prefixLength = PrefixLength.forCode( matcher.group(2).length() );
docType = matcher.group(3);;
docType = matcher.group(3);
serial = matcher.group(4);
} else {
throw new IllegalArgumentException("EPC Pure Identity is invalid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ParseGSRN {
private String epcPureIdentityURI;
private TableItem tableItem;

public static ChoiceStep Builder() {
public static ChoiceStep Builder() throws Exception {
return new Steps();
}

Expand Down Expand Up @@ -59,7 +59,7 @@ private void parse() {
String companyPrefixBin = inputBin.substring(14,14+tableItem.getM());
String serialWithExtensionBin = inputBin.substring(14+tableItem.getM(),14+tableItem.getM()+tableItem.getN());
String filterDec = Long.toString( Long.parseLong(filterBin, 2) );
String companyPrefixDec = Converter.binToDec(companyPrefixBin); //Long.toString( Long.parseLong(companyPrefixBin, 2) );
String companyPrefixDec = Converter.binToDec(companyPrefixBin);

serviceReference = Converter.strZero(Converter.binToDec(serialWithExtensionBin), tableItem.getDigits() );
companyPrefix = Converter.strZero(companyPrefixDec, tableItem.getL());
Expand Down Expand Up @@ -247,13 +247,6 @@ public ParseGSRN build() {
return new ParseGSRN(this);
}

// @Override
// public SerialStep withExtensionDigit(SSCCExtensionDigit extensionDigit) {
// this.extensionDigit = extensionDigit;
// return this;
// }


@Override
public BuildStep withFilterValue(GSRNFilterValue filterValue) {
this.filterValue = filterValue;
Expand Down
Loading

0 comments on commit 1015684

Please sign in to comment.