Skip to content
Snippets Groups Projects
process.js 42.3 KiB
Newer Older
    
    if (type == DocumentTemplate.types.HTML || type == DocumentTemplate.types.TXT || type == DocumentTemplate.types.EML)
    {
        return [util.decodeBase64String(bindata), type];
    }
    
    return ["", type];
}

/**
 * loads a template
 * @param {String} pTemplateId the id of the template
 * @param {Boolean} pResolveSubtemplates true, if subtemplates should be resolved
 * 
 * @return {DocumentTemplate}
 */
DocumentTemplateUtils.getTemplate = function (pTemplateId, pResolveSubtemplates)
{    
    var assignmentTable = "DOCUMENTTEMPLATE";
    var assignmentName= "DOCUMENT";
    var keyword = "TEMPLATE";

    var binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword);
    if (binMeta.length != 0)
    {                   
        return new DocumentTemplate(
                    db.getBinaryContent(binMeta[0][db.BINARY_ID], SqlUtils.getBinariesAlias()),
                    DocumentTemplate.types.fromBinaryMetadata(binMeta[0]),
                    binMeta[0][db.BINARY_FILENAME],
                    pResolveSubtemplates, pTemplateId);
    }
    
    return null;
}

/**
 * loads the mimetype from a fileUpload or if it's empty from a template in ASYS_BINARIES
 * @param {String} pTemplateId the id of the template
 * @param {FileUpload} pFileUpload upload object
 * 
 * @return {String} mimetype
 */
DocumentTemplateUtils.getMimeType = function (pTemplateId, pFileUpload)
{
    var type;
    
    if (pFileUpload && pFileUpload.isFilled())
    {
        type = pFileUpload.mimeType;
    }
    else
    {
        var assignmentTable = "DOCUMENTTEMPLATE";
        var assignmentName= "DOCUMENT";
        var keyword = "TEMPLATE";
        
        var binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword);
            let binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword);
            type = binMeta[0][db.BINARY_MIMETYPE];
}

/**
 * loads the type from a fileUpload or if it's empty from a template in ASYS_BINARIES
 * @param {String} pTemplateId the id of the template
 * @param {FileUpload} pFileUpload upload object
 * 
 * @return {String} type via DocumentTemplate.types or null
 */
DocumentTemplateUtils.getContentType = function (pTemplateId, pFileUpload)
{
    var type;
    
    if (pFileUpload.isFilled())
    {
        type = DocumentTemplate.types.fromFileExtension(pFileUpload.fileExtension);
    }
    else
    {
        var assignmentTable = "DOCUMENTTEMPLATE";
        var assignmentName= "DOCUMENT";
        var keyword = "TEMPLATE";
        
        var binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword);
            let binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword);
            type = DocumentTemplate.types.fromBinaryMetadata(binMeta[0]);
        }
Johannes Hörmann's avatar
Johannes Hörmann committed
    }