Search in sources :

Example 11 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class SearchProducerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    try {
        GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
        if (options.isRaw()) {
            optionsBuilder = optionsBuilder.raw();
        }
        optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, type.getClassDefinition());
        ResultHandler<?> handler = (object, parentResult) -> {
            try {
                queue.put(object.asObjectable());
            } catch (InterruptedException ex) {
                log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
            }
            return true;
        };
        RepositoryService repository = context.getRepository();
        repository.searchObjectsIterative(type.getClassDefinition(), query, handler, optionsBuilder.build(), true, operation.getResult());
    } catch (SchemaException ex) {
        log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            if (!operation.isFinished()) {
                operation.producerFinish();
            }
        }
    }
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ExportOptions(com.evolveum.midpoint.ninja.opts.ExportOptions) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) BlockingQueue(java.util.concurrent.BlockingQueue) NinjaContext(com.evolveum.midpoint.ninja.impl.NinjaContext) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) List(java.util.List) Log(com.evolveum.midpoint.ninja.util.Log) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Log(com.evolveum.midpoint.ninja.util.Log) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 12 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class CountRepositoryAction method execute.

@Override
public void execute() throws Exception {
    RepositoryService repository = context.getRepository();
    FileReference fileReference = options.getFilter();
    if (fileReference != null && options.getFilter() == null) {
        throw new NinjaException("Type must be defined");
    }
    List<ObjectTypes> types = NinjaUtils.getTypes(options.getType());
    int total = 0;
    OperationResult result = new OperationResult(OPERATION_COUNT);
    for (ObjectTypes type : types) {
        ObjectQuery query = NinjaUtils.createObjectQuery(options.getFilter(), context, type.getClassDefinition());
        int count = repository.countObjects(type.getClassDefinition(), query, new ArrayList<>(), result);
        if (count == 0 && options.getType() == null) {
            continue;
        }
        log.info("{}:\t{}", type.name(), count);
        total += count;
    }
    log.info("===\nTotal:\t{}", total);
}
Also used : NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) FileReference(com.evolveum.midpoint.ninja.util.FileReference) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 13 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class InfoRepositoryAction method execute.

@Override
public void execute() {
    MidpointConfiguration config = context.getMidpointConfiguration();
    System.out.println("MidPoint home: " + config.getMidpointHome());
    System.out.println("Java home: " + System.getProperty("java.home"));
    RepositoryService repository = context.getRepository();
    OperationResult repoTestResult = new OperationResult("repo.test");
    repository.repositorySelfTest(repoTestResult);
    repoTestResult.close();
    System.out.println("Repository test: " + repoTestResult.getStatus());
    try {
        RepositoryDiag repositoryDiag = repository.getRepositoryDiag();
        System.out.println("Repository diag:" + "\n Type: " + repositoryDiag.getImplementationShortName() + "\n Description: " + repositoryDiag.getImplementationDescription() + "\n JDBC URL: " + repositoryDiag.getRepositoryUrl() + "\n Driver type: " + repositoryDiag.getDriverShortName() + "\n Driver version: " + repositoryDiag.getDriverVersion() + "\n Additional details:");
        for (LabeledString detail : repositoryDiag.getAdditionalDetails()) {
            System.out.println(" - " + detail.getLabel() + ": " + detail.getData());
        }
    } catch (Exception e) {
        // Fatal crash during Ninja start is more likely than this, but just to be sure...
        System.err.println("Unexpected problem during repo diag: " + e);
    }
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RepositoryDiag(com.evolveum.midpoint.schema.RepositoryDiag) LabeledString(com.evolveum.midpoint.schema.LabeledString) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 14 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class DeleteRepositoryTest method deleteByOid.

@Test
public void deleteByOid() {
    String type = ObjectTypes.ROLE.name();
    String oid = SystemObjectsType.ROLE_DELEGATOR.value();
    String[] input = new String[] { "-m", getMidpointHome(), "delete", "-o", oid, "-t", type };
    OperationResult result = new OperationResult("delete by oid");
    ExecutionValidator preExecValidator = (context) -> {
        RepositoryService repo = context.getRepository();
        PrismObject role = repo.getObject(ObjectTypes.ROLE.getClassDefinition(), oid, GetOperationOptions.createRawCollection(), result);
        AssertJUnit.assertNotNull(role);
    };
    ExecutionValidator postExecValidator = (context) -> {
        RepositoryService repo = context.getRepository();
        try {
            repo.getObject(ObjectTypes.ROLE.getClassDefinition(), oid, GetOperationOptions.createRawCollection(), result);
            AssertJUnit.fail();
        } catch (ObjectNotFoundException ex) {
        }
    };
    executeTest(preExecValidator, postExecValidator, input);
}
Also used : UnusedTestElement(com.evolveum.midpoint.tools.testng.UnusedTestElement) AssertJUnit(org.testng.AssertJUnit) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemObjectsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) BeforeMethod(org.testng.annotations.BeforeMethod) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) Test(org.testng.annotations.Test) PrismObject(com.evolveum.midpoint.prism.PrismObject) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) Test(org.testng.annotations.Test)

Example 15 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class ImportInvalidRepositoryTest method test100Import.

@Test
public void test100Import() {
    String[] input = new String[] { "-m", getMidpointHome(), "import", "-i", RESOURCES_FOLDER + "/unknown-nodes.zip", "-z" };
    executeTest(null, context -> {
        RepositoryService repo = context.getRepository();
        OperationResult result = new OperationResult("count objects");
        int count = repo.countObjects(ObjectType.class, null, null, result);
        AssertJUnit.assertEquals(0, count);
    }, context -> {
        RepositoryService repo = context.getRepository();
        OperationResult result = new OperationResult("count");
        int count = repo.countObjects(ObjectType.class, null, null, result);
        AssertJUnit.assertEquals(16, count);
        count = repo.countObjects(OrgType.class, null, null, result);
        AssertJUnit.assertEquals(1, count);
    }, true, true, input);
    List<String> out = getSystemOut();
    AssertJUnit.assertEquals(out.toString(), 5, out.size());
    AssertJUnit.assertTrue(getSystemErr().isEmpty());
}
Also used : OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) Test(org.testng.annotations.Test)

Aggregations

RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)27 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 Test (org.testng.annotations.Test)8 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)7 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 List (java.util.List)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3