Ejemplo n.º 1
0
  /**
   * Re-enable a property. This field will appear again in object instances.
   *
   * @param name the name of the property to enable
   * @since 2.4M2
   */
  public void enableField(String name) {
    PropertyClass pclass = (PropertyClass) safeget(name);

    if (pclass != null) {
      pclass.setDisabled(false);
    }

    setDirty(true);
  }
Ejemplo n.º 2
0
 public void flushCache() {
   Object[] props = getPropertyNames();
   for (int i = 0; i < props.length; i++) {
     String propname = (String) props[i];
     PropertyClass propclass = (PropertyClass) get(propname);
     if (propclass != null) {
       propclass.flushCache();
     }
   }
 }
Ejemplo n.º 3
0
  public BaseCollection fromValueMap(Map<String, ?> map, BaseCollection object) {
    for (PropertyClass property : (Collection<PropertyClass>) getFieldList()) {
      String name = property.getName();
      Object formvalue = map.get(name);
      if (formvalue != null) {
        BaseProperty objprop;
        objprop = property.fromValue(formvalue);
        if (objprop != null) {
          objprop.setObject(object);
          object.safeput(name, objprop);
        }
      }
    }

    return object;
  }
Ejemplo n.º 4
0
  public boolean validateObject(BaseObject obj, XWikiContext context) throws XWikiException {
    boolean isValid = true;
    Object[] props = getPropertyNames();
    for (int i = 0; i < props.length; i++) {
      String propname = (String) props[i];
      BaseProperty property = (BaseProperty) obj.get(propname);
      PropertyClass propclass = (PropertyClass) get(propname);
      isValid &= propclass.validateProperty(property, context);
    }

    String validSript = getValidationScript();
    if ((validSript != null) && (!validSript.trim().equals(""))) {
      isValid &= executeValidationScript(obj, validSript, context);
    }

    return isValid;
  }
Ejemplo n.º 5
0
  @Override
  public List<ObjectDiff> getDiff(Object oldObject, XWikiContext context) {
    ArrayList<ObjectDiff> difflist = new ArrayList<ObjectDiff>();
    BaseClass oldClass = (BaseClass) oldObject;
    for (PropertyClass newProperty : (Collection<PropertyClass>) getFieldList()) {
      String propertyName = newProperty.getName();
      PropertyClass oldProperty = (PropertyClass) oldClass.get(propertyName);
      String propertyType = newProperty.getClassType();

      if (oldProperty == null) {
        difflist.add(
            new ObjectDiff(
                getXClassReference(),
                getNumber(),
                "",
                ObjectDiff.ACTION_PROPERTYADDED,
                propertyName,
                propertyType,
                "",
                ""));
      } else if (!oldProperty.equals(newProperty)) {
        difflist.add(
            new ObjectDiff(
                getXClassReference(),
                getNumber(),
                "",
                ObjectDiff.ACTION_PROPERTYCHANGED,
                propertyName,
                propertyType,
                "",
                ""));
      }
    }

    for (PropertyClass oldProperty : (Collection<PropertyClass>) oldClass.getFieldList()) {
      String propertyName = oldProperty.getName();
      PropertyClass newProperty = (PropertyClass) get(propertyName);
      String propertyType = oldProperty.getClassType();

      if (newProperty == null) {
        difflist.add(
            new ObjectDiff(
                getXClassReference(),
                getNumber(),
                "",
                ObjectDiff.ACTION_PROPERTYREMOVED,
                propertyName,
                propertyType,
                "",
                ""));
      }
    }

    return difflist;
  }
Ejemplo n.º 6
0
  /**
   * Get the list of disabled property definitions that exist in this class. The resulting list is
   * unmodifiable, but the contained elements are live.
   *
   * @return an unmodifiable list containing the disabled properties of the class
   * @see PropertyClass#isDisabled()
   * @since 2.4M2
   */
  public List<PropertyClass> getDisabledProperties() {
    @SuppressWarnings("unchecked")
    Collection<PropertyClass> allProperties = getFieldList();
    if (allProperties == null) {
      return Collections.emptyList();
    }

    List<PropertyClass> disabledProperties = new ArrayList<PropertyClass>();

    for (PropertyClass property : allProperties) {
      if (property != null && property.isDisabled()) {
        disabledProperties.add(property);
      }
    }

    Collections.sort(disabledProperties);
    return Collections.unmodifiableList(disabledProperties);
  }
