Search in sources :

Example 1 with SchemaHandlingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType in project midpoint by Evolveum.

the class PageAccounts method createIntentChoices.

private IModel<List<String>> createIntentChoices() {
    return new AbstractReadOnlyModel<List<String>>() {

        @Override
        public List<String> getObject() {
            List<String> intentList = new ArrayList<>();
            ResourceItemDto dto = resourceModel.getObject();
            PrismObject<ResourceType> resourcePrism;
            if (dto == null) {
                return intentList;
            }
            String oid = dto.getOid();
            OperationResult result = new OperationResult(OPERATION_GET_INTENTS);
            try {
                resourcePrism = getModelService().getObject(ResourceType.class, oid, null, createSimpleTask(OPERATION_GET_INTENTS), result);
                ResourceType resource = resourcePrism.asObjectable();
                SchemaHandlingType schemaHandling = resource.getSchemaHandling();
                for (ResourceObjectTypeDefinitionType r : schemaHandling.getObjectType()) {
                    intentList.add(r.getIntent());
                }
            } catch (Exception e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load intents from resource.", e);
                error("Couldn't load intents from resource.");
                return null;
            }
            return intentList;
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ResourceItemDto(com.evolveum.midpoint.web.page.admin.configuration.dto.ResourceItemDto) ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) ArrayList(java.util.ArrayList) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 2 with SchemaHandlingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType in project midpoint by Evolveum.

the class TestSanity method checkOpenDjSchemaHandling.

private void checkOpenDjSchemaHandling(ResourceType resource, String source) {
    SchemaHandlingType schemaHandling = resource.getSchemaHandling();
    for (ResourceObjectTypeDefinitionType resObjectTypeDef : schemaHandling.getObjectType()) {
        if (resObjectTypeDef.getKind() == ShadowKindType.ACCOUNT) {
            String name = resObjectTypeDef.getIntent();
            assertNotNull("Resource " + resource + " from " + source + " has an schemaHandlig account definition without intent", name);
            assertNotNull("Account type " + name + " in " + resource + " from " + source + " does not have object class", resObjectTypeDef.getObjectClass());
        }
        if (resObjectTypeDef.getKind() == ShadowKindType.ENTITLEMENT) {
            String name = resObjectTypeDef.getIntent();
            assertNotNull("Resource " + resource + " from " + source + " has an schemaHandlig entitlement definition without intent", name);
            assertNotNull("Entitlement type " + name + " in " + resource + " from " + source + " does not have object class", resObjectTypeDef.getObjectClass());
        }
    }
}
Also used : SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)

Example 3 with SchemaHandlingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType in project midpoint by Evolveum.

the class ConsistencyTest method test124AddAccountDirectAlreadyExists.

//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
    final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    Task task = taskManager.createTaskInstance();
    SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo.getSchemaHandling();
    SynchronizationType oldSynchronization = resourceTypeOpenDjrepo.getSynchronization();
    try {
        // we will reapply this schema handling after this test finish
        ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
        assertNotNull("null definition for sync delta", syncDef);
        ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
        ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
        repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
        requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA, RESOURCE_OPENDJ_OID, ResourceType.class, task, null, parentResult);
        PrismObject<ResourceType> res = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, parentResult);
        // LOGGER.trace("resource schema handling after modify: {}",
        // prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
        repoAddObjectFromFile(USER_ABOMBA_FILENAME, parentResult);
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, parentResult);
        String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
        ShadowType abombaShadow = repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult).asObjectable();
        assertShadowName(abombaShadow, "uid=abomba,OU=people,DC=example,DC=com");
        repoAddObjectFromFile(USER_ABOM_FILENAME, parentResult);
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOM_OID, UserType.class, task, null, parentResult);
        String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
        ShadowType abomShadow = repositoryService.getObject(ShadowType.class, abomOid, null, parentResult).asObjectable();
        assertShadowName(abomShadow, "uid=abomba1,OU=people,DC=example,DC=com");
        ReferenceDelta abombaDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, new PrismReferenceValue(abombaOid));
        ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID, abombaDeleteAccDelta, UserType.class, prismContext);
        modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task, parentResult);
        assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
        repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult);
        ReferenceDelta abomDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, abomShadow.asPrismObject());
        ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID, abomDeleteAccDelta, UserType.class, prismContext);
        modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task, parentResult);
        assertUserNoAccountRef(USER_ABOM_OID, parentResult);
        try {
            repositoryService.getObject(ShadowType.class, abomOid, null, parentResult);
            fail("Expected that shadow abom does not exist, but it is");
        } catch (ObjectNotFoundException ex) {
        // this is expected
        } catch (Exception ex) {
            fail("Expected object not found exception but got " + ex);
        }
        LOGGER.info("starting second execution request for user abomba");
        OperationResult result = new OperationResult("Add account already exist result.");
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, result);
        String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
        ShadowType abombaShadow2 = repositoryService.getObject(ShadowType.class, abombaOid2, null, result).asObjectable();
        assertShadowName(abombaShadow2, "uid=abomba,OU=people,DC=example,DC=com");
        result.computeStatus();
        LOGGER.info("Displaying execute changes result");
        display(result);
        // return the previous changes of resource back
        Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta.createModificationReplaceContainerCollection(ResourceType.F_SCHEMA_HANDLING, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
        PropertyDelta syncDelta = PropertyDelta.createModificationReplaceProperty(ResourceType.F_SYNCHRONIZATION, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSynchronization);
        ((Collection) schemaHandlingDelta).add(syncDelta);
        repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
    } catch (Exception ex) {
        LOGGER.info("error: " + ex.getMessage(), ex);
        throw ex;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) JAXBException(javax.xml.bind.JAXBException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 4 with SchemaHandlingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType in project midpoint by Evolveum.

the class ResourceCarefulAntUtil method initAnts.

public static void initAnts(List<CarefulAnt<ResourceType>> ants, final File resourceFile, final PrismContext prismContext) {
    final PrismObjectDefinition<ResourceType> resourceDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class);
    ants.add(new CarefulAnt<ResourceType>() {

        @Override
        public ItemDelta<?, ?> createDelta(int iteration) {
            return prismContext.deltaFactory().property().createModificationReplaceProperty(ResourceType.F_DESCRIPTION, resourceDef, "Blah " + iteration);
        }

        @Override
        public void assertModification(PrismObject<ResourceType> resource, int iteration) {
            assertEquals("Wrong description in iteration " + iteration, "Blah " + iteration, resource.asObjectable().getDescription());
        }
    });
    ants.add(new CarefulAnt<ResourceType>() {

        SchemaHandlingType schemaHandling;

        @Override
        public ItemDelta<?, ?> createDelta(int iteration) throws SchemaException {
            schemaHandling = createNewSchemaHandling(resourceFile, iteration, prismContext);
            return prismContext.deltaFactory().container().createModificationReplace(ResourceType.F_SCHEMA_HANDLING, prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class), schemaHandling.asPrismContainerValue().clone());
        }

        @Override
        public void assertModification(PrismObject<ResourceType> resource, int iteration) {
            if (!schemaHandling.equals(resource.asObjectable().getSchemaHandling())) {
                System.out.println("Expected: " + PrismUtil.serializeQuietly(prismContext, schemaHandling));
                System.out.println("Real: " + PrismUtil.serializeQuietly(prismContext, resource.asObjectable().getSchemaHandling()));
                fail("Wrong schemaHandling in iteration" + iteration);
            }
        // assertEquals("Wrong schemaHandling in iteration "+iteration, schemaHandling, resource.asObjectable().getSchemaHandling());
        }
    });
    ants.add(new CarefulAnt<ResourceType>() {

        SchemaDefinitionType xmlSchemaDef;

        @Override
        public ItemDelta<?, ?> createDelta(int iteration) throws SchemaException {
            xmlSchemaDef = createNewXmlSchemaDef(resourceFile, iteration, prismContext);
            return prismContext.deltaFactory().property().createModificationReplaceProperty(ItemPath.create(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), resourceDef, xmlSchemaDef);
        }

        @Override
        public void assertModification(PrismObject<ResourceType> resource, int iteration) {
            List<Element> orgigElements = xmlSchemaDef.getAny();
            List<Element> newElements = resource.asObjectable().getSchema().getDefinition().getAny();
            assertEquals("Wrong number of elements in schema definition in iteration " + iteration, orgigElements.size(), newElements.size());
        // TODO look inside elements
        }
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) List(java.util.List)

Example 5 with SchemaHandlingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType in project midpoint by Evolveum.

the class ResourceCarefulAntUtil method createNewSchemaHandling.

private static SchemaHandlingType createNewSchemaHandling(File resourceFile, int iteration, PrismContext prismContext) throws SchemaException {
    PrismObject<ResourceType> resource = parseResource(resourceFile, prismContext);
    SchemaHandlingType schemaHandling = resource.asObjectable().getSchemaHandling();
    ResourceObjectTypeDefinitionType accountType = schemaHandling.getObjectType().iterator().next();
    List<ResourceAttributeDefinitionType> attrDefs = accountType.getAttribute();
    ResourceAttributeDefinitionType attributeDefinitionType = attrDefs.get(rnd.nextInt(attrDefs.size()));
    attributeDefinitionType.setDescription(Integer.toString(iteration));
    return schemaHandling;
}
Also used : SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Aggregations

SchemaHandlingType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType)6 ResourceObjectTypeDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 CommonException (com.evolveum.midpoint.util.exception.CommonException)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 IOException (java.io.IOException)2 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)1 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 VariableItemPathSegment (com.evolveum.midpoint.prism.path.VariableItemPathSegment)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)1