public SDMSGroup create(SystemEnvironment env, String p_name, Long p_deleteVersion)
      throws SDMSException {
    Long p_creatorUId = env.cEnv.uid();
    Long p_createTs = env.txTime();
    Long p_changerUId = env.cEnv.uid();
    Long p_changeTs = env.txTime();

    if (env.tx.mode == SDMSTransaction.READONLY) {

      throw new FatalException(new SDMSMessage(env, "01110182049", "Group"));
    }
    validate(env, p_name, p_deleteVersion, p_creatorUId, p_createTs, p_changerUId, p_changeTs);

    env.tx.beginSubTransaction(env);
    SDMSGroupGeneric o =
        new SDMSGroupGeneric(
            env, p_name, p_deleteVersion, p_creatorUId, p_createTs, p_changerUId, p_changeTs);

    SDMSGroup p;
    try {
      env.tx.addToChangeSet(env, o.versions, true);
      env.tx.addToTouchSet(env, o.versions, true);
      table.put(env, o.id, o.versions);
      env.tx.commitSubTransaction(env);
      p = (SDMSGroup) (o.toProxy());
      p.current = true;
    } catch (SDMSException e) {
      p = (SDMSGroup) (o.toProxy());
      p.current = true;
      env.tx.rollbackSubTransaction(env);
      throw e;
    }

    if (!checkCreatePrivs(env, p))
      throw new AccessViolationException(p.accessViolationMessage(env, "01402270738"));

    return p;
  }
 public static SDMSGroup getObject(SystemEnvironment env, Long id, long version)
     throws SDMSException {
   return (SDMSGroup) table.get(env, id, version);
 }
