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()); }
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); }
private PrismContainerDefinition<ActivationType> getActivationDefinition() { if (activationDefinition == null) { ComplexTypeDefinition focusDefinition = prismContext.getSchemaRegistry().findComplexTypeDefinition(FocusType.COMPLEX_TYPE); activationDefinition = focusDefinition.findContainerDefinition(FocusType.F_ACTIVATION); } return activationDefinition; }
private <T extends ShadowType> PrismObjectDefinition<T> getShadowDefinition(Class<T> type) { return prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type); }
private Class getClassForType(QName type) { return prismContext.getSchemaRegistry().determineCompileTimeClass(type); }
// 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 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; }
// 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; }