Ejemplo n.º 7
0
  public Element toXML() {
    Element cel = new DOMElement("class");

    Element el = new DOMElement("name");
    el.addText((getName() == null) ? "" : getName());
    cel.add(el);

    el = new DOMElement("customClass");
    el.addText((getCustomClass() == null) ? "" : getCustomClass());
    cel.add(el);

    el = new DOMElement("customMapping");
    el.addText((getCustomMapping() == null) ? "" : getCustomMapping());
    cel.add(el);

    el = new DOMElement("defaultViewSheet");
    el.addText((getDefaultViewSheet() == null) ? "" : getDefaultViewSheet());
    cel.add(el);

    el = new DOMElement("defaultEditSheet");
    el.addText((getDefaultEditSheet() == null) ? "" : getDefaultEditSheet());
    cel.add(el);

    el = new DOMElement("defaultWeb");
    el.addText((getDefaultWeb() == null) ? "" : getDefaultWeb());
    cel.add(el);

    el = new DOMElement("nameField");
    el.addText((getNameField() == null) ? "" : getNameField());
    cel.add(el);

    el = new DOMElement("validationScript");
    el.addText((getValidationScript() == null) ? "" : getValidationScript());
    cel.add(el);

    // Iterate over values sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator it = getSortedIterator();
    while (it.hasNext()) {
      PropertyClass bprop = (PropertyClass) it.next();
      cel.add(bprop.toXML());
    }
    return cel;
  }
Ejemplo n.º 8
0
  public BaseCollection fromMap(Map<String, ?> map, BaseCollection object) {
    for (PropertyClass property : (Collection<PropertyClass>) getFieldList()) {
      String name = property.getName();
      Object formvalues = map.get(name);
      if (formvalues != null) {
        BaseProperty objprop;
        if (formvalues instanceof String[]) {
          objprop = property.fromStringArray(((String[]) formvalues));
        } else {
          objprop = property.fromString(formvalues.toString());
        }

        if (objprop != null) {
          objprop.setObject(object);
          object.safeput(name, objprop);
        }
      }
    }

    return object;
  }
Ejemplo n.º 9
0
  /**
   * Get the list of disabled properties that exist in a given object. This list is a subset of all
   * the disabled properties in a class, since the object could have been created and stored before
   * some of the class properties were added. The resulting list is unmodifiable, but the contained
   * elements are live.
   *
   * @param object the instance of this class where the disabled properties must exist
   * @return an unmodifiable list containing the disabled properties of the given object
   * @see PropertyClass#isDisabled()
   * @since 2.4M2
   */
  public List<PropertyClass> getDisabledObjectProperties(BaseObject object) {
    List<PropertyClass> disabledProperties = getDisabledProperties();
    if (disabledProperties == null) {
      return Collections.emptyList();
    }

    List<PropertyClass> disabledObjectProperties =
        new ArrayList<PropertyClass>(disabledProperties.size());

    for (PropertyClass property : disabledProperties) {
      try {
        if (object.get(property.getName()) != null) {
          disabledObjectProperties.add(property);
        }
      } catch (XWikiException ex) {
        // Not really gonna happen
      }
    }

    return Collections.unmodifiableList(disabledObjectProperties);
  }
Ejemplo n.º 10
0
  public void fromXML(Element cel) throws XWikiException {
    try {
      int j = 1;
      setName(cel.element("name").getText());
      Element cclel = cel.element("customClass");
      if (cclel != null) {
        setCustomClass(cclel.getText());
        j++;
      }
      Element cmapel = cel.element("customMapping");
      if (cmapel != null) {
        setCustomMapping(cmapel.getText());
        j++;
      }
      Element cdvsel = cel.element("defaultViewSheet");
      if (cdvsel != null) {
        setDefaultViewSheet(cdvsel.getText());
        j++;
      }
      Element cdesel = cel.element("defaultEditSheet");
      if (cdesel != null) {
        setDefaultViewSheet(cdesel.getText());
        j++;
      }
      Element cdwel = cel.element("defaultWeb");
      if (cdwel != null) {
        setDefaultWeb(cdwel.getText());
        j++;
      }
      Element cnfel = cel.element("nameField");
      if (cnfel != null) {
        setNameField(cnfel.getText());
        j++;
      }

      Element valel = cel.element("validationScript");
      if (valel != null) {
        setValidationScript(valel.getText());
        j++;
      }

      @SuppressWarnings("unchecked")
      List<Element> list = cel.elements();
      for (int i = j; i < list.size(); i++) {
        Element pcel = list.get(i);
        String name = pcel.getName();
        String classType = pcel.element("classType").getText();
        PropertyClassProvider provider = null;
        try {
          // First try to use the specified class type as hint.
          provider = Utils.getComponent(PropertyClassProvider.class, classType);
        } catch (Exception e) {
          // In previous versions the class type was the full Java class name of the property class
          // implementation. Extract the hint by removing the Java package prefix and the Class
          // suffix.
          classType =
              StringUtils.removeEnd(StringUtils.substringAfterLast(classType, "."), "Class");
          provider = Utils.getComponent(PropertyClassProvider.class, classType);
        }
        // We should use PropertyClassInterface (instead of PropertyClass, its default
        // implementation) but it
        // doesn't have the fromXML method and adding it breaks the backwards compatibility. We make
        // the
        // assumption that all property classes extend PropertyClass.
        PropertyClass property = (PropertyClass) provider.getInstance();
        property.setName(name);
        property.setObject(this);
        property.fromXML(pcel);
        safeput(name, property);
      }
    } catch (Exception e) {
      throw new XWikiException(
          XWikiException.MODULE_XWIKI_CLASSES,
          XWikiException.ERROR_XWIKI_CLASSES_PROPERTY_CLASS_INSTANCIATION,
          "Error instanciating property class",
          e,
          null);
    }
  }
Ejemplo n.º 11
0
  @Override
  public void merge(
      ElementInterface previousElement,
      ElementInterface newElement,
      MergeConfiguration configuration,
      XWikiContext context,
      MergeResult mergeResult) {
    BaseClass previousClass = (BaseClass) previousElement;
    BaseClass newClass = (BaseClass) newElement;

    setCustomClass(
        MergeUtils.mergeCharacters(
            previousClass.getCustomClass(),
            newClass.getCustomClass(),
            getCustomClass(),
            mergeResult));

    setCustomMapping(
        MergeUtils.mergeCharacters(
            previousClass.getCustomMapping(),
            newClass.getCustomMapping(),
            getCustomMapping(),
            mergeResult));

    setDefaultWeb(
        MergeUtils.mergeCharacters(
            previousClass.getDefaultWeb(), newClass.getDefaultWeb(), getDefaultWeb(), mergeResult));

    setDefaultViewSheet(
        MergeUtils.mergeCharacters(
            previousClass.getDefaultViewSheet(),
            newClass.getDefaultViewSheet(),
            getDefaultViewSheet(),
            mergeResult));

    setDefaultEditSheet(
        MergeUtils.mergeCharacters(
            previousClass.getDefaultEditSheet(),
            newClass.getDefaultEditSheet(),
            getDefaultEditSheet(),
            mergeResult));

    setNameField(
        MergeUtils.mergeCharacters(
            previousClass.getNameField(), newClass.getNameField(), getNameField(), mergeResult));

    // Properties

    List<ObjectDiff> classDiff = newClass.getDiff(previousClass, context);
    for (ObjectDiff diff : classDiff) {
      PropertyClass propertyResult = (PropertyClass) getField(diff.getPropName());
      PropertyClass previousProperty = (PropertyClass) previousClass.getField(diff.getPropName());
      PropertyClass newProperty = (PropertyClass) newClass.getField(diff.getPropName());

      if (diff.getAction() == ObjectDiff.ACTION_PROPERTYADDED) {
        if (propertyResult == null) {
          // Add if none has been added by user already
          addField(
              diff.getPropName(),
              configuration.isProvidedVersionsModifiables()
                  ? newClass.getField(diff.getPropName())
                  : newClass.getField(diff.getPropName()).clone());
          mergeResult.setModified(true);
        } else if (!propertyResult.equals(newProperty)) {
          // XXX: collision between DB and new: property to add but already exists in the DB
          mergeResult
              .getLog()
              .error("Collision found on class property [{}]", newProperty.getReference());
        }
      } else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYREMOVED) {
        if (propertyResult != null) {
          if (propertyResult.equals(previousProperty)) {
            // Delete if it's the same as previous one
            removeField(diff.getPropName());
            mergeResult.setModified(true);
          } else {
            // XXX: collision between DB and new: property to remove but not the same as previous
            // version
            mergeResult
                .getLog()
                .error("Collision found on class property [{}]", previousProperty.getReference());
          }
        } else {
          // Already removed from DB, lets assume the user is prescient
          mergeResult
              .getLog()
              .warn("Object property [{}] already removed", previousProperty.getReference());
        }
      } else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYCHANGED) {
        if (propertyResult != null) {
          if (propertyResult.equals(previousProperty)) {
            // Let some automatic migration take care of that modification between DB and new
            addField(diff.getPropName(), newClass.getField(diff.getPropName()));
            mergeResult.setModified(true);
          } else if (!propertyResult.equals(newProperty)) {
            propertyResult.merge(
                previousProperty, newProperty, configuration, context, mergeResult);
          }
        } else {
          // XXX: collision between DB and new: property to modify but does not exists in DB
          // Lets assume it's a mistake to fix
          mergeResult
              .getLog()
              .warn("Collision found on class property [{}]", newProperty.getReference());

          addField(diff.getPropName(), newClass.getField(diff.getPropName()));
          mergeResult.setModified(true);
        }
      }
    }
  }
