Exemplo n.º 1
0
 /** Performs the mainteance. */
 public void run(String[] args) {
   CoralSession coralSession = sessionFactory.getRootSession();
   try {
     execute(coralSession, args);
   } finally {
     coralSession.close();
   }
 }
  public void execute(
      Context context,
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      CoralSession coralSession)
      throws ProcessingException {
    try {
      long groupId = parameters.getLong("group_id");
      RoleResource group = RoleResourceImpl.getRoleResource(coralSession, groupId);

      long[] roleIds = parameters.getLongs("role_id");
      Set<Role> roles = new HashSet<Role>();
      for (int i = 0; i < roleIds.length; i++) {
        roles.add(coralSession.getSecurity().getRole(roleIds[i]));
      }
      long[] selectedRoleIds = parameters.getLongs("selected_role_id");
      Set<Role> selectedRoles = new HashSet<Role>();
      for (int i = 0; i < selectedRoleIds.length; i++) {
        selectedRoles.add(coralSession.getSecurity().getRole(selectedRoleIds[i]));
      }
      RoleImplication[] roleImplications = group.getRole().getImplications();
      Set<Role> currentRoles = new HashSet<Role>();
      for (RoleImplication ri : roleImplications) {
        if (ri.getSuperRole().equals(group.getRole())) {
          currentRoles.add(ri.getSubRole());
        }
      }

      CoralSession rootCoralSession = sessionFactory.getRootSession();
      try {
        for (Role role : roles) {
          if (selectedRoles.contains(role)) {
            if (!currentRoles.contains(role)) {
              rootCoralSession.getSecurity().addSubRole(group.getRole(), role);
            }
          } else {
            if (currentRoles.contains(role)) {
              rootCoralSession.getSecurity().deleteSubRole(group.getRole(), role);
            }
          }
        }
      } finally {
        rootCoralSession.close();
      }
      templatingContext.put("result", "updated_successfully");
    } catch (Exception e) {
      templatingContext.put("result", "exception");
      templatingContext.put("trace", new StackTrace(e));
    }
  }
Exemplo n.º 3
0
 public UpdateFeeds(
     Logger logger,
     CoralSessionFactory sessionFactory,
     HttpFeedService httpFeedService,
     SiteService siteService) {
   this.log = logger;
   this.sessionFactory = sessionFactory;
   this.siteService = siteService;
   this.httpFeedService = httpFeedService;
   CoralSession coralSession = sessionFactory.getRootSession();
   try {
     httpFeedResourceClass =
         coralSession.getSchema().getResourceClass(HttpFeedResource.CLASS_NAME);
   } catch (EntityDoesNotExistException e) {
     throw new ComponentInitializationError(
         "Could not find '" + HttpFeedResource.CLASS_NAME + "' resource class");
   } finally {
     coralSession.close();
   }
 }
Exemplo n.º 4
0
 @Override
 public void tearDown() throws Exception {
   coral.close();
   super.tearDown();
 }