Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

76
LINES

< > BotCompany Repo | #1026002 - HCRUD_Concepts

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (13551L) is out of date.

sclass HCRUD_Concepts<A extends Concept> extends HCRUD_Data {
  Concepts cc = db_mainConcepts();
  Class<A> cClass;
  new L<IVF1<A>> onCreateOrUpdate;
  MapSO filters; // fields to filter by/add to new objects
  
  *(Class<A> *cClass) {}
  
  S itemName() { ret shortName(cClass); }
  
  //LS fields() { ret conceptFields(cClass); }
  
  L<MapSO> list() {
    ret lambdaMap itemToMapForList(defaultSort(asList(listConcepts())));
  }
  
  Cl<A> listConcepts() {
    ret conceptsWhere(cc, cClass, mapToParams(filters));
  }
  
  L<A> defaultSort(L<A> l) { ret l; }
  
  MapSO emptyObject() {
    A c = unlisted(cClass);
    print("fieldOrder", getFieldOrder(c));
    ret printStruct("emptyObject", itemToMap(c));
  }
  
  MapSO itemToMap(A c) {
    if (c == null) null;
    ret putKeysFirst(getFieldOrder(c), conceptToMap_gen_withNullValues(c));
  }
  
  MapSO itemToMapForList(A c) {
    if (c == null) null;
    MapSO map = itemToMap(c);
    massageItemMapForList(c, map);
    ret map;
  }
  
  // overridable
  void massageItemMapForList(A c, MapSO map) {
  }
  
  MapSO getObject(O id) {
    ret itemToMap(getConcept(cc, cClass, toLong(id)));
  }
  
  O createObject(SS map) {
    A c = cnew(cc, cClass);
    cset(c, mapToParams(filters));
    cSmartSet(c, mapToParams(map));
    pcallFAll(onCreateOrUpdate, c);
    ret c.id;
  }
  
  S updateObject(O id, SS map) {
    A c = getConcept(cc, cClass, toLong(id));
    if (c == null) ret "Object " + id + " not found";
    cSmartSet(c, mapToParams(map));
    pcallFAll(onCreateOrUpdate, c);
    ret "Object " + id + " updated";
  }
  
  S deleteObject(O id) {
    A c = getConcept(cc, cClass, toLong(id));
    if (c == null) ret "Object not found";
    deleteConcept(c);
    ret "Object deleted";
  }
  
  HCRUD_Concepts<A> addFilter(S field, O value) {
    filters = orderedMapPutOrCreate(filters, field, value);
    this;
  }
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1026002
Snippet name: HCRUD_Concepts
Eternal ID of this version: #1026002/30
Text MD5: f056dd0dfe32cd90dfbf61fdd45946c8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-27 18:41:18
Source code size: 1953 bytes / 76 lines
Pitched / IR pitched: No / No
Views / Downloads: 108 / 345
Version history: 29 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1026002 & http://1026002.tinybrain.de