public static <T> String serializeValue(
      T value, QName itemName, PrismContext prismContext, String language) throws SchemaException {
    //		System.out.println("value serialization");
    if (value == null) {
      return null;
    }

    XNodeSerializer serializer = prismContext.getXnodeProcessor().createSerializer();

    if (value instanceof List) {
      List<T> values = (List<T>) value;
      if (values.isEmpty()) {
        return null;
      }
      throw new UnsupportedOperationException("take your chance.");
    }

    PrismValue pVal = null;

    if (value instanceof Containerable) {
      pVal = ((Containerable) value).asPrismContainerValue();
    } else if (value instanceof Referencable) {
      pVal = ((Referencable) value).asReferenceValue();
    } else {
      pVal = new PrismPropertyValue<T>(value);
    }

    XNode node = serializer.serializeItemValue(pVal, null);
    String s = prismContext.getParserDom().serializeToString(node, itemName);
    //		System.out.println("serialized: " + s);
    return s;
    //		throw new UnsupportedOperationException("need to be implemented");
  }
  @Override
  public void setValue(T value) {
    this.actualValue = value;

    checkPrismContext();
    if (value != null && prismContext.canSerialize(value)) {
      try {
        this.valueForStorageWhenEncoded =
            prismContext.xmlSerializer().serializeAnyData(value, new QName("value"));
      } catch (SchemaException e) {
        throw new SystemException(
            "Couldn't serialize value of type " + value.getClass() + ": " + e.getMessage(), e);
      }
      this.valueForStorageWhenNotEncoded = null;
      encodingScheme = EncodingScheme.PRISM;
    } else if (value == null || value instanceof Serializable) {
      this.valueForStorageWhenNotEncoded = value;
      this.valueForStorageWhenEncoded = null;
      encodingScheme = EncodingScheme.NONE;
      if (value instanceof Itemable) {
        throw new IllegalStateException(
            "Itemable value is used as not-encoded serializable item; value = " + value);
      }
    } else {
      throw new IllegalStateException(
          "Attempt to put non-serializable item "
              + value.getClass()
              + " into "
              + this.getClass().getSimpleName());
    }
  }
  public static <T> T deserializeValue(
      String value,
      Class clazz,
      QName itemName,
      ItemDefinition itemDef,
      PrismContext prismContext,
      String language)
      throws SchemaException {
    // System.out.println("item value deserialization");

    XNode xnode = prismContext.getParserDom().parse(value);

    //		System.out.println("xnode: " + xnode.debugDump());

    XNode xmap = null;
    if (xnode instanceof RootXNode) {
      xmap = ((RootXNode) xnode).getSubnode();
    }

    //		System.out.println("xmap: " + xmap);
    //		else if (xnode instanceof MapXNode){
    //			xmap = (MapXNode) xnode;
    //		} else if (xnode instanceof PrimitiveXNode){
    //			xmap = new MapXNode();
    //			xmap.put(itemName, xnode);
    //		}

    Item item = prismContext.getXnodeProcessor().parseItem(xmap, itemName, itemDef);

    //		System.out.println("item: " + item.debugDump());

    if (item instanceof PrismProperty) {
      PrismProperty prop = (PrismProperty) item;

      if (prop.isSingleValue()) {
        return (T) prop.getRealValue();
      }
      return (T) prop.getRealValues();
    } else if (item instanceof PrismContainer) {
      PrismContainer cont = (PrismContainer) item;
      return (T) cont.getValue().asContainerable();
    } else if (item instanceof PrismReference) {
      PrismReference ref = (PrismReference) item;
      return (T) ref.getValue();
    }
    if (item != null) {
      return (T) item.getValue(0);
    }
    //		if (prismContext.getBeanConverter().canConvert(clazz)){
    //			prismContext.getBeanConverter().unmarshall(xmap, clazz);
    //		} else{
    //			prismContext.getXnodeProcessor().parseContainer(xnode, clazz);
    //		}

    throw new UnsupportedOperationException("need to be implemented");
  }
 public static String serializeItemValue(
     QName itemName,
     ItemDefinition def,
     PrismValue value,
     PrismContext prismContext,
     String language)
     throws SchemaException {
   XNodeSerializer serializer = prismContext.getXnodeProcessor().createSerializer();
   XNode node = serializer.serializeItemValue(value, def);
   String s = prismContext.getParserDom().serializeToString(node, itemName);
   // System.out.println("serialized ITEM VALUE: " + s);
   return s;
 }
  @Test
  public void testParseModelContextPrism() throws Exception {
    System.out.println("===[ testParseModelContextPrism ]===");

    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();

    // WHEN
    PrismContainer<LensContextType> lensContextType =
        prismContext.parseContainer(
            MODEL_CONTEXT_FILE, LensContextType.class, PrismContext.LANG_XML);

    // THEN
    System.out.println("Parsed LensContextType: " + lensContextType.getValue().asContainerable());
  }
Esempio n. 6
0
  public <O extends ObjectType> O resolveObject(ObjectReferenceType ref) {
    Validate.notNull(ref.getOid(), "Object oid must not be null");
    Validate.notNull(ref.getType(), "Object type must not be null");

    Class type = prismContext.getSchemaRegistry().determineCompileTimeClass(ref.getType());
    return resolveObject(type, ref.getOid());
  }
Esempio n. 7
0
 public static <O extends Objectable, T> PropertyDelta<T> createDelta(
     ItemPath propertyPath, Class<O> compileTimeClass, PrismContext prismContext) {
   PrismObjectDefinition<O> objectDefinition =
       prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(compileTimeClass);
   PrismPropertyDefinition propDef = objectDefinition.findPropertyDefinition(propertyPath);
   return new PropertyDelta<T>(propertyPath, propDef, prismContext);
 }
 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");
 }
  @Test
  public void testParseTaskFile() throws Exception {
    System.out.println("===[ testParseTaskFile ]===");

    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();

    // WHEN
    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE, PrismContext.LANG_XML);

    // THEN
    System.out.println("Parsed task:");
    System.out.println(task.debugDump());

    assertTask(task);
  }
