Beispiel #1
0
 public String getFeatures(String locationId) {
   Location location = LocationDAO.getInstance().get(Long.valueOf(locationId));
   if (location == null) return "";
   String features = "";
   for (GlobalRoomFeature feature : location.getGlobalRoomFeatures()) {
     if (!features.isEmpty()) features += ", ";
     features +=
         "<span title='"
             + feature.getLabel()
             + "' style='white-space:nowrap;'>"
             + feature.getLabelWithType()
             + "</span>";
   }
   for (DepartmentRoomFeature feature : location.getDepartmentRoomFeatures()) {
     if (!features.isEmpty()) features += ", ";
     features +=
         "<span title='"
             + feature.getLabel()
             + "' style='white-space:nowrap;'>"
             + feature.getLabelWithType()
             + "</span>";
   }
   return features;
 }
  protected RoomFeature createOrUpdateFeature(
      FeatureInterface feature,
      List<Long> add,
      List<Long> drop,
      Long sessionId,
      org.hibernate.Session hibSession,
      SessionContext context,
      boolean future) {
    Department d =
        feature.isDepartmental()
            ? lookuDepartment(hibSession, feature.getDepartment(), future, sessionId)
            : null;
    if (feature.isDepartmental() && d == null) return null;

    RoomFeature rf =
        (feature.getId() == null ? null : lookupFeature(hibSession, feature, future, sessionId));

    if (rf == null) {
      if (!future && feature.getId() != null)
        throw new GwtRpcException(MESSAGES.errorRoomFeatureDoesNotExist(feature.getId()));
      if (d == null) {
        context.checkPermission(Right.GlobalRoomFeatureAdd);
        rf = new GlobalRoomFeature();
        ((GlobalRoomFeature) rf).setSession(SessionDAO.getInstance().get(sessionId));
      } else {
        context.checkPermission(d, Right.DepartmentRoomFeatureAdd);
        rf = new DepartmentRoomFeature();
        ((DepartmentRoomFeature) rf).setDepartment(d);
      }
      rf.setRooms(new HashSet<Location>());
    } else {
      if (rf instanceof GlobalRoomFeature) {
        context.checkPermission(rf, Right.GlobalRoomFeatureEdit);
      } else {
        context.checkPermission(rf, Right.DepartmenalRoomFeatureEdit);
        ((DepartmentRoomFeature) rf).setDepartment(d);
      }
    }

    for (Iterator i = RoomFeature.getAllGlobalRoomFeatures(sessionId).iterator(); i.hasNext(); ) {
      RoomFeature x = (RoomFeature) i.next();
      if ((x.getLabel().equalsIgnoreCase(feature.getLabel())
              || x.getAbbv().equalsIgnoreCase(feature.getAbbreviation()))
          && !x.getUniqueId().equals(rf.getUniqueId()))
        throw new GwtRpcException(
            MESSAGES.errorRoomFeatureAlreadyExists(
                feature.getLabel(), SessionDAO.getInstance().get(sessionId).getLabel()));
    }

    if (rf instanceof DepartmentRoomFeature) {
      for (Iterator i = RoomFeature.getAllDepartmentRoomFeatures(d).iterator(); i.hasNext(); ) {
        RoomFeature x = (RoomFeature) i.next();
        if ((x.getLabel().equalsIgnoreCase(feature.getLabel())
                || x.getAbbv().equalsIgnoreCase(feature.getAbbreviation()))
            && !x.getUniqueId().equals(rf.getUniqueId()))
          throw new GwtRpcException(
              MESSAGES.errorRoomFeatureAlreadyExists(
                  feature.getLabel(), d.getSession().getLabel()));
      }
    }

    rf.setAbbv(feature.getAbbreviation());
    rf.setLabel(feature.getLabel());
    rf.setFeatureType(
        feature.getType() == null
            ? null
            : RoomFeatureTypeDAO.getInstance().get(feature.getType().getId(), hibSession));

    hibSession.saveOrUpdate(rf);

    if (add != null && !add.isEmpty())
      for (Location location : lookupLocations(hibSession, add, future, sessionId)) {
        rf.getRooms().add(location);
        location.getFeatures().add(rf);
        hibSession.saveOrUpdate(location);
      }

    if (drop != null && !drop.isEmpty())
      for (Location location : lookupLocations(hibSession, drop, future, sessionId)) {
        rf.getRooms().remove(location);
        location.getFeatures().remove(rf);
        hibSession.saveOrUpdate(location);
      }

    hibSession.saveOrUpdate(rf);

    ChangeLog.addChange(
        hibSession,
        context,
        rf,
        ChangeLog.Source.ROOM_FEATURE_EDIT,
        (feature.getId() == null ? ChangeLog.Operation.CREATE : ChangeLog.Operation.UPDATE),
        null,
        rf instanceof DepartmentRoomFeature ? ((DepartmentRoomFeature) rf).getDepartment() : null);

    return rf;
  }