Exemplo n.º 1
0
    def store(self, mdt_data):
        """
        Method to store MDT into DB. Uses JSON provided.
        Example MDT:
        {
            "_id": "mymdt",
            "docrule_id": ["1", "2"],
            "description": "description of this metadata template",
            "fields": {
               "1": {
                   "type": "integer",
                   "field_name": "Employee ID",
                   "description": "Unique (Staff) ID of the person associated with the document"
               },
               "2": {
                   "type": "string",
                   "length": 60,
                   "field_name": "Employee Name",
                   "description": "Name of the person associated with the document"
               },
            },
            "parallel": {
               "1": [ "1", "2"],
            }
        }

        """
        mdt = MetaDataTemplate()
        if self.validate_mdt(mdt_data):
            mdt.populate_from_DMS(mdt_data)
            try:
                mdt.save()
                log.debug(
                    'MetaDataTemplateManager.store added mdt with _id: %s' %
                    mdt._id)
                return {"status": "ok", "mdt_id": "%s" % mdt._id}
            except ResourceConflict, e:
                log.error(
                    'MetaDataTemplateManager.store ResourceConflict error: %s'
                    % e)
                pass