Esempio n. 10
0
  public static <T> String toRepo(
      ItemDefinition parentDefinition, QName itemName, T value, PrismContext prismContext)
      throws SchemaException, JAXBException {
    if (value == null) {
      return null;
    }

    if (value instanceof Objectable) {
      return prismContext.serializeObjectToString(
          ((Objectable) value).asPrismObject(), PrismContext.LANG_XML);
    }

    ItemDefinition definition = null;
    if (parentDefinition instanceof PrismContainerDefinition) {
      definition = ((PrismContainerDefinition) parentDefinition).findItemDefinition(itemName);
      if (definition == null) {
        definition = parentDefinition;
      }
    } else {
      definition = parentDefinition;
    }

    return ValueSerializationUtil.serializeValue(
        value,
        definition,
        itemName,
        parentDefinition.getName(),
        prismContext,
        PrismContext.LANG_XML);
  }
Esempio n. 11
0
 private PrismContainerDefinition<ActivationType> getActivationDefinition() {
   if (activationDefinition == null) {
     ComplexTypeDefinition focusDefinition =
         prismContext.getSchemaRegistry().findComplexTypeDefinition(FocusType.COMPLEX_TYPE);
     activationDefinition = focusDefinition.findContainerDefinition(FocusType.F_ACTIVATION);
   }
   return activationDefinition;
 }
Esempio n. 12
0
 public static <T extends Objectable> void revive(Objectable object, PrismContext prismContext)
     throws DtoTranslationException {
   try {
     prismContext.adopt(object);
   } catch (SchemaException ex) {
     throw new DtoTranslationException(ex.getMessage(), ex);
   }
 }
 public String getObjectDeltaXml() {
   ObjectDeltaType objectDeltaType =
       taskDto.getExtensionPropertyRealValue(
           SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA, ObjectDeltaType.class);
   if (objectDeltaType == null) {
     return null;
   }
   PrismContext prismContext = ((MidPointApplication) Application.get()).getPrismContext();
   try {
     return WebXmlUtil.stripNamespaceDeclarations(
         prismContext.serializeAnyData(
             objectDeltaType,
             SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA,
             PrismContext.LANG_XML));
   } catch (SchemaException e) {
     throw new SystemException("Couldn't serialize object delta: " + e.getMessage(), e);
   }
 }
  @Test
  public void testParseTaskRoundtrip() throws Exception {
    System.out.println("===[ testParseTaskRoundtrip ]===");

    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();

    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE);

    System.out.println("Parsed task:");
    System.out.println(task.debugDump());

    assertTask(task);

    // SERIALIZE

    String serializedTask = prismContext.serializeObjectToString(task, PrismContext.LANG_XML);

    System.out.println("serialized task:");
    System.out.println(serializedTask);

    // RE-PARSE

    PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask);

    System.out.println("Re-parsed task:");
    System.out.println(reparsedTask.debugDump());

    // Cannot assert here. It will cause parsing of some of the raw values and diff will fail
    assertTask(reparsedTask);

    ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask);
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Delta is not empty", objectDelta.isEmpty());

    PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask);
  }
  @Override
  public T getValue() {

    if (actualValue != null) {
      return actualValue;
    }

    if (valueForStorageWhenNotEncoded != null) {
      actualValue = valueForStorageWhenNotEncoded;
      return actualValue;
    }

    if (valueForStorageWhenEncoded != null) {
      if (prismContext == null) {
        throw new IllegalStateException(
            "PrismContext not set for SerializationSafeContainer holding "
                + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH));
      }

      if (encodingScheme == EncodingScheme.PRISM) {
        try {
          PrismValue prismValue =
              prismContext.parserFor(valueForStorageWhenEncoded).xml().parseItemValue();
          actualValue = prismValue != null ? prismValue.getRealValue() : null;
        } catch (SchemaException e) {
          throw new SystemException(
              "Couldn't deserialize value from JAXB: "
                  + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH),
              e);
        }
        return actualValue;
      } else {
        throw new IllegalStateException("Unexpected encoding scheme " + encodingScheme);
      }
    }

    return null;
  }
 private void debugDumpValue(int indent, StringBuilder sb, T value) {
   if (value instanceof DebugDumpable) {
     DebugUtil.debugDumpWithLabel(sb, "value", (DebugDumpable) value, indent);
     return;
   }
   String stringValue = null;
   if (value instanceof ExpressionType) {
     // brutal hack...
     String xml = null;
     try {
       xml =
           prismContext
               .xmlSerializer()
               .serializeRealValue(value, SchemaConstantsGenerated.C_EXPRESSION);
       stringValue = DebugUtil.fixIndentInMultiline(indent, DebugDumpable.INDENT_STRING, xml);
     } catch (SchemaException e) {
       LOGGER.warn("Couldn't serialize an expression: {}", value, e);
     }
   }
   if (stringValue == null) {
     stringValue = String.valueOf(value);
   }
   DebugUtil.debugDumpWithLabel(sb, "value", stringValue, indent);
 }
Esempio n. 17
0
 Object parseObjectFromXML(String xml) throws SchemaException {
   return prismContext.parseAnyData(xml, PrismContext.LANG_XML);
 }
Esempio n. 18
0
 private <T extends ShadowType> PrismObjectDefinition<T> getShadowDefinition(Class<T> type) {
   return prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
 }
