private void removeValue(AjaxRequestTarget target) {
    ValueWrapper wrapper = model.getObject();
    ItemWrapper propertyWrapper = wrapper.getItem();

    List<ValueWrapper> values = propertyWrapper.getValues();
    Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);

    switch (wrapper.getStatus()) {
      case ADDED:
        values.remove(wrapper);
        break;
      case DELETED:
        error("Couldn't delete already deleted item: " + wrapper.toString());
        target.add(((PageBase) getPage()).getFeedbackPanel());
      case NOT_CHANGED:
        wrapper.setStatus(ValueStatus.DELETED);
        break;
    }

    int count = countUsableValues(propertyWrapper);
    if (count == 0 && !hasEmptyPlaceholder(propertyWrapper)) {
      if (inputPanel instanceof ValueChoosePanel) {
        values.add(
            new ValueWrapper(propertyWrapper, new PrismReferenceValue(null), ValueStatus.ADDED));
      } else {
        values.add(
            new ValueWrapper(propertyWrapper, new PrismPropertyValue(null), ValueStatus.ADDED));
      }
    }
    ListView parent = findParent(ListView.class);
    target.add(parent.getParent());
  }
  private boolean isAddButtonVisible() {
    ValueWrapper valueWrapper = model.getObject();

    if (valueWrapper.isReadonly()) {
      return false;
    }

    ItemWrapper propertyWrapper = valueWrapper.getItem();
    Item property = propertyWrapper.getItem();

    ItemDefinition definition = property.getDefinition();
    int max = definition.getMaxOccurs();
    List<ValueWrapper> usableValues = getUsableValues(propertyWrapper);
    if (usableValues.indexOf(valueWrapper) != usableValues.size() - 1) {
      return false;
    }

    if (max == -1) {
      return true;
    }

    if (countNonDeletedValues(propertyWrapper) >= max) {
      return false;
    }

    return isAccessible(definition, propertyWrapper.getContainer().getObject().getStatus());
  }
  private boolean isAddButtonVisible() {
    Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
    ValueWrapper valueWrapper = valueWrapperModel.getObject();

    if (valueWrapper.isReadonly()) {
      return false;
    }

    ItemWrapper propertyWrapper = valueWrapper.getItem();
    Item property = propertyWrapper.getItem();

    ItemDefinition definition = property.getDefinition();
    int max = definition.getMaxOccurs();
    List<ValueWrapper> usableValues = getUsableValues(propertyWrapper);
    if (usableValues.indexOf(valueWrapper) != usableValues.size() - 1) {
      return false;
    }

    if (max == -1) {
      return true;
    }

    if (countNonDeletedValues(propertyWrapper) >= max) {
      return false;
    }

    if (propertyWrapper.getContainer() == null) {
      return true; // TODO
    }
    return isAccessible(definition, getContainerStatus(propertyWrapper));
  }
  private boolean isRemoveButtonVisible() {
    ValueWrapper valueWrapper = valueWrapperModel.getObject();

    if (valueWrapper.isReadonly()) {
      return false;
    }
    Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
    if (inputPanel instanceof ValueChoosePanel
        || inputPanel instanceof AssociationValueChoicePanel) {
      return true;
    }

    ItemWrapper propertyWrapper = valueWrapper.getItem();
    ItemDefinition definition = propertyWrapper.getItem().getDefinition();
    int min = definition.getMinOccurs();

    int count = countNonDeletedValues(propertyWrapper);
    if (count <= 1 || count <= min) {
      return false;
    }

    if (propertyWrapper.getContainer() == null) {
      return true; // TODO
    }

    return isAccessible(definition, getContainerStatus(propertyWrapper));
  }
  private void addValue(AjaxRequestTarget target) {
    ValueWrapper wrapper = model.getObject();
    ItemWrapper propertyWrapper = wrapper.getItem();
    propertyWrapper.addValue();

    ListView parent = findParent(ListView.class);
    target.add(parent.getParent());
  }
  public boolean hasChanged() {
    for (ItemWrapper item : getItems()) {
      if (item.hasChanged()) {
        return true;
      }
    }

    return false;
  }
 public ItemWrapper findPropertyWrapper(QName name) {
   Validate.notNull(name, "QName must not be null.");
   for (ItemWrapper wrapper : getItems()) {
     if (name.equals(wrapper.getItem().getElementName())) {
       return wrapper;
     }
   }
   return null;
 }
 private void addValue(AjaxRequestTarget target) {
   Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
   ValueWrapper wrapper = valueWrapperModel.getObject();
   ItemWrapper propertyWrapper = wrapper.getItem();
   LOGGER.debug("Adding value of {}", propertyWrapper);
   propertyWrapper.addValue();
   ListView parent = findParent(ListView.class);
   target.add(parent.getParent());
 }
  private boolean hasEmptyPlaceholder(ItemWrapper property) {
    for (ValueWrapper value : property.getValues()) {
      value.normalize(property.getItemDefinition().getPrismContext());
      if (ValueStatus.ADDED.equals(value.getStatus()) && !value.hasValueChanged()) {
        return true;
      }
    }

    return false;
  }
 private int countNonDeletedValues(ItemWrapper property) {
   int count = 0;
   for (ValueWrapper value : property.getValues()) {
     value.normalize(property.getItemDefinition().getPrismContext());
     if (ValueStatus.DELETED.equals(value.getStatus())) {
       continue;
     }
     count++;
   }
   return count;
 }
  private List<ValueWrapper> getUsableValues(ItemWrapper property) {
    List<ValueWrapper> values = new ArrayList<>();
    for (ValueWrapper value : property.getValues()) {
      value.normalize(property.getItemDefinition().getPrismContext());
      if (ValueStatus.DELETED.equals(value.getStatus())) {
        continue;
      }
      values.add(value);
    }

    return values;
  }
 public void revive(PrismContext prismContext) throws SchemaException {
   if (container != null) {
     container.revive(prismContext);
   }
   if (containerDefinition != null) {
     containerDefinition.revive(prismContext);
   }
   if (properties != null) {
     for (ItemWrapper itemWrapper : properties) {
       itemWrapper.revive(prismContext);
     }
   }
 }
Exemple #13
0
 @Override
 public View getView(int position, View convView, ViewGroup viewGroup) {
   ItemWrapper wr;
   if (convView == null) {
     LayoutInflater inf = LayoutInflater.from(viewGroup.getContext());
     convView = inf.inflate(R.layout.accounts_list_item, null);
     wr = new ItemWrapper(convView);
     convView.setTag(wr);
   } else {
     wr = (ItemWrapper) convView.getTag();
   }
   wr.populateFrom(position);
   return convView;
 }
  boolean isItemVisible(ItemWrapper item) {
    ItemDefinition def = item.getItemDefinition();
    if (def.isIgnored() || def.isOperational()) {
      return false;
    }

    if (def instanceof PrismPropertyDefinition && skipProperty((PrismPropertyDefinition) def)) {
      return false;
    }

    // we decide not according to status of this container, but according to
    // the status of the whole object
    if (objectWrapper.getStatus() == ContainerStatus.ADDING) {
      return def.canAdd();
    }

    // otherwise, object.getStatus() is MODIFYING

    if (def.canModify()) {
      return showEmpty(item);
    } else {
      if (def.canRead()) {
        return showEmpty(item);
      }
      return false;
    }
  }
  private int countUsableValues(ItemWrapper property) {
    int count = 0;
    for (ValueWrapper value : property.getValues()) {
      value.normalize(property.getItemDefinition().getPrismContext());

      if (ValueStatus.DELETED.equals(value.getStatus())) {
        continue;
      }

      if (ValueStatus.ADDED.equals(value.getStatus()) && !value.hasValueChanged()) {
        continue;
      }

      count++;
    }
    return count;
  }
Exemple #16
0
  protected String as_item(List<FieldMetadata> fieldMetadata, ItemWrapper w) {
    StringBuilder sb = new StringBuilder();

    for (FieldMetadata fm : fieldMetadata) {
      if (fm.isValid()) {
        Field field = fm.getField();
        Annotation annotation = fm.getAnnotation();
        Renderer renderer = instatiateRenderer(fm);
        FieldError fieldError = errors != null ? errors.getFieldError(field.getName()) : null;
        fm.setError(fieldError);

        sb.append(w.beforeItem(fm));

        sb.append(w.beforeItemLabel(fm));
        sb.append(renderer.renderLabel(this, fm));
        sb.append(w.afterItemLabel(fm));

        sb.append(w.beforeItemField(fm));
        sb.append(renderer.renderField(this, fm));
        sb.append(w.afterItemField(fm));

        sb.append(w.afterItem(fm));
      }
    }

    return sb.toString();
  }
 private boolean showEmpty(ItemWrapper item) {
   ObjectWrapper objectWrapper = getObject();
   List<ValueWrapper> valueWrappers = item.getValues();
   boolean isEmpty;
   if (valueWrappers == null) {
     isEmpty = true;
   } else {
     isEmpty = valueWrappers.isEmpty();
   }
   if (!isEmpty && valueWrappers.size() == 1) {
     ValueWrapper value = valueWrappers.get(0);
     if (ValueStatus.ADDED.equals(value.getStatus())) {
       isEmpty = true;
     }
   }
   return objectWrapper.isShowEmpty() || !isEmpty;
 }
Exemple #18
0
  public ObjectDelta getObjectDelta() throws SchemaException {
    if (ContainerStatus.ADDING.equals(getStatus())) {
      return createAddingObjectDelta();
    }

    ObjectDelta delta =
        new ObjectDelta(object.getCompileTimeClass(), ChangeType.MODIFY, object.getPrismContext());
    delta.setOid(object.getOid());

    List<ContainerWrapper> containers = getContainers();
    // sort containers by path size
    Collections.sort(containers, new PathSizeComparator());

    for (ContainerWrapper containerWrapper : getContainers()) {
      // create ContainerDelta for association container
      // HACK HACK HACK create correct procession for association container data
      // according to its structure
      if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
        ContainerDelta<ShadowAssociationType> associationDelta =
            ContainerDelta.createDelta(
                ShadowType.F_ASSOCIATION, containerWrapper.getItemDefinition());
        List<AssociationWrapper> associationItemWrappers =
            (List<AssociationWrapper>) containerWrapper.getItems();
        for (AssociationWrapper associationItemWrapper : associationItemWrappers) {
          List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues();
          for (ValueWrapper assocValueWrapper : assocValueWrappers) {
            PrismContainerValue<ShadowAssociationType> assocValue =
                (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue();
            if (assocValueWrapper.getStatus() == ValueStatus.DELETED) {
              associationDelta.addValueToDelete(assocValue.clone());
            } else if (assocValueWrapper.getStatus().equals(ValueStatus.ADDED)) {
              associationDelta.addValueToAdd(assocValue.clone());
            }
          }
        }
        delta.addModification(associationDelta);
      } else {
        if (!containerWrapper.hasChanged()) {
          continue;
        }

        for (ItemWrapper itemWrapper : (List<ItemWrapper>) containerWrapper.getItems()) {
          if (!itemWrapper.hasChanged()) {
            continue;
          }
          ItemPath containerPath =
              containerWrapper.getPath() != null ? containerWrapper.getPath() : new ItemPath();
          if (itemWrapper instanceof PropertyWrapper) {
            ItemDelta pDelta = computePropertyDeltas((PropertyWrapper) itemWrapper, containerPath);
            if (!pDelta.isEmpty()) {
              delta.addModification(pDelta);
            }
          }

          if (itemWrapper instanceof ReferenceWrapper) {
            ReferenceDelta pDelta =
                computeReferenceDeltas((ReferenceWrapper) itemWrapper, containerPath);
            if (!pDelta.isEmpty()) {
              delta.addModification(pDelta);
            }
          }
        }
      }
    }
    // returning container to previous order
    Collections.sort(containers, new ItemWrapperComparator());

    // Make sure we have all the definitions
    if (object.getPrismContext() != null) {
      object.getPrismContext().adopt(delta);
    }
    return delta;
  }
Exemple #19
0
  private ObjectDelta createAddingObjectDelta() throws SchemaException {
    PrismObject object = this.object.clone();

    List<ContainerWrapper> containers = getContainers();
    // sort containers by path size
    Collections.sort(containers, new PathSizeComparator());

    for (ContainerWrapper containerWrapper : getContainers()) {

      if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
        PrismContainer associationContainer =
            object.findOrCreateContainer(ShadowType.F_ASSOCIATION);
        List<AssociationWrapper> associationItemWrappers =
            (List<AssociationWrapper>) containerWrapper.getItems();
        for (AssociationWrapper associationItemWrapper : associationItemWrappers) {
          List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues();
          for (ValueWrapper assocValueWrapper : assocValueWrappers) {
            PrismContainerValue<ShadowAssociationType> assocValue =
                (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue();
            associationContainer.add(assocValue.clone());
          }
        }
        continue;
      }

      if (!containerWrapper.hasChanged()) {
        continue;
      }

      PrismContainer container = containerWrapper.getItem();
      ItemPath path = containerWrapper.getPath();
      if (containerWrapper.getPath() != null) {
        container = container.clone();
        if (path.size() > 1) {
          ItemPath parentPath = path.allExceptLast();
          PrismContainer parent = object.findOrCreateContainer(parentPath);
          parent.add(container);
        } else {
          PrismContainer existing = object.findContainer(container.getElementName());
          if (existing == null) {
            object.add(container);
          } else {
            continue;
          }
        }
      } else {
        container = object;
      }

      for (ItemWrapper propertyWrapper : (List<ItemWrapper>) containerWrapper.getItems()) {
        if (!propertyWrapper.hasChanged()) {
          continue;
        }

        Item property = propertyWrapper.getItem().clone();
        if (container.findProperty(property.getElementName()) != null) {
          continue;
        }
        for (ValueWrapper valueWrapper : propertyWrapper.getValues()) {
          valueWrapper.normalize(object.getPrismContext());
          if (!valueWrapper.hasValueChanged()
              || ValueStatus.DELETED.equals(valueWrapper.getStatus())) {
            continue;
          }

          if (property.hasRealValue(valueWrapper.getValue())) {
            continue;
          }

          PrismValue cloned = clone(valueWrapper.getValue());
          if (cloned != null) {
            property.add(cloned);
          }
        }

        if (!property.isEmpty()) {
          container.add(property);
        }
      }
    }

    // cleanup empty containers
    cleanupEmptyContainers(object);

    ObjectDelta delta = ObjectDelta.createAddDelta(object);

    // returning container to previous order
    Collections.sort(containers, new ItemWrapperComparator());

    if (InternalsConfig.consistencyChecks) {
      delta.checkConsistence(true, true, true, ConsistencyCheckScope.THOROUGH);
    }

    return delta;
  }
