作者 朱兆平

部分报文格式生成及验证

... ... @@ -61,6 +61,14 @@
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
</plugins>
</build>
... ...
... ... @@ -8,4 +8,8 @@ public class BASE {
return StringUtils.hasText(var);
}
final public String SPLIT_CODE = "/";
final public String CRLF = "\n";
}
... ...
package com.sunyo.wlpt.base.model.efreight.fwb;
import com.sunyo.wlpt.base.model.efreight.BASE;
import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBException;
import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBExceptionType;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* SPH
* Special Handing Details
... ... @@ -11,7 +19,7 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
* SPH/ECC/ELI
* CRLF
*/
public class FWB_SPH {
public class FWB_SPH extends BASE implements FWB_BASE {
/**
* NODE:SPH
... ... @@ -23,5 +31,47 @@ public class FWB_SPH {
* DEMO:
* /ELI
*/
private String sph_code;
private List<String> sph_code;
public List<String> getSph_code() {
return sph_code;
}
public void setSph_code(List<String> sph_code) {
this.sph_code = sph_code;
}
public boolean codeCheck(String code) throws FWBException {
String patternStr = "^[A-Z]{3}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(code);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.SPH_CODE_FAILD);
}
return true;
}
@Override
public String getFWBNodeText() throws FWBException {
StringBuilder sb = new StringBuilder("");
if (sph_code!=null && !sph_code.isEmpty()){
if (sph_code.size()>9){
throw new FWBException(FWBExceptionType.SPH_LENGTH_FAILD);
}
sb.append(getNodeName());
for (String code : sph_code) {
if(codeCheck(code)){
sb.append(SPLIT_CODE).append(code);
}
}
sb.append(CRLF);
}
return sb.toString();
}
@Override
public String getNodeName() {
return "SPH";
}
}
... ...
... ... @@ -99,6 +99,9 @@ public enum FWBExceptionType {
REF_SOMA_REGEX_FAILD("2031", "REF- Sender Office Message Address RegEx Faild"),
REF_SPID_REGEX_FAILD("206", "REF- Sender Participant Idenfitication RegEx Faild,缺少关联节点信息"),
SPH_LENGTH_FAILD("2520", "SPH-最多只支持9个操作代码信息"),
SPH_CODE_FAILD("2522", "SPH-代码格式信息有误"),
OCI_CSRC_ERROR("297", "缺少 Other Customs,Security And Regulatory Control Information Identifier");
/**
... ...