Esempio n. 19
0
  @Test
  public void test610ChangePassword() throws Exception {
    final String TEST_NAME = "test610ChangePassword";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    ResourceAttributeContainer resourceObject =
        createResourceObject("uid=drake,ou=People,dc=example,dc=com", "Sir Francis Drake", "Drake");
    PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);

    OperationResult addResult = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    // Add a testing object
    cc.addObject(shadow, null, addResult);

    String entryUuid = (String) resourceObject.getIdentifier().getValue().getValue();
    SearchResultEntry entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry before change", entry);
    String passwordBefore = OpenDJController.getAttributeValue(entry, "userPassword");
    // We have set no password during create, therefore the password should
    // be empty
    assertNull(passwordBefore);

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceObject.getDefinition().getComplexTypeDefinition();

    Collection<ResourceAttribute<?>> identifiers = resourceObject.getIdentifiers();
    // Determine object class from the schema

    OperationResult result = new OperationResult(this.getClass().getName() + ".testFetchObject");

    // WHEN

    Set<Operation> changes = new HashSet<Operation>();
    ProtectedStringType passPs = protector.encryptString("salalala");

    ItemDeltaType propMod = new ItemDeltaType();
    // create modification path
    Document doc = DOMUtil.getDocument();
    ItemPathType path = new ItemPathType("credentials/password/value");
    //		PropertyPath propPath = new PropertyPath(new
    // PropertyPath(ResourceObjectShadowType.F_CREDENTIALS), CredentialsType.F_PASSWORD);
    propMod.setPath(path);

    // set the replace value
    MapXNode passPsXnode = prismContext.getBeanConverter().marshalProtectedDataType(passPs);
    RawType value = new RawType(passPsXnode, prismContext);
    propMod.getValue().add(value);

    // set the modificaion type
    propMod.setModificationType(ModificationTypeType.REPLACE);

    PropertyDelta passDelta =
        (PropertyDelta) DeltaConvertor.createItemDelta(propMod, shadow.getDefinition());
    PropertyModificationOperation passwordModification =
        new PropertyModificationOperation(passDelta);
    changes.add(passwordModification);

    //		PasswordChangeOperation passwordChange = new PasswordChangeOperation(passPs);
    //		changes.add(passwordChange);
    cc.modifyObject(accountDefinition, identifiers, changes, result);

    // THEN

    entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry after change", entry);

    String passwordAfter = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull(passwordAfter);

    System.out.println("Account password: " + passwordAfter);
  }
  public static <T> String serializeValue(
      T value,
      ItemDefinition def,
      QName itemName,
      QName parentName,
      PrismContext prismContext,
      String language)
      throws SchemaException {
    //		System.out.println("value serialization");
    if (value == null) {
      return null;
    }

    XNodeSerializer serializer = prismContext.getXnodeProcessor().createSerializer();

    if (value instanceof List) {
      List<T> values = (List<T>) value;
      if (values.isEmpty()) {
        return null;
      }

      if (def instanceof PrismPropertyDefinition) {
        PrismProperty prop = (PrismProperty) def.instantiate(itemName);
        for (T val : values) {
          PrismPropertyValue<T> pValue = new PrismPropertyValue<T>(val);
          prop.add(pValue);
        }

        XNode node = serializer.serializeItem(prop);
        if (node instanceof ListXNode) {
          ListXNode xList = (ListXNode) node;
          if (xList.size() == 1) {
            XNode sub = xList.iterator().next();
            if (!(sub instanceof MapXNode)) {
              throw new IllegalArgumentException("must be a map");
            }

            String s = prismContext.getParserDom().serializeToString(sub, parentName);
            //						System.out.println("serialized: " + s);
            return s;

          } else {
            MapXNode xmap = new MapXNode();
            xmap.put(itemName, xList);
            String s = prismContext.getParserDom().serializeToString(xmap, parentName);
            //						System.out.println("serialized: " + s);
            return s;
            //						throw new IllegalArgumentException("Check your data.");
          }

          //					MapXNode xmap = xList.new MapXNode();
          //					xmap.put(def.getName(), xList);

        }
        String s = prismContext.getParserDom().serializeToString(node, def.getName());
        //				System.out.println("serialized: " + s);
        return s;
      } else if (def instanceof PrismContainerDefinition) {
        PrismContainer pc = (PrismContainer) def.instantiate();
        for (T val : values) {
          //					PrismContainerValue pcVal = new PrismContainerValue<Containerable>((Containerable)
          // val);
          PrismContainerValue pcVal = ((Containerable) val).asPrismContainerValue();
          pc.add(pcVal.clone());
        }
        XNode node = serializer.serializeItem(pc);
        if (node instanceof ListXNode) {
          ListXNode xList = (ListXNode) node;
          MapXNode xmap = new MapXNode();
          xmap.put(def.getName(), xList);
          String s = prismContext.getParserDom().serializeToString(xmap, parentName);
          //					System.out.println("serialized: " + s);
          return s;
        }
        String s = prismContext.getParserDom().serializeToString(node, def.getName());
        //				System.out.println("serialized: " + s);
        return s;
      }
    }

    PrismValue pVal = null;

    if (value instanceof Containerable) {
      pVal = ((Containerable) value).asPrismContainerValue();
    } else if (value instanceof Referencable) {
      pVal = ((Referencable) value).asReferenceValue();
    } else {
      pVal = new PrismPropertyValue<T>(value);
    }

    //		Class clazz = prismContext.getSchemaRegistry().determineCompileTimeClass(itemName);
    //		PrismContainerDefinition def =
    // prismContext.getSchemaRegistry().determineDefinitionFromClass(clazz);
    //
    //		ItemDefinition def =
    // prismContext.getSchemaRegistry().findItemDefinitionByElementName(itemName);

    //		QName itemName = null;
    if (def != null) {
      itemName = def.getName();
    }

    XNode node = serializer.serializeItemValue(pVal, def);
    String s = prismContext.getParserDom().serializeToString(node, itemName);
    //		System.out.println("serialized: " + s);
    return s;
    //		throw new UnsupportedOperationException("need to be implemented");
  }
  public static <T> String serializeValue(
      T value,
      PrismPropertyDefinition def,
      QName itemName,
      PrismContext prismContext,
      String langXml)
      throws SchemaException {
    //		System.out.println("value serialization");
    if (value == null) {
      return null;
    }

    XNodeSerializer serializer = prismContext.getXnodeProcessor().createSerializer();

    if (value instanceof List) {
      List<T> values = (List<T>) value;
      if (values.isEmpty()) {
        return null;
      }

      if (def instanceof PrismPropertyDefinition) {
        PrismProperty prop = (PrismProperty) def.instantiate();
        for (T val : values) {
          PrismPropertyValue<T> pValue = new PrismPropertyValue<T>(val);
          prop.add(pValue);
        }
        XNode node = serializer.serializeItem(prop);
        if (node instanceof ListXNode) {
          ListXNode xList = (ListXNode) node;
          MapXNode xmap = new MapXNode();
          xmap.put(def.getName(), xList);
          String s = prismContext.getParserDom().serializeToString(xmap, def.getName());
          //					System.out.println("serialized: " + s);
          return s;
        }
        String s = prismContext.getParserDom().serializeToString(node, def.getName());
        //				System.out.println("serialized: " + s);
        return s;
      }
    }

    PrismValue pVal = null;

    if (value instanceof Containerable) {
      pVal = ((Containerable) value).asPrismContainerValue();
    } else if (value instanceof Referencable) {
      pVal = ((Referencable) value).asReferenceValue();
    } else {
      PrismProperty pp = def.instantiate();
      pVal = new PrismPropertyValue<T>(value);
      pp.add(pVal);
      XNode xnode = serializer.serializeItemValue(pVal, def);
      if (xnode == null) {
        throw new IllegalArgumentException("null node after serialization");
      }
      MapXNode xmap = null;
      if (xnode instanceof RootXNode) {
        XNode sub = ((RootXNode) xnode).getSubnode();
        if (!(sub instanceof MapXNode)) {
          throw new IllegalArgumentException("not uspported yet");
        }
        xmap = (MapXNode) sub;
      } else if (xnode instanceof MapXNode) {
        xmap = (MapXNode) xnode;
      } else if (xnode instanceof PrimitiveXNode) {
        String s = ((PrimitiveXNode) xnode).getStringValue();
        return s;
        //
      } else {
        throw new IllegalStateException("hmmm");
      }

      XNode node = xmap.get(itemName);
      String s = prismContext.getParserDom().serializeToString(node, itemName);
    }

    XNode node = serializer.serializeItemValue(pVal, def);
    String s = prismContext.getParserDom().serializeToString(node, itemName);
    //		System.out.println("serialized: " + s);
    return s;
    //		throw new UnsupportedOperationException("need to be implemented");

  }
