SHARE
TWEET

Untitled

a guest Nov 15th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def handleAttr(def className, attrName, def attr) {
  2.     def attrCode = api.metainfo.getMetaClass(className).getAttribute(attrName).type.code;
  3.  
  4.     switch (attrCode) {
  5.       case ['object', 'boLinks', 'backBOLinks']:
  6.         return ['UUID': attr?.UUID, 'title': attr?.title];
  7.       case ['catalogItem', 'catalogItemSet']:
  8.         return ['UUID': attr?.UUID, 'code': attr?.code, 'title': attr?.title];
  9.       default:
  10.         return attr;
  11.     }
  12. }
  13.  
  14. def getData(def requestData) {
  15.     if(!requestData?.className) {
  16.       "Не задан код справочника или класса".with{ utils.throwReadableException(it, null); }
  17.     }
  18.    
  19.     def queryColumns = requestData.queryColumns ?: [:];
  20.     def selectAttrs = requestData.selectColumns ?: api.metainfo.getMetaClass(requestData.className).attributes*.code;
  21.    
  22.     return modules.common.gson(utils.find(requestData.className, queryColumns).collect{ obj ->
  23.       selectAttrs.collectEntries { attr ->
  24.           return ["${attr}": handleAttr(requestData.className, attr, obj."${attr}")];
  25.       }
  26.     });
  27. }
  28.  
  29. def requestData = [className: 'ae$subSystem', selectColumns: ['currentProject']]; //with select columns
  30. requestData = [className: 'ae$subSystem']; //select all attributes from class
  31. requestData = [className: 'cycle']; //select all attributes from catalog
  32. requestData = [className: '']; //validate input data
  33.  
  34. return getData(requestData);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top