Search in sources :

Example 6 with View

use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.

the class ViewRepositoryInfo method dumpHtml.

public String dumpHtml() {
    StringBuilder content = new StringBuilder("<html><head><title>Views</title></head><body>");
    for (View view : viewRepository.getAll()) {
        dumpHtml(view, content);
    }
    content.append("</body></html>");
    return content.toString();
}
Also used : View(com.haulmont.cuba.core.global.View)

Example 7 with View

use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.

the class ViewRepositoryInfo method dumpHtml.

protected void dumpHtml(ViewProperty viewProperty, StringBuilder content, String indent) {
    content.append("<br/>").append("\n");
    content.append(indent);
    content.append("- ").append(viewProperty.getName());
    View innerView = viewProperty.getView();
    if (innerView != null) {
        if (StringUtils.isNotEmpty(innerView.getName())) {
            String metaClassName = metadata.getSession().getClass(innerView.getEntityClass()).getName();
            content.append(" -> <a href=\"#").append(metaClassName).append("__").append(innerView.getName()).append("\">").append(metaClassName).append("/").append(innerView.getName()).append("</a>");
        } else {
            for (ViewProperty innerProperty : innerView.getProperties()) {
                dumpHtml(innerProperty, content, "&nbsp;&nbsp;&nbsp;&nbsp;" + indent);
            }
        }
    }
}
Also used : ViewProperty(com.haulmont.cuba.core.global.ViewProperty) View(com.haulmont.cuba.core.global.View)

Example 8 with View

use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.

the class SoftDeleteTest method testOneToMany_CleanupMode.

@Test
public void testOneToMany_CleanupMode() {
    System.out.println("===================== BEGIN testOneToMany_CleanupMode =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        em.setSoftDeletion(false);
        View view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView").addProperty("role", new View(Role.class, "testView").addProperty("name")));
        User user = em.find(User.class, userId, view);
        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(2, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToMany_CleanupMode =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) View(com.haulmont.cuba.core.global.View)

Example 9 with View

use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.

the class SoftDeleteTest method testOneToOne.

@Test
public void testOneToOne() {
    System.out.println("===================== BEGIN testOneToOne =====================");
    // test fetchMode = AUTO
    System.out.println("===================== BEGIN testOneToOne fetchMode = AUTO =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"));
        SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
        assertNotNull(oneToOneA);
        assertNotNull(oneToOneA.getB());
        assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = BATCH
    System.out.println("===================== BEGIN testOneToOneBy fetchMode = BATCH =====================");
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"), FetchMode.BATCH);
        SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
        assertNotNull(oneToOneA);
        assertNotNull(oneToOneA.getB());
        assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = UNDEFINED
    System.out.println("===================== BEGIN testOneToOneBy fetchMode = UNDEFINED =====================");
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"), FetchMode.UNDEFINED);
        SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id, view);
        assertNotNull(oneToOneA);
        assertNotNull(oneToOneA.getB());
        assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOne =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) SoftDeleteOneToOneA(com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA) View(com.haulmont.cuba.core.global.View)

Example 10 with View

use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.

the class SoftDeleteTest method testOneToOneMappedBy.

@Test
public void testOneToOneMappedBy() {
    System.out.println("===================== BEGIN testOneToOneMappedBy =====================");
    // test fetchMode = AUTO
    System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = AUTO =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"));
        SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
        assertNotNull(oneToOneB);
        assertNull(oneToOneB.getA());
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = BATCH
    System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = BATCH =====================");
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"), FetchMode.BATCH);
        SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
        assertNotNull(oneToOneB);
        assertNull(oneToOneB.getA());
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = UNDEFINED
    System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = UNDEFINED =====================");
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"), FetchMode.UNDEFINED);
        SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
        assertNotNull(oneToOneB);
        assertNull(oneToOneB.getA());
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOneMappedBy =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) SoftDeleteOneToOneB(com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB) View(com.haulmont.cuba.core.global.View)

Aggregations

View (com.haulmont.cuba.core.global.View)55 Test (org.junit.Test)24 EntityManager (com.haulmont.cuba.core.EntityManager)22 Transaction (com.haulmont.cuba.core.Transaction)21 User (com.haulmont.cuba.security.entity.User)19 Group (com.haulmont.cuba.security.entity.Group)10 MetaClass (com.haulmont.chile.core.model.MetaClass)5 ViewProperty (com.haulmont.cuba.core.global.ViewProperty)5 UserRole (com.haulmont.cuba.security.entity.UserRole)5 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 Entity (com.haulmont.cuba.core.entity.Entity)2 ViewRepository (com.haulmont.cuba.core.global.ViewRepository)2 Role (com.haulmont.cuba.security.entity.Role)2 SoftDeleteOneToOneB (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB)2 QueryRunner (com.haulmont.bali.db.QueryRunner)1 MetadataObject (com.haulmont.chile.core.model.MetadataObject)1 DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)1 QueryResult (com.haulmont.cuba.core.entity.QueryResult)1 Server (com.haulmont.cuba.core.entity.Server)1