Esempio n. 22
0
 private ExpressionVariables processInnerVariables(
     ExpressionVariables variables, String contextDescription, Task task, OperationResult result)
     throws SchemaException, ObjectNotFoundException {
   if (expressionType == null
       || expressionType.getVariable() == null
       || expressionType.getVariable().isEmpty()) {
     // shortcut
     return variables;
   }
   ExpressionVariables newVariables = new ExpressionVariables();
   for (Entry<QName, Object> entry : variables.entrySet()) {
     newVariables.addVariableDefinition(entry.getKey(), entry.getValue());
   }
   for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
     QName varName = variableDefType.getName();
     if (varName == null) {
       throw new SchemaException("No variable name in expression in " + contextDescription);
     }
     if (variableDefType.getObjectRef() != null) {
       ObjectReferenceType ref = variableDefType.getObjectRef();
       ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType()));
       ObjectType varObject =
           objectResolver.resolve(
               ref,
               ObjectType.class,
               null,
               "variable " + varName + " in " + contextDescription,
               task,
               result);
       newVariables.addVariableDefinition(varName, varObject);
     } else if (variableDefType.getValue() != null) {
       // Only string is supported now
       Object valueObject = variableDefType.getValue();
       if (valueObject instanceof String) {
         newVariables.addVariableDefinition(varName, valueObject);
       } else if (valueObject instanceof Element) {
         newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent());
       } else if (valueObject instanceof RawType) {
         newVariables.addVariableDefinition(
             varName, ((RawType) valueObject).getParsedValue(null, varName));
       } else {
         throw new SchemaException(
             "Unexpected type "
                 + valueObject.getClass()
                 + " in variable definition "
                 + varName
                 + " in "
                 + contextDescription);
       }
     } else if (variableDefType.getPath() != null) {
       ItemPath itemPath = variableDefType.getPath().getItemPath();
       Object resolvedValue =
           ExpressionUtil.resolvePath(
               itemPath, variables, null, objectResolver, contextDescription, task, result);
       newVariables.addVariableDefinition(varName, resolvedValue);
     } else {
       throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
     }
   }
   return newVariables;
 }
