Exemplo n.º 1
0
  private CallableResult<List<AssignmentItemDto>> loadAssignments() throws Exception {
    LOGGER.debug("Loading assignments.");
    CallableResult callableResult = new CallableResult();
    List<AssignmentItemDto> list = new ArrayList<AssignmentItemDto>();
    callableResult.setValue(list);

    PrismObject<UserType> user = principalModel.getObject();
    if (user == null || user.findContainer(UserType.F_ASSIGNMENT) == null) {
      return callableResult;
    }

    Task task = createSimpleTask(OPERATION_LOAD_ASSIGNMENTS);
    OperationResult result = task.getResult();
    callableResult.setResult(result);

    PrismContainer assignments = user.findContainer(UserType.F_ASSIGNMENT);
    List<PrismContainerValue> values = assignments.getValues();
    for (PrismContainerValue assignment : values) {
      AssignmentItemDto item = createAssignmentItem(user, assignment, task, result);
      if (item != null) {
        list.add(item);
      }
    }
    result.recordSuccessIfUnknown();
    result.recomputeStatus();

    Collections.sort(list);

    LOGGER.debug("Finished assignments loading.");

    return callableResult;
  }
Exemplo n.º 2
0
  private List<ContainerWrapper> createReportContainers(PageBase pageBase) throws SchemaException {
    List<ContainerWrapper> containers = new ArrayList<ContainerWrapper>();

    PrismContainer container = object.findContainer(ReportType.F_CONFIGURATION);
    ContainerStatus status = container != null ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;

    if (container == null) {
      PrismSchema schema =
          ReportTypeUtil.parseReportConfigurationSchema(
              (PrismObject<ReportType>) object, object.getPrismContext());
      PrismContainerDefinition definition =
          ReportTypeUtil.findReportConfigurationDefinition(schema);
      if (definition == null) {
        return containers;
      }
      container = definition.instantiate();
    }

    ContainerWrapper wrapper =
        new ContainerWrapper(
            this, container, status, new ItemPath(ReportType.F_CONFIGURATION), pageBase);
    addSubresult(wrapper.getResult());

    containers.add(wrapper);

    return containers;
  }
  private List<PrismContainer> getChildrenContainers(PrismObject parent) {
    List<PrismContainer> containers = new ArrayList<>();
    if (ObjectType.class.isAssignableFrom(parent.getCompileTimeClass())) {
      containers.add(parent.findContainer(ObjectType.F_TRIGGER));
    }

    if (LookupTableType.class.isAssignableFrom(parent.getCompileTimeClass())) {
      containers.add(parent.findContainer(LookupTableType.F_ROW));
    }

    if (FocusType.class.isAssignableFrom(parent.getCompileTimeClass())) {
      containers.add(parent.findContainer(FocusType.F_ASSIGNMENT));
    }

    if (AbstractRoleType.class.isAssignableFrom(parent.getCompileTimeClass())) {
      containers.add(parent.findContainer(AbstractRoleType.F_INDUCEMENT));
      containers.add(parent.findContainer(AbstractRoleType.F_EXCLUSION));
      containers.add(parent.findContainer(AbstractRoleType.F_AUTHORIZATION));
      PrismContainer policyConstraints =
          parent.findContainer(AbstractRoleType.F_POLICY_CONSTRAINTS);
      if (policyConstraints != null) {
        containers.add(policyConstraints.findContainer(PolicyConstraintsType.F_MAX_ASSIGNEES));
        containers.add(policyConstraints.findContainer(PolicyConstraintsType.F_MIN_ASSIGNEES));
      }
    }

    return containers;
  }
Exemplo n.º 4
0
  private List<ContainerWrapper> createCustomContainerWrapper(
      PrismObject object, QName name, PageBase pageBase) {
    PrismContainer container = object.findContainer(name);
    ContainerStatus status = container == null ? ContainerStatus.ADDING : ContainerStatus.MODIFYING;
    List<ContainerWrapper> list = new ArrayList<ContainerWrapper>();
    if (container == null) {
      PrismContainerDefinition definition = getDefinition().findContainerDefinition(name);
      container = definition.instantiate();
    }

    ContainerWrapper wrapper =
        new ContainerWrapper(this, container, status, new ItemPath(name), pageBase);
    addSubresult(wrapper.getResult());
    list.add(wrapper);
    // list.addAll(createContainerWrapper(container, null, pageBase));
    if (!ShadowType.F_ASSOCIATION.equals(name)) {
      // [pm] is this OK? "name" is the name of the container itself; originally here was an empty
      // path - that seems more logical
      list.addAll(createContainerWrapper(container, new ItemPath(name), pageBase));
    }

    return list;
  }