Ejemplo n.º 12
0
  public void populateData() throws Exception {
    int groupSize = 1;
    // m_mlsEngine.getPropertyFieldGroups().Length;
    MLSCmaFields mlsCmaFields = m_engine.getCmaFields();
    String caption = "";
    String displayName = "";
    String typeID = "2";
    String displayRule = "";
    int[] resultFiled = getResultFields();
    for (int x = 0; x < resultFiled.length; x++) {
      CmaField cmaField = mlsCmaFields.getStdField(resultFiled[x]);
      if (cmaField != null) {
        if (resultFiled[x] != Tcs.Mls.TCSStandardResultFields.STDF_DEFTYPE_NODEFNAME)
          caption = cmaField.getCaption();
        else caption = "DEF type";
        displayName = cmaField.getDisplayName();
        if (StringSupport.isNullOrEmpty(displayName)) {
          displayName = Tcs.Mls.TCSStandardResultFields.getXmlName(resultFiled[x]);
          if (resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFLASTMOD) {
            displayName = "Last Modified Date Time";
          }
        }

        if (StringSupport.isNullOrEmpty(displayName)) displayName = StringSupport.Trim(caption);

        typeID = String.valueOf(cmaField.type);
        displayRule = cmaField.getDisplayRule();
        if (StringSupport.isNullOrEmpty(displayRule)) {
          displayRule = Tcs.Mls.TCSStandardResultFields.getDisplayRule(resultFiled[x]);
          if (resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFLASTMOD
              || resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFSTATUSDATE)
            displayRule = "5";
        }

        if (StringSupport.isNullOrEmpty(displayRule)) displayRule = "4";

      } else {
        displayName = Tcs.Mls.TCSStandardResultFields.getXmlName(resultFiled[x]);
        typeID =
            String.valueOf(
                PropertyClass.getDataTypeID(
                    Tcs.Mls.TCSStandardResultFields.getDataType(resultFiled[x])));
        displayRule = Tcs.Mls.TCSStandardResultFields.getDisplayRule(resultFiled[x]);
        if (resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFLASTMOD) {
          displayRule = "5";
          displayName = "Last Modified Date Time";
        }

        if (resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFSTATUSDATE) {
          displayRule = "5";
        }
      }
      if (resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFLASTMOD) {
        typeID = "7";
      }

      if (resultFiled[x] == Tcs.Mls.TCSStandardResultFields.STDF_STDFSTATUSDATE) {
        typeID = "3";
      }

      DataAggResultFieldType resultFieldType = new DataAggResultFieldType();
      resultFieldType.setSystemName(Tcs.Mls.TCSStandardResultFields.getXmlName(resultFiled[x]));
      resultFieldType.setReferenceName(resultFieldType.getSystemName().toUpperCase());
      resultFieldType.setDisplayName(displayName);
      resultFieldType.setDataTypeID(typeID);
      resultFieldType.setDataTypeDescription(
          PropertyClass.getDataTypeDescription(Integer.valueOf(typeID)));
      // if (x != TCSStandardResultFields.STDF_CMAFEATURE && x !=
      // TCSStandardResultFields.STDF_STDFROOMDIM)
      resultFieldType.setIsStandard("1");
      // else
      //    resultFieldType.IsStandard = "0";
      // resultFieldType.VisibleFlag = caption.Length == 0 ? "N" : "Y";
      resultFieldType.setDisplayRule(displayRule);
      resultFieldType.setRetsLongName(((cmaField != null) ? cmaField.retsLongName : ""));
      addToResultTable(resultFieldType);
    }
  }