Esempio n. 23
0
  // normally this method returns an InputPanel;
  // however, for some special readonly types (like ObjectDeltaType) it will return a Panel
  private Panel createTypedInputComponent(String id) {
    final Item item = model.getObject().getItem().getItem();

    Panel panel = null;
    if (item instanceof PrismProperty) {
      final PrismProperty property = (PrismProperty) item;
      PrismPropertyDefinition definition = property.getDefinition();
      QName valueType = definition.getTypeName();

      final String baseExpression = "value.value"; // pointing to prism property real value

      ContainerWrapper containerWrapper = model.getObject().getItem().getContainer();
      if (containerWrapper != null && containerWrapper.getPath() != null) {
        if (ShadowType.F_ASSOCIATION.getLocalPart().equals(containerWrapper.getPath().toString())) {
          return new TextDetailsPanel(id, new PropertyModel<String>(model, baseExpression)) {

            @Override
            public String createAssociationTooltip() {
              return createAssociationTooltipText(property);
            }
          };
        }
      }

      // fixing MID-1230, will be improved with some kind of annotation or something like that
      // now it works only in description
      if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
        return new TextAreaPanel(id, new PropertyModel(model, baseExpression));
      }

      // the same for requester and approver comments in workflows [mederly] - this is really ugly,
      // as it is specific to each approval form
      if (AssignmentCreationApprovalFormType.F_REQUESTER_COMMENT.equals(definition.getName())
          || AssignmentCreationApprovalFormType.F_COMMENT.equals(definition.getName())) {
        return new TextAreaPanel(id, new PropertyModel(model, baseExpression));
      }

      if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
        return WebMiscUtil.createEnumPanel(
            ActivationStatusType.class,
            id,
            new PropertyModel<ActivationStatusType>(model, baseExpression),
            this);
      } else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
        return WebMiscUtil.createEnumPanel(
            LockoutStatusType.class,
            id,
            new PropertyModel<LockoutStatusType>(model, baseExpression),
            this);
      } else {
        // nothing to do
      }

      if (DOMUtil.XSD_DATETIME.equals(valueType)) {
        panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(model, baseExpression));

      } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
        panel =
            new PasswordPanel(
                id,
                new PropertyModel<ProtectedStringType>(model, baseExpression),
                model.getObject().isReadonly());

      } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
        panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(model, baseExpression));

      } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
        InputPanel inputPanel;
        PrismPropertyDefinition def = property.getDefinition();

        if (def.getValueEnumerationRef() != null) {
          PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
          String lookupTableUid = valueEnumerationRef.getOid();
          Task task = pageBase.createSimpleTask("loadLookupTable");
          OperationResult result = task.getResult();

          Collection<SelectorOptions<GetOperationOptions>> options =
              SelectorOptions.createCollection(
                  LookupTableType.F_ROW,
                  GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
          final PrismObject<LookupTableType> lookupTable =
              WebModelUtils.loadObject(
                  LookupTableType.class, lookupTableUid, options, pageBase, task, result);

          inputPanel =
              new AutoCompleteTextPanel<String>(
                  id,
                  new LookupPropertyModel<String>(
                      model, baseExpression + ".orig", lookupTable.asObjectable()),
                  String.class) {

                @Override
                public Iterator<String> getIterator(String input) {
                  return prepareAutoCompleteList(input, lookupTable).iterator();
                }
              };

        } else {

          inputPanel =
              new TextPanel<>(
                  id, new PropertyModel<String>(model, baseExpression + ".orig"), String.class);
        }

        if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
          inputPanel.getBaseFormComponent().setRequired(true);
        }
        panel = inputPanel;

      } else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
        panel =
            new UploadDownloadPanel(id, model.getObject().isReadonly()) {

              @Override
              public InputStream getStream() {
                return new ByteArrayInputStream(
                    (byte[]) ((PrismPropertyValue) model.getObject().getValue()).getValue());
                //                		return super.getStream();
              }

              @Override
              public void updateValue(byte[] file) {
                ((PrismPropertyValue) model.getObject().getValue()).setValue(file);
              }

              @Override
              public void uploadFilePerformed(AjaxRequestTarget target) {
                super.uploadFilePerformed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
              }

              @Override
              public void removeFilePerformed(AjaxRequestTarget target) {
                super.removeFilePerformed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
              }

              @Override
              public void uploadFileFailed(AjaxRequestTarget target) {
                super.uploadFileFailed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                target.add(((PageBase) getPage()).getFeedbackPanel());
              }
            };

      } else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
        panel =
            new ModificationsPanel(
                id,
                new AbstractReadOnlyModel<DeltaDto>() {
                  @Override
                  public DeltaDto getObject() {
                    if (model.getObject() == null
                        || model.getObject().getValue() == null
                        || ((PrismPropertyValue) model.getObject().getValue()).getValue() == null) {
                      return null;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    ObjectDeltaType objectDeltaType =
                        (ObjectDeltaType)
                            ((PrismPropertyValue) model.getObject().getValue()).getValue();
                    try {
                      ObjectDelta delta =
                          DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
                      return new DeltaDto(delta);
                    } catch (SchemaException e) {
                      throw new IllegalStateException(
                          "Couldn't convert object delta: " + objectDeltaType);
                    }
                  }
                });
      } else {
        Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
        if (type != null && type.isPrimitive()) {
          type = ClassUtils.primitiveToWrapper(type);
        }

        if (isEnum(property)) {
          return WebMiscUtil.createEnumPanel(
              definition, id, new PropertyModel<>(model, baseExpression), this);
        }
        //                  // default QName validation is a bit weird, so let's treat QNames as
        // strings [TODO finish this - at the parsing side]
        //                  if (type == QName.class) {
        //                      type = String.class;
        //                  }

        PrismPropertyDefinition def = property.getDefinition();

        if (def.getValueEnumerationRef() != null) {
          PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
          String lookupTableUid = valueEnumerationRef.getOid();
          Task task = pageBase.createSimpleTask("loadLookupTable");
          OperationResult result = task.getResult();

          Collection<SelectorOptions<GetOperationOptions>> options =
              SelectorOptions.createCollection(
                  LookupTableType.F_ROW,
                  GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
          final PrismObject<LookupTableType> lookupTable =
              WebModelUtils.loadObject(
                  LookupTableType.class, lookupTableUid, options, pageBase, task, result);

          panel =
              new AutoCompleteTextPanel<String>(
                  id,
                  new LookupPropertyModel<String>(
                      model,
                      baseExpression,
                      lookupTable == null ? null : lookupTable.asObjectable()),
                  type) {

                @Override
                public Iterator<String> getIterator(String input) {
                  return prepareAutoCompleteList(input, lookupTable).iterator();
                }

                @Override
                public void checkInputValue(
                    AutoCompleteTextField input,
                    AjaxRequestTarget target,
                    LookupPropertyModel model) {
                  Iterator<String> lookupTableValuesIterator =
                      prepareAutoCompleteList("", lookupTable).iterator();

                  String value = input.getInput();
                  boolean isValueExist = false;
                  if (value != null) {
                    if (value.trim().equals("")) {
                      isValueExist = true;
                    } else {
                      while (lookupTableValuesIterator.hasNext()) {
                        String lookupTableValue = lookupTableValuesIterator.next();
                        if (value.trim().equals(lookupTableValue)) {
                          isValueExist = true;
                          break;
                        }
                      }
                    }
                  }
                  if (isValueExist) {
                    input.setModelValue(new String[] {value});
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                  } else {
                    input.error(
                        "Entered value doesn't match any of available values and will not be saved.");
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                  }
                }
              };

        } else {
          panel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression), type);
        }
      }
    } else if (item instanceof PrismReference) {
      //        	((PrismReferenceDefinition) item.getDefinition()).
      Class typeFromName = null;
      PrismContext prismContext = item.getPrismContext();
      if (prismContext == null) {
        prismContext = pageBase.getPrismContext();
      }
      QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
      if (targetTypeName != null && prismContext != null) {
        typeFromName = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
      }
      final Class typeClass =
          typeFromName != null
              ? typeFromName
              : (item.getDefinition().getTypeClassIfKnown() != null
                  ? item.getDefinition().getTypeClassIfKnown()
                  : FocusType.class);
      panel =
          new ValueChoosePanel(
              id, new PropertyModel<>(model, "value"), item.getValues(), false, typeClass);
    }

    return panel;
  }
 private PolyString toPolyString(String orig) {
   PolyString polyString = new PolyString(orig);
   polyString.recompute(prismContext.getDefaultPolyStringNormalizer());
   return polyString;
 }
 private String polyStringNorm(String orig) {
   return prismContext.getDefaultPolyStringNormalizer().normalize(orig);
 }