Exemplo n.º 5
0
  private List<ContainerWrapper> createResourceContainerWrapper(
      PrismObject<ConnectorType> connector, PageBase pageBase) throws SchemaException {

    PrismContainer container = object.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);

    ConnectorType connectorType = connector.asObjectable();
    PrismSchema schema =
        ConnectorTypeUtil.parseConnectorSchema(connectorType, connector.getPrismContext());
    PrismContainerDefinition definition =
        ConnectorTypeUtil.findConfigurationContainerDefintion(connectorType, schema);

    ContainerStatus status = container != null ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;
    if (container == null) {
      // brutal hack - the definition has (errorneously) set maxOccurs =
      // unbounded. But there can be only one configuration container.
      // See MID-2317 and related issues
      PrismContainerDefinition definitionFixed = definition.clone();
      definitionFixed.setMaxOccurs(1);
      container = definitionFixed.instantiate();
    }

    return createContainerWrapper(
        container, new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION), pageBase);
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  private List<ContainerWrapper> createContainers(PageBase pageBase) {
    result = new OperationResult(CREATE_CONTAINERS);

    List<ContainerWrapper> containers = new ArrayList<ContainerWrapper>();

    try {
      Class clazz = object.getCompileTimeClass();
      if (ShadowType.class.isAssignableFrom(clazz)) {
        PrismContainer attributes = object.findContainer(ShadowType.F_ATTRIBUTES);
        ContainerStatus status = attributes != null ? getStatus() : ContainerStatus.ADDING;
        if (attributes == null) {
          PrismContainerDefinition definition =
              object.getDefinition().findContainerDefinition(ShadowType.F_ATTRIBUTES);
          attributes = definition.instantiate();
        }

        ContainerWrapper container =
            new ContainerWrapper(
                this, attributes, status, new ItemPath(ShadowType.F_ATTRIBUTES), pageBase);
        addSubresult(container.getResult());

        container.setMain(true);
        containers.add(container);

        if (hasResourceCapability(
            ((ShadowType) object.asObjectable()).getResource(), ActivationCapabilityType.class)) {
          containers.addAll(
              createCustomContainerWrapper(object, ShadowType.F_ACTIVATION, pageBase));
        }
        if (hasResourceCapability(
            ((ShadowType) object.asObjectable()).getResource(), CredentialsCapabilityType.class)) {
          containers.addAll(
              createCustomContainerWrapper(object, ShadowType.F_CREDENTIALS, pageBase));
        }

        PrismContainer<ShadowAssociationType> associationContainer =
            object.findOrCreateContainer(ShadowType.F_ASSOCIATION);
        container =
            new ContainerWrapper(
                this,
                associationContainer,
                ContainerStatus.MODIFYING,
                new ItemPath(ShadowType.F_ASSOCIATION),
                pageBase);
        addSubresult(container.getResult());
        containers.add(container);
      } else if (ResourceType.class.isAssignableFrom(clazz)) {
        containers = createResourceContainers(pageBase);
      } else if (ReportType.class.isAssignableFrom(clazz)) {
        containers = createReportContainers(pageBase);
      } else {
        ContainerWrapper container =
            new ContainerWrapper(this, object, getStatus(), null, pageBase);
        addSubresult(container.getResult());
        containers.add(container);

        containers.addAll(createContainerWrapper(object, null, pageBase));
      }
    } catch (Exception ex) {
      // TODO: shouldn't be this exception thrown????
      LoggingUtils.logUnexpectedException(LOGGER, "Error occurred during container wrapping", ex);
      result.recordFatalError(
          "Error occurred during container wrapping, reason: " + ex.getMessage(), ex);
    }

    Collections.sort(containers, new ItemWrapperComparator());
    result.recomputeStatus();
    result.recordSuccessIfUnknown();

    return containers;
  }