Esempio n. 3
0
  public void go(SystemEnvironment sysEnv) throws SDMSException {
    final DateTime dt = new DateTime(new Date());
    boolean secondsIgnore = false;
    boolean duplicateFilterIgnore = false;
    boolean ignoreUpperRange = false;
    String warning = null;

    final SDMSInterval ival = (SDMSInterval) obj.resolve(sysEnv);
    ivalId = obj.objId;

    if (with.containsKey(ParseStr.S_BASE)) {
      final WithHash baseIntervalWith = (WithHash) with.get(ParseStr.S_BASE);
      if (baseIntervalWith == null) {
        ival.setBaseInterval(sysEnv, null);
        ival.setBaseIntervalMultiplier(sysEnv, null);
      } else {
        final Integer baseInterval = (Integer) baseIntervalWith.get(ParseStr.S_INTERVAL);
        final Integer baseIntervalMultiplier = IntervalUtil.getMultiplier(sysEnv, baseIntervalWith);

        ival.setBaseInterval(sysEnv, baseInterval);
        ival.setBaseIntervalMultiplier(sysEnv, baseIntervalMultiplier);
      }
    }

    if (with.containsKey(ParseStr.S_DURATION)) {
      final WithHash durationWith = (WithHash) with.get(ParseStr.S_DURATION);
      if (durationWith == null) {
        ival.setDuration(sysEnv, null);
        ival.setDurationMultiplier(sysEnv, null);
      } else {
        final Integer duration = (Integer) durationWith.get(ParseStr.S_INTERVAL);
        final Integer durationMultiplier = IntervalUtil.getMultiplier(sysEnv, durationWith);

        ival.setDuration(sysEnv, duration);
        ival.setDurationMultiplier(sysEnv, durationMultiplier);
      }
    }

    if (with.containsKey(ParseStr.S_SYNCTIME)) {
      if (IntervalUtil.getDateTime(sysEnv, dt, with, ParseStr.S_SYNCTIME)) secondsIgnore = true;
      dt.fixToMinDate();
      dt.suppressSeconds();
      ival.setSyncTime(sysEnv, dt.toLong());
    }

    if (with.containsKey(ParseStr.S_STARTTIME)) {
      if (with.get(ParseStr.S_STARTTIME) == null) {
        ival.setStartTime(sysEnv, null);
      } else {
        if (IntervalUtil.getDateTime(sysEnv, dt, with, ParseStr.S_STARTTIME)) secondsIgnore = true;
        dt.fixToMinDate();
        dt.suppressSeconds();
        ival.setStartTime(sysEnv, dt.toLong());
      }
    }

    if (with.containsKey(ParseStr.S_ENDTIME)) {
      if (with.get(ParseStr.S_ENDTIME) == null) {
        ival.setEndTime(sysEnv, null);
      } else {
        if (IntervalUtil.getDateTime(sysEnv, dt, with, ParseStr.S_ENDTIME)) secondsIgnore = true;
        dt.fixToMaxDate();
        dt.suppressSeconds();
        ival.setEndTime(sysEnv, dt.toLong());
      }
    }

    final Long startTime = ival.getStartTime(sysEnv);
    final Long endTime = ival.getEndTime(sysEnv);
    if ((startTime != null) && (endTime != null)) {
      final TimerDate startDate = new TimerDate(new DateTime(startTime, false).toDate());
      final TimerDate endDate = new TimerDate(new DateTime(endTime, false).toDate());

      if (endDate.eq(startDate))
        throw new CommonErrorException(
            new SDMSMessage(
                sysEnv,
                "04210011321",
                ParseStr.S_STARTTIME + " and " + ParseStr.S_ENDTIME + " must be different"));
    }

    if (with.containsKey(ParseStr.S_EMBEDDED)) {
      final String embeddedName = (String) with.get(ParseStr.S_EMBEDDED);
      if (embeddedName == null) ival.setEmbeddedIntervalId(sysEnv, null);
      else {
        final SDMSInterval embeddedIval =
            SDMSIntervalTable.idx_name_getUnique(
                sysEnv, IntervalUtil.mapIdName(embeddedName, obj.seId));
        final Long embeddedIvalId = embeddedIval.getId(sysEnv);

        ival.setEmbeddedIntervalId(sysEnv, embeddedIvalId);
      }
    }

    if ((ival.getEmbeddedIntervalId(sysEnv) != null) && (ival.getDuration(sysEnv) != null))
      throw new CommonErrorException(
          new SDMSMessage(
              sysEnv,
              "04311251855",
              "intervals with " + ParseStr.S_EMBEDDED + " cannot have " + ParseStr.S_DURATION));

    if (with.containsKey(ParseStr.S_DELAY)) {
      warning = "DELAY not longer supported";
    }

    if (with.containsKey(ParseStr.S_INVERSE)) {
      final Boolean isInverse = (Boolean) with.get(ParseStr.S_INVERSE);
      ival.setIsInverse(sysEnv, isInverse);
    }

    if (with.containsKey(ParseStr.S_MERGE)) {
      warning = "MERGE not longer supported";
    }

    if (with.containsKey(ParseStr.S_SELECTION)) {
      IntervalUtil.killSelections(sysEnv, ivalId);
      switch (IntervalUtil.createSelections(sysEnv, ivalId, with)) {
        case IntervalUtil.IGNORED_SECONDS:
          secondsIgnore = true;
          break;
        case IntervalUtil.IGNORED_UPPER_RANGE:
          ignoreUpperRange = true;
      }
    }

    if (with.containsKey(ParseStr.S_FILTER)) {
      IntervalUtil.killFilter(sysEnv, ivalId);
      duplicateFilterIgnore = IntervalUtil.createFilter(sysEnv, ivalId, obj.seSpec, with);
    }

    ival.setSeId(sysEnv, obj.seId);

    checkSet = new HashSet();
    checkStructure(sysEnv, ivalId);

    SystemEnvironment.timer.notifyChange(sysEnv, ival, TimerThread.ALTER);

    if (with.containsKey(ParseStr.S_GROUP)) {
      final String gName = (String) with.get(ParseStr.S_GROUP);
      final Long gId =
          SDMSGroupTable.idx_name_deleteVersion_getUnique(sysEnv, new SDMSKey(gName, new Long(0)))
              .getId(sysEnv);
      ChownChecker.check(sysEnv, gId);
      ival.setOwnerId(sysEnv, gId);
    }

    if (duplicateFilterIgnore)
      result.setFeedback(
          new SDMSMessage(
              sysEnv,
              "04209270127",
              "Interval created (WARNING: duplicate " + ParseStr.S_FILTER + " will be ignored)"));
    else if (secondsIgnore)
      result.setFeedback(
          new SDMSMessage(
              sysEnv, "04209201344", "Interval altered (WARNING: seconds will be ignored)"));
    else if (ignoreUpperRange)
      result.setFeedback(
          new SDMSMessage(
              sysEnv, "04209270144", "Interval created (WARNING: upper range(s) will be ignored)"));
    else
      result.setFeedback(
          new SDMSMessage(
              sysEnv, "04207241731", "Interval altered" + (warning == null ? "" : ". " + warning)));
  }