Esempio n. 26
0
 private Class getClassForType(QName type) {
   return prismContext.getSchemaRegistry().determineCompileTimeClass(type);
 }
Esempio n. 27
0
  /**
   * Retrieves all definitions. Augments them by count of campaigns (all + open ones).
   *
   * <p>TODO query parameters, customizable sorting definitions and campaigns counts are expected to
   * be low, so we can afford to go through all of them here
   */
  public Collection<PrismObject<AccessCertificationDefinitionForReportType>>
      searchCertificationDefinitions()
          throws ConfigurationException, SchemaException, ObjectNotFoundException,
              CommunicationException, SecurityViolationException {

    Task task = taskManager.createTaskInstance();
    OperationResult result = task.getResult();
    Collection<SelectorOptions<GetOperationOptions>> options =
        SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
    List<PrismObject<AccessCertificationDefinitionType>> definitions =
        model.searchObjects(AccessCertificationDefinitionType.class, null, options, task, result);
    final Map<String, PrismObject<AccessCertificationDefinitionForReportType>>
        definitionsForReportMap = new HashMap<>();
    for (PrismObject<AccessCertificationDefinitionType> definition : definitions) {
      // create subclass with the values copied from the superclass
      PrismObject<AccessCertificationDefinitionForReportType> definitionForReport =
          prismContext
              .createObjectable(AccessCertificationDefinitionForReportType.class)
              .asPrismObject();
      for (Item<?, ?> item : definition.getValue().getItems()) {
        definitionForReport.getValue().add(item.clone());
      }
      definitionsForReportMap.put(definition.getOid(), definitionForReport);
    }

    ResultHandler<AccessCertificationCampaignType> handler =
        new ResultHandler<AccessCertificationCampaignType>() {
          @Override
          public boolean handle(
              PrismObject<AccessCertificationCampaignType> campaignObject,
              OperationResult parentResult) {
            AccessCertificationCampaignType campaign = campaignObject.asObjectable();
            if (campaign.getDefinitionRef() != null) {
              String definitionOid = campaign.getDefinitionRef().getOid();
              PrismObject<AccessCertificationDefinitionForReportType> definitionObject =
                  definitionsForReportMap.get(definitionOid);
              if (definitionObject != null) {
                AccessCertificationDefinitionForReportType definition =
                    definitionObject.asObjectable();
                int campaigns = definition.getCampaigns() != null ? definition.getCampaigns() : 0;
                definition.setCampaigns(campaigns + 1);
                AccessCertificationCampaignStateType state = campaign.getState();
                if (state != AccessCertificationCampaignStateType.CREATED && state != CLOSED) {
                  int openCampaigns =
                      definition.getOpenCampaigns() != null ? definition.getOpenCampaigns() : 0;
                  definition.setOpenCampaigns(openCampaigns + 1);
                }
              }
            }
            return true;
          }
        };
    model.searchObjectsIterative(
        AccessCertificationCampaignType.class, null, handler, null, task, result);

    List<PrismObject<AccessCertificationDefinitionForReportType>> rv =
        new ArrayList<>(definitionsForReportMap.values());
    Collections.sort(
        rv,
        new Comparator<PrismObject<AccessCertificationDefinitionForReportType>>() {
          @Override
          public int compare(
              PrismObject<AccessCertificationDefinitionForReportType> o1,
              PrismObject<AccessCertificationDefinitionForReportType> o2) {
            String n1 = o1.asObjectable().getName().getOrig();
            String n2 = o2.asObjectable().getName().getOrig();
            if (n1 == null) {
              n1 = "";
            }
            return n1.compareTo(n2);
          }
        });
    for (PrismObject<AccessCertificationDefinitionForReportType> defObject : rv) {
      AccessCertificationDefinitionForReportType def = defObject.asObjectable();
      if (def.getCampaigns() == null) {
        def.setCampaigns(0);
      }
      if (def.getOpenCampaigns() == null) {
        def.setOpenCampaigns(0);
      }
    }
    return rv;
  }
