Esempio n. 1
0
  private void checkStructure(final SystemEnvironment sysEnv, final Long checkId)
      throws SDMSException {
    if (checkSet.contains(checkId)) return;
    checkSet.add(checkId);

    final SDMSInterval checkIval = SDMSIntervalTable.getObject(sysEnv, checkId);
    final Long embeddedIntervalId = checkIval.getEmbeddedIntervalId(sysEnv);

    if (embeddedIntervalId != null) {
      if (embeddedIntervalId.equals(ivalId))
        throw new CommonErrorException(
            new SDMSMessage(sysEnv, "04209121544", "cyclic references not allowed"));

      checkStructure(sysEnv, embeddedIntervalId);
    }

    final Vector ihList = SDMSIntervalHierarchyTable.idx_parentId.getVector(sysEnv, checkId);
    final Iterator ihIt = ihList.iterator();
    while (ihIt.hasNext()) {
      final SDMSIntervalHierarchy ih = (SDMSIntervalHierarchy) ihIt.next();
      final Long childId = ih.getChildId(sysEnv);

      if (childId.equals(ivalId))
        throw new CommonErrorException(
            new SDMSMessage(sysEnv, "04209121547", "cyclic references not allowed"));

      checkStructure(sysEnv, childId);
    }
  }
Esempio n. 2
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"));
  }