Search in sources :

Example 31 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method addTriggers.

protected void addTriggers(String oid, Collection<XMLGregorianCalendar> timestamps, String uri, boolean makeDistinct) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Task task = createPlainTask("addTriggers");
    OperationResult result = task.getResult();
    Collection<TriggerType> triggers = timestamps.stream().map(ts -> new TriggerType().timestamp(ts).handlerUri(uri)).map(ts -> makeDistinct ? addRandomValue(ts) : ts).collect(Collectors.toList());
    ObjectDelta<ObjectType> delta = prismContext.deltaFor(ObjectType.class).item(ObjectType.F_TRIGGER).addRealValues(triggers).asObjectDeltaCast(oid);
    executeChanges(delta, null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : com.evolveum.midpoint.model.test.asserter(com.evolveum.midpoint.model.test.asserter) StringUtils(org.apache.commons.lang.StringUtils) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) Entry(org.opends.server.types.Entry) com.evolveum.midpoint.test.asserter(com.evolveum.midpoint.test.asserter) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) MidpointFunctions(com.evolveum.midpoint.model.api.expr.MidpointFunctions) MutableInt(org.apache.commons.lang.mutable.MutableInt) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) TransportService(com.evolveum.midpoint.notifications.api.transports.TransportService) com.evolveum.prism.xml.ns._public.types_3(com.evolveum.prism.xml.ns._public.types_3) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Task(com.evolveum.midpoint.task.api.Task) TaskUtil(com.evolveum.midpoint.task.api.TaskUtil) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) FilterInvocation(org.springframework.security.web.FilterInvocation) ModuleWebSecurityConfiguration(com.evolveum.midpoint.authentication.api.ModuleWebSecurityConfiguration) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) QName(javax.xml.namespace.QName) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) FocusValuePolicyOriginResolver(com.evolveum.midpoint.model.common.stringpolicy.FocusValuePolicyOriginResolver) Clock(com.evolveum.midpoint.common.Clock) java.util(java.util) Authorization(com.evolveum.midpoint.security.api.Authorization) AuthenticationModuleNameConstants(com.evolveum.midpoint.authentication.api.util.AuthenticationModuleNameConstants) com.evolveum.midpoint.util(com.evolveum.midpoint.util) AuthenticationModuleState(com.evolveum.midpoint.authentication.api.AuthenticationModuleState) MiscUtil.or0(com.evolveum.midpoint.util.MiscUtil.or0) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) ActivityBasedTaskHandler(com.evolveum.midpoint.repo.common.activity.run.task.ActivityBasedTaskHandler) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) com.evolveum.midpoint.model.api(com.evolveum.midpoint.model.api) HookRegistry(com.evolveum.midpoint.model.api.hooks.HookRegistry) TestUtil(com.evolveum.midpoint.test.util.TestUtil) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ConnectException(java.net.ConnectException) AfterClass(org.testng.annotations.AfterClass) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) AuthorizationParameters(com.evolveum.midpoint.security.enforcer.api.AuthorizationParameters) IOException(java.io.IOException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) File(java.io.File) ActivityReportUtil(com.evolveum.midpoint.repo.common.activity.run.reports.ActivityReportUtil) ModelElementContext(com.evolveum.midpoint.model.api.context.ModelElementContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReferenceResolver(com.evolveum.midpoint.model.api.util.ReferenceResolver) OpenDJController(com.evolveum.midpoint.test.ldap.OpenDJController) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemName(com.evolveum.midpoint.prism.path.ItemName) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) MiscUtil.argCheck(com.evolveum.midpoint.util.MiscUtil.argCheck) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AuthorityUtils(org.springframework.security.core.authority.AuthorityUtils) ProvisioningStatistics(com.evolveum.midpoint.schema.statistics.ProvisioningStatistics) TaskDebugUtil(com.evolveum.midpoint.task.api.TaskDebugUtil) com.evolveum.midpoint.schema.util(com.evolveum.midpoint.schema.util) NotificationManager(com.evolveum.midpoint.notifications.api.NotificationManager) CommonTaskBeans(com.evolveum.midpoint.repo.common.activity.run.CommonTaskBeans) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager) AuthorizationConstants(com.evolveum.midpoint.security.api.AuthorizationConstants) PerformanceInformation(com.evolveum.midpoint.repo.api.perf.PerformanceInformation) com.evolveum.icf.dummy.resource(com.evolveum.icf.dummy.resource) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) Collections.singleton(java.util.Collections.singleton) TaskActivityManager(com.evolveum.midpoint.repo.common.activity.TaskActivityManager) InformationSource(com.evolveum.midpoint.schema.util.task.ActivityProgressInformationBuilder.InformationSource) ItemSecurityConstraints(com.evolveum.midpoint.security.enforcer.api.ItemSecurityConstraints) DirectoryException(org.opends.server.types.DirectoryException) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) PrismObject.asObjectableList(com.evolveum.midpoint.prism.PrismObject.asObjectableList) ConfigAttribute(org.springframework.security.access.ConfigAttribute) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) Experimental(com.evolveum.midpoint.util.annotation.Experimental) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) BeforeMethod(org.testng.annotations.BeforeMethod) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ValuePolicyProcessor(com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor) PrismObjectAsserter(com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter) SecurityContext(org.springframework.security.core.context.SecurityContext) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) DashboardService(com.evolveum.midpoint.model.api.interaction.DashboardService) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) F_TIMESTAMP(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType.F_TIMESTAMP) SecurityConfig(org.springframework.security.access.SecurityConfig) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) NotNull(org.jetbrains.annotations.NotNull) Authentication(org.springframework.security.core.Authentication) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) AssertJUnit(org.testng.AssertJUnit) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OrgFilter(com.evolveum.midpoint.prism.query.OrgFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) BucketingConfigurationOverrides(com.evolveum.midpoint.repo.common.activity.run.buckets.BucketingConfigurationOverrides) Objects.requireNonNull(java.util.Objects.requireNonNull) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PrismContainerDefinitionAsserter(com.evolveum.midpoint.test.asserter.prism.PrismContainerDefinitionAsserter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) BucketingManager(com.evolveum.midpoint.repo.common.activity.run.buckets.BucketingManager) GuiProfiledPrincipalManager(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipalManager) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) SecurityEnforcer(com.evolveum.midpoint.security.enforcer.api.SecurityEnforcer) FileInputStream(java.io.FileInputStream) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Consumer(java.util.function.Consumer) Message(com.evolveum.midpoint.notifications.api.transports.Message) UnusedTestElement(com.evolveum.midpoint.tools.testng.UnusedTestElement) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) com.evolveum.midpoint.test(com.evolveum.midpoint.test) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 32 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class SqaleRepoModifyObjectTest method test315ReplaceAssignmentWithCid.

@Test
public void test315ReplaceAssignmentWithCid() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
    OperationResult result = createOperationResult();
    MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
    given("object with existing container values");
    List<AssignmentType> assignments = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable().getAssignment().stream().map(ass -> // we need to get it out of original parent
    ass.clone().lifecycleState(// some change
    String.valueOf(ass.getId()))).collect(Collectors.toList());
    and("delta replacing the values with the same values again (with CIDs already)");
    ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).replace(assignments.stream().map(ass -> ass.asPrismContainerValue()).collect(Collectors.toList())).asObjectDelta(user1Oid);
    when("modifyObject is called");
    repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
    then("operation is successful");
    assertThatOperationResult(result).isSuccess();
    and("serialized form (fullObject) is updated");
    UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
    assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
    List<AssignmentType> newAssignments = userObject.getAssignment();
    assertThat(newAssignments).hasSize(assignments.size());
    and("new assignment rows replace the old ones");
    MUser row = selectObjectByOid(QUser.class, user1Oid);
    assertThat(row.version).isEqualTo(originalRow.version + 1);
    // no need for change
    assertThat(row.containerIdSeq).isEqualTo(originalRow.containerIdSeq);
    QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
    List<MAssignment> aRows = select(a, a.ownerOid.eq(UUID.fromString(user1Oid)));
    assertThat(aRows).hasSize(assignments.size()).allMatch(aRow -> String.valueOf(aRow.cid).equals(aRow.lifecycleState));
}
Also used : QService(com.evolveum.midpoint.repo.sqale.qmodel.role.QService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SqaleUtils(com.evolveum.midpoint.repo.sqale.SqaleUtils) MService(com.evolveum.midpoint.repo.sqale.qmodel.role.MService) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) BigDecimal(java.math.BigDecimal) Assertions(org.assertj.core.api.Assertions) MReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.MReference) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) BeforeClass(org.testng.annotations.BeforeClass) MContainerType(com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MTask(com.evolveum.midpoint.repo.sqale.qmodel.task.MTask) QConnector(com.evolveum.midpoint.repo.sqale.qmodel.connector.QConnector) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) QUserMapping(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Item(com.evolveum.midpoint.prism.Item) Jsonb(com.evolveum.midpoint.repo.sqale.jsonb.Jsonb) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Assert.assertEquals(org.testng.Assert.assertEquals) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) QObjectReferenceMapping(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReferenceMapping) MShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.MShadow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) TestUtil(com.evolveum.midpoint.test.util.TestUtil) Comparator.comparing(java.util.Comparator.comparing) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) QObjectReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.repo.sqale.qmodel.assignment(com.evolveum.midpoint.repo.sqale.qmodel.assignment) PrismObject(com.evolveum.midpoint.prism.PrismObject) QShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.QShadow) MUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemName(com.evolveum.midpoint.prism.path.ItemName) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Assert.assertTrue(org.testng.Assert.assertTrue) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QTask(com.evolveum.midpoint.repo.sqale.qmodel.task.QTask) com.evolveum.midpoint.repo.sqale.qmodel.accesscert(com.evolveum.midpoint.repo.sqale.qmodel.accesscert) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 33 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class SqaleRepoModifyObjectTest method test332ModifiedCertificationCaseStoresIt.

@Test
public void test332ModifiedCertificationCaseStoresIt() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
    OperationResult result = createOperationResult();
    MAccessCertificationCampaign originalRow = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
    given("delta adding case for campaign 1");
    ObjectDelta<AccessCertificationCampaignType> delta = prismContext.deltaFor(AccessCertificationCampaignType.class).item(ItemPath.create(AccessCertificationCampaignType.F_CASE, CAMPAIGN_1_CASE_2_ID, AccessCertificationCaseType.F_OUTCOME)).replace("People are the problem").asObjectDelta(accessCertificationCampaign1Oid);
    when("modifyObject is called");
    repositoryService.modifyObject(AccessCertificationCampaignType.class, accessCertificationCampaign1Oid, delta.getModifications(), result);
    then("operation is successful");
    assertThatOperationResult(result).isSuccess();
    and("serialized form (fullObject) is updated");
    AccessCertificationCampaignType campaignObjectAfter = repositoryService.getObject(AccessCertificationCampaignType.class, accessCertificationCampaign1Oid, retrieveWithCases(), result).asObjectable();
    assertThat(campaignObjectAfter.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
    List<AccessCertificationCaseType> casesAfter = campaignObjectAfter.getCase();
    assertThat(casesAfter).isNotNull();
    assertThat(casesAfter.get(1).getId()).isEqualTo(CAMPAIGN_1_CASE_2_ID);
    and("campaign row is created");
    MAccessCertificationCampaign row = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
    assertThat(row.version).isEqualTo(originalRow.version + 1);
    and("case row is created");
    QAccessCertificationCase a = QAccessCertificationCaseMapping.getAccessCertificationCaseMapping().defaultAlias();
    List<MAccessCertificationCase> caseRows = select(a, a.ownerOid.eq(UUID.fromString(accessCertificationCampaign1Oid)));
    assertThat(caseRows).hasSize(2);
    caseRows.sort(comparing(tr -> tr.cid));
    MAccessCertificationCase aRow = caseRows.get(1);
    assertThat(aRow.cid).isEqualTo(CAMPAIGN_1_CASE_2_ID);
    assertThat(aRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_CASE);
    assertThat(aRow.targetRefTargetOid).isNull();
    assertThat(aRow.objectRefTargetOid).isEqualTo(accCertCampaign1Case2ObjectOid);
    assertThat(aRow.objectRefTargetType).isEqualTo(MObjectType.USER);
    assertCachedUri(aRow.objectRefRelationId, relationRegistry.getDefaultRelation());
    assertThat(aRow.outcome).isEqualTo("People are the problem");
    assertThat(aRow.stageNumber).isEqualTo(5);
    assertThat(aRow.campaignIteration).isEqualTo(7);
    // Check that case (container) fullObject was updated, as opposed to campaign (object) fullObject
    PrismContainerValue<AccessCertificationCaseType> fullObjectCval = prismContext.parserFor(new String(aRow.fullObject, StandardCharsets.UTF_8)).parseItemValue();
    // Unchanged
    assertThat(fullObjectCval.asContainerable().getStageNumber()).isEqualTo(5);
    assertThat(fullObjectCval.asContainerable().getIteration()).isEqualTo(7);
    // Changed
    assertThat(fullObjectCval.asContainerable().getOutcome()).isEqualTo("People are the problem");
}
Also used : QService(com.evolveum.midpoint.repo.sqale.qmodel.role.QService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SqaleUtils(com.evolveum.midpoint.repo.sqale.SqaleUtils) MService(com.evolveum.midpoint.repo.sqale.qmodel.role.MService) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) BigDecimal(java.math.BigDecimal) Assertions(org.assertj.core.api.Assertions) MReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.MReference) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) BeforeClass(org.testng.annotations.BeforeClass) MContainerType(com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MTask(com.evolveum.midpoint.repo.sqale.qmodel.task.MTask) QConnector(com.evolveum.midpoint.repo.sqale.qmodel.connector.QConnector) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) QUserMapping(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Item(com.evolveum.midpoint.prism.Item) Jsonb(com.evolveum.midpoint.repo.sqale.jsonb.Jsonb) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Assert.assertEquals(org.testng.Assert.assertEquals) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) QObjectReferenceMapping(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReferenceMapping) MShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.MShadow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) TestUtil(com.evolveum.midpoint.test.util.TestUtil) Comparator.comparing(java.util.Comparator.comparing) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) QObjectReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.repo.sqale.qmodel.assignment(com.evolveum.midpoint.repo.sqale.qmodel.assignment) PrismObject(com.evolveum.midpoint.prism.PrismObject) QShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.QShadow) MUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemName(com.evolveum.midpoint.prism.path.ItemName) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Assert.assertTrue(org.testng.Assert.assertTrue) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QTask(com.evolveum.midpoint.repo.sqale.qmodel.task.QTask) com.evolveum.midpoint.repo.sqale.qmodel.accesscert(com.evolveum.midpoint.repo.sqale.qmodel.accesscert) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 34 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class RoleMemberListRepoTest method fillDatabase.

@Test
public void fillDatabase() throws SchemaException, ObjectAlreadyExistsException {
    OperationResult operationResult = createOperationResult();
    for (int roleIndex = ROLE_MIN; roleIndex <= ROLE_MAX; roleIndex++) {
        String name = String.format("role-%05d", roleIndex);
        RoleType role = new RoleType(prismContext).name(PolyStringType.fromOrig(name));
        try {
            repositoryService.addObject(role.asPrismObject(), null, operationResult);
            roleOids.add(role.getOid());
            System.out.println("Created role " + name);
        } catch (ObjectAlreadyExistsException e) {
            // never mind, we'll use the existing one
            QRole r = aliasFor(QRole.class);
            MRole existingRow = selectOne(r, r.nameOrig.eq(name));
            roleOids.add(existingRow.oid.toString());
            System.out.println("Reused existing role " + name);
        }
    }
    for (int userIndex = USER_MIN; userIndex <= USER_MAX; userIndex++) {
        String name = String.format("user-%07d", userIndex);
        UserType user = new UserType(prismContext).name(PolyStringType.fromOrig(name));
        addRoles(user);
        try {
            repositoryService.addObject(user.asPrismObject(), null, operationResult);
            System.out.println("Created user " + name + " with " + user.getRoleMembershipRef().size() + " roles");
        } catch (ObjectAlreadyExistsException e) {
            System.out.println("User " + name + " already exists");
        }
    }
}
Also used : RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) MRole(com.evolveum.midpoint.repo.sqale.qmodel.role.MRole) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) QRole(com.evolveum.midpoint.repo.sqale.qmodel.role.QRole) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 35 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class OrgClosureConcurrencyTest method _test300AddRemoveNodesMT.

protected void _test300AddRemoveNodesMT(final boolean random) throws Exception {
    OperationResult opResult = new OperationResult("===[ test300AddRemoveNodesMT ]===");
    info("test300AddRemoveNodes starting with random = " + random);
    final Set<ObjectType> nodesToRemove = Collections.synchronizedSet(new HashSet<>());
    final Set<ObjectType> nodesToAdd = Collections.synchronizedSet(new HashSet<>());
    final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<>());
    for (int level = 0; level < getConfiguration().getNodeRoundsForLevel().length; level++) {
        int rounds = getConfiguration().getNodeRoundsForLevel()[level];
        List<String> levelOids = orgsByLevels.get(level);
        generateNodesAtOneLevel(nodesToRemove, nodesToAdd, OrgType.class, rounds, levelOids, opResult);
    }
    int numberOfRunners = THREADS;
    final List<Thread> runners = Collections.synchronizedList(new ArrayList<>());
    for (int i = 0; i < numberOfRunners; i++) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (true) {
                        ObjectType objectType = getNext(nodesToRemove, random);
                        if (objectType == null) {
                            break;
                        }
                        logger.info("Removing {}", objectType);
                        int remaining;
                        try {
                            removeObject(objectType);
                            synchronized (OrgClosureConcurrencyTest.this) {
                                nodesToRemove.remove(objectType);
                                remaining = nodesToRemove.size();
                            }
                            info(Thread.currentThread().getName() + " removed " + objectType + "; remaining: " + remaining);
                        } catch (ObjectNotFoundException e) {
                            // this is OK
                            info(Thread.currentThread().getName() + ": " + objectType + " already deleted");
                            // give other threads a chance
                            Thread.sleep(300);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    exceptions.add(e);
                } finally {
                    runners.remove(Thread.currentThread());
                }
            }
        };
        Thread t = new Thread(runnable);
        runners.add(t);
        t.start();
    }
    waitForRunnersCompletion(runners);
    if (!nodesToRemove.isEmpty()) {
        throw new AssertionError("Nodes to remove is not empty, see the console or log: " + nodesToRemove);
    }
    if (!exceptions.isEmpty()) {
        throw new AssertionError("Found exceptions: " + exceptions);
    }
    rebuildGraph();
    checkClosure(orgGraph.vertexSet());
    info("Consistency after removing OK");
    numberOfRunners = THREADS;
    for (int i = 0; i < numberOfRunners; i++) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (true) {
                        ObjectType objectType = getNext(nodesToAdd, random);
                        if (objectType == null) {
                            break;
                        }
                        logger.info("Adding {}", objectType);
                        try {
                            addObject(objectType.clone());
                            // rebuildGraph();
                            // checkClosure(orgGraph.vertexSet());
                            int remaining;
                            synchronized (OrgClosureConcurrencyTest.this) {
                                nodesToAdd.remove(objectType);
                                remaining = nodesToAdd.size();
                            }
                            info(Thread.currentThread().getName() + " re-added " + objectType + "; remaining: " + remaining);
                        } catch (ObjectAlreadyExistsException e) {
                            // this is OK
                            info(Thread.currentThread().getName() + ": " + objectType + " already exists");
                            // give other threads a chance
                            Thread.sleep(300);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    exceptions.add(e);
                } finally {
                    runners.remove(Thread.currentThread());
                }
            }
        };
        Thread t = new Thread(runnable);
        runners.add(t);
        t.start();
    }
    waitForRunnersCompletion(runners);
    if (!nodesToAdd.isEmpty()) {
        throw new AssertionError("Nodes to add is not empty, see the console or log: " + nodesToAdd);
    }
    if (!exceptions.isEmpty()) {
        throw new AssertionError("Found exceptions: " + exceptions);
    }
    rebuildGraph();
    checkClosure(orgGraph.vertexSet());
    info("Consistency after re-adding OK");
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)142 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)84 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)76 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)69 SystemException (com.evolveum.midpoint.util.exception.SystemException)50 PrismObject (com.evolveum.midpoint.prism.PrismObject)39 Test (org.testng.annotations.Test)36 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)31 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)29 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)28 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)27 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)24 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)24 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)22 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)22 QName (javax.xml.namespace.QName)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)17 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)17