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 @@
<name>leadQuickAcquisition</name>
<title>{$QUICK_ENTRY_LEAD_QUICK_ACQUISITION}</title>
<contentType>FILE</contentType>
<state>INVISIBLE</state>
<stateProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/stateProcess.js</stateProcess>
<onValueChange>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js</onValueChange>
</entityField>
......@@ -249,6 +250,13 @@
<name>#PROVIDER_AGGREGATES</name>
<useAggregates v="true" />
</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>
<recordContainers>
<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");
import("system.entities");
import("KeywordRegistry_basic");
import("LeadQuickAcquisition_lib");
import("Sql_lib");
if(vars.get("$local.value"))
......@@ -11,7 +12,11 @@ if(vars.get("$local.value"))
//Get file, call web service and get response.
var upload = new FileUpload(vars.get("$local.value"));
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)
{
......@@ -19,58 +24,15 @@ if(vars.get("$local.value"))
EntityConsumerUtils.rmInsertedConsumerRows("Communications");
//Filling necessary fields for company address
if (response.street && response.buildingNo && response.postalCode && response.city)
{
var addressFields = {
"ADDRESS" : response.street,
"BUILDINGNO" : response.buildingNo,
"ZIP" : response.zip,
"CITY" : response.city
};
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);
}
var addressFields = {
"ADDRESS" : response.address,
"ZIP" : response.postalCode,
"CITY" : response.city,
"COUNTRY" : response.country,
"STATE" : response.state
};
neon.addRecord("OrgAddresses", addressFields)
if(response.companyName) neon.setFieldValue("$field.ORGANISATION_NAME", response.companyName);
......@@ -120,7 +82,6 @@ if(vars.get("$local.value"))
if(response.firstName) neon.setFieldValue("$field.FIRSTNAME", response.firstName);
if(response.lastName) neon.setFieldValue("$field.LASTNAME", response.lastName);
}
}
/**
......
import("system.vars");
import("system.result");
import("system.neon");
import("LeadQuickAcquisition_lib");
var isMailSigWebserviceEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled();
var isBusinessCardWebserviceEnabled = LeadQuickAcquisitionMailSigUtils.isEnabled();
var state = null;
if (isBusinessCardWebserviceEnabled || isMailSigWebserviceEnabled) state = neon.COMPONENTSTATE_AUTO;
else state = neon.COMPONENTSTATE_INVISIBLE;
result.string(state);
\ No newline at end of file
if ((isBusinessCardWebserviceEnabled || isMailSigWebserviceEnabled) && vars.get("$field.businessCardLanguage"))
{
result.string(neon.COMPONENTSTATE_EDITABLE);
}
\ No newline at end of file
......@@ -11264,6 +11264,10 @@ Bitte Datumseingabe prüfen</value>
<key>Post office box number</key>
<value>Postfachnummer</value>
</entry>
<entry>
<key>Business Card Language</key>
<value>Visitenkarten Sprache</value>
</entry>
</keyValueMap>
<font name="Dialog" style="0" size="11" />
</language>
......@@ -21,6 +21,10 @@
<editMode v="true" />
<entityField>#ENTITY</entityField>
<fields>
<entityFieldLink>
<name>635e909b-a5f8-4afe-b16f-ad9ff0ffba03</name>
<entityField>businessCardLanguage</entityField>
</entityFieldLink>
<entityFieldLink>
<name>8ed8f12d-2a91-4009-8868-55a0c11880ff</name>
<entityField>leadQuickAcquisition</entityField>
......
import("WsValidation_lib");
import("system.logging");
import("system.project");
import("system.neon");
......@@ -10,9 +9,11 @@ import("system.net");
import("system.auth");
import("system.util");
import("system.fileIO");
import("system.swing");
import("KeywordRegistry_basic");
import("Sql_lib");
import("Email_lib");
import("Util_lib");
/**
* Object for storing the webservice response and
......@@ -49,9 +50,10 @@ function LeadQuickAcquisition(){}
/**
* Method which calls the web service and gives the information back as object.
* @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.
*/
LeadQuickAcquisition.callWebService = function(pFile)
LeadQuickAcquisition.callWebService = function(pFile, pLang)
{
var response = new WebserviceResponse();
......@@ -63,7 +65,7 @@ LeadQuickAcquisition.callWebService = function(pFile)
case "application/pdf":
case "image/tiff":
case "image/gif":
response = LeadQuickAcquisition.handleBusinessCard(pFile.bindata);
response = LeadQuickAcquisition.handleBusinessCard(pFile.bindata, pLang);
break;
case "message/rfc822":
response = LeadQuickAcquisition.handleMailSig(Email.fromRFC(pFile.bindata));
......@@ -80,16 +82,17 @@ LeadQuickAcquisition.callWebService = function(pFile)
/**
* Method which is especially for handling business cards.
* @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.
*/
LeadQuickAcquisition.handleBusinessCard = function(pFile)
LeadQuickAcquisition.handleBusinessCard = function(pFile, pLang)
{
var isEnabled = LeadQuickAcquisitionBusinessCardUtils.isEnabled();
var response = null;
if (isEnabled)
{
response = LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard(pFile);
response = LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard(pFile, pLang);
response = LeadQuickAcquisitionBusinessCardUtils._transformToResponse(response);
}
......@@ -136,32 +139,66 @@ LeadQuickAcquisitionBusinessCardUtils.isEnabled = function()
/**
* Method which calls the webservice for business card.
* @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 pwd = project.getInstanceConfigValue("custom.abbyy.ocr.password", "");
var language = "German";
//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"}';
var reply = plugin.run(null,"de.adito.plugin.OCR.BusinessCardRecognizer", [appId, pwd, pFile ,language])[0];
//Error codes are defined in the java plugin.
if (reply == "552")
{
throw new Error("Abbyy ocr plugin has not enough credits!");
}
else if (reply == "555")
{
throw new Error("The Abbyy ocr plugin request could not be completed!");
}
else if (reply == "550")
var authConf = auth.createConfigForBasicAuth()
.userName(appId)
.password(pwd);
var conf = net.createConfigForRestWebserviceCall()
.url("https://cloud.ocrsdk.com/processBusinessCard")
.actionType("POST")
.addQueryParameter("language", pLang)
.addQueryParameter("exportFormat", "xml")
.addQueryParameter("xml:WriteFieldComponents", "true")
.requestEntity(pFile);
var response = util.decodeBase64String(net.callRestWebservice(conf, authConf));
var responseXml = response.substring(response.indexOf("<response>"), response.length);
var taskId = new XML(responseXml).task.@id;
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 reply;
return [response, pLang];
}
/**
......@@ -172,22 +209,32 @@ LeadQuickAcquisitionBusinessCardUtils._callWebServiceBusinessCard = function(pFi
LeadQuickAcquisitionBusinessCardUtils._transformToResponse = function(pReply)
{
var response = new WebserviceResponse();
var parsedData = JSON.parse(pReply);
var lang = pReply[1];
pReply = pReply[0];
if(parsedData.Company) response.companyName = parsedData.Company;
if(parsedData.Email) response.emailAddress = parsedData.Email;
if(parsedData.Web) response.website = parsedData.Web;
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)
logging.log("Abbyy reponse: " + pReply.toString());
var getNodesValue = function(pResponse, pType)
{
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;
}
......
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