Search in sources :

Example 11 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class TestJaxbSanity method testAssignmentEquals.

@Test
public void testAssignmentEquals() throws JAXBException, SchemaException, FileNotFoundException {
    System.out.println("\n\n ===[testAssnignmentEquals]===\n");
    // GIVEN
    JAXBElement<UserType> userEl1 = JaxbTestUtil.getInstance().unmarshalElement(new File(USER_BARBOSSA_FILENAME), UserType.class);
    UserType user = userEl1.getValue();
    assertNotNull(user);
    AssignmentType userAssignmentType = user.getAssignment().get(0);
    assertNotNull(userAssignmentType);
    System.out.println("\n*** user assignment");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(userAssignmentType));
    JAXBElement<ObjectModificationType> modEl = JaxbTestUtil.getInstance().unmarshalElement(new File(TEST_DIR, "user-barbossa-modify-delete-assignment-account-opendj-attr.xml"), ObjectModificationType.class);
    ObjectModificationType mod = modEl.getValue();
    assertNotNull(mod);
    //FIXME : modification value -> rawType...
    RawType rawType = mod.getItemDelta().get(0).getValue().get(0);
    ItemDefinition assignmentDefinition = PrismTestUtil.getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
    assertNotNull(assignmentDefinition);
    AssignmentType assignmentType = ((PrismContainerValue<AssignmentType>) rawType.getParsedValue(assignmentDefinition, null)).getValue();
    //                was: (JAXBElement<AssignmentType>) mod.getItemDelta().get(0).getValue().get(0).getContent().get(0);
    assertNotNull(assignmentType);
    System.out.println("\n*** assignment");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(assignmentType));
    // WHEN, THEN
    assertTrue("Assignment not equals", userAssignmentType.equals(assignmentType));
    assertTrue("HashCode does not match", userAssignmentType.hashCode() == assignmentType.hashCode());
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) File(java.io.File) Test(org.testng.annotations.Test)

Example 12 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class SearchPanel method createPropertiesList.

private List<Property> createPropertiesList() {
    List<Property> list = new ArrayList<>();
    Search search = getModelObject();
    List<ItemDefinition> defs = search.getAllDefinitions();
    for (ItemDefinition def : defs) {
        list.add(new Property(def));
    }
    Collections.sort(list);
    return list;
}
Also used : ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition)

Example 13 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class AssignmentEditorDto method prepareAssignmentAttributes.

private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignment, PageBase pageBase) {
    List<ACAttributeDto> acAtrList = new ArrayList<>();
    if (assignment == null || assignment.getConstruction() == null || assignment.getConstruction().getAttribute() == null || assignment.getConstruction() == null) {
        return acAtrList;
    }
    OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
    ConstructionType construction = assignment.getConstruction();
    PrismObject<ResourceType> resource = construction.getResource() != null ? construction.getResource().asPrismObject() : null;
    if (resource == null) {
        resource = getReference(construction.getResourceRef(), result, pageBase);
    }
    try {
        PrismContext prismContext = pageBase.getPrismContext();
        RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.PRESENTATION, prismContext);
        RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
        if (objectClassDefinition == null) {
            return attributes;
        }
        PrismContainerDefinition definition = objectClassDefinition.toResourceAttributeContainerDefinition();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
        }
        Collection<ItemDefinition> definitions = definition.getDefinitions();
        for (ResourceAttributeDefinitionType attribute : assignment.getConstruction().getAttribute()) {
            for (ItemDefinition attrDef : definitions) {
                if (attrDef instanceof PrismPropertyDefinition) {
                    PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) attrDef;
                    if (propertyDef.isOperational() || propertyDef.isIgnored()) {
                        continue;
                    }
                    if (ItemPathUtil.getOnlySegmentQName(attribute.getRef()).equals(propertyDef.getName())) {
                        acAtrList.add(ACAttributeDto.createACAttributeDto(propertyDef, attribute, prismContext));
                        break;
                    }
                }
            }
        }
        result.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
        result.recordFatalError("Exception occurred during assignment attribute loading.", ex);
    } finally {
        result.recomputeStatus();
    }
    return acAtrList;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 14 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test150CreateWrapperShadow.