Esempio n. 4
0
  public void go(SystemEnvironment sysEnv) throws SDMSException {
    try {
      obj.resolve(sysEnv);
    } catch (final NotFoundException nfe) {

    }
    final Long seId = obj.seId;

    final Vector mappedPath = new Vector(obj.path);
    final String mappedName = (String) mappedPath.remove(mappedPath.size() - 1);

    final SDMSSchedule parent = SDMSScheduleTable.getSchedule(sysEnv, mappedPath);
    final Long parentId = parent.getId(sysEnv);

    if (SDMSScheduleTable.idx_parentId_name.containsKey(
        sysEnv, new SDMSKey(parentId, mappedName))) {
      if (replace) {
        final AlterSchedule as = new AlterSchedule(obj, with, Boolean.FALSE);
        as.setEnv(env);
        as.go(sysEnv);
        result = as.result;
        return;
      }

      throw new DuplicateKeyException(
          new SDMSMessage(
              sysEnv,
              "04207251651",
              "Object with name $1 already exists within $2",
              mappedName,
              SDMSScheduleTable.getObject(sysEnv, parentId).pathString(sysEnv)));
    }

    final Long ivalId;
    final String intervalName = (String) with.get(ParseStr.S_INTERVAL);
    if (intervalName == null) ivalId = null;
    else {
      final SDMSInterval ival =
          SDMSIntervalTable.idx_name_getUnique(sysEnv, IntervalUtil.mapIdName(intervalName, seId));
      ivalId = ival.getId(sysEnv);
    }

    final Long uId = env.uid();
    final SDMSUser u = SDMSUserTable.getObject(sysEnv, uId);
    final Long gId;
    if (!with.containsKey(ParseStr.S_GROUP)) {
      gId = u.getDefaultGId(sysEnv);
    } else {
      final String gName = (String) with.get(ParseStr.S_GROUP);
      gId =
          SDMSGroupTable.idx_name_deleteVersion_getUnique(sysEnv, new SDMSKey(gName, new Long(0)))
              .getId(sysEnv);
      if (!SDMSMemberTable.idx_gId_uId.containsKey(sysEnv, new SDMSKey(gId, uId))
          && !SDMSMemberTable.idx_gId_uId.containsKey(
              sysEnv, new SDMSKey(SDMSObject.adminGId, uId))) {
        throw new CommonErrorException(
            new SDMSMessage(
                sysEnv,
                "03401151027",
                "User $1 does not belong to Group $2",
                u.getName(sysEnv),
                gName));
      }
    }

    Long inheritPrivs;
    if (with.containsKey(ParseStr.S_INHERIT)) {
      inheritPrivs = (Long) with.get(ParseStr.S_INHERIT);
      if (inheritPrivs == null) inheritPrivs = new Long(0);
    } else inheritPrivs = null;

    long lpriv = (inheritPrivs == null ? parent.getPrivilegeMask() : inheritPrivs.longValue());
    if ((parent.getPrivilegeMask() & lpriv) != lpriv) {
      throw new CommonErrorException(new SDMSMessage(sysEnv, "03202061327", "Incompatible grant"));
    }

    inheritPrivs = new Long(lpriv);

    if (!with.containsKey(ParseStr.S_ACTIVE)) active = Boolean.TRUE;
    else active = (Boolean) with.get(ParseStr.S_ACTIVE);

    String tz;
    String warning = "";
    if (with.containsKey(ParseStr.S_TIME)) {
      tz = (String) with.get(ParseStr.S_TIME);
      TimeZone tmp = TimeZone.getTimeZone(tz);
      if (!tz.equals(tmp.getID())) {
        throw new CommonErrorException(
            new SDMSMessage(sysEnv, "03207031503", "Time Zone " + tz + " unknown"));
      }
    } else {
      TimeZone tmp = TimeZone.getDefault();
      tz = tmp.getID();
    }

    SDMSScheduleTable.table.create(
        sysEnv, mappedName, gId, ivalId, parentId, tz, seId, active, inheritPrivs);

    result.setFeedback(new SDMSMessage(sysEnv, "04207251652", "Schedule created"));
  }
