Search in sources :

Example 21 with ItemDefinition

use of com.evolveum.midpoint.prism.ItemDefinition 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 22 with ItemDefinition

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

the class AssignmentTablePanel method handleModifyAssignmentDelta.

private void handleModifyAssignmentDelta(AssignmentEditorDto assDto, PrismContainerDefinition assignmentDef, PrismContainerValue newValue, ObjectDelta<T> userDelta) throws SchemaException {
    LOGGER.debug("Handling modified assignment '{}', computing delta.", new Object[] { assDto.getName() });
    PrismValue oldValue = assDto.getOldValue();
    Collection<? extends ItemDelta> deltas = oldValue.diff(newValue);
    for (ItemDelta delta : deltas) {
        ItemPath deltaPath = delta.getPath().rest();
        ItemDefinition deltaDef = assignmentDef.findItemDefinition(deltaPath);
        delta.setParentPath(WebComponentUtil.joinPath(oldValue.getPath(), delta.getPath().allExceptLast()));
        delta.applyDefinition(deltaDef);
        userDelta.addModification(delta);
    }
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with ItemDefinition

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

the class RObjectDeltaOperation method toRepo.

public static RObjectDeltaOperation toRepo(RAuditEventRecord record, ObjectDeltaOperation operation, PrismContext prismContext) throws DtoTranslationException {
    RObjectDeltaOperation auditDelta = new RObjectDeltaOperation();
    auditDelta.setRecord(record);
    try {
        if (operation.getObjectDelta() != null) {
            ObjectDelta delta = operation.getObjectDelta();
            String xmlDelta = DeltaConvertor.toObjectDeltaTypeXml(delta, DeltaConversionOptions.createSerializeReferenceNames());
            auditDelta.setDelta(xmlDelta);
            auditDelta.setDeltaOid(delta.getOid());
            auditDelta.setDeltaType(RUtil.getRepoEnumValue(delta.getChangeType(), RChangeType.class));
        }
        if (operation.getExecutionResult() != null) {
            ItemDefinition def = prismContext.getSchemaRegistry().findItemDefinitionByElementName(SchemaConstantsGenerated.C_OPERATION_RESULT);
            RUtil.copyResultFromJAXB(def, SchemaConstantsGenerated.C_OPERATION_RESULT, operation.getExecutionResult().createOperationResultType(), auditDelta, prismContext);
        }
        auditDelta.setObjectName(RPolyString.toRepo(operation.getObjectName()));
        auditDelta.setResourceOid(operation.getResourceOid());
        auditDelta.setResourceName(RPolyString.toRepo(operation.getResourceName()));
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
    return auditDelta;
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RChangeType(com.evolveum.midpoint.repo.sql.data.common.enums.RChangeType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 24 with ItemDefinition

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

the class QueryInterpreter2 method findAndCreateRestrictionInternal.

private <T extends ObjectFilter> Restriction findAndCreateRestrictionInternal(T filter, InterpretationContext context, Restriction parent, ItemPathResolver resolver, JpaEntityDefinition baseEntityDefinition) throws QueryException {
    if (filter instanceof AndFilter) {
        return new AndRestriction(context, (AndFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof OrFilter) {
        return new OrRestriction(context, (OrFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof NotFilter) {
        return new NotRestriction(context, (NotFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof FullTextFilter) {
        return new FullTextRestriction(context, (FullTextFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof InOidFilter) {
        return new InOidRestriction(context, (InOidFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof OrgFilter) {
        return new OrgRestriction(context, (OrgFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof TypeFilter) {
        TypeFilter typeFilter = (TypeFilter) filter;
        JpaEntityDefinition refinedEntityDefinition = resolver.findRestrictedEntityDefinition(baseEntityDefinition, typeFilter.getType());
        return new TypeRestriction(context, typeFilter, refinedEntityDefinition, parent);
    } else if (filter instanceof ExistsFilter) {
        ExistsFilter existsFilter = (ExistsFilter) filter;
        ItemPath path = existsFilter.getFullPath();
        ItemDefinition definition = existsFilter.getDefinition();
        ProperDataSearchResult<JpaDataNodeDefinition> searchResult = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaDataNodeDefinition.class, context.getPrismContext());
        if (searchResult == null) {
            throw new QueryException("Path for ExistsFilter (" + path + ") doesn't point to a hibernate entity or property within " + baseEntityDefinition);
        }
        return new ExistsRestriction(context, existsFilter, searchResult.getEntityDefinition(), parent);
    } else if (filter instanceof RefFilter) {
        RefFilter refFilter = (RefFilter) filter;
        ItemPath path = refFilter.getFullPath();
        ItemDefinition definition = refFilter.getDefinition();
        ProperDataSearchResult<JpaReferenceDefinition> searchResult = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaReferenceDefinition.class, context.getPrismContext());
        if (searchResult == null) {
            throw new QueryException("Path for RefFilter (" + path + ") doesn't point to a reference item within " + baseEntityDefinition);
        }
        return new ReferenceRestriction(context, refFilter, searchResult.getEntityDefinition(), parent, searchResult.getLinkDefinition());
    } else if (filter instanceof PropertyValueFilter) {
        PropertyValueFilter valFilter = (PropertyValueFilter) filter;
        ItemPath path = valFilter.getFullPath();
        ItemDefinition definition = valFilter.getDefinition();
        ProperDataSearchResult<JpaPropertyDefinition> propDefRes = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaPropertyDefinition.class, context.getPrismContext());
        if (propDefRes == null) {
            throw new QueryException("Couldn't find a proper data item to query, given base entity " + baseEntityDefinition + " and this filter: " + valFilter.debugDump());
        }
        // TODO can't be unified?
        if (propDefRes.getTargetDefinition() instanceof JpaAnyPropertyDefinition) {
            return new AnyPropertyRestriction(context, valFilter, propDefRes.getEntityDefinition(), parent, propDefRes.getLinkDefinition());
        } else {
            return new PropertyRestriction(context, valFilter, propDefRes.getEntityDefinition(), parent, propDefRes.getLinkDefinition());
        }
    } else if (filter instanceof NoneFilter || filter instanceof AllFilter || filter instanceof UndefinedFilter) {
        // these should be filtered out by the client
        throw new IllegalStateException("Trivial filters are not supported by QueryInterpreter: " + filter.debugDump());
    } else {
        throw new IllegalStateException("Unknown filter: " + filter.debugDump());
    }
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) ProperDataSearchResult(com.evolveum.midpoint.repo.sql.query2.resolution.ProperDataSearchResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 25 with ItemDefinition

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

the class RUser method copyFromJAXB.

public static void copyFromJAXB(UserType jaxb, RUser repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    RFocus.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
    repo.setFullName(RPolyString.copyFromJAXB(jaxb.getFullName()));
    repo.setGivenName(RPolyString.copyFromJAXB(jaxb.getGivenName()));
    repo.setFamilyName(RPolyString.copyFromJAXB(jaxb.getFamilyName()));
    repo.setHonorificPrefix(RPolyString.copyFromJAXB(jaxb.getHonorificPrefix()));
    repo.setHonorificSuffix(RPolyString.copyFromJAXB(jaxb.getHonorificSuffix()));
    repo.setEmployeeNumber(jaxb.getEmployeeNumber());
    repo.setLocalityUser(RPolyString.copyFromJAXB(jaxb.getLocality()));
    repo.setAdditionalName(RPolyString.copyFromJAXB(jaxb.getAdditionalName()));
    repo.setEmailAddress(jaxb.getEmailAddress());
    repo.setTelephoneNumber(jaxb.getTelephoneNumber());
    repo.setCostCenter(jaxb.getCostCenter());
    repo.setLocale(jaxb.getLocale());
    repo.setTimezone(jaxb.getTimezone());
    repo.setPreferredLanguage(jaxb.getPreferredLanguage());
    repo.setTitle(RPolyString.copyFromJAXB(jaxb.getTitle()));
    repo.setNickName(RPolyString.copyFromJAXB(jaxb.getNickName()));
    ItemDefinition def = jaxb.asPrismObject().getDefinition();
    RUtil.copyResultFromJAXB(def, jaxb.F_RESULT, jaxb.getResult(), repo, repositoryContext.prismContext);
    //sets
    repo.setEmployeeType(RUtil.listToSet(jaxb.getEmployeeType()));
    repo.setOrganizationalUnit(RUtil.listPolyToSet(jaxb.getOrganizationalUnit()));
    repo.setOrganization(RUtil.listPolyToSet(jaxb.getOrganization()));
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition)

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