@Test
public void test150CreateWrapperShadow() throws Exception {
    final String TEST_NAME = "test150CreateWrapperShadow";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<ShadowType> shadow = getShadowModel(accountJackOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
    ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING, task);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
    assertEquals("wrong number of containers in " + objectWrapper, 9, objectWrapper.getContainers().size());
    ContainerWrapper<ShadowAttributesType> attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "prismContainer.shadow.mainPanelDisplayName", new ItemPath(ShadowType.F_ATTRIBUTES), attributesContainer, true, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_JACK_FULL_NAME);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_JACK_USERNAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());
    ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
    WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    assertEquals("Wrong attributes container wrapper readOnly", Boolean.FALSE, (Boolean) attributesContainerWrapper.isReadonly());
    ItemWrapper fullnameWrapper = attributesContainerWrapper.findPropertyWrapper(dummyResourceCtl.getAttributeFullnameQName());
    // Is this OK?
    assertEquals("Wrong attribute fullname readOnly", Boolean.FALSE, (Boolean) fullnameWrapper.isReadonly());
    assertEquals("Wrong attribute fullname visible", Boolean.TRUE, (Boolean) fullnameWrapper.isVisible());
    ItemDefinition fullNameDefinition = fullnameWrapper.getItemDefinition();
    display("fullname attribute definition", fullNameDefinition);
    assertEquals("Wrong attribute fullname definition.canRead", Boolean.TRUE, (Boolean) fullNameDefinition.canRead());
    assertEquals("Wrong attribute fullname definition.canAdd", Boolean.TRUE, (Boolean) fullNameDefinition.canAdd());
    assertEquals("Wrong attribute fullname definition.canModify", Boolean.TRUE, (Boolean) fullNameDefinition.canModify());
    // MID-3144
    if (fullNameDefinition.getDisplayOrder() == null || fullNameDefinition.getDisplayOrder() < 100 || fullNameDefinition.getDisplayOrder() > 400) {
        AssertJUnit.fail("Wrong fullname definition.displayOrder: " + fullNameDefinition.getDisplayOrder());
    }
    assertEquals("Wrong attribute fullname definition.displayName", "Full Name", fullNameDefinition.getDisplayName());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemWrapper(com.evolveum.midpoint.web.component.prism.ItemWrapper) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 15 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.

the class ReportTypeUtil method applyConfigurationDefinition.

public static void applyConfigurationDefinition(PrismObject<ReportType> report, ObjectDelta delta, PrismContext prismContext) throws SchemaException {
    PrismSchema schema = ReportTypeUtil.parseReportConfigurationSchema(report, prismContext);
    PrismContainerDefinition<ReportConfigurationType> definition = ReportTypeUtil.findReportConfigurationDefinition(schema);
    if (definition == null) {
        //no definition found for container
        throw new SchemaException("Couldn't find definitions for report type " + report + ".");
    }
    Collection<ItemDelta> modifications = delta.getModifications();
    for (ItemDelta itemDelta : modifications) {
        if (itemDelta.hasCompleteDefinition()) {
            continue;
        }
        ItemDefinition def = definition.findItemDefinition(itemDelta.getPath().tail());
        if (def != null) {
            itemDelta.applyDefinition(def);
        }
    }
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ReportConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportConfigurationType)

Aggregations

ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)35 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)6 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 QName (javax.xml.namespace.QName)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)5 ArrayList (java.util.ArrayList)5 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismValue (com.evolveum.midpoint.prism.PrismValue)4 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)4 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)3 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)3 Task (com.evolveum.midpoint.task.api.Task)3