Esempio n. 5
0
  public void go(SystemEnvironment sysEnv) throws SDMSException {
    Long sgId = null;
    Long ZERO = new Long(0);

    if (!sysEnv.cEnv.gid().contains(SDMSObject.adminGId)) {
      SDMSPrivilege p = new SDMSPrivilege();
      Vector v = SDMSMemberTable.idx_uId.getVector(sysEnv, sysEnv.cEnv.uid());
      for (int i = 0; i < v.size(); i++) {
        SDMSMember m = (SDMSMember) v.get(i);
        try {
          SDMSGrant gr =
              SDMSGrantTable.idx_objectId_gId_getUnique(
                  sysEnv, new SDMSKey(ZERO, m.getGId(sysEnv)));
          p.addPriv(sysEnv, gr.getPrivs(sysEnv).longValue());
        } catch (NotFoundException nfe) {

        }
      }
      try {
        if (sysEnv.selectGroup != null) {
          SDMSGroup sg = SDMSGroupTable.idx_name_getUnique(sysEnv, sysEnv.selectGroup);
          sgId = sg.getId(sysEnv);
        }
      } catch (NotFoundException nfe) {

      }
      if (!(p.can(SDMSPrivilege.MANAGE_SEL) || (sgId != null && sysEnv.cEnv.gid().contains(sgId))))
        throw new AccessViolationException(
            new SDMSMessage(sysEnv, "03003081235", "Insufficient Privileges"));
    }

    int read = 0;
    SDMSOutputContainer d_container = null;

    if (cl_size > 0) {
      clist = new int[cl_size];
      ctype = new int[cl_size];
    }

    try {
      Statement stmt = sysEnv.dbConnection.createStatement();
      ResultSet rset = stmt.executeQuery(selectCmd);
      ResultSetMetaData mdset = rset.getMetaData();
      Vector desc = collist(mdset);
      d_container = new SDMSOutputContainer(sysEnv, "Selected Values", desc);
      while (rset.next()) {
        Vector data = new Vector();
        int j = 0;
        for (int i = 1; i <= desc.size(); i++) {
          Object o = rset.getObject(i);
          if (cl_size > 0 && j < cl_size && i == clist[j]) {
            o = convert(sysEnv, o, j);
            j++;
          }
          data.addElement((rset.wasNull() ? null : o));
        }
        d_container.addData(sysEnv, data);
        read++;
      }
      stmt.close();
      sysEnv.dbConnection.commit();
    } catch (SQLException sqle) {

      try {

        sysEnv.dbConnection.rollback();
      } catch (SQLException sqle2) {

        throw new RecoverableException(new SDMSMessage(sysEnv, "03310281524", "Connection lost"));
      }

      throw new CommonErrorException(
          new SDMSMessage(sysEnv, "03204170024", "SQL Error : $1", sqle.toString()));
    }

    if (sv != null && sv.size() > 0) {
      int sca[] = new int[sv.size()];
      for (int i = 0; i < sv.size(); i++) {
        sca[i] = ((Integer) sv.get(i)).intValue();
        if (sca[i] >= d_container.columns)
          throw new CommonErrorException(
              new SDMSMessage(
                  sysEnv,
                  "03003081227",
                  "The sort column specified ($1) exceeds the number of columns in the output",
                  new Integer(sca[i])));
      }
      Collections.sort(d_container.dataset, d_container.getComparator(sysEnv, sca));
    }

    result.setOutputContainer(d_container);
    result.setFeedback(
        new SDMSMessage(sysEnv, "03204112153", "$1 Row(s) selected", new Integer(read)));
  }