Search in sources :

Example 81 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class AbstractLdapHierarchyTest method test310RenameUserGorc.

@Test
public void test310RenameUserGorc() throws Exception {
    final String TEST_NAME = "test310RenameUserGorc";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(AbstractLdapHierarchyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> userBefore = createUser(USER_GORC_USERNAME, USER_GORC_GIVEN_NAME, USER_GORC_FAMILY_NAME, orgCortuvHradOid);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modifyObjectReplaceProperty(UserType.class, userGorcOid, UserType.F_NAME, task, result, new PolyString(USER_GORC_USERNAME2));
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    dumpOrgTree();
    dumpLdap();
    PrismObject<UserType> userAfter = getAndAssertUser(USER_GORC_USERNAME2, ORG_CORTUV_HRAD_NAME2, ORG_ROYULA_CARPATHIA_NAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 82 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class AbstractLdapHierarchyTest method test300RenameOrgCortuvHrad.

@Test
public void test300RenameOrgCortuvHrad() throws Exception {
    final String TEST_NAME = "test300RenameOrgCortuvHrad";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(AbstractLdapHierarchyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<OrgType> orgBefore = createOrg(ORG_CORTUV_HRAD_NAME, orgRolyulaCarpathiaOid);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    display("Adding org", orgBefore);
    modifyObjectReplaceProperty(OrgType.class, orgCortuvHradOid, OrgType.F_NAME, task, result, new PolyString(ORG_CORTUV_HRAD_NAME2));
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    dumpOrgTree();
    dumpLdap();
    PrismObject<OrgType> orgAfter = getAndAssertFunctionalOrg(ORG_CORTUV_HRAD_NAME2, orgRolyulaCarpathiaOid);
    assertEquals("Cortuv hrad org OID changed after rename", orgCortuvHradOid, orgAfter.getOid());
    getAndAssertUser(USER_DEZI_USERNAME, ORG_VYSNE_VLKODLAKY_NAME, ORG_CORTUV_HRAD_NAME2, ORG_ROYULA_CARPATHIA_NAME);
    assertSubOrgs(orgAfter, 1);
    assertSubOrgs(orgRolyulaCarpathiaOid, 1);
    assertSubOrgs(ORG_TOP_OID, 1);
    assertSubOrgs(orgVysneVlkodlakyOid, 0);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 83 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class TestActivation method test600AddUser1.

// attempt to simulate MID-3348 (unsuccessful for now)
@Test
public void test600AddUser1() throws Exception {
    final String TEST_NAME = "test600AddUser1";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestActivation.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user1 = prismContext.createObject(UserType.class);
    DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_NAME).replace(new PolyString("user1")).item(UserType.F_ASSIGNMENT).add(ObjectTypeUtil.createAssignmentTo(resourceDummyCoral).asPrismContainerValue()).item(ACTIVATION_ADMINISTRATIVE_STATUS_PATH).replace(ActivationStatusType.DISABLED).asObjectDelta(null).applyTo((PrismObject) user1);
    ObjectDelta<UserType> addDelta = user1.createAddDelta();
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(addDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    user1 = getUser(user1.getOid());
    display("User after change execution", user1);
    DummyAccount dummyAccount = dummyResourceCoral.getAccountByUsername("user1");
    display("Dummy account", dummyAccount);
    checkSuspendedAttribute(dummyAccount, Boolean.TRUE);
    String accountOid = getSingleLinkOid(user1);
    PrismObject<ShadowType> shadow = getShadowModel(accountOid);
    display("Shadow: ", shadow);
// TODO check real state of the account and shadow
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestValidityRecomputeTask(com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test) AbstractSynchronizationStoryTest(com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)

Example 84 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class RObjectTextInfo method createItemsSet.

public static <T extends ObjectType> Set<RObjectTextInfo> createItemsSet(@NotNull ObjectType object, @NotNull RObject repo, @NotNull RepositoryContext repositoryContext) {
    FullTextSearchConfigurationType config = repositoryContext.repositoryService.getFullTextSearchConfiguration();
    if (!FullTextSearchConfigurationUtil.isEnabled(config)) {
        return Collections.emptySet();
    }
    Set<ItemPath> paths = FullTextSearchConfigurationUtil.getFullTextSearchItemPaths(config, object.getClass());
    List<PrismValue> values = new ArrayList<>();
    for (ItemPath path : paths) {
        Object o = object.asPrismObject().find(path);
        if (o == null) {
        // shouldn't occur
        } else if (o instanceof PrismValue) {
            values.add((PrismValue) o);
        } else if (o instanceof Item) {
            values.addAll(((Item<?, ?>) o).getValues());
        } else {
            throw new IllegalStateException("Unexpected value " + o + " in " + object + " at " + path);
        }
    }
    // not a (hash) set in order to preserve order
    List<String> allWords = new ArrayList<>();
    for (PrismValue value : values) {
        if (value == null) {
            continue;
        }
        if (value instanceof PrismPropertyValue) {
            Object realValue = value.getRealValue();
            if (realValue == null) {
            // skip
            } else if (realValue instanceof String) {
                append(allWords, (String) realValue, repositoryContext.prismContext);
            } else if (realValue instanceof PolyString) {
                append(allWords, (PolyString) realValue, repositoryContext.prismContext);
            } else {
                append(allWords, realValue.toString(), repositoryContext.prismContext);
            }
        }
    }
    LOGGER.trace("Indexing {}:\n  items: {}\n  values: {}\n  words:  {}", object, paths, values, allWords);
    return createItemsSet(repo, allWords);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismValue(com.evolveum.midpoint.prism.PrismValue) Item(com.evolveum.midpoint.prism.Item) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 85 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method modifyObject.

@Override
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, RepoModifyOptions options, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
    Validate.notNull(modifications, "Modifications must not be null.");
    Validate.notNull(type, "Object class in delta must not be null.");
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(result, "Operation result must not be null.");
    OperationResult subResult = result.createSubresult(MODIFY_OBJECT);
    subResult.addParam("type", type.getName());
    subResult.addParam("oid", oid);
    subResult.addCollectionOfSerializablesAsParam("modifications", modifications);
    if (modifications.isEmpty() && !RepoModifyOptions.isExecuteIfNoChanges(options)) {
        LOGGER.debug("Modification list is empty, nothing was modified.");
        subResult.recordStatus(OperationResultStatus.SUCCESS, "Modification list is empty, nothing was modified.");
        return;
    }
    if (InternalsConfig.encryptionChecks) {
        CryptoUtil.checkEncrypted(modifications);
    }
    if (InternalsConfig.consistencyChecks) {
        ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
    } else {
        ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
    }
    if (LOGGER.isTraceEnabled()) {
        for (ItemDelta modification : modifications) {
            if (modification instanceof PropertyDelta<?>) {
                PropertyDelta<?> propDelta = (PropertyDelta<?>) modification;
                if (propDelta.getPath().equivalent(new ItemPath(ObjectType.F_NAME))) {
                    Collection<PrismPropertyValue<PolyString>> values = propDelta.getValues(PolyString.class);
                    for (PrismPropertyValue<PolyString> pval : values) {
                        PolyString value = pval.getValue();
                        LOGGER.trace("NAME delta: {} - {}", value.getOrig(), value.getNorm());
                    }
                }
            }
        }
    }
    final String operation = "modifying";
    int attempt = 1;
    SqlPerformanceMonitor pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart("modifyObject");
    try {
        while (true) {
            try {
                objectUpdater.modifyObjectAttempt(type, oid, modifications, options, subResult);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, subResult);
                pm.registerOperationNewTrial(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)168 Test (org.testng.annotations.Test)103 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)90 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)67 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)53 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)44 Task (com.evolveum.midpoint.task.api.Task)41 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 QName (javax.xml.namespace.QName)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)16 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)15 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)12 ArrayList (java.util.ArrayList)12 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 File (java.io.File)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)8 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)8