use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestRefinedSchema method assertAccountObjectDefinition.
private void assertAccountObjectDefinition(ResourceObjectDefinition accountDef, LayerType sourceLayer, LayerType validationLayer) {
assertRObjectClassDef(accountDef, sourceLayer, validationLayer);
System.out.println("Refined account definition:");
System.out.println(accountDef.debugDump());
if (accountDef instanceof ResourceObjectTypeDefinition) {
assertEquals("Wrong kind", ShadowKindType.ACCOUNT, ((ResourceObjectTypeDefinition) accountDef).getKind());
}
Collection<? extends ResourceAttributeDefinition<?>> accAttrsDef = accountDef.getAttributeDefinitions();
assertNotNull("Null attributeDefinitions", accAttrsDef);
assertFalse("Empty attributeDefinitions", accAttrsDef.isEmpty());
assertEquals("Unexpected number of attributeDefinitions", 55, accAttrsDef.size());
ResourceAttributeDefinition<?> disabledAttribute = accountDef.findAttributeDefinition("ds-pwp-account-disabled");
assertNotNull("No ds-pwp-account-disabled attribute", disabledAttribute);
assertTrue("ds-pwp-account-disabled not ignored", disabledAttribute.isIgnored());
ResourceAttributeDefinition<?> displayNameAttributeDef = accountDef.getDisplayNameAttribute();
assertNotNull("No account displayNameAttribute", displayNameAttributeDef);
assertEquals("Wrong account displayNameAttribute", new QName(MidPointConstants.NS_RI, "uid"), displayNameAttributeDef.getItemName());
// This is compatibility with PrismContainerDefinition, it should work well
Collection<? extends ItemDefinition<?>> propertyDefinitions = accountDef.getDefinitions();
assertNotNull("Null propertyDefinitions", propertyDefinitions);
assertFalse("Empty propertyDefinitions", propertyDefinitions.isEmpty());
assertEquals("Unexpected number of propertyDefinitions", 55, propertyDefinitions.size());
ResourceAttributeContainerDefinition resAttrContainerDef = accountDef.toResourceAttributeContainerDefinition();
assertNotNull("No ResourceAttributeContainerDefinition", resAttrContainerDef);
System.out.println("\nResourceAttributeContainerDefinition (" + sourceLayer + ")");
System.out.println(resAttrContainerDef.debugDump());
ResourceObjectDefinition rComplexTypeDefinition = resAttrContainerDef.getComplexTypeDefinition();
System.out.println("\nResourceAttributeContainerDefinition ComplexTypeDefinition (" + sourceLayer + ")");
System.out.println(rComplexTypeDefinition.debugDump());
if (accountDef instanceof ResourceObjectTypeDefinition) {
assertRefinedToLayer(rComplexTypeDefinition, sourceLayer);
}
ResourceAttributeDefinition<?> riUidAttrDef = resAttrContainerDef.findAttributeDefinition(new ItemName(MidPointConstants.NS_RI, "uid"));
assertNotNull("No ri:uid def in ResourceAttributeContainerDefinition", riUidAttrDef);
System.out.println("\nri:uid def " + riUidAttrDef.getClass() + " (" + sourceLayer + ")");
System.out.println(riUidAttrDef.debugDump());
if (accountDef instanceof ResourceObjectTypeDefinition) {
assertRefinedToLayer(riUidAttrDef, sourceLayer);
if (validationLayer == LayerType.PRESENTATION) {
assertFalse("Can update " + riUidAttrDef + " from ResourceAttributeContainerDefinition (" + sourceLayer + ")", riUidAttrDef.canModify());
} else {
assertTrue("Cannot update " + riUidAttrDef + " from ResourceAttributeContainerDefinition (" + sourceLayer + ")", riUidAttrDef.canModify());
}
Collection<? extends ResourceAttributeDefinition<?>> definitionsFromResAttrContainerDef = resAttrContainerDef.getDefinitions();
for (ResourceAttributeDefinition<?> definitionFromResAttrContainerDef : definitionsFromResAttrContainerDef) {
assertRefinedToLayer(definitionFromResAttrContainerDef, sourceLayer);
}
}
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class BasicValidatorTest method resource1Valid.
@Test
public void resource1Valid() throws Exception {
OperationResult result = createOperationResult();
EventHandler<Objectable> handler = new EventHandler<>() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
return EventResult.cont();
}
@Override
public EventResult postMarshall(Objectable object, Element objectElement, OperationResult objectResult) {
PrismObject<?> prismObject = object.asPrismObject();
displayDumpable("Validating resource:", prismObject);
prismObject.checkConsistence();
PrismContainer<?> extensionContainer = prismObject.getExtension();
PrismProperty<Integer> menProp = extensionContainer.findProperty(new ItemName("http://myself.me/schemas/whatever", "menOnChest"));
assertNotNull("No men on a dead man chest!", menProp);
assertEquals("Wrong number of men on a dead man chest", (Integer) 15, menProp.getAnyRealValue());
PrismPropertyDefinition<?> menPropDef = menProp.getDefinition();
assertNotNull("Men on a dead man chest NOT defined", menPropDef);
assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName());
assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic());
return EventResult.cont();
}
@Override
public void handleGlobalError(OperationResult currentResult) {
/* nothing */
}
};
validateFile("resource-1-valid.xml", handler, result);
AssertJUnit.assertTrue(result.isSuccess());
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ResourceAttributeRefPanelFactory method getChoicesList.
private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
PrismPropertyWrapper<?> wrapper = ctx.unwrapWrapperModel();
// attribute/ref
if (wrapper == null) {
return Collections.emptyList();
}
// attribute value
if (wrapper.getParent() == null) {
return Collections.emptyList();
}
// attribute
ItemWrapper<?, ?> attributeWrapper = wrapper.getParent().getParent();
if (attributeWrapper == null) {
return Collections.emptyList();
}
PrismContainerValueWrapper<?> itemWrapper = attributeWrapper.getParent();
if (itemWrapper == null) {
return Collections.emptyList();
}
if (!(itemWrapper instanceof ConstructionValueWrapper)) {
return Collections.emptyList();
}
ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;
try {
ResourceSchema schema = constructionWrapper.getRefinedSchema();
if (schema == null) {
return new ArrayList<>();
}
ResourceObjectDefinition rOcd = schema.findObjectDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
if (rOcd == null) {
return Collections.emptyList();
}
if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
Collection<ResourceAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
return associationDefs.stream().map(ResourceAssociationDefinition::getName).collect(Collectors.toList());
}
Collection<? extends ResourceAttributeDefinition<?>> attrDefs = rOcd.getAttributeDefinitions();
return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
} catch (SchemaException e) {
LOGGER.warn("Cannot get resource attribute definitions");
}
return Collections.emptyList();
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ChildOfReportParamWrapperFactory method createWrapper.
@Override
public PrismReferenceWrapper<R> createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException {
ItemName name = def.getItemName();
Item<PrismValue, ItemDefinition> childItem = parent.getNewValue().findItem(name);
if ((skipCreateWrapper(def, ItemStatus.NOT_CHANGED, context, childItem == null || CollectionUtils.isEmpty(childItem.getValues()))) || !(childItem.getRealValue() instanceof RawType)) {
LOGGER.trace("Skipping creating wrapper for non-existent item. It is not supported for {}", def);
if (parent != null && parent.getNewValue() != null) {
parent.getNewValue().remove(childItem);
}
return null;
}
if (childItem == null) {
childItem = parent.getNewValue().findOrCreateItem(name);
}
PrismReference newItem = (PrismReference) def.instantiate();
ObjectReferenceType parsedRealValue = ((RawType) childItem.getRealValue()).getParsedRealValue(ObjectReferenceType.class);
newItem.add(parsedRealValue.asReferenceValue());
PrismReferenceWrapper<R> itemWrapper = createWrapperInternal(parent, newItem, ItemStatus.NOT_CHANGED, context);
itemWrapper.setMetadata(context.isMetadata());
itemWrapper.setProcessProvenanceMetadata(context.isProcessMetadataFor(itemWrapper.getPath()));
registerWrapperPanel(itemWrapper);
List<PrismReferenceValueWrapperImpl<R>> valueWrappers = createValuesWrapper(itemWrapper, newItem, context);
itemWrapper.getValues().addAll(valueWrappers);
itemWrapper.setShowEmpty(context.isShowEmpty(), false);
setupWrapper(itemWrapper);
return itemWrapper;
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ConstructionAssociationPanel method addNewShadowRefValuePerformed.
private void addNewShadowRefValuePerformed(AjaxRequestTarget target, ResourceAssociationDefinition def) {
ObjectFilter filter = WebComponentUtil.createAssociationShadowRefFilter(def, getPageBase().getPrismContext(), resourceModel.getObject().getOid());
ObjectBrowserPanel<ShadowType> objectBrowserPanel = new ObjectBrowserPanel<ShadowType>(getPageBase().getMainPopupBodyId(), ShadowType.class, Collections.singletonList(ShadowType.COMPLEX_TYPE), false, getPageBase(), filter) {
private static final long serialVersionUID = 1L;
@Override
protected void onSelectPerformed(AjaxRequestTarget target, ShadowType object) {
getPageBase().hideMainPopup(target);
try {
PrismContainerWrapper<ConstructionType> constructionContainerWrapper = ConstructionAssociationPanel.this.getModelObject();
PrismContainerWrapper<ResourceObjectAssociationType> associationWrapper = constructionContainerWrapper.findContainer(ConstructionType.F_ASSOCIATION);
List<PrismContainerValue<ResourceObjectAssociationType>> associationValueList = associationWrapper.getItem().getValues();
PrismContainerValue<ResourceObjectAssociationType> associationValue;
if (CollectionUtils.isEmpty(associationValueList)) {
associationValue = associationWrapper.getItem().createNewValue();
} else {
associationValue = associationValueList.get(0);
}
ItemName associationRefPath = def.getName();
associationValue.asContainerable().setRef(new ItemPathType(associationRefPath));
ExpressionType newAssociationExpression = associationValue.asContainerable().beginOutbound().beginExpression();
ExpressionUtil.addShadowRefEvaluatorValue(newAssociationExpression, object.getOid(), getPageBase().getPrismContext());
} catch (SchemaException ex) {
LOGGER.error("Couldn't find association container: {}", ex.getLocalizedMessage());
}
target.add(ConstructionAssociationPanel.this);
}
};
getPageBase().showMainPopup(objectBrowserPanel, target);
}
Aggregations