Ejemplo n.º 1
0
  public boolean isValid(NavigationContext nc) {
    if (!super.isValid(nc)) return false;

    ActiveEntity activeEntity;

    // if we're coming from a redirector then it means that we may not need to rerun our queries
    final EntityRedirectorPage redirectorPage = getRedirectorPage();
    if (redirectorPage == null) {
      log.error(
          "No redirector page specified for entity page " + getQualifiedNameIncludingTreeId());
      return false;
    }

    EntitySubtypeRedirectInfo esri =
        EntityRedirectorPage.getEntitySubtypeRedirectInfo(
            nc, redirectorPage.getEntityIdRequestParamValue(nc));
    if (esri != null) activeEntity = (ActiveEntity) esri.getData();
    else {
      // if we get here it means we need to run our queries to get the active person
      ConnectionContext cc;
      try {
        cc = nc.getConnection(null, false);
      } catch (Exception e) {
        log.error(e);
        throw new NestableRuntimeException(e);
      }

      try {
        activeEntity = this.redirectorPage.getActiveEntity(nc, cc);
      } catch (Exception e) {
        log.error(e);
        throw new NestableRuntimeException(e);
      } finally {
        try {
          cc.close();
        } catch (SQLException e) {
          log.error(e);
          throw new NestableRuntimeException(e);
        }
      }
    }

    ((EntityPageState) nc.getActiveState()).setActiveEntity(activeEntity);
    return true;
  }
Ejemplo n.º 2
0
  public void testHierarchyTables() throws SQLException, NamingException {
    Table entity1Table = populatedSchema.getTables().getByName("Entity_1");
    Table entity2Table = populatedSchema.getTables().getByName("Entity_2");
    EntityHierarchyTable entity1HierarchyTable =
        (EntityHierarchyTable) populatedSchema.getTables().getByName("Entity_1_Hierarchy");
    RelationshipMapTable entity12RelationshipTable =
        (RelationshipMapTable) populatedSchema.getTables().getByName("Entity_1_2_Relationship");

    assertNotNull(entity1Table);
    assertNotNull(entity2Table);
    assertNotNull(entity1HierarchyTable);
    assertNotNull(entity12RelationshipTable);

    DatabaseConnValueContext dbvc = new BasicDatabaseConnValueContext();
    dbvc.setConnectionProvider(TestUtils.getConnProvider(this.getClass().getPackage().getName()));
    dbvc.setDefaultDataSource(this.getClass().getPackage().getName());
    ConnectionContext cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);

    final int entity1RowsCreateCount = 3;
    final int created =
        createEntity1RowAndChildren(
            cc,
            entity1Table,
            entity1HierarchyTable,
            null,
            "Entity 1.",
            entity1RowsCreateCount,
            2,
            0);

    cc.commitAndClose();

    cc = dbvc.getConnection(this.getClass().getPackage().getName(), true);

    /*
            assertNotNull(entity1HierarchyTable.getHierarchyRow(cc, EntityHierarchyTable.RELTYPEID_OBJ_HIERARCHY_PARENT, entity1IdValue, entity2IdValue));
            assertNotNull(entity12RelationshipTable.getRelationshipRow(cc, RelationshipMapTable.RELTYPEID_OBJ_HIERARCHY_CHILD, entity1IdValue, entity2IdValue));
    */

    cc.close();
  }