Exemple #20
0
  private void addItemDelta(
      ItemWrapper itemWrapper,
      ItemDelta pDelta,
      ItemDefinition propertyDef,
      ItemPath containerPath) {
    for (ValueWrapper valueWrapper : itemWrapper.getValues()) {
      valueWrapper.normalize(propertyDef.getPrismContext());
      ValueStatus valueStatus = valueWrapper.getStatus();
      if (!valueWrapper.hasValueChanged()
          && (ValueStatus.NOT_CHANGED.equals(valueStatus)
              || ValueStatus.ADDED.equals(valueStatus))) {
        continue;
      }

      // TODO: need to check if the resource has defined
      // capabilities
      // todo this is bad hack because now we have not tri-state
      // checkbox
      if (SchemaConstants.PATH_ACTIVATION.equivalent(containerPath)) {

        if (object.asObjectable() instanceof ShadowType
            && (((ShadowType) object.asObjectable()).getActivation() == null
                || ((ShadowType) object.asObjectable()).getActivation().getAdministrativeStatus()
                    == null)) {

          if (!hasResourceCapability(
              ((ShadowType) object.asObjectable()).getResource(), ActivationCapabilityType.class)) {
            continue;
          }
        }
      }

      PrismValue newValCloned = clone(valueWrapper.getValue());
      PrismValue oldValCloned = clone(valueWrapper.getOldValue());
      switch (valueWrapper.getStatus()) {
        case ADDED:
          if (newValCloned != null) {
            if (SchemaConstants.PATH_PASSWORD.equivalent(containerPath)) {
              // password change will always look like
              // add,
              // therefore we push replace
              pDelta.setValuesToReplace(Arrays.asList(newValCloned));
            } else if (propertyDef.isSingleValue()) {
              // values for single-valued properties
              // should be pushed via replace
              // in order to prevent problems e.g. with
              // summarizing deltas for
              // unreachable resources
              pDelta.setValueToReplace(newValCloned);
            } else {
              pDelta.addValueToAdd(newValCloned);
            }
          }
          break;
        case DELETED:
          if (newValCloned != null) {
            pDelta.addValueToDelete(newValCloned);
          }
          if (oldValCloned != null) {
            pDelta.addValueToDelete(oldValCloned);
          }
          break;
        case NOT_CHANGED:
          // this is modify...
          if (propertyDef.isSingleValue()) {
            // newValCloned.isEmpty()
            if (newValCloned != null && !newValCloned.isEmpty()) {
              pDelta.setValuesToReplace(Arrays.asList(newValCloned));
            } else {
              if (oldValCloned != null) {
                pDelta.addValueToDelete(oldValCloned);
              }
            }
          } else {
            if (newValCloned != null && !newValCloned.isEmpty()) {
              pDelta.addValueToAdd(newValCloned);
            }
            if (oldValCloned != null) {
              pDelta.addValueToDelete(oldValCloned);
            }
          }
          break;
      }
    }
  }
Exemple #21
0
 private ContainerStatus getContainerStatus(ItemWrapper propertyWrapper) {
   final ObjectWrapper objectWrapper = propertyWrapper.getContainer().getObject();
   return objectWrapper != null ? objectWrapper.getStatus() : ContainerStatus.MODIFYING;
 }