<commit_before>/**
 * @license
 * Copyright 2019 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.nanos.crunch',
  name: 'RemoveJunctionsOnUserRemoval',

  documentation: 'Rule to remove any user-capability relationships when a user is removed',

  implements: [
    'foam.nanos.ruler.RuleAction'
  ],

  javaImports: [
    'foam.core.ContextAgent',
    'foam.core.X',
    'foam.nanos.auth.User',
    'static foam.mlang.MLang.*'
  ],

  methods: [
    {
      name: 'applyAction',
      javaCode: `
      agency.submit(x, new ContextAgent() {
        @Override
        public void execute(X x) {
          ((User) obj).getCapabilities(x).getJunctionDAO().removeAll();
        }
      }, "Remove Junctions On User Removal");
      `
    }
  ]
});<commit_msg>Fixed remove junctions on user removal<commit_after>/**
 * @license
 * Copyright 2019 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.nanos.crunch',
  name: 'RemoveJunctionsOnUserRemoval',

  documentation: 'Rule to remove any user-capability relationships when a user is removed',

  implements: [
    'foam.nanos.ruler.RuleAction'
  ],

  javaImports: [
    'foam.dao.DAO',
    'foam.nanos.crunch.UserCapabilityJunction',
    'foam.core.ContextAgent',
    'foam.core.X',
    'foam.nanos.auth.User',
    'static foam.mlang.MLang.*',
    'foam.nanos.auth.LifecycleAware',
    'java.util.List',
    'foam.dao.ArraySink'
  ],

  methods: [
    {
      name: 'applyAction',
      javaCode: `
      agency.submit(x, new ContextAgent() {
        @Override
        public void execute(X x) {
          if ( ((LifecycleAware) obj).getLifecycleState() == foam.nanos.auth.LifecycleState.DELETED ) {
            DAO dao = (DAO) x.get("userCapabilityJunctionDAO");
            List<UserCapabilityJunction> list= ((ArraySink) dao
              .where(EQ(UserCapabilityJunction.SOURCE_ID, ((User) obj).getId()))
              .select(new ArraySink()))
              .getArray();
            dao.where(EQ(UserCapabilityJunction.SOURCE_ID, ((User) obj).getId())).removeAll();
          }
        }
      }, "Remove Junctions On User Removal");
      `
    }
  ]
});
{'fraction_non_alphanumeric': 0.1471111111111111, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 2.6423948220064726, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '822557', 'n_tokens_mistral': 767, 'n_tokens_neox': 758, 'n_words': 139}