Esempio n. 28
0
  // normally this method returns an InputPanel;
  // however, for some special readonly types (like ObjectDeltaType) it will return a Panel
  private Panel createTypedInputComponent(String id) {
    //        ValueWrapper valueWrapper = model.getObject();
    //        ItemWrapper itemWrapper =
    final Item item = valueWrapperModel.getObject().getItem().getItem();

    Panel panel = null;
    if (item instanceof PrismProperty) {
      final PrismProperty property = (PrismProperty) item;
      PrismPropertyDefinition definition = property.getDefinition();
      final QName valueType = definition.getTypeName();

      final String baseExpression = "value.value"; // pointing to prism property real value

      // fixing MID-1230, will be improved with some kind of annotation or something like that
      // now it works only in description
      if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
        return new TextAreaPanel(id, new PropertyModel(valueWrapperModel, baseExpression), null);
      }

      if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
        return WebComponentUtil.createEnumPanel(
            ActivationStatusType.class,
            id,
            new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression),
            this);
      } else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
        return new LockoutStatusPanel(
            id, new PropertyModel<LockoutStatusType>(valueWrapperModel, baseExpression));
      } else {
        // nothing to do
      }

      if (DOMUtil.XSD_DATETIME.equals(valueType)) {
        panel =
            new DatePanel(
                id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));

      } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
        boolean showRemovePasswordButton = true;
        if (pageBase instanceof PageUser
            && ((PageUser) pageBase).getObjectWrapper().getObject() != null
            && ((PageUser) pageBase).getObjectWrapper().getObject().getOid() != null
            && ((PageUser) pageBase)
                .getObjectWrapper()
                .getObject()
                .getOid()
                .equals(SecurityUtils.getPrincipalUser().getOid())) {
          showRemovePasswordButton = false;
        }
        panel =
            new PasswordPanel(
                id,
                new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression),
                valueWrapperModel.getObject().isReadonly(),
                showRemovePasswordButton);
      } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
        panel =
            new TriStateComboPanel(
                id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));

      } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
        InputPanel inputPanel;
        PrismPropertyDefinition def = property.getDefinition();

        if (def.getValueEnumerationRef() != null) {
          PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
          String lookupTableUid = valueEnumerationRef.getOid();
          Task task = pageBase.createSimpleTask("loadLookupTable");
          OperationResult result = task.getResult();

          Collection<SelectorOptions<GetOperationOptions>> options =
              SelectorOptions.createCollection(
                  LookupTableType.F_ROW,
                  GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
          final PrismObject<LookupTableType> lookupTable =
              WebModelServiceUtils.loadObject(
                  LookupTableType.class, lookupTableUid, options, pageBase, task, result);

          if (lookupTable != null) {

            inputPanel =
                new AutoCompleteTextPanel<String>(
                    id,
                    new LookupPropertyModel<String>(
                        valueWrapperModel, baseExpression + ".orig", lookupTable.asObjectable()),
                    String.class) {

                  @Override
                  public Iterator<String> getIterator(String input) {
                    return prepareAutoCompleteList(input, lookupTable).iterator();
                  }
                };

          } else {
            inputPanel =
                new TextPanel<>(
                    id,
                    new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"),
                    String.class);
          }

        } else {

          inputPanel =
              new TextPanel<>(
                  id,
                  new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"),
                  String.class);
        }

        if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
          inputPanel.getBaseFormComponent().setRequired(true);
        }
        panel = inputPanel;

      } else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
        panel =
            new UploadDownloadPanel(id, valueWrapperModel.getObject().isReadonly()) {

              @Override
              public InputStream getStream() {
                Object object =
                    ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
                return object != null
                    ? new ByteArrayInputStream((byte[]) object)
                    : new ByteArrayInputStream(new byte[0]);
                //                		return super.getStream();
              }

              @Override
              public void updateValue(byte[] file) {
                ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).setValue(file);
              }

              @Override
              public void uploadFilePerformed(AjaxRequestTarget target) {
                super.uploadFilePerformed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
              }

              @Override
              public void removeFilePerformed(AjaxRequestTarget target) {
                super.removeFilePerformed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
              }

              @Override
              public void uploadFileFailed(AjaxRequestTarget target) {
                super.uploadFileFailed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                target.add(((PageBase) getPage()).getFeedbackPanel());
              }
            };

      } else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
        panel =
            new ModificationsPanel(
                id,
                new AbstractReadOnlyModel<DeltaDto>() {
                  @Override
                  public DeltaDto getObject() {
                    if (valueWrapperModel.getObject() == null
                        || valueWrapperModel.getObject().getValue() == null
                        || ((PrismPropertyValue) valueWrapperModel.getObject().getValue())
                                .getValue()
                            == null) {
                      return null;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    ObjectDeltaType objectDeltaType =
                        (ObjectDeltaType)
                            ((PrismPropertyValue) valueWrapperModel.getObject().getValue())
                                .getValue();
                    try {
                      ObjectDelta delta =
                          DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
                      return new DeltaDto(delta);
                    } catch (SchemaException e) {
                      throw new IllegalStateException(
                          "Couldn't convert object delta: " + objectDeltaType);
                    }
                  }
                });
      } else if (QueryType.COMPLEX_TYPE.equals(valueType)
          || CleanupPoliciesType.COMPLEX_TYPE.equals(valueType)) {
        return new TextAreaPanel(
            id,
            new AbstractReadOnlyModel() {
              @Override
              public Object getObject() {
                if (valueWrapperModel.getObject() == null
                    || valueWrapperModel.getObject().getValue() == null) {
                  return null;
                }
                PrismPropertyValue ppv =
                    (PrismPropertyValue) valueWrapperModel.getObject().getValue();
                if (ppv == null || ppv.getValue() == null) {
                  return null;
                }
                QName name = property.getElementName();
                if (name == null && property.getDefinition() != null) {
                  name = property.getDefinition().getName();
                }
                if (name == null) {
                  name = SchemaConstants.C_VALUE;
                }
                PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                try {
                  return prismContext.serializeAnyData(ppv.getValue(), name, PrismContext.LANG_XML);
                } catch (SchemaException e) {
                  throw new SystemException(
                      "Couldn't serialize property value of type: "
                          + valueType
                          + ": "
                          + e.getMessage(),
                      e);
                }
              }
            },
            10);
      } else {
        Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
        if (type != null && type.isPrimitive()) {
          type = ClassUtils.primitiveToWrapper(type);
        }

        if (isEnum(property)) {
          return WebComponentUtil.createEnumPanel(
              definition, id, new PropertyModel<>(valueWrapperModel, baseExpression), this);
        }
        //                  // default QName validation is a bit weird, so let's treat QNames as
        // strings [TODO finish this - at the parsing side]
        //                  if (type == QName.class) {
        //                      type = String.class;
        //                  }

        PrismPropertyDefinition def = property.getDefinition();

        if (def.getValueEnumerationRef() != null) {
          PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
          String lookupTableUid = valueEnumerationRef.getOid();
          Task task = pageBase.createSimpleTask("loadLookupTable");
          OperationResult result = task.getResult();

          Collection<SelectorOptions<GetOperationOptions>> options =
              SelectorOptions.createCollection(
                  LookupTableType.F_ROW,
                  GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
          final PrismObject<LookupTableType> lookupTable =
              WebModelServiceUtils.loadObject(
                  LookupTableType.class, lookupTableUid, options, pageBase, task, result);

          if (lookupTable != null) {

            panel =
                new AutoCompleteTextPanel<String>(
                    id,
                    new LookupPropertyModel<String>(
                        valueWrapperModel,
                        baseExpression,
                        lookupTable == null ? null : lookupTable.asObjectable()),
                    type) {

                  @Override
                  public Iterator<String> getIterator(String input) {
                    return prepareAutoCompleteList(input, lookupTable).iterator();
                  }

                  @Override
                  public void checkInputValue(
                      AutoCompleteTextField input,
                      AjaxRequestTarget target,
                      LookupPropertyModel model) {
                    Iterator<String> lookupTableValuesIterator =
                        prepareAutoCompleteList("", lookupTable).iterator();

                    String value = input.getInput();
                    boolean isValueExist = false;
                    if (value != null) {
                      if (value.trim().equals("")) {
                        isValueExist = true;
                      } else {
                        while (lookupTableValuesIterator.hasNext()) {
                          String lookupTableValue = lookupTableValuesIterator.next();
                          if (value.trim().equals(lookupTableValue)) {
                            isValueExist = true;
                            break;
                          }
                        }
                      }
                    }
                    if (isValueExist) {
                      input.setModelValue(new String[] {value});
                      target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    } else {
                      input.error(
                          "Entered value doesn't match any of available values and will not be saved.");
                      target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    }
                  }
                };

          } else {

            panel =
                new TextPanel<>(
                    id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
          }

        } else {
          panel =
              new TextPanel<>(
                  id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
        }
      }
    } else if (item instanceof PrismReference) {
      PrismContext prismContext = item.getPrismContext();
      if (prismContext == null) {
        prismContext = pageBase.getPrismContext();
      }
      QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
      Class targetClass = null;
      if (targetTypeName != null && prismContext != null) {
        targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
      }
      final Class typeClass =
          targetClass != null
              ? targetClass
              : (item.getDefinition().getTypeClassIfKnown() != null
                  ? item.getDefinition().getTypeClassIfKnown()
                  : FocusType.class);
      Collection typeClasses = new ArrayList();

      // HACK HACK MID-3201 MID-3231
      if (isUserOrgItem(item, typeClass)) {
        typeClasses.add(UserType.class);
        typeClasses.add(OrgType.class);
      } else {
        typeClasses.add(typeClass);
      }

      panel =
          new ValueChoosePanel(
              id,
              new PropertyModel<>(valueWrapperModel, "value"),
              item.getValues(),
              false,
              typeClasses);

    } else if (item instanceof PrismContainer<?>) {
      AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
      final PrismContainer container = (PrismContainer) item;
      PrismContainerDefinition definition = container.getDefinition();
      QName valueType = definition.getTypeName();

      if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {

        PrismContext prismContext = item.getPrismContext();
        if (prismContext == null) {
          prismContext = pageBase.getPrismContext();
        }

        ShadowType shadowType =
            ((ShadowType) itemWrapper.getContainer().getObject().getObject().asObjectable());
        PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
        // 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(shadowType.asPrismObject());
        } catch (SchemaException e) {
          throw new SystemException(e.getMessage(), e);
        }
        RefinedAssociationDefinition assocDef = itemWrapper.getRefinedAssociationDefinition();
        RefinedObjectClassDefinition assocTargetDef = assocDef.getAssociationTarget();

        ObjectQuery query =
            getAssociationsSearchQuery(
                prismContext,
                resource,
                assocTargetDef.getTypeName(),
                assocTargetDef.getKind(),
                assocTargetDef.getIntent());

        List values = item.getValues();
        return new AssociationValueChoicePanel(
            id, valueWrapperModel, values, false, ShadowType.class, query, assocTargetDef);
      }
    }

    return panel;
  }