Search in sources :

Example 6 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class DeleteTest method delete001.

@Test
public void delete001() throws Exception {
    final File file = new File("./../../samples/dsee/odsee-localhost-advanced-sync.xml");
    if (!file.exists()) {
        LOGGER.warn("skipping addGetDSEESyncDoubleTest, file {} not found.", new Object[] { file.getPath() });
        return;
    }
    List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(file).parseObjects();
    List<String> oids = new ArrayList<String>();
    OperationResult result = new OperationResult("Delete Test");
    for (int i = 0; i < elements.size(); i++) {
        PrismObject object = elements.get(i);
        LOGGER.info("Adding object {}, type {}", new Object[] { i, object.getCompileTimeClass().getSimpleName() });
        oids.add(repositoryService.addObject(object, null, result));
    }
    for (int i = 0; i < elements.size(); i++) {
        PrismObject object = elements.get(i);
        LOGGER.info("Deleting object {}, type {}", new Object[] { i, object.getCompileTimeClass().getSimpleName() });
        repositoryService.deleteObject(object.getCompileTimeClass(), oids.get(i), result);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 7 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class SearchTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
    FullTextSearchConfigurationType fullTextConfig = new FullTextSearchConfigurationType();
    FullTextSearchIndexedItemsConfigurationType entry = new FullTextSearchIndexedItemsConfigurationType();
    entry.getItem().add(new ItemPath(ObjectType.F_NAME).asItemPathType());
    entry.getItem().add(new ItemPath(ObjectType.F_DESCRIPTION).asItemPathType());
    fullTextConfig.getIndexed().add(entry);
    repositoryService.applyFullTextSearchConfiguration(fullTextConfig);
    LOGGER.info("Applying full text search configuration: {}", fullTextConfig);
    List<PrismObject<? extends Objectable>> objects = prismContext.parserFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects();
    objects.addAll(prismContext.parserFor(new File(FOLDER_BASIC, "objects-2.xml")).parseObjects());
    OperationResult result = new OperationResult("add objects");
    for (PrismObject object : objects) {
        repositoryService.addObject(object, null, result);
    }
    result.recomputeStatus();
    assertTrue(result.isSuccess());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class SchemaProcessor method updatePrismObject.

private Set<JDefinedClass> updatePrismObject(Outline outline) {
    Set<JDefinedClass> containers = new HashSet<JDefinedClass>();
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        QName qname = getCClassInfoQName(entry.getValue());
        if (qname == null) {
            continue;
        }
        boolean isDirectPrismObject = hasAnnotation(classOutline, A_PRISM_OBJECT);
        boolean isIndirectPrismObject = hasParentAnnotation(classOutline, A_PRISM_OBJECT);
        if (!isIndirectPrismObject) {
            continue;
        }
        JDefinedClass definedClass = classOutline.implClass;
        createDefaultConstructor(definedClass);
        createPrismContextObjectableConstructor(definedClass);
        createAsPrismObject(definedClass);
        if (!isDirectPrismObject) {
            continue;
        }
        definedClass._implements(CLASS_MAP.get(Objectable.class));
        containers.add(definedClass);
        //inserting PrismObject field into ObjectType class
        JVar container = definedClass.field(JMod.PRIVATE, PrismObject.class, CONTAINER_FIELD_NAME);
        //create getContainer
        //            createGetContainerMethod(classOutline, container);
        //create setContainer
        createSetContainerMethod(definedClass, container);
        //create asPrismObject()
        createAsPrismContainer(classOutline, container);
        // Objectable is also Containerable, we also need these
        createAsPrismContainerValueInObject(definedClass);
        createSetContainerValueMethodInObject(definedClass, container);
        print("Creating toString, equals, hashCode methods.");
        //create toString, equals, hashCode
        createToStringMethod(definedClass, METHOD_AS_PRISM_CONTAINER);
        createEqualsMethod(classOutline, METHOD_AS_PRISM_CONTAINER);
        createHashCodeMethod(definedClass, METHOD_AS_PRISM_CONTAINER);
        //create toDebugName, toDebugType
        createToDebugName(definedClass);
        createToDebugType(definedClass);
    }
    removeCustomGeneratedMethod(outline);
    return containers;
}
Also used : QName(javax.xml.namespace.QName) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Entry(java.util.Map.Entry) CClassInfo(com.sun.tools.xjc.model.CClassInfo) NClass(com.sun.tools.xjc.model.nav.NClass) Objectable(com.evolveum.midpoint.prism.Objectable) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 9 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class OrgStructTest method test001addOrgStructObjectsIncorrect.

@Test
public void test001addOrgStructObjectsIncorrect() throws Exception {
    OperationResult opResult = new OperationResult("test001addOrgStructObjectsIncorrect");
    List<PrismObject<? extends Objectable>> orgStructIncorrect = prismContext.parserFor(new File(ORG_STRUCT_OBJECTS_INCORRECT)).parseObjects();
    for (PrismObject<? extends Objectable> o : orgStructIncorrect) {
        repositoryService.addObject((PrismObject<ObjectType>) o, null, opResult);
    }
    opResult.computeStatusIfUnknown();
    AssertJUnit.assertTrue(opResult.isSuccess());
    Session session = open();
    try {
        LOGGER.info("==============CLOSURE TABLE==========");
        // descendants of F007 - F007<0>, F009<1>, F008<2>, F0010<2>
        Criteria criteria = session.createCriteria(ROrgClosure.class).createCriteria("ancestor", "anc").setFetchMode("ancestor", FetchMode.JOIN).add(Restrictions.eq("anc.oid", ORG_F007_OID));
        List<ROrgClosure> orgClosure = criteria.list();
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}", c.getDescendant());
        }
        AssertJUnit.assertEquals(4, orgClosure.size());
        criteria = session.createCriteria(ROrgClosure.class).createCriteria("ancestor", "anc").setFetchMode("ancestor", FetchMode.JOIN).add(Restrictions.eq("anc.oid", ORG_F009_OID));
        orgClosure = criteria.list();
        AssertJUnit.assertEquals(3, orgClosure.size());
        ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_NAME).eq(ELAINE_NAME1).build();
        List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, opResult);
        AssertJUnit.assertNotNull(users);
        AssertJUnit.assertEquals(1, users.size());
        UserType elaine1 = users.get(0).asObjectable();
        LOGGER.info("--->elaine1<----");
        AssertJUnit.assertEquals("Expected name elaine1, but got " + elaine1.getName().getOrig(), "elaine1", elaine1.getName().getOrig());
        AssertJUnit.assertEquals("Expected elaine has one org ref, but got " + elaine1.getParentOrgRef().size(), 2, elaine1.getParentOrgRef().size());
        AssertJUnit.assertEquals("Parent org ref oid not equal.", "00000000-8888-6666-0000-100000000011", elaine1.getParentOrgRef().get(0).getOid());
    } finally {
        close(session);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Criteria(org.hibernate.Criteria) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) Objectable(com.evolveum.midpoint.prism.Objectable) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 10 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class OrgStructTest method test001addOrgStructObjects.

