Skip to content
Snippets Groups Projects
Commit b053f27e authored by Daniel Tran's avatar Daniel Tran Committed by Sebastian Pongratz
Browse files

[Projekt: xRM-ContactManagement][TicketNr.: 1069662][Abbyy-Visitenkarten-Scan:...

[Projekt: xRM-ContactManagement][TicketNr.: 1069662][Abbyy-Visitenkarten-Scan: letzter Buchstabe des Nachnamens, Hausnummer und Firmenname machen Probleme]
- Added new field for business card lang to entity and edit view.
- Make new field only visible when abbyy is enabled.
- Added translation for new field.
- Customized state process, to make upload field for business
    card only visible when in previous step, a corresponding
    language for this business card was selected.
parent 071a9505
No related branches found
No related tags found
No related merge requests found
...@@ -223,6 +223,7 @@ ...@@ -223,6 +223,7 @@
<name>leadQuickAcquisition</name> <name>leadQuickAcquisition</name>
<title>{$QUICK_ENTRY_LEAD_QUICK_ACQUISITION}</title> <title>{$QUICK_ENTRY_LEAD_QUICK_ACQUISITION}</title>
<contentType>FILE</contentType> <contentType>FILE</contentType>
<state>INVISIBLE</state>
<stateProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/stateProcess.js</stateProcess> <stateProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/stateProcess.js</stateProcess>
<onValueChange>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js</onValueChange> <onValueChange>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js</onValueChange>
</entityField> </entityField>
...@@ -249,6 +250,13 @@ ...@@ -249,6 +250,13 @@
<name>#PROVIDER_AGGREGATES</name> <name>#PROVIDER_AGGREGATES</name>
<useAggregates v="true" /> <useAggregates v="true" />
</entityProvider> </entityProvider>
<entityField>
<name>businessCardLanguage</name>
<title>Business Card Language</title>
<consumer>Languages</consumer>
<state>INVISIBLE</state>
<stateProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/businesscardlanguage/stateProcess.js</stateProcess>
</entityField>
</entityFields> </entityFields>
<recordContainers> <recordContainers>
<jDitoRecordContainer> <jDitoRecordContainer>
......
import("system.result");
import("system.neon");
import("LeadQuickAcquisition_lib");
var isMailSigWebserviceEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled();
var isBusinessCardWebserviceEnabled = LeadQuickAcquisitionMailSigUtils.isEnabled();
if (isBusinessCardWebserviceEnabled || isMailSigWebserviceEnabled)
{
result.string(neon.COMPONENTSTATE_EDITABLE);
}
...@@ -4,6 +4,7 @@ import("Entity_lib"); ...@@ -4,6 +4,7 @@ import("Entity_lib");
import("system.entities"); import("system.entities");
import("KeywordRegistry_basic"); import("KeywordRegistry_basic");
import("LeadQuickAcquisition_lib"); import("LeadQuickAcquisition_lib");
import("Sql_lib");
if(vars.get("$local.value")) if(vars.get("$local.value"))
...@@ -11,7 +12,11 @@ if(vars.get("$local.value")) ...@@ -11,7 +12,11 @@ if(vars.get("$local.value"))
//Get file, call web service and get response. //Get file, call web service and get response.
var upload = new FileUpload(vars.get("$local.value")); var upload = new FileUpload(vars.get("$local.value"));
var response = new WebserviceResponse(); var response = new WebserviceResponse();
response = LeadQuickAcquisition.callWebService(upload); var lang = newSelect("AB_LANGUAGE.NAME_LATIN")
.from("AB_LANGUAGE")
.where("AB_LANGUAGE.ISO3", vars.get("$field.businessCardLanguage"))
.cell();
response = LeadQuickAcquisition.callWebService(upload, lang);
if (response != null) if (response != null)
{ {
...@@ -19,58 +24,15 @@ if(vars.get("$local.value")) ...@@ -19,58 +24,15 @@ if(vars.get("$local.value"))
EntityConsumerUtils.rmInsertedConsumerRows("Communications"); EntityConsumerUtils.rmInsertedConsumerRows("Communications");
//Filling necessary fields for company address //Filling necessary fields for company address
if (response.street && response.buildingNo && response.postalCode && response.city) var addressFields = {
{ "ADDRESS" : response.address,
var addressFields = { "ZIP" : response.postalCode,
"ADDRESS" : response.street, "CITY" : response.city,
"BUILDINGNO" : response.buildingNo, "COUNTRY" : response.country,
"ZIP" : response.zip, "STATE" : response.state
"CITY" : response.city };
};
neon.addRecord("OrgAddresses", addressFields)
if (response.country && response.state)
{
addressFields.COUNTRY = response.country;
addressFields.STATE = response.state;
}
neon.addRecord("OrgAdresses", addressFields)
}
else if(response.address)
{
var orgAddressPresets = {
"AddressSearch" : response.address
};
var getRowsConfig = entities.createConfigForLoadingRows()
.entity("AddressValidation_entity")
.provider("FullAddressValidation")
.fields(["CITY", "ZIP", "STREET"])
.addParameter("CurrentValue_param", response.address);
var rows = entities.getRows(getRowsConfig);
if (rows.length > 0)
{
var affectedRow = rows[0];
if (affectedRow["CITY"])
orgAddressPresets.CITY = affectedRow["CITY"];
if (affectedRow["ZIP"])
{
orgAddressPresets.ZIP = affectedRow["ZIP"];
}
if (affectedRow["STREET"])
{
orgAddressPresets.ADDRESS = affectedRow["STREET"];
}
}
neon.addRecord("OrgAddresses", orgAddressPresets);
}
if(response.companyName) neon.setFieldValue("$field.ORGANISATION_NAME", response.companyName); if(response.companyName) neon.setFieldValue("$field.ORGANISATION_NAME", response.companyName);
...@@ -120,7 +82,6 @@ if(vars.get("$local.value")) ...@@ -120,7 +82,6 @@ if(vars.get("$local.value"))
if(response.firstName) neon.setFieldValue("$field.FIRSTNAME", response.firstName); if(response.firstName) neon.setFieldValue("$field.FIRSTNAME", response.firstName);
if(response.lastName) neon.setFieldValue("$field.LASTNAME", response.lastName); if(response.lastName) neon.setFieldValue("$field.LASTNAME", response.lastName);
} }
} }
/** /**
......
import("system.vars");
import("system.result"); import("system.result");
import("system.neon"); import("system.neon");
import("LeadQuickAcquisition_lib"); import("LeadQuickAcquisition_lib");
var isMailSigWebserviceEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled(); var isMailSigWebserviceEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled();
var isBusinessCardWebserviceEnabled = LeadQuickAcquisitionMailSigUtils.isEnabled(); var isBusinessCardWebserviceEnabled = LeadQuickAcquisitionMailSigUtils.isEnabled();
var state = null;
if (isBusinessCardWebserviceEnabled || isMailSigWebserviceEnabled) state = neon.COMPONENTSTATE_AUTO; if ((isBusinessCardWebserviceEnabled || isMailSigWebserviceEnabled) && vars.get("$field.businessCardLanguage"))
else state = neon.COMPONENTSTATE_INVISIBLE; {
result.string(neon.COMPONENTSTATE_EDITABLE);
result.string(state); }
\ No newline at end of file \ No newline at end of file
...@@ -11264,6 +11264,10 @@ Bitte Datumseingabe prüfen</value> ...@@ -11264,6 +11264,10 @@ Bitte Datumseingabe prüfen</value>
<key>Post office box number</key> <key>Post office box number</key>
<value>Postfachnummer</value> <value>Postfachnummer</value>
</entry> </entry>
<entry>
<key>Business Card Language</key>
<value>Visitenkarten Sprache</value>
</entry>
</keyValueMap> </keyValueMap>
<font name="Dialog" style="0" size="11" /> <font name="Dialog" style="0" size="11" />
</language> </language>
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
<editMode v="true" /> <editMode v="true" />
<entityField>#ENTITY</entityField> <entityField>#ENTITY</entityField>
<fields> <fields>
<entityFieldLink>
<name>635e909b-a5f8-4afe-b16f-ad9ff0ffba03</name>
<entityField>businessCardLanguage</entityField>
</entityFieldLink>
<entityFieldLink> <entityFieldLink>
<name>8ed8f12d-2a91-4009-8868-55a0c11880ff</name> <name>8ed8f12d-2a91-4009-8868-55a0c11880ff</name>
<entityField>leadQuickAcquisition</entityField> <entityField>leadQuickAcquisition</entityField>
......
import("WsValidation_lib");
import("system.logging"); import("system.logging");
import("system.project"); import("system.project");
import("system.neon"); import("system.neon");
...@@ -10,9 +9,11 @@ import("system.net"); ...@@ -10,9 +9,11 @@ import("system.net");
import("system.auth"); import("system.auth");
import("system.util"); import("system.util");
import("system.fileIO"); import("system.fileIO");
import("system.swing");
import("KeywordRegistry_basic"); import("KeywordRegistry_basic");
import("Sql_lib"); import("Sql_lib");
import("Email_lib"); import("Email_lib");
import("Util_lib");
/** /**
* Object for storing the webservice response and * Object for storing the webservice response and
...@@ -49,9 +50,10 @@ function LeadQuickAcquisition(){} ...@@ -49,9 +50,10 @@ function LeadQuickAcquisition(){}
/** /**
* Method which calls the web service and gives the information back as object. * Method which calls the web service and gives the information back as object.
* @param pFile the file which will send to the webservice. * @param pFile the file which will send to the webservice.
* @param pLang The language which will be used to recognize the business card.
* @return {Object} the reply from the web service. * @return {Object} the reply from the web service.
*/ */
LeadQuickAcquisition.callWebService = function(pFile) LeadQuickAcquisition.callWebService = function(pFile, pLang)
{ {
var response = new WebserviceResponse(); var response = new WebserviceResponse();
...@@ -63,7 +65,7 @@ LeadQuickAcquisition.callWebService = function(pFile) ...@@ -63,7 +65,7 @@ LeadQuickAcquisition.callWebService = function(pFile)
case "application/pdf": case "application/pdf":
case "image/tiff": case "image/tiff":
case "image/gif": case "image/gif":
response = LeadQuickAcquisition.handleBusinessCard(pFile.bindata); response = LeadQuickAcquisition.handleBusinessCard(pFile.bindata, pLang);
break; break;
case "message/rfc822": case "message/rfc822":
response = LeadQuickAcquisition.handleMailSig(Email.fromRFC(pFile.bindata)); response = LeadQuickAcquisition.handleMailSig(Email.fromRFC(pFile.bindata));
...@@ -80,16 +82,17 @@ LeadQuickAcquisition.callWebService = function(pFile) ...@@ -80,16 +82,17 @@ LeadQuickAcquisition.callWebService = function(pFile)
/** /**
* Method which is especially for handling business cards. * Method which is especially for handling business cards.
* @param pFile the file which will send to the webservice. * @param pFile the file which will send to the webservice.
* @param pLang The language which will be used to recognize the business card.
* @return {Object} the reply from the web service. * @return {Object} the reply from the web service.
*/ */
LeadQuickAcquisition.handleBusinessCard = function(pFile) LeadQuickAcquisition.handleBusinessCard = function(pFile, pLang)
{ {
var isEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled(); var isEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled();
var response = null; var response = null;
if (isEnabled) if (isEnabled)
{ {
response = LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard(pFile); response = LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard(pFile, pLang);
response = LeadQuickAcquisitionBusinessCardUtils._transformToResponse(response); response = LeadQuickAcquisitionBusinessCardUtils._transformToResponse(response);
} }
...@@ -136,32 +139,66 @@ LeadQuickAcquisitionBusinessCardUtils.isEnabled = function() ...@@ -136,32 +139,66 @@ LeadQuickAcquisitionBusinessCardUtils.isEnabled = function()
/** /**
* Method which calls the webservice for business card. * Method which calls the webservice for business card.
* @param pFile the file which will send to the webservice. * @param pFile the file which will send to the webservice.
* @return {Object} the reply from the web service. * @param pLang The language which will be used to recognize the business card.
* @return {Array} Result array (0: recognized business card, 1: language which was used for recognition).
*/ */
LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard = function(pFile) LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard = function(pFile, pLang)
{ {
var appId = project.getInstanceConfigValue("custom.abbyy.ocr.appId", ""); var appId = project.getInstanceConfigValue("custom.abbyy.ocr.appId", "");
var pwd = project.getInstanceConfigValue("custom.abbyy.ocr.password", ""); var pwd = project.getInstanceConfigValue("custom.abbyy.ocr.password", "");
var language = "German"; var authConf = auth.createConfigForBasicAuth()
.userName(appId)
//var reply = '{"Company":"eisner","Email":"mustermann@motyp.de","Address":"Hauptstraße 21 ■ 12345 Berlin","Web":null,"Phone":null,"Fax":"028 01 83 999 019","Job":"Fliesenverlegemeister","Mobile":"0171 23 456 78","Name":"Max Mustermann"}'; .password(pwd);
var reply = plugin.run(null,"de.adito.plugin.OCR.BusinessCardRecognizer", [appId, pwd, pFile ,language])[0]; var conf = net.createConfigForRestWebserviceCall()
.url("https://cloud.ocrsdk.com/processBusinessCard")
//Error codes are defined in the java plugin. .actionType("POST")
if (reply == "552") .addQueryParameter("language", pLang)
{ .addQueryParameter("exportFormat", "xml")
throw new Error("Abbyy ocr plugin has not enough credits!"); .addQueryParameter("xml:WriteFieldComponents", "true")
} .requestEntity(pFile);
else if (reply == "555")
{ var response = util.decodeBase64String(net.callRestWebservice(conf, authConf));
throw new Error("The Abbyy ocr plugin request could not be completed!"); var responseXml = response.substring(response.indexOf("<response>"), response.length);
} var taskId = new XML(responseXml).task.@id;
else if (reply == "550") var getStatus = function(pTaskId){
conf = net.createConfigForRestWebserviceCall()
.url("https://cloud.ocrsdk.com/getTaskStatus")
.addQueryParameter("taskId", pTaskId);
response = util.decodeBase64String(net.callRestWebservice(conf, authConf));
responseXml = response.substring(response.indexOf("<response>"));
return [new XML(responseXml).task.@resultUrl, new XML(responseXml).task.@status];
};
if (taskId)
{ {
throw new Error("The Abbyy ocr plugin credentials are wrong!") var resultUrl = "";
var taskStatus = getStatus(taskId)[1];
while(taskStatus != "Completed" && taskStatus != "ProcessingFailed" && taskStatus != "Deleted" && taskStatus != "NotEnoughCredits")
{
[resultUrl, taskStatus] = getStatus(taskId);
}
switch(taskStatus.toString()){
case "Completed":
conf = net.createConfigForRestWebserviceCall()
.url(resultUrl)
.actionType("GET");
response = util.decodeBase64String(net.callRestWebservice(conf, auth.createConfigForNoAuth()));
response = new XML(response.substring(response.indexOf("<businessCard"), response.indexOf("</document>")));
break;
case "ProcessingFailed":
throw new Error("Abbyy: Processing of the business card failed!")
break;
case "Deleted":
throw new Error("Abbyy: The requested, recognized business card was deleted.")
break;
case "NotEnoughCredits":
throw new Error("Abbyy: Not enough credits!")
break;
}
} }
return [response, pLang];
return reply;
} }
/** /**
...@@ -172,22 +209,32 @@ LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard = function(pFi ...@@ -172,22 +209,32 @@ LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard = function(pFi
LeadQuickAcquisitionBusinessCardUtils._transformToResponse = function(pReply) LeadQuickAcquisitionBusinessCardUtils._transformToResponse = function(pReply)
{ {
var response = new WebserviceResponse(); var response = new WebserviceResponse();
var parsedData = JSON.parse(pReply); var lang = pReply[1];
pReply = pReply[0];
if(parsedData.Company) response.companyName = parsedData.Company; logging.log("Abbyy reponse: " + pReply.toString());
if(parsedData.Email) response.emailAddress = parsedData.Email;
if(parsedData.Web) response.website = parsedData.Web; var getNodesValue = function(pResponse, pType)
if(parsedData.Phone) response.phoneNumber = parsedData.Phone;
if(parsedData.Mobile) response.mobilePhone = parsedData.Mobile;
if(parsedData.Name)
{
response.firstName = parsedData.Name.substring(0, parsedData.Name.indexOf(" ", 0));
response.lastName = parsedData.Name.substring(parsedData.Name.lastIndexOf(" ", parsedData.Name.indexOf(" ", 0))+1, parsedData.Name.length-1);
}
if (WsValidationUtils.isWsEnabled(WsValidationType.get().TYPE_ADDRESS_NOMINATIM) && parsedData.Address)
{ {
response.address = parsedData.Address; return Utils.isNotNullOrEmptyString(pResponse.field.(@type==pType).value[0]) ? pResponse.field.(@type==pType).value[0].toString() : "";
} };
response.companyName = getNodesValue(pReply, "Company");
response.emailAddress = getNodesValue(pReply, "Email");
response.website = getNodesValue(pReply, "Web");
response.phoneNumber = getNodesValue(pReply, "Phone");
response.mobilePhone = getNodesValue(pReply, "Mobile");
response.firstName = Utils.isNotNullOrEmptyString(pReply.field.(@type == "Name").fieldComponents.fieldComponent.(@type=="FirstName").value[0]) ?
pReply.field.(@type == "Name").fieldComponents.fieldComponent.(@type=="FirstName").value[0].toString() : "";
response.lastName = Utils.isNotNullOrEmptyString(pReply.field.(@type == "Name").fieldComponents.fieldComponent.(@type=="LastName").value[0]) ?
pReply.field.(@type == "Name").fieldComponents.fieldComponent.(@type=="LastName").value[0].toString() : "";
response.address = Utils.isNotNullOrEmptyString(pReply.field.(@type == "Address").fieldComponents.fieldComponent.(@type=="StreetAddress").value[0])
? pReply.field.(@type == "Address").fieldComponents.fieldComponent.(@type=="StreetAddress").value[0].toString()
: "";
response.postalCode = Utils.isNotNullOrEmptyString(pReply.field.(@type == "Address").fieldComponents.fieldComponent.(@type=="ZipCode").value[0]) ?
pReply.field.(@type == "Address").fieldComponents.fieldComponent.(@type=="ZipCode").value[0].toString() : "";
response.city = Utils.isNotNullOrEmptyString(pReply.field.(@type == "Address").fieldComponents.fieldComponent.(@type=="City").value[0]) ?
pReply.field.(@type == "Address").fieldComponents.fieldComponent.(@type=="City").value[0].toString() : "";
return response; return response;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment