public void deleteCategory(String id, String componentId) {
    Connection con = initCon();
    try {
      // First delete all resources of category
      List<ResourceDetail> resources = getResourcesByCategory(id);
      ResourceDetail resource;
      for (int r = 0; r < resources.size(); r++) {
        resource = resources.get(r);

        ResourcesManagerDAO.deleteResource(con, resource.getId());
        deleteIndex("Resource", resource.getId(), componentId);
      }

      // Then delete category itself
      ResourcesManagerDAO.deleteCategory(con, id);
      deleteIndex(id, "Category", componentId);
    } catch (Exception e) {
      throw new ResourcesManagerRuntimeException(
          "ResourcesManagerBmEJB.deleteCategory()",
          SilverpeasRuntimeException.ERROR,
          "resourcesManager.EX_DELETE_CATEGORY",
          e);
    } finally {
      fermerCon(con);
    }
  }
 public List<ReservationDetail> getReservations(String instanceId) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getReservations(con, instanceId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getReservations()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_RESERVATIONS",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public List<CategoryDetail> getCategories(String instanceId) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getCategories(con, instanceId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getCategories()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_CATEGORIES",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public List<String> getManagers(int resourceId) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getManagers(con, resourceId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getManagers()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_MANAGERS",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public void removeManager(int resourceId, int managerId) {
   Connection con = initCon();
   try {
     ResourcesManagerDAO.removeManager(con, resourceId, managerId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.removeManager()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_REMOVE_MANAGER",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public List<ResourceDetail> getResourcesByCategory(String categoryId) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getResourcesByCategory(con, categoryId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getResourcesByCategory()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_RESOURCES_BY_CATEGORY",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public void updateReservation(ReservationDetail reservationCourante) {
   Connection con = initCon();
   try {
     ResourcesManagerDAO.updateReservation(con, reservationCourante);
     createIndex(reservationCourante);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.updateReservation()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_UPDATE_RESERVATION",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public List<ResourceReservableDetail> getResourcesReservable(
     String instanceId, Date startDate, Date endDate) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getResourcesReservable(con, instanceId, startDate, endDate);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getResourcesReservable()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_RESOURCES_RESERVABLE",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public void deleteResource(String id, String componentId) {
   Connection con = initCon();
   try {
     ResourcesManagerDAO.deleteResource(con, id);
     deleteIndex(id, "Resource", componentId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.deleteResource()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_DELETE_RESOURCE",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public void updateCategory(CategoryDetail category) {
   Connection con = initCon();
   try {
     ResourcesManagerDAO.updateCategory(con, category);
     createIndex_Category(category);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.updateCategory()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_UPDATE_CATEGORY",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public ResourceDetail getResource(String id) {
   Connection con = initCon();
   try {
     ResourceDetail resource = ResourcesManagerDAO.getResource(con, id);
     return resource;
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getResource()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_RESOURCE",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public String getStatusResourceOfReservation(String resourceId, String reservationId) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getStatusResourceOfReservation(
         con, Integer.parseInt(resourceId), Integer.parseInt(reservationId));
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getMonthReservationOfCategory()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_MONTHLY_RESERVATIONS",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public void updateResourceStatus(
     String status, int resourceId, int reservationId, String componentId) {
   Connection con = initCon();
   try {
     ResourcesManagerDAO.updateResourceStatus(con, status, resourceId, reservationId, componentId);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.updateResourceStatus()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_UPDATE_RESOURCE",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public List<ReservationDetail> getMonthReservation(
     String instanceId, Date monthDate, String userId, String language) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.getMonthReservation(con, instanceId, monthDate, userId, language);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.getMonthReservation()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_GET_MONTHLY_RESERVATIONS",
         e);
   } finally {
     fermerCon(con);
   }
 }
 public List<ResourceDetail> verificationReservation(
     String instanceId, String listeReservation, Date startDate, Date endDate) {
   Connection con = initCon();
   try {
     return ResourcesManagerDAO.verificationReservation(
         con, instanceId, listeReservation, startDate, endDate);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.verificationReservation()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_CHECK_RESERVATIONS",
         e);
   } finally {
     fermerCon(con);
   }
 }
  /** * Gestion des catégories ** */
  public void createCategory(CategoryDetail category) {
    Connection con = initCon();
    try {
      int id = ResourcesManagerDAO.createCategory(con, category);

      category.setId(Integer.toString(id));
      createIndex_Category(category);
    } catch (Exception e) {
      throw new ResourcesManagerRuntimeException(
          "ResourcesManagerBmEJB.createCategory()",
          SilverpeasRuntimeException.ERROR,
          "resourcesManager.EX_CREATE_CATEGORY",
          e);
    } finally {
      fermerCon(con);
    }
  }
 /** * Gestion des réservations * */
 public void saveReservation(ReservationDetail reservation, String listReservationCurrent) {
   Connection con = initCon();
   try {
     String idReservation =
         ResourcesManagerDAO.saveReservation(con, reservation, listReservationCurrent);
     reservation.setId(idReservation);
     createIndex(reservation);
   } catch (Exception e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.saveReservation()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_SAVE_RESERVATION",
         e);
   } finally {
     fermerCon(con);
   }
 }
  public void deleteReservation(String id, String componentId) {
    Connection con = initCon();
    try {
      deleteIndex(id, "Reservation", componentId);

      // delete attached file
      AttachmentController.deleteAttachmentByCustomerPK(new ForeignPK(id, componentId));

      ResourcesManagerDAO.deleteReservation(con, id);
    } catch (Exception e) {
      throw new ResourcesManagerRuntimeException(
          "ResourcesManagerBmEJB.deleteReservation()",
          SilverpeasRuntimeException.ERROR,
          "resourcesManager.EX_DELETE_RESERVATION",
          e);
    } finally {
      fermerCon(con);
    }
  }
  /** ** Gestion des ressources ** */
  public String createResource(ResourceDetail resource) {
    Connection con = initCon();
    try {
      String id = ResourcesManagerDAO.createResource(con, resource);

      resource.setId(id);
      createIndex_Resource(resource);

      return id;
    } catch (Exception e) {
      throw new ResourcesManagerRuntimeException(
          "ResourcesManagerBmEJB.createResource()",
          SilverpeasRuntimeException.ERROR,
          "resourcesManager.EX_CREATE_RESOURCE",
          e);
    } finally {
      fermerCon(con);
    }
  }
 public void addManagers(int resourceId, List<String> managers) {
   Connection con = initCon();
   try {
     ResourcesManagerDAO.removeAllManagers(con, resourceId);
     Iterator<String> it = managers.iterator();
     while (it.hasNext()) {
       String manager = it.next();
       String managerId = manager.split("/")[0];
       addManager(resourceId, Integer.parseInt(managerId));
     }
   } catch (SQLException e) {
     throw new ResourcesManagerRuntimeException(
         "ResourcesManagerBmEJB.addManagers()",
         SilverpeasRuntimeException.ERROR,
         "resourcesManager.EX_ADD_MANAGER",
         e);
   } finally {
     fermerCon(con);
   }
 }