Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://servicodados.ibge.gov.br/api/v1/localidades/municipios */
- function defineStructure() {
- addColumn("cod", DatasetFieldType.STRING);
- addColumn("municipio");
- addColumn("uf");
- addColumn("uf_sigla");
- addColumn("regiao");
- setKey(["cod", "municipio"]);
- addIndex(["cod"]);
- addIndex(["cod", "municipio", "uf_sigla"]);
- }
- function createDataset(fields, constraints, sortFields) {
- var dataset = DatasetBuilder.newDataset();
- dataset.addColumn("cod");
- dataset.addColumn("municipio");
- dataset.addColumn("uf");
- dataset.addColumn("uf_sigla");
- dataset.addColumn("regiao");
- var cidadesRetorno = getDados();
- for (var index = 0; index < cidadesRetorno.length; index++) {
- dataset.addRow(cidadesRetorno[index]);
- }
- return dataset;
- }
- function onSync(lastSyncDate) {
- var dataset = DatasetBuilder.newDataset();
- var cidadesRetorno = getDados();
- for (var index = 0; index < cidadesRetorno.length; index++) {
- dataset.addOrUpdateRow(cidadesRetorno[index]);
- }
- return dataset;
- }
- function getDados() {
- var clientService = fluigAPI.getAuthorizeClientService();
- var data = {
- companyId: String(getValue("WKCompany")),
- serviceCode: 'IBGE',
- endpoint: '/api/v1/localidades/municipios',
- method: 'get',
- }
- var vo = clientService.invoke(JSON.stringify(data));
- var objeto = JSON.parse(vo.getResult());
- // var cidades = new java.util.ArrayList();
- var cidades = [];
- if (vo.getHttpStatusResult() == 200) {
- if (vo.getResult() == null || vo.getResult().isEmpty()) {
- cidades.push([
- "Retorno vazio ou com erro",
- "Retorno vazio ou com erro"
- ]);
- return cidades;
- } else {
- for (var index = 0; index < objeto.length; index++) {
- cidades.push([
- String(objeto[index].id),
- objeto[index].nome,
- objeto[index].microrregiao.mesorregiao.UF.nome,
- objeto[index].microrregiao.mesorregiao.UF.sigla,
- objeto[index].microrregiao.mesorregiao.UF.regiao.nome
- ]);
- }
- return cidades;
- }
- }
- }
Add Comment
Please, Sign In to add comment