att
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
function beforeStateEntry(sequenceId) {
|
||||
appendDebugPublicacao("beforeStateEntry sequenceId=" + sequenceId);
|
||||
|
||||
if (sequenceId == 7) {
|
||||
anexarDocumentoDoCardSeNecessario();
|
||||
publicarDocumento();
|
||||
}
|
||||
|
||||
if (sequenceId == 7) {
|
||||
var attachments = hAPI.listAttachments();
|
||||
var hasAttachment = attachments && attachments.size() > 0;
|
||||
appendDebugPublicacao("validacao anexos: total=" + (attachments ? attachments.size() : 0));
|
||||
|
||||
if (!hasAttachment) {
|
||||
appendDebugPublicacao("validacao anexos: nenhum anexo encontrado apos processamento.");
|
||||
throw "\n\nNao identificamos nenhum documento anexado, volte ao formulario e anexe pelo menos um documento para avancar a solicitacao.\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function anexarDocumentoDoCardSeNecessario() {
|
||||
try {
|
||||
var attachments = hAPI.listAttachments();
|
||||
if (attachments && attachments.size() > 0) {
|
||||
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: solicitacao ja possui " + attachments.size() + " anexo(s).");
|
||||
return;
|
||||
}
|
||||
|
||||
var anexoIdStr = (hAPI.getCardValue("anexo_documento_id") || "") + "";
|
||||
anexoIdStr = anexoIdStr.replace(/^\s+|\s+$/g, "");
|
||||
if (!anexoIdStr) {
|
||||
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: campo anexo_documento_id vazio.");
|
||||
return;
|
||||
}
|
||||
|
||||
var anexoId = parseInt(anexoIdStr, 10);
|
||||
if (isNaN(anexoId) || anexoId <= 0) {
|
||||
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: anexo_documento_id invalido: " + anexoIdStr);
|
||||
return;
|
||||
}
|
||||
|
||||
hAPI.attachDocument(anexoId);
|
||||
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: hAPI.attachDocument OK documentId=" + anexoId);
|
||||
|
||||
var attachmentsDepois = hAPI.listAttachments();
|
||||
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: total anexos apos attachDocument = " + (attachmentsDepois ? attachmentsDepois.size() : 0));
|
||||
} catch (e) {
|
||||
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: ERRO " + e);
|
||||
}
|
||||
}
|
||||
|
||||
function appendDebugPublicacao(msg) {
|
||||
try {
|
||||
var atual = (hAPI.getCardValue("debug_publicacao") || "") + "";
|
||||
var prefix = atual ? atual + "\n" : "";
|
||||
hAPI.setCardValue("debug_publicacao", prefix + msg);
|
||||
} catch (e) {
|
||||
log.warn("appendDebugPublicacao falhou: " + e);
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
function publicarDocumento() {
|
||||
var radioGed = (hAPI.getCardValue("radio_ged") || "") + "";
|
||||
var idPastaSelecionadaRaw = (hAPI.getCardValue("idPastaSelecionada") || "") + "";
|
||||
log.info("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## radio_ged=" + radioGed + " idPastaSelecionada=" + idPastaSelecionadaRaw);
|
||||
appendDebugPublicacao("publicarDocumento: radio_ged=" + radioGed + " idPastaSelecionada=" + idPastaSelecionadaRaw);
|
||||
|
||||
if (radioGed != "publica_ged") {
|
||||
log.info("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## Nao publicar no ECM (radio_ged diferente de publica_ged).");
|
||||
appendDebugPublicacao("publicarDocumento: radio_ged diferente de publica_ged.");
|
||||
return;
|
||||
}
|
||||
|
||||
var attachments = hAPI.listAttachments();
|
||||
log.info("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## attachments.size=" + (attachments ? attachments.size() : 0));
|
||||
appendDebugPublicacao("publicarDocumento: attachments.size=" + (attachments ? attachments.size() : 0));
|
||||
|
||||
for (var i = 0; i < attachments.size(); i++) {
|
||||
var docDto = attachments.get(i);
|
||||
log.info("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## analisando anexo documentId=" + docDto.getDocumentId() + " version=" + docDto.getVersion() + " documentType=" + docDto.getDocumentType());
|
||||
appendDebugPublicacao("publicarDocumento: analisando documentId=" + docDto.getDocumentId() + " version=" + docDto.getVersion() + " type=" + docDto.getDocumentType());
|
||||
|
||||
try {
|
||||
docAPI.copyDocumentToUploadArea(docDto.getDocumentId(), docDto.getVersion());
|
||||
|
||||
docDto.setDocumentId(0);
|
||||
|
||||
var idPastaSelecionada = parseInt((hAPI.getCardValue("idPastaSelecionada") || "") + "", 10);
|
||||
if (isNaN(idPastaSelecionada) || idPastaSelecionada <= 0) {
|
||||
log.warn("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## idPastaSelecionada invalido. Documento nao sera publicado no ECM.");
|
||||
appendDebugPublicacao("publicarDocumento: idPastaSelecionada invalido.");
|
||||
continue;
|
||||
}
|
||||
|
||||
docDto.setParentDocumentId(idPastaSelecionada);
|
||||
|
||||
var attachArray = new java.util.ArrayList();
|
||||
var mainAttach = docAPI.newAttachment();
|
||||
mainAttach.setFileName(docDto.getPhisicalFile());
|
||||
mainAttach.setPrincipal(true);
|
||||
mainAttach.setAttach(false);
|
||||
attachArray.add(mainAttach);
|
||||
|
||||
docDto.setActiveVersion(true);
|
||||
docDto.setColleagueId(getValue("WKUser"));
|
||||
docDto.setPublisherId(getValue("WKUser"));
|
||||
|
||||
if (hAPI.getCardValue("radio_data_validade") == "com_data_validade") {
|
||||
docDto.setExpires(true);
|
||||
|
||||
if (hAPI.getCardValue("inicio_validade") != "") {
|
||||
var inicioValidade = (hAPI.getCardValue("inicio_validade") || "") + "";
|
||||
var dataInicioSplit = inicioValidade.split("-");
|
||||
var anoInicio = dataInicioSplit[0];
|
||||
var mesInicio = parseFloat(dataInicioSplit[1]) - 1;
|
||||
var diaInicio = dataInicioSplit[2];
|
||||
var dInicio = new Date(anoInicio, mesInicio, diaInicio);
|
||||
docDto.setValidationStartDate(dInicio);
|
||||
}
|
||||
|
||||
if (hAPI.getCardValue("expiracao_validade") != "") {
|
||||
var dataVencimento = (hAPI.getCardValue("expiracao_validade") || "") + "";
|
||||
var dataSplit = dataVencimento.split("-");
|
||||
var ano = dataSplit[0];
|
||||
var mes = parseFloat(dataSplit[1]) - 1;
|
||||
var dia = dataSplit[2];
|
||||
var d = new Date(ano, mes, dia);
|
||||
docDto.setExpirationDate(d);
|
||||
}
|
||||
|
||||
if (hAPI.getCardValue("dias_antes_expiracao") != "") {
|
||||
var diasAntesExpiracao = parseInt(hAPI.getCardValue("dias_antes_expiracao"), 10);
|
||||
docDto.setNotificationDays(diasAntesExpiracao);
|
||||
}
|
||||
} else {
|
||||
docDto.setExpires(false);
|
||||
}
|
||||
|
||||
log.info("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## before create document");
|
||||
var doc = docAPI.createDocument(docDto, attachArray, null, null, null);
|
||||
log.info("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## DOCUMENTO CRIADO COM O ID: " + doc.getDocumentId());
|
||||
appendDebugPublicacao("publicarDocumento: documento publicado no ECM com id=" + doc.getDocumentId());
|
||||
} catch (e) {
|
||||
log.error("PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## falha ao publicar anexo documentId=" + docDto.getDocumentId() + " erro=" + e);
|
||||
appendDebugPublicacao("publicarDocumento: ERRO ao publicar documentId=" + docDto.getDocumentId() + " erro=" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function appendDebugPublicacao(msg) {
|
||||
try {
|
||||
var atual = (hAPI.getCardValue("debug_publicacao") || "") + "";
|
||||
var prefix = atual ? atual + "\n" : "";
|
||||
hAPI.setCardValue("debug_publicacao", prefix + msg);
|
||||
} catch (e) {
|
||||
log.warn("appendDebugPublicacao falhou: " + e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user