@Override
 public void removeCapability(CapabilityVO capabilityToRemove) throws CapabilityManagerException {
   try {
     userSecurityProfileManager.removeAllAssignedUserCapability(capabilityToRemove);
     capabilityDAO.delete(capabilityToRemove.getId());
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
 }
  @Override
  public void updateCapability(CapabilityVO capabilityToUpdate) throws CapabilityManagerException {
    try {
      Capability capability = SecurityEntityValueObjectConverter.toCapability(capabilityToUpdate);
      Capability existingCapability = capabilityDAO.findData(capability.getId());
      final Collection<CapabilityAction> updatedActions = capability.getActions();
      final Collection<CapabilityAction> currentActions = existingCapability.getActions();
      existingCapability.setActions(
          CollectionsUtility.updateCollection(
              updatedActions,
              currentActions,
              new CollectionItemDeleteStrategy<CapabilityAction>() {
                @Override
                public void delete(CapabilityAction objectTodelete)
                    throws CollectionMergeException {
                  try {
                    capabilityActionDAO.delete(objectTodelete.getId());
                  } catch (Exception ex) {
                    throw new CollectionMergeException(ex);
                  }
                }
              },
              new CollectionItemUpdateStrategy<CapabilityAction>() {
                @Override
                public void update(CapabilityAction itemToUpdate, CapabilityAction itemToCopy)
                    throws CollectionMergeException {
                  itemToUpdate.setAction(itemToCopy.getAction());
                  itemToUpdate.setCapability(itemToCopy.getCapability());
                }
              }));

      // update fields
      existingCapability.setDescription(capability.getDescription());
      existingCapability.setTitle(capability.getTitle());
      existingCapability.setResource(capability.getResource());
      existingCapability.setApplication(capability.getApplication());

      validate(existingCapability);
      capabilityDAO.update(existingCapability);
    } catch (Exception e) {
      throw new CapabilityManagerException(e);
    }
  }
 @Override
 public CapabilityVO findCapabilityWithId(Long id) throws CapabilityManagerException {
   CapabilityVO foundCapabilityVO = null;
   try {
     Capability capability = capabilityDAO.findData(id);
     foundCapabilityVO = SecurityEntityValueObjectConverter.toCapabilityVO(capability);
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
   return foundCapabilityVO;
 }
 @Override
 public void addActionsToCapability(List<ActionVO> actions, CapabilityVO capabilityVO)
     throws CapabilityManagerException {
   try {
     Capability capability = capabilityDAO.findData(capabilityVO.getId());
     List<CapabilityAction> actionsToAdd = new ArrayList<CapabilityAction>();
     Action action;
     CapabilityAction capabilityAction;
     for (ActionVO actionVO : actions) {
       action = SecurityEntityValueObjectConverter.toAction(actionVO);
       capabilityAction = new CapabilityAction();
       capabilityAction.setAction(action);
       capabilityAction.setCapability(capability);
       actionsToAdd.add(capabilityAction);
     }
     capability.getActions().addAll(actionsToAdd);
     capabilityDAO.update(capability);
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
 }
 @Override
 public List<CapabilityVO> findAllCapabilities() throws CapabilityManagerException {
   List<Capability> allCapability = capabilityDAO.findAllData();
   List<CapabilityVO> allCapabilityVO = new ArrayList<CapabilityVO>(allCapability.size());
   try {
     for (Capability capabilty : allCapability) {
       allCapabilityVO.add(SecurityEntityValueObjectConverter.toCapabilityVO(capabilty));
     }
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
   return allCapabilityVO;
 }
 private List<Capability> findCapabilityEntitiesWithResourceName(String resourceName)
     throws CapabilityManagerException {
   List<Capability> capabilities = null;
   try {
     Map<String, Object> parameters = new HashMap<String, Object>();
     parameters.put(Capability.QUERY_PARAM_RESOURCE_NAME, resourceName);
     capabilities =
         capabilityDAO.findAllDataUsingNamedQuery(
             Capability.NAMED_QUERY_FIND_BY_RESOURCE_NAME, parameters);
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
   return capabilities;
 }
 @Override
 public CapabilityVO createNewCapability(CapabilityVO capabilityToCreate)
     throws CapabilityManagerException {
   CapabilityVO createdCapabilityVO = null;
   try {
     Capability capability = SecurityEntityValueObjectConverter.toCapability(capabilityToCreate);
     validate(capability);
     capabilityDAO.create(capability);
     createdCapabilityVO = SecurityEntityValueObjectConverter.toCapabilityVO(capability);
     LOG.log(Level.FINE, "capability {0} created", createdCapabilityVO);
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
   return createdCapabilityVO;
 }
 @Override
 public CapabilityVO findCapabilityWithTitle(String capabilityTitle)
     throws CapabilityManagerException, NonExistentEntityException {
   CapabilityVO foundCapabilityVO = null;
   try {
     Map<String, Object> parameter = new HashMap<String, Object>();
     parameter.put(Capability.QUERY_PARAM_TITLE, capabilityTitle);
     Capability capability =
         capabilityDAO.findUniqueDataUsingNamedQuery(
             Capability.NAMED_QUERY_FIND_BY_TITLE, parameter);
     foundCapabilityVO = SecurityEntityValueObjectConverter.toCapabilityVO(capability);
   } catch (NonExistentEntityException e) {
     throw e;
   } catch (Exception e) {
     throw new CapabilityManagerException(e);
   }
   return foundCapabilityVO;
 }