use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class ImportRepositoryTest method test100ImportByOid.
@Test
public void test100ImportByOid() {
String[] input = new String[] { "-m", getMidpointHome(), "import", "-o", "00000000-8888-6666-0000-100000000001", "-i", RESOURCES_FOLDER + "/org-monkey-island-simple.xml.zip", "-z" };
ByteArrayOutputStream bos = new ByteArrayOutputStream();
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(1, 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());
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class ImportRepositoryTest method test110ImportByFilterAsOption.
@Test
public void test110ImportByFilterAsOption() throws Exception {
String[] input = new String[] { "-m", getMidpointHome(), "import", "-f", "<equal><path>name</path><value>F0002</value></equal>", "-i", RESOURCES_FOLDER + "/org-monkey-island-simple.xml.zip", "-z" };
ByteArrayOutputStream bos = new ByteArrayOutputStream();
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 objects");
int count = repo.countObjects(ObjectType.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());
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class ImportRepositoryTest method test120ImportByFilterAsFile.
@Test
public void test120ImportByFilterAsFile() throws Exception {
String[] input = new String[] { "-m", getMidpointHome(), "import", "-f", "@src/test/resources/filter.xml", "-i", RESOURCES_FOLDER + "/org-monkey-island-simple.xml.zip", "-z" };
ByteArrayOutputStream bos = new ByteArrayOutputStream();
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 users");
int count = repo.countObjects(ObjectType.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());
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class NinjaContextTest method setupRepositoryViaMidpointHome.
@Test
public void setupRepositoryViaMidpointHome() throws Exception {
JCommander jc = NinjaUtils.setupCommandLineParser();
jc.parse("-m", "./target/midpoint-home", "-U", "jdbc:postgresql://localhost/midpoint", "-u", "midpoint", "-p", "qwe123");
ConnectionOptions options = NinjaUtils.getOptions(jc, ConnectionOptions.class);
NinjaContext ctx = new NinjaContext(null);
ctx.init(options);
RepositoryService service = ctx.getRepository();
OperationResult result = new OperationResult("get user");
PrismObject obj = service.getObject(UserType.class, SystemObjectsType.USER_ADMINISTRATOR.value(), null, result);
System.out.println(obj.debugDump());
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class ImportObjects method execute.
public boolean execute() {
System.out.println("Starting objects import.");
File objects = new File(filePath);
if (!objects.exists() || !objects.canRead()) {
System.out.println("XML file with objects '" + objects.getAbsolutePath() + "' doesn't exist or can't be read.");
return false;
}
InputStream input = null;
ClassPathXmlApplicationContext context = null;
try {
System.out.println("Loading spring contexts.");
context = new ClassPathXmlApplicationContext(CONTEXTS);
InputStreamReader reader = new InputStreamReader(new FileInputStream(objects), "utf-8");
input = new ReaderInputStream(reader, reader.getEncoding());
final RepositoryService repository = context.getBean("repositoryService", RepositoryService.class);
PrismContext prismContext = context.getBean(PrismContext.class);
EventHandler handler = new EventHandler() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
return EventResult.cont();
}
@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
try {
String displayName = getDisplayName(object);
System.out.println("Importing object " + displayName);
repository.addObject((PrismObject<ObjectType>) object, null, objectResult);
} catch (Exception ex) {
objectResult.recordFatalError("Unexpected problem: " + ex.getMessage(), ex);
System.out.println("Exception occurred during import, reason: " + ex.getMessage());
ex.printStackTrace();
}
objectResult.recordSuccessIfUnknown();
if (objectResult.isAcceptable()) {
// Continue import
return EventResult.cont();
} else {
return EventResult.skipObject(objectResult.getMessage());
}
}
@Override
public void handleGlobalError(OperationResult currentResult) {
}
};
Validator validator = new Validator(prismContext, handler);
validator.setVerbose(true);
validator.setValidateSchema(validateSchema);
OperationResult result = new OperationResult("Import objeccts");
validator.validate(input, result, OperationConstants.IMPORT_OBJECT);
result.recomputeStatus();
if (!result.isSuccess()) {
System.out.println("Operation result was not success, dumping result.\n" + result.debugDump(3));
}
} catch (Exception ex) {
System.out.println("Exception occurred during import task, reason: " + ex.getMessage());
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(input);
destroyContext(context);
}
System.out.println("Objects import finished.");
return true;
}
Aggregations