Search in sources :

Example 41 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TextFormatter method getItemPathLabel.

private String getItemPathLabel(ItemPath path, Definition deltaDefinition, PrismObjectDefinition objectDefinition) {
    NameItemPathSegment lastNamedSegment = path.lastNamed();
    StringBuilder sb = new StringBuilder();
    for (ItemPathSegment segment : path.getSegments()) {
        if (segment instanceof NameItemPathSegment) {
            if (sb.length() > 0) {
                sb.append("/");
            }
            Definition itemDefinition;
            if (objectDefinition == null) {
                if (segment == lastNamedSegment) {
                    // definition for last segment is the definition taken from delta
                    // this may be null but we don't care
                    itemDefinition = deltaDefinition;
                } else {
                    // definitions for previous segments are unknown
                    itemDefinition = null;
                }
            } else {
                // todo we could make this iterative (resolving definitions while walking down the path); but this is definitely simpler to implement and debug :)
                itemDefinition = objectDefinition.findItemDefinition(path.allUpToIncluding(segment));
            }
            if (itemDefinition != null && itemDefinition.getDisplayName() != null) {
                sb.append(resolve(itemDefinition.getDisplayName()));
            } else {
                sb.append(((NameItemPathSegment) segment).getName().getLocalPart());
            }
        } else if (segment instanceof IdItemPathSegment) {
            sb.append("[").append(((IdItemPathSegment) segment).getId()).append("]");
        }
    }
    return sb.toString();
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 42 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method modifyRoleAddInducementTarget.

protected void modifyRoleAddInducementTarget(String roleOid, String targetOid, boolean reconcileAffected, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    if (task == null) {
        task = createTask(AbstractModelIntegrationTest.class.getName() + ".modifyRoleAddInducementTarget");
    }
    OperationResult result = task.getResult();
    AssignmentType inducement = new AssignmentType();
    ObjectReferenceType targetRef = new ObjectReferenceType();
    targetRef.setOid(targetOid);
    inducement.setTargetRef(targetRef);
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationAddContainer(RoleType.class, roleOid, new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT)), prismContext, inducement);
    ModelExecuteOptions options = new ModelExecuteOptions();
    options.setReconcileAffected(reconcileAffected);
    modelService.executeChanges(MiscSchemaUtil.createCollection(roleDelta), options, task, result);
    result.computeStatus();
    if (reconcileAffected) {
        TestUtil.assertInProgressOrSuccess(result);
    } else {
        TestUtil.assertSuccess(result);
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 43 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method modifyRoleAddConstruction.

protected void modifyRoleAddConstruction(String roleOid, long inducementId, String resourceOid) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Task task = createTask(AbstractModelIntegrationTest.class.getName() + ".modifyRoleAddConstruction");
    OperationResult result = task.getResult();
    ConstructionType construction = new ConstructionType();
    ObjectReferenceType resourceRedRef = new ObjectReferenceType();
    resourceRedRef.setOid(resourceOid);
    construction.setResourceRef(resourceRedRef);
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationAddContainer(RoleType.class, roleOid, new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(inducementId), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), prismContext, construction);
    modelService.executeChanges(MiscSchemaUtil.createCollection(roleDelta), null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 44 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestFind method testFindAssignment2Construction.

@Test
public void testFindAssignment2Construction() throws SchemaException, SAXException, IOException {
    final String TEST_NAME = "testFindAssignment2ConstructionHowto";
    System.out.println("===[ " + TEST_NAME + " ]===");
    // GIVEN
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(AssignmentType.F_ACCOUNT_CONSTRUCTION));
    // WHEN
    PrismProperty<AccountConstructionType> property = findUserProperty(path);
    // THEN
    assertEquals("Wrong property value (path=" + path + ")", "Just do it", property.getRealValue().getHowto());
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) AccountConstructionType(com.evolveum.midpoint.prism.foo.AccountConstructionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 45 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestPath method assertNormalizedPath.

private void assertNormalizedPath(ItemPath normalized, Object... expected) {
    assertEquals("wrong path length", normalized.size(), expected.length);
    for (int i = 0; i < normalized.size(); i += 2) {
        ItemPathSegment nameSegment = normalized.getSegments().get(i);
        assert nameSegment instanceof NameItemPathSegment : "Expected name segment but it was " + nameSegment.getClass();
        QName name = ((NameItemPathSegment) nameSegment).getName();
        assert name != null : "name is null";
        assert name.getNamespaceURI().equals(NS) : "wrong namespace: " + name.getNamespaceURI();
        assert name.getLocalPart().equals(expected[i]) : "wrong local name, expected " + expected[i] + ", was " + name.getLocalPart();
        if (i + 1 < expected.length) {
            ItemPathSegment idSegment = normalized.getSegments().get(i + 1);
            assert idSegment instanceof IdItemPathSegment : "Expected is segment but it was " + nameSegment.getClass();
            Long id = ((IdItemPathSegment) idSegment).getId();
            assertId(id, (Long) expected[i + 1]);
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Aggregations

NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)69 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)61 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)46 Test (org.testng.annotations.Test)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 QName (javax.xml.namespace.QName)20 Task (com.evolveum.midpoint.task.api.Task)19 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)15 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)14 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 UserType (com.evolveum.midpoint.prism.foo.UserType)7 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)7 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4