Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getConfig() {
- return {
- community: "licoes-aprendidas"
- }
- }
- function createDataset(fields, constraints, sortFields) {
- var datasetLicoesAprend = "ds_licoesAprend";
- var datasetPaiFilhoSeguranca = "ds_paiFilhoSeguranca";
- var numero_solicitacao = 0;
- var dataset = DatasetBuilder.newDataset();
- dataset.addColumn('id');
- dataset.addColumn('version');
- // var gson = new com.google.gson.Gson();
- var parser = new com.google.gson.JsonParser();
- if (constraints != null) {
- for (i = 0; i < constraints.length; i++) {
- if (constraints[i].fieldName == "numero_solicitacao" && constraints[i].initialValue != "") {
- numero_solicitacao = constraints[i].initialValue;
- }
- }
- }
- var resultado = DatasetFactory.getDataset(datasetLicoesAprend, null, [
- DatasetFactory.createConstraint("numero_solicitacao", numero_solicitacao, numero_solicitacao, ConstraintType.MUST)
- ], null);
- try {
- var clientService = fluigAPI.getAuthorizeClientService();
- var link_src = '/api/public/ecm/document/documentfile/';
- var img_principal_html = '<div class="row"><div class="col-md-12" id="img-principal" style="width: calc(100% - 30px); display: flex; justify-content: center;"><img src="' + resultado.getValue('0', 'linkDownload_1') + '" style="height: 300px;"></div></div>';
- var html = '<div class="row" style="width: 100%; margin: 30px 0; float: left; font-family: "Open Sans", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.42857143; color: #58595b;">';
- var type_img_principal = resultado.getValue('0', 'img_principal');
- var img_esquerda = "";
- var img_direita = "";
- var img_centro = "";
- var video = "";
- var count = 0;
- html += '<div class="row" style="display: flex; justify-content: center;">';
- if (type_img_principal == '1') {
- img_principal = resultado.getValue('0', 'idAnexo_1');
- img_esquerda = resultado.getValue('0', 'linkDownload_2');
- img_centro = resultado.getValue('0', 'linkDownload_3');
- img_direita = resultado.getValue('0', 'linkDownload_4');
- if (img_esquerda) {
- count = count + 1;
- }
- if (img_centro) {
- count = count + 1;
- }
- if (img_direita) {
- count = count + 1;
- }
- if (img_esquerda != "") {
- html = html + '<div class="col-md-4" id="img-lado-esquerdo" style="width: calc(100% / ' + count + ' - 30px); float: left; margin: 0 15px;"><img src="' + img_esquerda + '" style="width: auto; max-height: 200px;"></div>';
- }
- if (img_centro != "") {
- html = html + '<div class="col-md-4" id="img-centro" style="width: calc(100% / ' + count + ' - 30px); float: left; margin: 0 15px;"><img src="' + img_centro + '" style="width: auto; max-height: 200px;"></div>';
- }
- if (img_direita != "") {
- html = html + '<div class="col-md-4" id="img-lado-direito" style="width: calc(100% / ' + count + ' - 30px); float: right; margin: 0 15px;"><img src="' + img_direita + '" style="width: auto; max-height: 200px;"></div>';
- }
- }
- if (type_img_principal == '2') {
- img_principal = parseInt(resultado.getValue('0', 'idAnexo_2'));
- img_esquerda = resultado.getValue('0', 'linkDownload_3');
- video = resultado.getValue('0', 'linkDownload_1');
- img_direita = resultado.getValue('0', 'linkDownload_4');
- if (img_esquerda) {
- count = count + 1;
- }
- if (video) {
- count = count + 1;
- }
- if (img_direita) {
- count = count + 1;
- }
- if (img_esquerda != "") {
- html = html + '<div class="col-md-4" id="img-lado-esquerdo" style="width: calc(100% / ' + count + ' - 30px); float: left; margin: 0 15px;"><div><img src="' + img_esquerda + '" style="width: auto; max-height: 200px;"></div></div>';
- }
- if (video != "") {
- html = html + '<div class="col-md-4" id="video-preview" style="width: calc(100% / ' + count + ' - 30px); float: left; margin: 0 15px;"><div><video width="100%" controls="controls" src="' + video + '"><source type="video/mp4" src="' + link_src + video + '/1000' + '"><source type="video/avi" src=""><source type="video/3gp" src="' + link_src + video + '/1000' + '"></div></div>';
- }
- if (img_direita != "") {
- html = html + '<div class="col-md-4" id="img-lado-direito" style="width: calc(100% / ' + count + ' - 30px); float: left; margin: 0 15px;"><div><img src="' + img_direita + '" style="width: auto; max-height: 200px;"></div></div>';
- }
- }
- html = html + "</div></div>";
- var tipoSolicitacao = resultado.getValue('0', 'tipo_solicitacao');
- var TIPOS_SOLICITACAO = {
- novo: 1,
- atualizar: 2
- }
- // Informações do novo artigo
- var nArticleId = parseInt(resultado.getValue('0', 'id_artigo_publicado'));
- var nFolderId = parseInt(resultado.getValue('0', 'pasta_armazenamento'));
- var sTitle = new String(resultado.getValue('0', 'titulo_artigo'));
- var sContent = new String('<div style="word-wrap: break-word">' + resultado.getValue('0', 'artigo_sem_formatacao') + img_principal_html + html + '</div>')
- var sTags = new String(resultado.getValue('0', 'tags_busca'));
- var createVO;
- if (tipoSolicitacao == TIPOS_SOLICITACAO.novo) {
- log.info("CRIANDO NOVO ARTIGO");
- // Cria um rascunho
- createVO = createDraft(clientService, nFolderId, sTitle, sContent, sTags, img_principal, null, '');
- dataset.addRow(['create', createVO]);
- // Atribui o novo ID do artigo
- var result = parser.parse(createVO).getAsJsonObject();
- nArticleId = parseInt(result.getAsJsonObject("content").get("id"));
- } else {
- log.info("ATUALIZANDO ARTIGO JÁ EXISTENTE");
- // Atualiza sem incluir a capa
- update(clientService, nArticleId, nFolderId, sTitle, sContent, sTags, false);
- }
- // Muda a capa
- changeCover(clientService, nArticleId, nFolderId, sTitle, sContent, sTags, true, img_principal);
- // Configura e aplica a capa
- var updateVO = update(clientService, nArticleId, nFolderId, sTitle, sContent, sTags, false);
- // Versão do artigo
- var resultUpdate = parser.parse(updateVO).getAsJsonObject();
- var version = parseInt(resultUpdate.getAsJsonObject("content").get("version"));
- dataset.addRow([nArticleId, version]);
- // Segurança
- var seguranca = DatasetFactory.getDataset(datasetPaiFilhoSeguranca, null, [
- DatasetFactory.createConstraint('numero_solicitacao', numero_solicitacao, numero_solicitacao, ConstraintType.MUST)
- ], null);
- if (seguranca.rowsCount > 0) {
- var arrayPermissionVo = [];
- var typePermission = { 'user': 1, 'group': 2 }
- // Criar o array de Objetos com as permissões e tipo de permissão
- for (var s = 0; s < seguranca.rowsCount; s++) {
- var attributionType = parseInt(typePermission[seguranca.getValue(s, 'tipo_seguranca')]);
- var attributionValue = seguranca.getValue(s, 'seguranca_intens');
- if (
- attributionValue == "Todos" ||
- attributionValue == "LMS - Todos" ||
- attributionValue == "Todos os Usuários do Fluig"
- ) {
- attributionValue = "all";
- attributionType = 3;
- }
- var objSeg = {
- "attributionType": attributionType,
- "attributionValue": attributionValue,
- "securityLevel": parseInt(seguranca.getValue(s, 'nivel_seguranca')),
- "downloadEnabled": false
- }
- arrayPermissionVo.push(objSeg);
- }
- var permissao = {
- companyId : getValue("WKCompany") + '',
- serviceCode : 'SetDocumentPermissions',
- endpoint : '/public/2.0/documents/setDocumentPermissions',
- method : 'post',
- timeoutService: '100',
- params: {
- "documentId": parseInt(nArticleId),
- "documentPermissionVO": arrayPermissionVo
- }
- }
- clientService.invoke(JSONUtil.toJSON(permissao));
- }
- } catch (e) {
- log.info(e);
- dataset.addRow([e.message]);
- }
- return dataset;
- }
- function create(clientService, sFolderId, sTitle, sContent, sTags, sCoverId, sCoverName, nId) {
- var config = getConfig();
- var data = {
- companyId : getValue("WKCompany") + '',
- serviceCode : 'ArticlesCreate',
- endpoint : '/api/public/2.0/communities/articles/create',
- method : 'post',
- timeoutService: '100',
- params: {
- "id": '' + nId,
- "alias": '' + config.community,
- "articleCoverVO": {
- "pictureName": sCoverName,
- "pictureId": sCoverId
- },
- "categoryId": '' + sFolderId,
- "content": '' + sContent,
- "description": '' + sTitle,
- "expirationDate": "",
- "keyWord": '' + sTags,
- "version": 1000
- }
- };
- var vo = clientService.invoke(JSONUtil.toJSON(data));
- return vo.getResult();
- }
- function createDraft(clientService, nFolderId, sTitle, sContent, sTags, sCoverId, sCoverName, nId) {
- var config = getConfig();
- var data = {
- companyId : getValue("WKCompany") + '',
- serviceCode : 'CreateDraft',
- endpoint : '/api/public/2.0/communities/articles/createDraft',
- method : 'post',
- timeoutService: '100',
- params: {
- "id": '' + nId,
- "alias": '' + config.community,
- "articleCoverVO": {
- "pictureName": sCoverName,
- "pictureId": sCoverId
- },
- "categoryId": '' + nFolderId,
- "content": '' + sContent,
- "description": '' + sTitle,
- "expirationDate": "",
- "keyWord": '' + sTags,
- "version": 1000
- }
- }
- var vo = clientService.invoke(JSONUtil.toJSON(data));
- return vo.getResult();
- }
- function changeCover(clientService, nId, nFolderId, sTitle, sContent, sTags, bDraft, sIdCover) {
- var config = getConfig();
- var data = {
- companyId : getValue("WKCompany") + '',
- serviceCode : 'ChangeCover',
- endpoint : '/api/public/2.0/communities/articles/changeCover',
- method : 'post',
- timeoutService: '100',
- params: {
- "alias": '' + config.community,
- "articleCoverVO": {
- "pictureId": sIdCover,
- },
- "categoryId": '' + nFolderId,
- "content": '' + sContent,
- "description": '' + sTitle,
- "draft": bDraft,
- "expires": false,
- "id": '' + nId,
- "keyWord": '' + sTags,
- "topicId": "1",
- "userNotify": false,
- "version": 1000
- }
- }
- var vo = clientService.invoke(JSONUtil.toJSON(data));
- return vo.getResult();
- }
- function update(clientService, nId, sFolderId, sTitle, sContent, sTags, bDraft) {
- var config = getConfig();
- // Medidas um tanto arbitrárias, mas funcionais
- var articleCoverVO = {
- "width": 824,
- "height": 165,
- "coordinateX": 0,
- "coordinateY": 0,
- };
- var data = {
- companyId : getValue("WKCompany") + '',
- serviceCode : 'Update',
- endpoint : '/api/public/2.0/communities/articles/update',
- method : 'post',
- timeoutService: '100',
- params: {
- "alias": '' + config.community,
- "articleCoverVO": articleCoverVO,
- "categoryId": '' + sFolderId,
- "content": '' + sContent,
- "description": '' + sTitle,
- "draft": bDraft,
- "id": nId,
- "keyWord": '' + sTags,
- "topicId": '1',
- "version": 1000
- }
- }
- var vo = clientService.invoke(JSONUtil.toJSON(data));
- return vo.getResult();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement