Search in sources :

Example 11 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project midpoint by Evolveum.

the class OrgClosureManager method rebuild.

//endregion
//region Rebuilding or checking org closure
// we are already in the context of a transaction (and the org struct table is locked if possible)
// "check" here means "thorough check" (i.e. comparing with recomputed closure)
private void rebuild(boolean check, boolean rebuild, boolean stopOnFailure, final Context context, final Session session, OperationResult result) throws SchemaException {
    List existingEntries = null;
    if (check) {
        LOGGER.info("Reading from existing org closure table");
        Query selectQuery = session.createSQLQuery("SELECT descendant_oid, ancestor_oid, val from " + CLOSURE_TABLE_NAME).addScalar("descendant_oid", StringType.INSTANCE).addScalar("ancestor_oid", StringType.INSTANCE).addScalar("val", IntegerType.INSTANCE);
        existingEntries = selectQuery.list();
        LOGGER.info("{} entries read", existingEntries.size());
    }
    LOGGER.info("Computing org closure table from scratch");
    Query deleteQuery = session.createSQLQuery("delete from " + CLOSURE_TABLE_NAME);
    deleteQuery.executeUpdate();
    LOGGER.trace("Closure table content deleted");
    final int orgsTotal = repositoryService.countObjects(OrgType.class, new ObjectQuery(), result);
    final MutableInt orgsProcessed = new MutableInt(0);
    ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {

        @Override
        public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
            LOGGER.trace("Processing {}", object);
            handleAdd(object.getOid(), getParentOidsFromObject(object), context, session);
            orgsProcessed.add(1);
            int currentState = orgsProcessed.intValue();
            if (currentState % 100 == 0) {
                LOGGER.info("{} organizations processed (out of {})", currentState, orgsTotal);
            }
            return true;
        }
    };
    repositoryService.searchObjectsIterative(OrgType.class, new ObjectQuery(), handler, null, false, result);
    LOGGER.info("Org closure table was successfully recomputed (not committed yet); all {} organizations processed", orgsTotal);
    if (check) {
        LOGGER.info("Reading from recomputed org closure table");
        Query selectQuery = session.createSQLQuery("SELECT descendant_oid, ancestor_oid, val from " + CLOSURE_TABLE_NAME).addScalar("descendant_oid", StringType.INSTANCE).addScalar("ancestor_oid", StringType.INSTANCE).addScalar("val", IntegerType.INSTANCE);
        List recomputedEntries = selectQuery.list();
        LOGGER.info("{} entries read", recomputedEntries.size());
        compareOrgClosureTables(existingEntries, recomputedEntries, rebuild, result);
    } else {
        result.recordSuccess();
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Query(org.hibernate.Query) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) MutableInt(org.apache.commons.lang.mutable.MutableInt) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 12 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project uPortal by Jasig.

the class JpaBaseAggregationDaoTest method testUnclosedBaseAggregationRangeQuery.

@Test
public final void testUnclosedBaseAggregationRangeQuery() throws Exception {
    final IEntityGroup entityGroupA = mock(IEntityGroup.class);
    when(entityGroupA.getServiceName()).thenReturn(new CompositeName("local"));
    when(entityGroupA.getName()).thenReturn("Group A");
    when(compositeGroupService.findGroup("local.0")).thenReturn(entityGroupA);
    final IEntityGroup entityGroupB = mock(IEntityGroup.class);
    when(entityGroupB.getServiceName()).thenReturn(new CompositeName("local"));
    when(entityGroupB.getName()).thenReturn("Group B");
    when(compositeGroupService.findGroup("local.1")).thenReturn(entityGroupB);
    final MutableInt aggrs = new MutableInt();
    //Create 10 minutes of aggregations
    final DateTime start = new DateTime(1326734644000l, DateTimeZone.UTC).minuteOfDay().roundFloorCopy();
    final DateTime end = start.plusMinutes(10);
    final AggregationInterval interval = AggregationInterval.FIVE_MINUTE;
    final MutableObject startObj = new MutableObject();
    final MutableObject endObj = new MutableObject();
    this.executeInTransaction(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final Random r = new Random(0);
            final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
            final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
            populateDateTimeDimensions(start, end, new FunctionWithoutResult<Tuple<DateDimension, TimeDimension>>() {

                @Override
                protected void applyWithoutResult(Tuple<DateDimension, TimeDimension> input) {
                    final TimeDimension td = input.second;
                    final DateDimension dd = input.first;
                    final DateTime instant = td.getTime().toDateTime(dd.getDate());
                    if (startObj.getValue() == null) {
                        startObj.setValue(instant);
                    }
                    endObj.setValue(instant);
                    if (instant.equals(interval.determineStart(instant))) {
                        final AggregationIntervalInfo intervalInfo = aggregationIntervalHelper.getIntervalInfo(interval, instant);
                        final T baseAggregationA = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupA));
                        final T baseAggregationB = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupB));
                        for (int u = 0; u < r.nextInt(50); u++) {
                            updateAggregation(intervalInfo, baseAggregationA, r);
                            updateAggregation(intervalInfo, baseAggregationB, r);
                        }
                        if (aggrs.intValue() % 4 == 0) {
                            baseAggregationA.intervalComplete(5);
                        }
                        baseAggregationB.intervalComplete(5);
                        getAggregationDao().updateAggregation(baseAggregationA);
                        getAggregationDao().updateAggregation(baseAggregationB);
                        aggrs.add(2);
                    }
                }
            });
        }
    });
    //Verify all aggrs created
    assertEquals(4, aggrs.intValue());
    //Find unclosed 1 aggr
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final Collection<T> baseAggregations = getAggregationDao().getUnclosedAggregations(start.minusDays(1), end.plusDays(1), interval);
            assertEquals(1, baseAggregations.size());
            for (final T baseAggregationImpl : baseAggregations) {
                baseAggregationImpl.intervalComplete(5);
                getAggregationDao().updateAggregation(baseAggregationImpl);
            }
        }
    });
    //Find unclosed 0 aggr
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final Collection<T> baseAggregations = getAggregationDao().getUnclosedAggregations(start.minusDays(1), end.plusDays(1), interval);
            assertEquals(0, baseAggregations.size());
        }
    });
}
Also used : CompositeName(javax.naming.CompositeName) DateTime(org.joda.time.DateTime) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) IEntityGroup(org.apereo.portal.groups.IEntityGroup) FunctionWithoutResult(org.apereo.portal.concurrency.FunctionWithoutResult) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) Random(java.util.Random) MutableInt(org.apache.commons.lang.mutable.MutableInt) Collection(java.util.Collection) Tuple(org.apereo.portal.utils.Tuple) MutableObject(org.apache.commons.lang.mutable.MutableObject) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 13 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project midpoint by Evolveum.

the class AbstractLdapConnTest method singleInfernoSearch.

private void singleInfernoSearch(ObjectQuery query, int expectedNumberOfResults, Integer offset, Integer maxSize, String sortAttrName, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ObjectPaging paging = ObjectPaging.createPaging(offset, maxSize);
    paging.setOrdering(getAttributePath(resource, sortAttrName), OrderDirection.ASCENDING);
    query.setPaging(paging);
    final MutableInt count = new MutableInt();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            count.increment();
            return true;
        }
    };
    modelService.searchObjectsIterative(ShadowType.class, query, handler, null, task, result);
    assertEquals("Unexpected number of search results", expectedNumberOfResults, count.intValue());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MutableInt(org.apache.commons.lang.mutable.MutableInt) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler)

Example 14 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project midpoint by Evolveum.

the class TestLdap method test800BigLdapSearch.

@Test
public void test800BigLdapSearch() throws Exception {
    final String TEST_NAME = "test800BigLdapSearch";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    assertUsers(NUM_INITIAL_USERS + 1);
    loadEntries("a");
    Task task = taskManager.createTaskInstance(TestLdap.class.getName() + "." + TEST_NAME);
    task.setOwner(getUser(USER_ADMINISTRATOR_OID));
    OperationResult result = task.getResult();
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_OPENDJ_OID, new QName(RESOURCE_OPENDJ_NAMESPACE, "inetOrgPerson"), prismContext);
    final MutableInt count = new MutableInt(0);
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
            count.increment();
            display("Found", shadow);
            return true;
        }
    };
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.searchObjectsIterative(ShadowType.class, query, handler, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertEquals("Unexpected number of search results", NUM_LDAP_ENTRIES + 8, count.getValue());
    assertUsers(NUM_INITIAL_USERS + 1);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MutableInt(org.apache.commons.lang.mutable.MutableInt) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 15 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project midpoint by Evolveum.

the class TestLdap method assertOpenDjAccountShadows.

private void assertOpenDjAccountShadows(int expected, boolean raw, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_OPENDJ_OID, new QName(RESOURCE_OPENDJ_NAMESPACE, "inetOrgPerson"), prismContext);
    final MutableInt count = new MutableInt(0);
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
            count.increment();
            display("Found", shadow);
            return true;
        }
    };
    Collection<SelectorOptions<GetOperationOptions>> options = null;
    if (raw) {
        options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
    }
    modelService.searchObjectsIterative(ShadowType.class, query, handler, options, task, result);
    assertEquals("Unexpected number of search results (raw=" + raw + ")", expected, count.getValue());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MutableInt(org.apache.commons.lang.mutable.MutableInt) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

MutableInt (org.apache.commons.lang.mutable.MutableInt)35 List (java.util.List)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 ArrayList (java.util.ArrayList)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Map (java.util.Map)4 Test (org.junit.Test)4 Versioned (voldemort.versioning.Versioned)4 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 MutableObject (org.apache.commons.lang.mutable.MutableObject)3 DateTime (org.joda.time.DateTime)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Random (java.util.Random)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 CompositeName (javax.naming.CompositeName)2