Search in sources :

Example 1 with ImportOptionsType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType in project midpoint by Evolveum.

the class MiscSchemaUtil method getDefaultImportOptions.

public static ImportOptionsType getDefaultImportOptions() {
    ImportOptionsType options = new ImportOptionsType();
    options.setOverwrite(false);
    options.setValidateStaticSchema(false);
    options.setValidateDynamicSchema(false);
    options.setEncryptProtectedValues(true);
    options.setFetchResourceSchema(false);
    options.setSummarizeErrors(true);
    options.setSummarizeSucceses(true);
    return options;
}
Also used : ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType)

Example 2 with ImportOptionsType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType in project midpoint by Evolveum.

the class ImportTest method test005ImportUsersWithOverwrite.

// Import the same thing again, this time with overwrite option. This should go well.
@Test
public void test005ImportUsersWithOverwrite() throws Exception {
    TestUtil.displayTestTile(this, "test005ImportUsersWithOverwrite");
    // GIVEN
    Task task = taskManager.createTaskInstance();
    OperationResult result = new OperationResult(ImportTest.class.getName() + "test005ImportUsersWithOverwrite");
    FileInputStream stream = new FileInputStream(IMPORT_USERS_OVERWRITE_FILE);
    ImportOptionsType options = getDefaultImportOptions();
    options.setOverwrite(true);
    dummyAuditService.clear();
    // WHEN
    modelService.importObjectsFromStream(stream, options, task, result);
    // THEN
    result.computeStatus();
    display("Result after import with overwrite", result);
    TestUtil.assertSuccess("Import failed (result)", result, 2);
    // list all users
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, new ObjectQuery(), null, task, result);
    // Three old users, one new
    assertEquals(5, users.size());
    for (PrismObject<UserType> user : users) {
        UserType userType = user.asObjectable();
        if (userType.getName().equals("jack")) {
            // OID and all the attributes should be the same
            assertEquals(USER_JACK_OID, userType.getOid());
            PrismAsserts.assertEqualsPolyString("wrong givenName", "Jack", userType.getGivenName());
            PrismAsserts.assertEqualsPolyString("wrong familyName", "Sparrow", userType.getFamilyName());
            PrismAsserts.assertEqualsPolyString("wrong fullName", "Cpt. Jack Sparrow", userType.getFullName());
        }
        if (userType.getName().equals("will")) {
            // OID should be the same, and there should be an employee type
            assertEquals(USER_WILL_OID, userType.getOid());
            assertTrue("Wrong Will's employee type", userType.getEmployeeType().contains("legendary"));
        }
        if (userType.getName().equals("guybrush")) {
            // OID may be different, there should be a locality attribute
            guybrushOid = userType.getOid();
            assertNotNull(guybrushOid);
            PrismAsserts.assertEqualsPolyString("Guybrush is not in the Caribbean", "Deep in the Caribbean", userType.getLocality());
        }
        if (userType.getName().equals("ht")) {
            // Herman should be here now
            hermanOid = userType.getOid();
            assertNotNull(hermanOid);
            PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman Toothrot", userType.getFullName());
            PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman", userType.getGivenName());
            PrismAsserts.assertEqualsPolyString("Herman is confused", "Toothrot", userType.getFamilyName());
        }
    }
    assertUsers(5);
    // Check audit
    display("Audit", dummyAuditService);
    // 1 failed, 7 succeeded
    dummyAuditService.assertRecords(8);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 3 with ImportOptionsType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType in project midpoint by Evolveum.

the class ImportTest method test031ReimportResource.

@Test
public void test031ReimportResource() throws Exception {
    final String TEST_NAME = "test031ReimportResource";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(ImportTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    FileInputStream stream = new FileInputStream(RESOURCE_DUMMY_CHANGED_FILE);
    ImportOptionsType options = getDefaultImportOptions();
    options.setOverwrite(true);
    IntegrationTestTools.assertNoRepoCache();
    dummyAuditService.clear();
    // WHEN
    modelService.importObjectsFromStream(stream, options, task, result);
    // THEN
    result.computeStatus();
    display("Result after import", result);
    TestUtil.assertSuccess("Import of " + RESOURCE_DUMMY_CHANGED_FILE + " has failed (result)", result, 2);
    IntegrationTestTools.assertNoRepoCache();
    PrismObject<ResourceType> repoResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    display("Reimported resource (repo)", repoResource);
    assertDummyResource(repoResource, true);
    IntegrationTestTools.assertNoRepoCache();
    MidPointAsserts.assertVersionIncrease(importedRepoResource, repoResource);
    PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
    display("Reimported resource (model)", resource);
    IntegrationTestTools.assertNoRepoCache();
    assertDummyResource(resource, false);
    MidPointAsserts.assertVersionIncrease(importedResource, resource);
    ResourceType resourceType = resource.asObjectable();
    assertNull("Synchronization not gone", resourceType.getSynchronization());
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(1);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ResourceType.class);
    dummyAuditService.assertExecutionSuccess();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 4 with ImportOptionsType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType in project midpoint by Evolveum.

the class PostInitialDataImport method importObject.

/**
 * @return true if it was success, otherwise false
 */
private boolean importObject(File file, Task task, OperationResult mainResult) {
    OperationResult result = mainResult.createSubresult(OPERATION_IMPORT_OBJECT);
    try {
        LOGGER.info("Starting post-initial import of file {}.", file.getName());
        ImportOptionsType options = new ImportOptionsType();
        options.overwrite(true);
        options.setModelExecutionOptions(new ModelExecuteOptionsType(prismContext).raw(false));
        model.importObjectsFromFile(file, options, task, result);
        result.recordSuccess();
        return true;
    } catch (Exception e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import object from file {}: ", e, file.getName(), e.getMessage());
        result.recordFatalError(e);
        LOGGER.info("\n{}", result.debugDump());
        return false;
    }
}
Also used : ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 5 with ImportOptionsType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType in project midpoint by Evolveum.

the class ImportTest method test040ImportUserHermanNoEncryption.

@Test
public void test040ImportUserHermanNoEncryption() throws Exception {
    final String TEST_NAME = "test040ImportUserHermanNoEncryption";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    InternalsConfig.readEncryptionChecks = false;
    Task task = taskManager.createTaskInstance();
    OperationResult result = new OperationResult(ImportTest.class.getName() + "." + TEST_NAME);
    FileInputStream stream = new FileInputStream(USER_HERMAN_FILE);
    ImportOptionsType importOptions = getDefaultImportOptions();
    importOptions.setEncryptProtectedValues(false);
    dummyAuditService.clear();
    // WHEN
    modelService.importObjectsFromStream(stream, importOptions, task, result);
    // THEN
    result.computeStatus();
    display("Result after good import", result);
    TestUtil.assertSuccess("Import has failed (result)", result);
    // Check import with fixed OID
    PrismObject<UserType> userHerman = getUser(USER_HERMAN_OID);
    display("Herman", userHerman);
    assertUser(userHerman, USER_HERMAN_OID, USER_HERMAN_USERNAME, "Herman Toothrot", "Herman", "Toothrot");
    // Check if the password was NOT encrypted
    ProtectedStringType protectedString = userHerman.asObjectable().getCredentials().getPassword().getValue();
    assertEquals("Er? Pirate sectrets still hidden?", "m0nk3y", protectedString.getClearValue());
    assertNull("Er? Encrypted data together with clear value?", protectedString.getEncryptedDataType());
    assertUsers(6);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(1);
    dummyAuditService.assertHasDelta(ChangeType.ADD, UserType.class);
    dummyAuditService.assertExecutionSuccess();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 ImportOptionsType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType)6 Task (com.evolveum.midpoint.task.api.Task)5 FileInputStream (java.io.FileInputStream)5 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)4 Test (org.testng.annotations.Test)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 ImportOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType)2 ModelExecuteOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)1 InputStream (java.io.InputStream)1 List (java.util.List)1