Beispiel #1
0
  private Panel createInputComponent(String id, IModel<String> labelModel, Form form) {
    ValueWrapper valueWrapper = valueWrapperModel.getObject();
    ObjectWrapper objectWrapper = null;
    if (valueWrapper.getItem().getContainer() != null) {
      objectWrapper = valueWrapper.getItem().getContainer().getObject();
    }
    Item property = valueWrapper.getItem().getItem();
    boolean required = property.getDefinition().getMinOccurs() > 0;

    Panel component = createTypedInputComponent(id);

    if (component instanceof InputPanel) {
      InputPanel inputPanel = (InputPanel) component;
      // adding valid from/to date range validator, if necessary
      ItemPath activation = new ItemPath(UserType.F_ACTIVATION);
      if (ActivationType.F_VALID_FROM.equals(property.getElementName())) {
        DateValidator validator = getActivationRangeValidator(form, activation);
        validator.setDateFrom((DateTimeField) inputPanel.getBaseFormComponent());
      } else if (ActivationType.F_VALID_TO.equals(property.getElementName())) {
        DateValidator validator = getActivationRangeValidator(form, activation);
        validator.setDateTo((DateTimeField) inputPanel.getBaseFormComponent());
      }

      final List<FormComponent> formComponents = inputPanel.getFormComponents();
      for (FormComponent formComponent : formComponents) {
        formComponent.setLabel(labelModel);
        formComponent.setRequired(required);

        if (formComponent instanceof TextField) {
          formComponent.add(new AttributeModifier("size", "42"));
        }
        formComponent.add(
            new AjaxFormComponentUpdatingBehavior("blur") {

              @Override
              protected void onUpdate(AjaxRequestTarget target) {}
            });

        // Validation occurs when submitting the form
        //            if (form != null) {
        //                AjaxFormValidatingBehavior validator = new
        // AjaxFormValidatingBehavior(form, "Blur");
        //
        //                formComponent.add(validator);
        //            }
      }
    }
    if (component == null) {
      throw new RuntimeException(
          "Cannot create input component for item "
              + property
              + " ("
              + valueWrapper
              + ") in "
              + objectWrapper);
    }
    return component;
  }
  static String getDisplayNameFromItem(Item item) {
    Validate.notNull(item, "Item must not be null.");

    String displayName = item.getDisplayName();
    if (StringUtils.isEmpty(displayName)) {
      QName name = item.getElementName();
      if (name != null) {
        displayName = name.getLocalPart();
      } else {
        displayName = item.getDefinition().getTypeName().getLocalPart();
      }
    }

    return displayName;
  }
 public static Collection<? extends PrismValue> deserializeItemValues(
     String value, Item item, String language) throws SchemaException {
   // System.out.println("item value deserialization");
   PrismContext prismContext = item.getPrismContext();
   XNode xnode = prismContext.getParserDom().parse(value);
   if (xnode instanceof RootXNode) {
     xnode = ((RootXNode) xnode).getSubnode();
   }
   // System.out.println("value: " + value);
   Item parsedItem =
       prismContext
           .getXnodeProcessor()
           .parseItem(xnode, item.getElementName(), item.getDefinition());
   return parsedItem.getValues();
   //		throw new UnsupportedOperationException("need to be implemented");
 }
  private <C extends Containerable> void serializeContainerValue(
      MapXNode xmap,
      PrismContainerValue<C> containerVal,
      PrismContainerDefinition<C> containerDefinition,
      SerializationContext ctx)
      throws SchemaException {
    Long id = containerVal.getId();
    if (id != null) {
      xmap.put(XNode.KEY_CONTAINER_ID, createPrimitiveXNodeAttr(id, DOMUtil.XSD_LONG));
    }
    if (containerVal.getConcreteType() != null) {
      xmap.setTypeQName(containerVal.getConcreteType());
      xmap.setExplicitTypeDeclaration(true);
    }

    Collection<QName> serializedItems = new ArrayList<>();
    if (containerDefinition != null) {
      // We have to serialize in the definition order. Some data formats (XML) are
      // ordering-sensitive. We need to keep that ordering otherwise the resulting
      // document won't pass schema validation
      for (ItemDefinition itemDef : containerDefinition.getDefinitions()) {
        QName elementName = itemDef.getName();
        Item<?, ?> item = containerVal.findItem(elementName);
        if (item != null) {
          XNode xsubnode = serializeItem(item, ctx);
          xmap.put(elementName, xsubnode);
          serializedItems.add(elementName);
        }
      }
    }
    // There are some cases when we do not have list of all elements in a container.
    // E.g. in run-time schema. Therefore we must also iterate over items and not just item
    // definitions.
    if (containerVal.getItems() != null) {
      for (Item<?, ?> item : containerVal.getItems()) {
        QName elementName = item.getElementName();
        if (serializedItems.contains(elementName)) {
          continue;
        }
        XNode xsubnode = serializeItem(item, ctx);
        xmap.put(elementName, xsubnode);
      }
    }
  }
  @Override
  public String getCaseInfoButtonTitle(
      IModel<? extends CertCaseOrDecisionDto> rowModel, PageBase page) {
    CertCaseOrDecisionDto dto = rowModel.getObject();
    AccessCertificationCaseType _case = dto.getCertCase();
    if (!(_case instanceof AccessCertificationAssignmentCaseType)) {
      return null; // should not occur, TODO treat gracefully
    }
    AccessCertificationAssignmentCaseType assignmentCase =
        (AccessCertificationAssignmentCaseType) _case;
    AssignmentType assignment = assignmentCase.getAssignment();

    List<String> infoList = new ArrayList<>();

    String assignmentOrInducement;
    if (Boolean.TRUE.equals(assignmentCase.isIsInducement())) {
      assignmentOrInducement =
          page.createStringResource("PageCert.message.textInducement").getString();
    } else {
      assignmentOrInducement =
          page.createStringResource("PageCert.message.textAssignment").getString();
    }
    String targetType = getLocalizedTypeName(_case.getTargetRef().getType(), page);
    String targetName = dto.getTargetName();
    String objectType = getLocalizedTypeName(_case.getObjectRef().getType(), page);
    String objectName = dto.getObjectName();

    infoList.add(
        page.createStringResource(
                "PageCert.message.assignment",
                assignmentOrInducement,
                emptyToDash(targetType),
                emptyToDash(targetName),
                emptyToDash(objectType),
                emptyToDash(objectName))
            .getString());

    if (StringUtils.isNotEmpty(assignment.getDescription())) {
      infoList.add(
          page.createStringResource("PageCert.message.textDescription", assignment.getDescription())
              .getString());
    }
    if (assignment.getOrder() != null) {
      infoList.add(
          page.createStringResource("PageCert.message.textOrder", assignment.getOrder())
              .getString());
    }
    if (assignment.getConstruction() != null) {
      if (assignment.getConstruction().getKind() != null) {
        infoList.add(
            page.createStringResource(
                    "PageCert.message.textKind",
                    page.createStringResource(assignment.getConstruction().getKind()).getString())
                .getString());
      }
      if (assignment.getConstruction().getIntent() != null) {
        infoList.add(
            page.createStringResource(
                    "PageCert.message.textIntent", assignment.getConstruction().getIntent())
                .getString());
      }
    }
    if (_case.getTargetRef().getRelation() != null) {
      infoList.add(
          page.createStringResource(
                  "PageCert.message.textRelation",
                  _case.getTargetRef().getRelation().getLocalPart())
              .getString());
    }
    Task task = page.createSimpleTask("dummy");
    if (assignment.getOrgRef() != null) {
      String orgName =
          WebModelServiceUtils.resolveReferenceName(
              assignment.getOrgRef(), page, task, task.getResult());
      infoList.add(page.createStringResource("PageCert.message.textOrg", orgName).getString());
    }
    if (assignment.getTenantRef() != null) {
      String tenantName =
          WebModelServiceUtils.resolveReferenceName(
              assignment.getTenantRef(), page, task, task.getResult());
      infoList.add(
          page.createStringResource("PageCert.message.textTenant", tenantName).getString());
    }

    PrismContainer<? extends Containerable> extensionContainer =
        assignment.asPrismContainerValue().findContainer(AssignmentType.F_EXTENSION);
    if (extensionContainer != null && !extensionContainer.isEmpty()) {
      List<String> extensionItemNameList = new ArrayList<>();
      for (Item extensionItem : extensionContainer.getValue().getItems()) {
        extensionItemNameList.add(extensionItem.getElementName().getLocalPart());
      }
      infoList.add(
          page.createStringResource(
                  "PageCert.message.textExtensions", StringUtils.join(extensionItemNameList, ", "))
              .getString());
    }

    if (assignment.getActivation() != null) {
      String validFrom = WebComponentUtil.formatDate(assignment.getActivation().getValidFrom());
      if (validFrom != null) {
        infoList.add(
            page.createStringResource("PageCert.message.textValidFrom", validFrom).getString());
      }
      String validTo = WebComponentUtil.formatDate(assignment.getActivation().getValidTo());
      if (validTo != null) {
        infoList.add(
            page.createStringResource("PageCert.message.textValidTo", validTo).getString());
      }
      if (assignment.getActivation().getAdministrativeStatus() != null) {
        infoList.add(
            page.createStringResource(
                    "PageCert.message.textAdministrativeState",
                    page.createStringResource(assignment.getActivation().getAdministrativeStatus())
                        .getString())
                .getString());
      }
    }

    String rv = StringUtils.join(infoList, "<br/>");
    return rv;
  }
Beispiel #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;
  }
Beispiel #7
0
 private boolean isUserOrgItem(Item item, Class referenceType) {
   return (referenceType == ObjectType.class || referenceType == FocusType.class)
       && (AbstractRoleType.F_APPROVER_REF.equals(item.getElementName())
           || AbstractRoleType.F_OWNER_REF.equals(item.getElementName()));
 }