private ContainerWrapper(
      ObjectWrapper objectWrapper,
      T container,
      ContainerStatus status,
      ItemPath path,
      boolean createProperties,
      PageBase pageBase) {
    Validate.notNull(container, "container must not be null.");
    Validate.notNull(status, "Container status must not be null.");
    Validate.notNull(pageBase, "pageBase must not be null.");

    this.objectWrapper = objectWrapper;
    this.container = container;
    this.status = status;
    this.path = path;
    main = path == null;
    readonly = objectWrapper.isReadonly(); // [pm] this is quite questionable
    showInheritedObjectAttributes = objectWrapper.isShowInheritedObjectAttributes();
    // have to be after setting "main" property
    containerDefinition = getItemDefinition();
    if (createProperties) {
      // HACK HACK HACK, the container wrapper should not parse itself. This code should not be
      // here.
      // Constructor should NOT parse the object
      // the createProperties parameter is here to avoid looping when parsing associations
      properties = createProperties(pageBase);
    } else {
      properties = new ArrayList<>();
    }
  }
 @Override
 public PrismContainerDefinition getItemDefinition() {
   if (main) {
     return objectWrapper.getDefinition();
   } else {
     return objectWrapper.getDefinition().findContainerDefinition(path);
   }
 }
  private ObjectWrapper loadUserWrapper(PrismObject<UserType> userToEdit) {
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    PrismObject<UserType> user = null;
    try {

      Collection options =
          SelectorOptions.createCollection(
              UserType.F_CREDENTIALS, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
      Task task = createSimpleTask(OPERATION_LOAD_USER);
      user =
          getModelService()
              .getObject(
                  UserType.class, SecurityUtils.getPrincipalUser().getOid(), options, task, result);

      result.recordSuccess();
    } catch (Exception ex) {
      result.recordFatalError("Couldn't get user.", ex);
      LoggingUtils.logException(LOGGER, "Couldn't load user PageMyQuestions", ex);
    }

    if (!result.isSuccess()) {
      showResultInSession(result);
    }

    if (user == null) {

      throw new RestartResponseException(PageDashboard.class);
    }

    ContainerStatus status = ContainerStatus.MODIFYING;
    ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
    ObjectWrapper wrapper;
    try {
      wrapper = owf.createObjectWrapper("pageMyPasswordQuestions.userDetails", null, user, status);
    } catch (Exception ex) {
      result.recordFatalError("Couldn't get user.", ex);
      LoggingUtils.logException(LOGGER, "Couldn't load user", ex);
      wrapper =
          owf.createObjectWrapper(
              "pageMyPasswordQuestions.userDetails", null, user, null, null, status, false);
    }
    //        ObjectWrapper wrapper = new ObjectWrapper("pageUser.userDetails", null, user, status);
    if (owf.getResult() != null && !WebMiscUtil.isSuccessOrHandledError(wrapper.getResult())) {
      showResultInSession(wrapper.getResult());
    }

    return wrapper;
  }
  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 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;
 }
  private List<ItemWrapper> createProperties(PageBase pageBase) {
    result = new OperationResult(CREATE_PROPERTIES);

    List<ItemWrapper> properties = new ArrayList<ItemWrapper>();

    PrismContainerDefinition definition = null;
    PrismObject parent = getObject().getObject();
    Class clazz = parent.getCompileTimeClass();
    if (ShadowType.class.isAssignableFrom(clazz)) {
      QName name = containerDefinition.getName();

      if (ShadowType.F_ATTRIBUTES.equals(name)) {
        try {
          definition = objectWrapper.getRefinedAttributeDefinition();

          if (definition == null) {
            PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
            PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

            definition =
                pageBase
                    .getModelInteractionService()
                    .getEditObjectClassDefinition(
                        (PrismObject<ShadowType>) objectWrapper.getObject(),
                        resource,
                        AuthorizationPhaseType.REQUEST)
                    .toResourceAttributeContainerDefinition();

            if (LOGGER.isTraceEnabled()) {
              LOGGER.trace("Refined account def:\n{}", definition.debugDump());
            }
          }
        } catch (Exception ex) {
          LoggingUtils.logException(
              LOGGER, "Couldn't load definitions from refined schema for shadow", ex);
          result.recordFatalError(
              "Couldn't load definitions from refined schema for shadow, reason: "
                  + ex.getMessage(),
              ex);

          return properties;
        }
      } else {
        definition = containerDefinition;
      }
    } else if (ResourceType.class.isAssignableFrom(clazz)) {
      if (containerDefinition != null) {
        definition = containerDefinition;
      } else {
        definition = container.getDefinition();
      }
    } else {
      definition = containerDefinition;
    }

    if (definition == null) {
      LOGGER.error(
          "Couldn't get property list from null definition {}",
          new Object[] {container.getElementName()});
      return properties;
    }

    // assignments are treated in a special way -- we display names of
    // org.units and roles
    // (but only if ObjectWrapper.isShowAssignments() is true; otherwise
    // they are filtered out by ObjectWrapper)
    if (container.getCompileTimeClass() != null
        && AssignmentType.class.isAssignableFrom(container.getCompileTimeClass())) {

      for (Object o : container.getValues()) {
        PrismContainerValue<AssignmentType> pcv = (PrismContainerValue<AssignmentType>) o;

        AssignmentType assignmentType = pcv.asContainerable();

        if (assignmentType.getTargetRef() == null) {
          continue;
        }

        // hack... we want to create a definition for Name
        // PrismPropertyDefinition def = ((PrismContainerValue)
        // pcv.getContainer().getParent()).getContainer().findProperty(ObjectType.F_NAME).getDefinition();
        PrismPropertyDefinition def =
            new PrismPropertyDefinition(
                ObjectType.F_NAME, DOMUtil.XSD_STRING, pcv.getPrismContext());

        if (OrgType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) {
          def.setDisplayName("Org.Unit");
          def.setDisplayOrder(100);
        } else if (RoleType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) {
          def.setDisplayName("Role");
          def.setDisplayOrder(200);
        } else {
          continue;
        }

        PrismProperty<Object> temp = def.instantiate();

        String value = formatAssignmentBrief(assignmentType);

        temp.setValue(new PrismPropertyValue<Object>(value));
        // TODO: do this.isReadOnly() - is that OK? (originally it was the default behavior for all
        // cases)
        properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED));
      }

    } else if (isShadowAssociation()) {
      PrismContext prismContext = objectWrapper.getObject().getPrismContext();
      Map<QName, PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>();
      if (objectWrapper.getAssociations() != null) {
        for (PrismContainerValue<ShadowAssociationType> cval : objectWrapper.getAssociations()) {
          ShadowAssociationType associationType = cval.asContainerable();
          QName assocName = associationType.getName();
          PrismContainer<ShadowAssociationType> fractionalContainer = assocMap.get(assocName);
          if (fractionalContainer == null) {
            fractionalContainer =
                new PrismContainer<>(
                    ShadowType.F_ASSOCIATION, ShadowAssociationType.class, cval.getPrismContext());
            fractionalContainer.setDefinition(cval.getParent().getDefinition());
            // HACK: set the name of the association as the element name so wrapper.getName() will
            // return correct data.
            fractionalContainer.setElementName(assocName);
            assocMap.put(assocName, fractionalContainer);
          }
          try {
            fractionalContainer.add(cval.clone());
          } catch (SchemaException e) {
            // Should not happen
            throw new SystemException("Unexpected error: " + e.getMessage(), e);
          }
        }
      }

      PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
      PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

      // HACK. The revive should not be here. Revive is no good. The next use of the resource will
      // cause parsing of resource schema. We need some centralized place to maintain live cached
      // copies
      // of resources.
      try {
        resource.revive(prismContext);
      } catch (SchemaException e) {
        throw new SystemException(e.getMessage(), e);
      }
      RefinedResourceSchema refinedSchema;
      CompositeRefinedObjectClassDefinition rOcDef;
      try {
        refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
        rOcDef = refinedSchema.determineCompositeObjectClassDefinition(parent);
      } catch (SchemaException e) {
        throw new SystemException(e.getMessage(), e);
      }
      // Make sure even empty associations have their wrappers so they can be displayed and edited
      for (RefinedAssociationDefinition assocDef : rOcDef.getAssociations()) {
        QName name = assocDef.getName();
        if (!assocMap.containsKey(name)) {
          PrismContainer<ShadowAssociationType> fractionalContainer =
              new PrismContainer<>(
                  ShadowType.F_ASSOCIATION, ShadowAssociationType.class, prismContext);
          fractionalContainer.setDefinition(getItemDefinition());
          // HACK: set the name of the association as the element name so wrapper.getName() will
          // return correct data.
          fractionalContainer.setElementName(name);
          assocMap.put(name, fractionalContainer);
        }
      }

      for (Entry<QName, PrismContainer<ShadowAssociationType>> assocEntry : assocMap.entrySet()) {
        // HACK HACK HACK, the container wrapper should not parse itself. This code should not be
        // here.
        AssociationWrapper assocWrapper =
            new AssociationWrapper(
                this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED);
        properties.add(assocWrapper);
      }

    } else { // if not an assignment

      if ((container.getValues().size() == 1 || container.getValues().isEmpty())
          && (containerDefinition == null || containerDefinition.isSingleValue())) {

        // there's no point in showing properties for non-single-valued
        // parent containers,
        // so we continue only if the parent is single-valued

        Collection<ItemDefinition> propertyDefinitions = definition.getDefinitions();
        for (ItemDefinition itemDef : propertyDefinitions) {
          if (itemDef instanceof PrismPropertyDefinition) {

            PrismPropertyDefinition def = (PrismPropertyDefinition) itemDef;
            if (def.isIgnored() || skipProperty(def)) {
              continue;
            }
            if (!showInheritedObjectAttributes
                && INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) {
              continue;
            }

            // capability handling for activation properties
            if (isShadowActivation() && !hasCapability(def)) {
              continue;
            }

            if (isShadowAssociation()) {
              continue;
            }

            PrismProperty property = container.findProperty(def.getName());
            boolean propertyIsReadOnly;
            // decision is based on parent object status, not this
            // container's one (because container can be added also
            // to an existing object)
            if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

              propertyIsReadOnly = !def.canModify();
            } else {
              propertyIsReadOnly = !def.canAdd();
            }
            if (property == null) {
              properties.add(
                  new PropertyWrapper(
                      this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED));
            } else {
              properties.add(
                  new PropertyWrapper(this, property, propertyIsReadOnly, ValueStatus.NOT_CHANGED));
            }
          } else if (itemDef instanceof PrismReferenceDefinition) {
            PrismReferenceDefinition def = (PrismReferenceDefinition) itemDef;

            if (INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) {
              continue;
            }

            PrismReference reference = container.findReference(def.getName());
            boolean propertyIsReadOnly;
            // decision is based on parent object status, not this
            // container's one (because container can be added also
            // to an existing object)
            if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

              propertyIsReadOnly = !def.canModify();
            } else {
              propertyIsReadOnly = !def.canAdd();
            }
            if (reference == null) {
              properties.add(
                  new ReferenceWrapper(
                      this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED));
            } else {
              properties.add(
                  new ReferenceWrapper(
                      this, reference, propertyIsReadOnly, ValueStatus.NOT_CHANGED));
            }
          }
        }
      }
    }

    Collections.sort(properties, new ItemWrapperComparator());

    result.recomputeStatus();

    return properties;
  }
示例#7
0
  private boolean isUser() {
    ObjectWrapper wrapper = getContainer().getObject();
    PrismObject object = wrapper.getObject();

    return UserType.class.isAssignableFrom(object.getCompileTimeClass());
  }
示例#8
0
 private ContainerStatus getContainerStatus(ItemWrapper propertyWrapper) {
   final ObjectWrapper objectWrapper = propertyWrapper.getContainer().getObject();
   return objectWrapper != null ? objectWrapper.getStatus() : ContainerStatus.MODIFYING;
 }