Ejemplo n.º 1
0
 String toUnsetCmd(String actionName) {
   StringBuffer cmd = new StringBuffer();
   cmd.append(CXT7090Constants.CXT7090MCMD_CMD_ATOMMODE + "\n");
   for (String p : mVars) { // this case is for call unset command by user directly
     cmd.append("unset " + this.getFName() + " " + p + "\n");
   }
   DObjectAction actObject =
       mOType.getAction("set"); // we use set action metadata for unset action
   for (Entry<String, String> pair : mTmpParams.entrySet()) {
     String attrName = pair.getKey();
     DObjectAttribute attrObj = actObject.getAttribute(attrName);
     String map2Rule = attrObj.getMap2rule();
     if (!CommonUtils.isNullOrSpace(map2Rule)
         && map2Rule.equals(CXT7090Constants.ATTR_MAP2RULE_1)) { // dynamic attribute
       cmd.append("unset " + this.getFName() + " " + pair.getValue().trim() + "\n");
     } else {
       cmd.append("unset " + this.getFName() + " " + attrName + "\n");
     }
   }
   cmd.append(CXT7090Constants.CXT7090MCMD_CMD_EXIT + "\n");
   return cmd.toString();
 }
Ejemplo n.º 2
0
  protected String parseCreateAndSetParams(
      String actionName,
      String[] params,
      Vector<String> err,
      TreeMap<String, DAttrGroupInst> attrGrps) {
    DObjectAction actObj = mOType.getAction(actionName);
    //		String nodeName = null;
    boolean init;
    if (this.isCreateAction(actionName))
      init = initParametersForCreate(actionName, params, err, attrGrps);
    else init = initParametersForSet(params, err);
    if (!init) return null;

    Set set = mTmpParams.entrySet();
    Iterator i = set.iterator();
    Vector<String> v = new Vector<String>();

    while (i.hasNext()) {

      Map.Entry<String, String> en = (Map.Entry<String, String>) i.next();
      String name = en.getKey();
      String oldName = name;
      if (this.isCreateAction(actionName) && ((name.equals("name"))))
        continue; // has been processed, remove id
      String value = en.getValue();
      String oldValue = value;
      value = this.removeSlashAndDoubleQuotes(value);
      DObjectAttribute attrObj = actObj.getAttribute(name);
      String stateful = attrObj.getStateful();
      if (!CommonUtils.isNullOrSpace(stateful) && CommonUtils.isConfirmed(stateful)) {
        mParams.put(name, value);
      }
      String map2rule = attrObj.getMap2rule();
      if (!CommonUtils.isNullOrSpace(map2rule)
          && !CXT7090Constants.ATTR_MAP2RULE_0.equals(map2rule)) { // 0 is default rule
        if (map2rule.equals(CXT7090Constants.ATTR_MAP2RULE_1)) {
          v.add(name);
        } else {
          err.add(0, "Invalid map2rule " + map2rule + " in action " + actionName + " " + getID());
          return null;
        }
      }
      String map2 = attrObj.getMap2();
      if (!CommonUtils.isNullOrSpace(map2)) {
        name = map2;
      }
      String attrgrpName = attrObj.getAttrGrp();
      if (!CommonUtils.isNullOrSpace(attrgrpName)) {
        if (name.startsWith(attrgrpName + "-")) {
          name = name.substring(attrgrpName.length() + 1); // substract group_name_
        }
        DObjectAttributeGrp ag = actObj.getAttributeGroup(attrgrpName);
        if (ag != null) {
          String agMap2 = ag.getMap2();
          if (!CommonUtils.isNullOrSpace(agMap2)) attrgrpName = agMap2;
        } else {
          if (CommonUtils.isNumber(
              attrgrpName)) { // in default, number attrgrp will be mapped to "[[]]"
            attrgrpName = "['" + attrgrpName + "']";
          }
        }
      } else {
        attrgrpName = "self";
      }
      String key = null;
      if (attrObj.isObjectName()) {
        String objName = value;
        DBaseObject obj = (DBaseObject) manager.getObject(objName);
        if (obj != null) {
          key = attrObj.getVReferto();
          if (!CommonUtils.isNullOrSpace(key)) {
            value = key.equals("lname") ? obj.getLName() : obj.getAttributeValue(key);
            if (value == null) {
              err.add(
                  0,
                  "Invalid vreferto value "
                      + key
                      + " ("
                      + obj.getID()
                      + ") of attribute "
                      + oldName
                      + " in action "
                      + actionName
                      + " "
                      + getID());
              return null;
            }
          } else {
            value = obj.getRName();
          }
        } else {
          //					err.add(0,"Invalid value " + value + " of attribute " + oldName + " in action " +
          //					actionName + " " + getID());
          //					return null;
          // Based on review, if no object is found, the string as the value
        }
      }
      key = attrObj.getVClosedby();
      if (!CommonUtils.isNullOrSpace(key)) {
        if (key.equals(CXT7090Constants.VCLOSEDBY_S)) {
          value = "'" + value + "'";
        }
      }
      this.addParameterToAttrGrp(attrgrpName, name, value, attrGrps);
    }

    if (v.size() > 0) { // exist dynamic attribute
      String name = null;
      String value = null;
      TreeMap<String, DParameterInst> checkedList = new TreeMap<String, DParameterInst>();
      for (int m = 0; m < v.size(); m++) {
        int Iam = -1;
        String findStr = null;
        name = v.elementAt(m);
        DObjectAttribute attrObj = actObj.getAttribute(name);
        String attrgrpName = attrObj.getAttrGrp();
        if (CommonUtils.isNullOrSpace(attrgrpName)) attrgrpName = "self";
        String attrName = attrObj.getAAttrName();
        String attrValue = attrObj.getAValueName();
        if (CommonUtils.isNullOrSpace(attrName) && CommonUtils.isNullOrSpace(attrValue)) {
          err.add(
              0,
              "Invalid map2rule metadata define of attribute "
                  + name
                  + " in action "
                  + actionName
                  + " "
                  + getID());
          return null;
        } else {
          if (!CommonUtils.isNullOrSpace(attrName)) {
            Iam = DParameterInst.I_AM_ATTR_VALUE;
            findStr = attrName;
          } else {
            Iam = DParameterInst.I_AM_ATTR_NAME;
            findStr = attrValue;
          }
        }
        DParameterInst p1 = checkedList.remove(name + "#" + attrgrpName);
        if (p1 != null) {
          DParameterInst p = removeParameterFromAttrGrp(attrgrpName, name, attrGrps);
          int Iam1 = p1.getIam();
          if (Iam1 == DParameterInst.I_AM_ATTR_NAME && Iam == DParameterInst.I_AM_ATTR_VALUE)
            addParameterToAttrGrp(attrgrpName, p1.mValue, p.mValue, attrGrps);
          else if (Iam == DParameterInst.I_AM_ATTR_NAME && Iam1 == DParameterInst.I_AM_ATTR_VALUE) {
            addParameterToAttrGrp(attrgrpName, p.mValue, p1.mValue, attrGrps);
          } else {
            err.add(
                0,
                "Invalid map2rule define for attribute1 "
                    + name
                    + " and attribute2  "
                    + p1.mName
                    + " in action "
                    + actionName
                    + " "
                    + getID());
            return null;
          }
        } else {
          p1 = removeParameterFromAttrGrp(attrgrpName, name, attrGrps);
          p1.setIam(Iam);
          checkedList.put(findStr + "#" + attrgrpName, p1);
        }
      }

      if (checkedList.size() != 0) {
        err.add(0, "Some map2rule attributes were not set in action " + actionName + " " + getID());
        return null;
      }
    }
    return "OK";
  }