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();
}
}
}
}
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);
}
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);
}
}
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);
}
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());
}
Aggregations