Boa Tarde,
Amigos,
Estou tentando criar um DataSet customizado, para pegar informações de um Outro Dataset Customizado porém filtrando alguns valores por constraints, porém ele não retorna nada. Poderiam me ajudar?
function createDataset(fields, constraints, sortFields) {
var dataset = DatasetBuilder.newDataset();
dataset.addColumn("CODHABILIDADE");
dataset.addColumn("DESCRICAOHABIL");
var c1 = DatasetFactory.createConstraint("CODHABILIDADE", null, null, ConstraintType.MUST);
var constraints = new Array(c1);
var returnFields = new Array("CODHABILIDADE","DESCRICAOHABIL");
var datasetIdioma = DatasetFactory.getDataset("ds_RhuHabilidadesData", returnFields, constraints, null);
for(var i = 0; i < datasetIdioma.length; i++){
dataset.addRow(new Array(datasetIdioma.getValue(i, "CODHABILIDADE"), datasetIdioma.getValue(i, "DESCRICAOHABIL")));
}
return dataset;
}
DataSet (ds_RhuHabilidadesData)
function createDataset(fields, constraints, sortFields) {
try {
return processResult(callService(fields, constraints, sortFields));
} catch(e) {
return processErrorResult(e, constraints);
}
}
function callService(fields, constraints, sortFields) {
var serviceData = data();
var params = serviceData.inputValues;
var properties = {};
properties["log.soap.messages"] = "false";
properties["disable.chunking"] = "false";
properties["use.ssl"] = "false";
properties["basic.authorization"] = "true";
properties["basic.authorization.username"] = "user";
properties["basic.authorization.password"] = "password";
verifyConstraints(serviceData.inputValues, constraints);
var serviceHelper = ServiceManager.getServiceInstance(serviceData.fluigService);
var serviceLocator = serviceHelper.instantiate(serviceData.locatorClass);
var service = serviceLocator.getRMIwsDataServer();
var headers = getSOAPHeaders(serviceHelper, serviceData.extraParams.headers);
var customClient = serviceHelper.getCustomClient(service, properties, headers);
var response = customClient.readView(params.dataServerName, params.filtro,
params.contexto);
return response;
}
function defineStructure() {
var dataset = processResult(callService());
var columns = dataset.getColumnsName();
for (var i = 0; i < dataset.getColumnsCount(); i++) {
if (!DatabaseManager.isReservedWord(columns[i])) {
addColumn(columns[i]);
} else {
addColumn('ds_' + columns[i]);
}
}
}
function onSync(lastSyncDate) {
var serviceData = data();
var synchronizedDataset = DatasetBuilder.newDataset();
try {
var resultDataset = processResult(callService());
if (resultDataset != null) {
var values = resultDataset.getValues();
for (var i = 0; i < values.length; i++) {
synchronizedDataset.addRow(values[i]);
}
}
} catch(e) {
log.info('Dataset synchronization error : ' + e.message);
}
return synchronizedDataset;
}
function verifyConstraints(params, constraints) {
if (constraints != null) {
for (var i = 0; i < constraints.length; i++) {
try {
params[constraints[i].fieldName] = JSON.parse(constraints[i].initialValue);
} catch(e) {
params[constraints[i].fieldName] = constraints[i].initialValue;
}
}
}
}
function processResult(result) {
var dataset = DatasetBuilder.newDataset();
var columns = new Array();
var factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
var parser = factory.newDocumentBuilder();
var source = new org.xml.sax.InputSource(new java.io.StringReader(result));
var xmlResponse = parser.parse(source);
var nodes = xmlResponse.getElementsByTagName("VHabilidades");
for (var i = 0; i < nodes.getLength(); i++) {
var children = nodes.item(i).getChildNodes();
for (var j = 0; j < children.getLength(); j++) {
if (children.item(j) instanceof org.w3c.dom.Element) {
var column = children.item(j).getNodeName();
if (columns.indexOf(column) < 0) {
columns.push(column);
dataset.addColumn(column);
}
}
}
}
for (var i = 0; i < nodes.getLength(); i++) {
var datasetRow = new Array();
var children = nodes.item(i).getChildNodes();
for (var j = 0; j < columns.length; j++) {
var node = children.getElementsByTagName(columns[j]);
if (node.getLength() > 0 && node.item(0).hasChildNodes) {
datasetRow.push(node.item(0).getFirstChild().getTextContent());
} else {
datasetRow.push("");
}
}
dataset.addRow(datasetRow);
}
return dataset;
}
function processErrorResult(error, constraints) {
var dataset = DatasetBuilder.newDataset();
var params = data().inputValues;
verifyConstraints(params, constraints);
dataset.addColumn('error');
dataset.addColumn('dataServerName');
dataset.addColumn('filtro');
dataset.addColumn('contexto');
var dataServerName = isPrimitive(params.dataServerName) ? params.dataServerName : JSONUtil.toJSON(params.dataServerName);
var filtro = isPrimitive(params.filtro) ? params.filtro : JSONUtil.toJSON(params.filtro);
var contexto = isPrimitive(params.contexto) ? params.contexto : JSONUtil.toJSON(params.contexto);
dataset.addRow([error.message, dataServerName, filtro, contexto]);
return dataset;
}
function getParamValue(param, assignment) {
if (assignment == 'VARIABLE') {
return getValue(param);
} else if (assignment == 'NULL') {
return null;
}
return param;
}
function isPrimitive(value) {
return ((typeof value === 'string') || value.substring !== undefined) || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'undefined';
}
function getObjectFactory(serviceHelper) {
var objectFactory = serviceHelper.instantiate("com.totvs.ObjectFactory");
return objectFactory;
}
function getSOAPHeaders(serviceHelper, headers) {
var soapHeaders = [];
return soapHeaders;
}
function data() {
return {
"fluigService" : "WSDATASERVER",
"operation" : "readView",
"soapService" : "WsDataServer",
"portType" : "IwsDataServer",
"locatorClass" : "com.totvs.WsDataServer",
"portTypeMethod" : "getRMIwsDataServer",
"parameters" : [ ],
"inputValues" : {
"dataServerName" : "RhuHabilidadesData",
"filtro" : "1=1",
"contexto" : "CODSISTEMA=G;CODCOLIGADA=1;CODUSUARIO=user"
},
"inputAssignments" : {
"dataServerName" : "VALUE",
"filtro" : "VALUE",
"contexto" : "VALUE"
},
"outputValues" : { },
"outputAssignments" : { },
"extraParams" : {
"logSoapMessages" : false,
"disableChunking" : false,
"useSSL" : false,
"basicAuthentication" : true,
"basicAuthenticationUsername" : "user",
"basicAuthenticationPassword" : "password",
"parseResult" : true,
"headers" : [ ],
"datasetkeys" : [ ],
"parserType" : "XML",
"mainNode" : "VHabilidades",
"enabled" : true
}
}
}
Código JavaScript
var div = document.getElementById("datasetDiv");
var constraints = new Array();
constraints.push(DatasetFactory.createConstraint("CODHABILIDADE", "060-0001", "060-0001", ConstraintType.MUST));
//Busca o dataset
try {
var dataset = DatasetFactory.getDataset("ds_RhuHabilidadesData", null, constraints, null);
div.innerHTML = showDataset(dataset);
} catch(erro) {
div.innerHTML = erro;
}
function showDataset(dataset) {
var tabela = "<table>";
//Monta o cabeçalho
tabela += "<tr>";
for (var i = 0; i < dataset.columns.length; i++) {
tabela += "<th>" + dataset.columns[i] + "</th>";
}
tabela += "</tr>";
//Monta os registros
for (var x = 0; x < dataset.values.length; x++) {
tabela += "<tr>";
var row = dataset.values[x];
for (var y = 0; y < dataset.columns.length; y++) {
tabela += "<td>" + row[dataset.columns[y]] + "</td>";
}
tabela += "</tr>";
}
tabela += "</table>";
return tabela;
}