@Test
public void test001addOrgStructObjects() throws Exception {
    OperationResult opResult = new OperationResult("test001addOrgStructObjects");
    List<PrismObject<? extends Objectable>> orgStruct = prismContext.parserFor(new File(ORG_STRUCT_OBJECTS)).parseObjects();
    for (PrismObject<? extends Objectable> o : orgStruct) {
        repositoryService.addObject((PrismObject<ObjectType>) o, null, opResult);
    }
    opResult.computeStatusIfUnknown();
    AssertJUnit.assertTrue(opResult.isSuccess());
    List<PrismObject<OrgType>> orgTypes = repositoryService.searchObjects(OrgType.class, new ObjectQuery(), null, opResult);
    AssertJUnit.assertNotNull(orgTypes);
    AssertJUnit.assertEquals(9, orgTypes.size());
    OrgType pRoot = repositoryService.getObject(OrgType.class, ORG_PROJECT_ROOT_OID, null, opResult).asObjectable();
    AssertJUnit.assertEquals("PRoot", pRoot.getName().getOrig());
    PrismObjectDefinition<UserType> userObjectDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
    ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_NAME).eq(ELAINE_NAME).build();
    List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, opResult);
    AssertJUnit.assertEquals(1, users.size());
    ELAINE_OID = users.get(0).getOid();
    testMonkeySubordinate();
    Session session = open();
    try {
        Query qCount = session.createQuery("select count(*) from ROrgClosure");
        assertCount(qCount, 19);
        // check descendants for F0001 org unit
        qCount = session.createQuery("select count(*) from ROrgClosure where ancestorOid = :ancestorOid");
        qCount.setParameter("ancestorOid", ORG_F001_OID);
        assertCount(qCount, 6);
        qCount = session.createQuery("select count(*) from ROrgClosure where ancestorOid = :ancestorOid and descendantOid = :descendantOid");
        qCount.setParameter("ancestorOid", ORG_F001_OID);
        qCount.setParameter("descendantOid", ORG_F006_OID);
        assertCount(qCount, 1);
    } finally {
        close(session);
    }
}
Also used : Query(org.hibernate.Query) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) Objectable(com.evolveum.midpoint.prism.Objectable) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

Objectable (com.evolveum.midpoint.prism.Objectable)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 File (java.io.File)9 Test (org.testng.annotations.Test)9 Node (org.w3c.dom.Node)7 Element (org.w3c.dom.Element)6 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 ArrayList (java.util.ArrayList)4 Validator (com.evolveum.midpoint.common.validator.Validator)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 FileInputStream (java.io.FileInputStream)2 QName (javax.xml.namespace.QName)2 Session (org.hibernate.Session)2 ResourceValidator (com.evolveum.midpoint.model.api.validator.ResourceValidator)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1