Example #1
0
  public void saveViewPrivilege(final PrivilegeInfo privilegeInfo) {
    final CMQueryResult result =
        view.select(anyAttribute(grantClass))
            .from(grantClass)
            .where(
                and(
                    condition(
                        attribute(grantClass, GROUP_ID_ATTRIBUTE), eq(privilegeInfo.getGroupId())),
                    condition(
                        attribute(grantClass, TYPE_ATTRIBUTE),
                        eq(PrivilegedObjectType.VIEW.getValue())))) //
            .run();

    for (final CMQueryRow row : result) {
      final CMCard grantCard = row.getCard(grantClass);
      final Long storedViewId =
          ((Integer) grantCard.get(PRIVILEGED_OBJECT_ID_ATTRIBUTE)).longValue();
      if (storedViewId.equals(privilegeInfo.getPrivilegedObjectId())) {
        updateGrantCard(grantCard, privilegeInfo);
        return;
      }
    }

    createViewGrantCard(privilegeInfo);
  }
Example #2
0
 private void createViewGrantCard(final PrivilegeInfo privilegeInfo) {
   final CMCardDefinition grantCardToBeCreated = view.createCardFor(grantClass);
   grantCardToBeCreated
       .set(GROUP_ID_ATTRIBUTE, privilegeInfo.getGroupId()) //
       .set(PRIVILEGED_OBJECT_ID_ATTRIBUTE, privilegeInfo.getPrivilegedObjectId()) //
       .set(MODE_ATTRIBUTE, privilegeInfo.getMode().getValue()) //
       .set(TYPE_ATTRIBUTE, PrivilegedObjectType.VIEW.getValue()) //
       .set(STATUS_ATTRIBUTE, CardStatus.ACTIVE.value()) //
       .save();
 }