Search in sources :

Example 66 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class ConsistencyTest method test511AssignAccountMorgan.

/**
	 * assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
	 * account should be linked to the user.
	 * @throws Exception
	 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    final String TEST_NAME = "test511AssignAccountMorgan";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeRunning();
    Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    //prepare new OU in opendj
    Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
    JAXBElement val = of.createValue(raw);
    expression.getExpressionEvaluator().add(val);
    MappingType mapping = new MappingType();
    mapping.setExpression(expression);
    ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
    attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    //		assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
    String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account        
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) 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) Entry(org.opends.server.types.Entry) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 67 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class ModelWebServiceTest method nonExistingUidModify.

@Test(expectedExceptions = FaultMessage.class)
public void nonExistingUidModify() throws FaultMessage, ObjectNotFoundException, SchemaException, JAXBException, IOException {
    final String oid = "1";
    ObjectDeltaType objectDeltaType = new ObjectDeltaType();
    objectDeltaType.setChangeType(ChangeTypeType.MODIFY);
    objectDeltaType.setObjectType(UserType.COMPLEX_TYPE);
    objectDeltaType.setOid(oid);
    ItemDeltaType mod1 = new ItemDeltaType();
    mod1.setModificationType(ModificationTypeType.ADD);
    //        ItemDeltaType.Value value = new ItemDeltaType.Value();
    //        value.getAny().add(DOMUtil.createElement(DOMUtil.getDocument(), new QName(SchemaConstants.NS_C, "fullName")));
    mod1.setPath(new ItemPathType(new ItemPath(UserType.F_FULL_NAME)));
    objectDeltaType.getItemDelta().add(mod1);
    when(repositoryService.getObject(any(Class.class), eq(oid), any(Collection.class), any(OperationResult.class))).thenThrow(new ObjectNotFoundException("Oid '" + oid + "' not found."));
    final UserType user = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
    setSecurityContext(user);
    ObjectDeltaListType deltaListType = new ObjectDeltaListType();
    deltaListType.getDelta().add(objectDeltaType);
    try {
        modelService.executeChanges(deltaListType, null);
    } catch (FaultMessage ex) {
        ModelTUtil.assertObjectNotFoundFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 68 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestModelWebServiceNegative method createShadowReplaceChange.

// TODO: more negative tests
private ObjectDeltaType createShadowReplaceChange(String oid, String path, final String value, QName type) {
    ObjectDeltaType objectChange = new ObjectDeltaType();
    objectChange.setOid(oid);
    objectChange.setChangeType(ChangeTypeType.MODIFY);
    objectChange.setObjectType(ObjectTypes.SHADOW.getTypeQName());
    ItemDeltaType itemDeltaType = new ItemDeltaType();
    itemDeltaType.setModificationType(ModificationTypeType.REPLACE);
    ItemPathType itemPath = new ItemPathType(path);
    itemDeltaType.setPath(itemPath);
    PrimitiveXNode<String> xnode = new PrimitiveXNode<>();
    ValueParser<String> valueParser = new ValueParser<String>() {

        @Override
        public String parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException {
            return value;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }

        @Override
        public String getStringValue() {
            return value;
        }

        @Override
        public Map<String, String> getPotentiallyRelevantNamespaces() {
            throw new UnsupportedOperationException();
        }
    };
    xnode.setValueParser(valueParser);
    if (type != null) {
        xnode.setExplicitTypeDeclaration(true);
        xnode.setTypeQName(type);
    }
    RawType rawValue = new RawType(xnode, prismContext);
    itemDeltaType.getValue().add(rawValue);
    objectChange.getItemDelta().add(itemDeltaType);
    return objectChange;
}
Also used : XNodeProcessorEvaluationMode(com.evolveum.midpoint.prism.marshaller.XNodeProcessorEvaluationMode) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ValueParser(com.evolveum.midpoint.prism.xnode.ValueParser) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 69 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class PagingConvertor method createPagingType.

public static PagingType createPagingType(ObjectPaging paging) {
    if (paging == null) {
        return null;
    }
    PagingType pagingType = new PagingType();
    pagingType.setOrderDirection(toOrderDirectionType(paging.getDirection()));
    pagingType.setMaxSize(paging.getMaxSize());
    pagingType.setOffset(paging.getOffset());
    if (paging.getOrderBy() != null) {
        pagingType.setOrderBy(new ItemPathType(paging.getOrderBy()));
    }
    return pagingType;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType)

Example 70 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class MidPointDataSource method getFieldValue.

@Override
public Object getFieldValue(JRField jrField) throws JRException {
    String fieldName = jrField.getName();
    if (fieldName.equals("oid")) {
        if (currentObject.getParent() instanceof PrismObject) {
            return ((PrismObject) currentObject.getParent()).getOid();
        } else {
            throw new IllegalStateException("oid property is not supported for " + currentObject.getClass());
        }
    } else if (PARENT_NAME.equals(fieldName)) {
        PrismContainerable parent1 = currentObject.getParent();
        if (!(parent1 instanceof PrismContainer)) {
            return null;
        }
        return ((PrismContainer) parent1).getParent();
    } else if (THIS_NAME.equals(fieldName)) {
        return currentObject;
    }
    ItemPathType itemPathType = new ItemPathType(fieldName);
    ItemPath path = itemPathType.getItemPath();
    Item i = currentObject.findItem(path);
    if (i == null) {
        return null;
    }
    if (i instanceof PrismProperty) {
        if (i.isSingleValue()) {
            return normalize(((PrismProperty) i).getRealValue(), jrField.getValueClass());
        }
        List normalized = new ArrayList<>();
        for (Object real : ((PrismProperty) i).getRealValues()) {
            normalized.add(normalize(real, jrField.getValueClass()));
        }
        return ((PrismProperty) i).getRealValues();
    } else if (i instanceof PrismReference) {
        if (i.isSingleValue()) {
            return ObjectTypeUtil.createObjectRef(((PrismReference) i).getValue());
        }
        List<Referencable> refs = new ArrayList<Referencable>();
        for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
            refs.add(ObjectTypeUtil.createObjectRef(refVal));
        }
        return refs;
    } else if (i instanceof PrismContainer) {
        if (i.isSingleValue()) {
            return ((PrismContainer) i).getValue().asContainerable();
        }
        List<Containerable> containers = new ArrayList<Containerable>();
        for (Object pcv : i.getValues()) {
            if (pcv instanceof PrismContainerValue) {
                containers.add(((PrismContainerValue) pcv).asContainerable());
            }
        }
        return containers;
    } else
        throw new JRException("Could not get value of the fileld: " + fieldName);
//		return 
//		throw new UnsupportedOperationException("dataSource.getFiledValue() not supported");
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) JRException(net.sf.jasperreports.engine.JRException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismContainerable(com.evolveum.midpoint.prism.PrismContainerable) PrismObject(com.evolveum.midpoint.prism.PrismObject) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReference(com.evolveum.midpoint.prism.PrismReference) ArrayList(java.util.ArrayList) List(java.util.List) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerable(com.evolveum.midpoint.prism.PrismContainerable) Containerable(com.evolveum.midpoint.prism.Containerable) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)114 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)58 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)27 Test (org.testng.annotations.Test)27 QName (javax.xml.namespace.QName)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)21 List (java.util.List)18 NotNull (org.jetbrains.annotations.NotNull)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)15 ArrayList (java.util.ArrayList)15 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)13 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)13 Collectors (java.util.stream.Collectors)13 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)11 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)11 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)11 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)11