refs #5712 feat(workerDms): docuware integration
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
fad28dc711
commit
b60cd2539a
|
@ -1,7 +1,7 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('checkFile', {
|
Self.remoteMethod('checkFile', {
|
||||||
description: 'Check if exist docuware file',
|
description: 'Check if exist docuware file',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -20,8 +20,14 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'signed',
|
arg: 'signed',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
required: true,
|
required: false,
|
||||||
description: 'If pdf is necessary to be signed'
|
description: 'If pdf is necessary to be signed'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
required: false,
|
||||||
|
description: 'The filter'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -34,7 +40,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.checkFile = async function(ctx, id, fileCabinet, signed) {
|
Self.checkFile = async function(id, fileCabinet, signed, filter) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const action = 'find';
|
const action = 'find';
|
||||||
|
|
||||||
|
@ -44,35 +50,39 @@ module.exports = Self => {
|
||||||
action: action
|
action: action
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
console.log(id, fileCabinet, signed, filter);
|
||||||
const searchFilter = {
|
if (!filter) {
|
||||||
condition: [
|
filter = {
|
||||||
{
|
condition: [
|
||||||
DBName: docuwareInfo.findById,
|
{
|
||||||
|
DBName: docuwareInfo.findById,
|
||||||
Value: [id]
|
Value: [id]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
sortOrder: [
|
sortOrder: [
|
||||||
{
|
{
|
||||||
Field: 'FILENAME',
|
Field: 'FILENAME',
|
||||||
Direction: 'Desc'
|
Direction: 'Desc'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = await Self.getOptions();
|
const options = await Self.getOptions();
|
||||||
|
|
||||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
||||||
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
||||||
|
console.log('FILTER', filter);
|
||||||
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
||||||
searchFilter,
|
filter,
|
||||||
options.headers
|
options.headers
|
||||||
);
|
);
|
||||||
const [documents] = response.data.Items;
|
const [documents] = response.data.Items;
|
||||||
|
console.log(response);
|
||||||
|
console.log(response.data);
|
||||||
if (!documents) return false;
|
if (!documents) return false;
|
||||||
|
|
||||||
const state = documents.Fields.find(field => field.FieldName == 'ESTADO');
|
const state = documents.Fields.find(field => field.FieldName == 'ESTADO');
|
||||||
|
|
|
@ -1,6 +1,28 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
/**
|
||||||
|
* Returns basic headers
|
||||||
|
*
|
||||||
|
* @param {string} cookie - The docuware cookie
|
||||||
|
* @return {object} - The headers
|
||||||
|
*/
|
||||||
|
Self.getOptions = async() => {
|
||||||
|
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
|
||||||
|
const headers = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Cookie': docuwareConfig.cookie
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
url: docuwareConfig.url,
|
||||||
|
headers
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the dialog id
|
* Returns the dialog id
|
||||||
*
|
*
|
||||||
|
@ -20,9 +42,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
const options = await Self.getOptions();
|
const options = await Self.getOptions();
|
||||||
|
|
||||||
if (!process.env.NODE_ENV)
|
|
||||||
return Math.round();
|
|
||||||
|
|
||||||
const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers);
|
const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers);
|
||||||
const dialogs = response.data.Dialog;
|
const dialogs = response.data.Dialog;
|
||||||
const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id;
|
const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id;
|
||||||
|
@ -44,9 +63,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!process.env.NODE_ENV)
|
|
||||||
return Math.round();
|
|
||||||
|
|
||||||
const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers);
|
const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers);
|
||||||
const fileCabinets = fileCabinetResponse.data.FileCabinet;
|
const fileCabinets = fileCabinetResponse.data.FileCabinet;
|
||||||
const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id;
|
const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id;
|
||||||
|
@ -55,24 +71,81 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns basic headers
|
* Returns docuware data
|
||||||
*
|
*
|
||||||
* @param {string} cookie - The docuware cookie
|
* @param {string} code - The fileCabinet code
|
||||||
* @return {object} - The headers
|
* @param {object} filter - The filter for docuware
|
||||||
|
* @param {object} parse - The fields parsed
|
||||||
|
* @return {object} - The data
|
||||||
*/
|
*/
|
||||||
Self.getOptions = async() => {
|
Self.get = async(code, filter, parse) => {
|
||||||
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
|
const options = await Self.getOptions();
|
||||||
const headers = {
|
const fileCabinetId = await Self.getFileCabinet(code);
|
||||||
headers: {
|
const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
const {data} = await axios.post(
|
||||||
'Cookie': docuwareConfig.cookie
|
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
||||||
|
filter,
|
||||||
|
options.headers
|
||||||
|
);
|
||||||
|
|
||||||
|
return parser(data, parse);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns docuware data
|
||||||
|
*
|
||||||
|
* @param {string} code - The fileCabinet code
|
||||||
|
* @param {any} id - The id of docuware
|
||||||
|
* @param {object} parse - The fields parsed
|
||||||
|
* @return {object} - The data
|
||||||
|
*/
|
||||||
|
Self.getById = async(code, id, parse) => {
|
||||||
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
|
fields: ['findById'],
|
||||||
|
where: {
|
||||||
|
code: code,
|
||||||
|
action: 'find'
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
const filter = {
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
DBName: docuwareInfo.findById,
|
||||||
|
Value: [id]
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return Self.get(code, filter, parse);
|
||||||
url: docuwareConfig.url,
|
|
||||||
headers
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns docuware data filtered
|
||||||
|
*
|
||||||
|
* @param {array} data - The data
|
||||||
|
* @param {object} parse - The fields parsed
|
||||||
|
* @return {object} - The data parsed
|
||||||
|
*/
|
||||||
|
function parser(data, parse) {
|
||||||
|
if (!(data && data.Items)) return data;
|
||||||
|
|
||||||
|
const parsed = [];
|
||||||
|
for (item of data.Items) {
|
||||||
|
const itemParsed = {};
|
||||||
|
item.Fields.map(field => {
|
||||||
|
if (field.ItemElementName.includes('Date')) field.Item = toDate(field.Item);
|
||||||
|
if (!parse) return itemParsed[field.FieldLabel] = field.Item;
|
||||||
|
if (parse[field.FieldLabel])
|
||||||
|
itemParsed[parse[field.FieldLabel]] = field.Item;
|
||||||
|
});
|
||||||
|
parsed.push(itemParsed);
|
||||||
|
}
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDate(value) {
|
||||||
|
if (!value) return;
|
||||||
|
return new Date(Number(value.substring(6, 19)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,8 +41,10 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.download = async function(ctx, id, fileCabinet) {
|
Self.download = async function(ctx, id, fileCabinet, filter) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
|
// REVIEW
|
||||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true);
|
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true);
|
||||||
if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists');
|
if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `vn`.`docuware`
|
||||||
|
(code, fileCabinetName, `action`, dialogName, findById)
|
||||||
|
VALUES('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO');
|
|
@ -0,0 +1,46 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('docuwareDownload', {
|
||||||
|
description: 'Download a worker document',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The document id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: `/:id/docuwareDownload`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.docuwareDownload = async function(ctx, id) {
|
||||||
|
// CHECK ROLE?
|
||||||
|
const filter = {
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
DBName: 'FILENAME',
|
||||||
|
Value: [id]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
return await Self.app.models.Docuware.download(ctx, id, 'hr', false, filter);
|
||||||
|
};
|
||||||
|
};
|
|
@ -5,6 +5,12 @@ module.exports = Self => {
|
||||||
description: 'Find all instances of the model matched by filter from the data source.',
|
description: 'Find all instances of the model matched by filter from the data source.',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The worker id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'Object',
|
type: 'Object',
|
||||||
|
@ -17,16 +23,17 @@ module.exports = Self => {
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/filter`,
|
path: `/:id/filter`,
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.filter = async(ctx, filter) => {
|
Self.filter = async(ctx, id, filter) => {
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const models = Self.app.models;
|
||||||
|
|
||||||
const account = await Self.app.models.VnUser.findById(userId);
|
const account = await models.VnUser.findById(userId);
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile
|
`SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile
|
||||||
FROM workerDocument wd
|
FROM workerDocument wd
|
||||||
|
@ -47,7 +54,31 @@ module.exports = Self => {
|
||||||
}]
|
}]
|
||||||
}, oldWhere]};
|
}, oldWhere]};
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
|
const workerDms = await conn.executeStmt(stmt);
|
||||||
|
|
||||||
return await conn.executeStmt(stmt);
|
// Get docuware info
|
||||||
|
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
||||||
|
const docuwareParse = {
|
||||||
|
'Document ID': 'dmsFk',
|
||||||
|
'Tipo Documento': 'description',
|
||||||
|
'Stored on': 'created',
|
||||||
|
};
|
||||||
|
const workerDocuware = await models.Docuware.getById('hr', 'BONO MOLA XAVIER', docuwareParse);// worker.lastName + worker.firstName);
|
||||||
|
|
||||||
|
for (document of workerDocuware) {
|
||||||
|
const defaultData = {
|
||||||
|
file: document.dmsFk + '.png',
|
||||||
|
isDocuware: true,
|
||||||
|
hardCopyNumber: null,
|
||||||
|
hasFile: false,
|
||||||
|
reference: worker.fi
|
||||||
|
};
|
||||||
|
|
||||||
|
document = Object.assign(document, defaultData);
|
||||||
|
}
|
||||||
|
console.log(workerDocuware);
|
||||||
|
console.log(workerDms);
|
||||||
|
|
||||||
|
return workerDms.concat(workerDocuware);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@ module.exports = Self => {
|
||||||
require('../methods/worker-dms/downloadFile')(Self);
|
require('../methods/worker-dms/downloadFile')(Self);
|
||||||
require('../methods/worker-dms/removeFile')(Self);
|
require('../methods/worker-dms/removeFile')(Self);
|
||||||
require('../methods/worker-dms/filter')(Self);
|
require('../methods/worker-dms/filter')(Self);
|
||||||
|
require('../methods/worker-dms/docuware')(Self);
|
||||||
|
|
||||||
Self.isMine = async function(ctx, dmsId) {
|
Self.isMine = async function(ctx, dmsId) {
|
||||||
const myUserId = ctx.req.accessToken.userId;
|
const myUserId = ctx.req.accessToken.userId;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="WorkerDms/filter"
|
url="WorkerDms/{{$ctrl.$params.id}}/filter"
|
||||||
link="{worker: $ctrl.$params.id}"
|
link="{worker: $ctrl.$params.id}"
|
||||||
limit="20"
|
limit="20"
|
||||||
data="$ctrl.workerDms"
|
data="$ctrl.workerDms"
|
||||||
|
@ -46,14 +46,14 @@
|
||||||
</span>
|
</span>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td shrink>
|
<vn-td shrink>
|
||||||
<vn-check
|
<vn-check
|
||||||
ng-model="document.hasFile"
|
ng-model="document.hasFile"
|
||||||
disabled="true">
|
disabled="true">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td shrink>
|
<vn-td shrink>
|
||||||
<span title="{{'Download file' | translate}}" class="link"
|
<span title="{{'Download file' | translate}}" class="link"
|
||||||
ng-click="$ctrl.downloadFile(document.dmsFk)">
|
ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)">
|
||||||
{{::document.file}}
|
{{::document.file}}
|
||||||
</span>
|
</span>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<vn-td shrink>
|
<vn-td shrink>
|
||||||
<vn-icon-button title="{{'Download file' | translate}}"
|
<vn-icon-button title="{{'Download file' | translate}}"
|
||||||
icon="cloud_download"
|
icon="cloud_download"
|
||||||
ng-click="$ctrl.downloadFile(document.dmsFk)">
|
ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td shrink>
|
<vn-td shrink>
|
||||||
|
@ -91,9 +91,9 @@
|
||||||
fixed-bottom-right>
|
fixed-bottom-right>
|
||||||
<vn-float-button icon="add"></vn-float-button>
|
<vn-float-button icon="add"></vn-float-button>
|
||||||
</a>
|
</a>
|
||||||
<vn-confirm
|
<vn-confirm
|
||||||
vn-id="confirm"
|
vn-id="confirm"
|
||||||
message="This file will be deleted"
|
message="This file will be deleted"
|
||||||
question="Are you sure you want to continue?"
|
question="Are you sure you want to continue?"
|
||||||
on-accept="$ctrl.deleteDms($data)">
|
on-accept="$ctrl.deleteDms($data)">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
|
|
|
@ -17,7 +17,8 @@ class Controller extends Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadFile(dmsId) {
|
downloadFile(dmsId, isDocuware) {
|
||||||
|
if (isDocuware) return this.vnFile.download(`api/workerDms/${dmsId}/docuwareDownload`);
|
||||||
this.vnFile.download(`api/workerDms/${dmsId}/downloadFile`);
|
this.vnFile.download(`api/workerDms/${dmsId}/downloadFile`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue