Package org.molgenis.model.elements

Examples of org.molgenis.model.elements.Field


  @Test
  public void export() throws IOException, TableException
  {
    TupleTable tupleTable = mock(TupleTable.class);
    Field field1 = when(mock(Field.class).getSqlName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getSqlName()).thenReturn("col2").getMock();
    when(tupleTable.getColumns()).thenReturn(Arrays.asList(field1, field2));
    Tuple row1 = mock(Tuple.class);
    when(row1.getNrCols()).thenReturn(2);
    when(row1.get("col1")).thenReturn("val1");
    when(row1.get("col2")).thenReturn("val2");
View Full Code Here


    when(tupleTable.getColOffset()).thenReturn(2);
    when(tupleTable.getColLimit()).thenReturn(3);
    when(tupleTable.getOffset()).thenReturn(1);
    when(tupleTable.getLimit()).thenReturn(2);

    Field field1 = when(mock(Field.class).getSqlName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getSqlName()).thenReturn("col2").getMock();
    when(tupleTable.getColumns()).thenReturn(Arrays.asList(field1, field2));
    Tuple row1 = mock(Tuple.class);
    when(row1.getNrCols()).thenReturn(2);
    when(row1.get("col1")).thenReturn("val1");
    when(row1.get("col2")).thenReturn("val2");
View Full Code Here

  @Test
  public void export() throws TableException, IOException
  {
    TupleTable tableModel = mock(TupleTable.class);
    Field field1 = when(mock(Field.class).getName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getName()).thenReturn("col2").getMock();
    Field field3 = when(mock(Field.class).getName()).thenReturn("col3").getMock();
    when(tableModel.getColumns()).thenReturn(Arrays.asList(field1, field2, field3));
    WritableTuple row1 = new KeyValueTuple();
    row1.set("col1", "val1.1");
    row1.set("col2", "val1.2");
    row1.set("col3", "val1.3");
View Full Code Here

    when(tableModel.getColLimit()).thenReturn(3);
    when(tableModel.getOffset()).thenReturn(1);
    when(tableModel.getLimit()).thenReturn(2);

    // verify that offsets and limits are ignored during export
    Field field1 = when(mock(Field.class).getName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getName()).thenReturn("col2").getMock();
    Field field3 = when(mock(Field.class).getName()).thenReturn("col3").getMock();
    when(tableModel.getColumns()).thenReturn(Arrays.asList(field1, field2, field3));
    WritableTuple row1 = new KeyValueTuple();
    row1.set("col1", "val1.1");
    row1.set("col2", "val1.2");
    row1.set("col3", "val1.3");
View Full Code Here

        NodeList indexfield_elements = elem.getElementsByTagName("indexfield");
        for (int l = 0; l < indexfield_elements.getLength(); l++)
        {
          elem = (Element) indexfield_elements.item(l);

          Field f = entity.getField(elem.getAttribute("name"));
          if (f == null)
          {
            // System.err.println(String.format(Error.
            // MISSING_INDEX_FIELD.msg,
            // elem.getAttribute("name")));
View Full Code Here

        jpaCascade = element.getAttribute("jpaCascade");
      }
    }

    // construct
    Field field = new Field(entity, MolgenisFieldTypes.getType(type), name, label, Boolean.parseBoolean(auto),
        Boolean.parseBoolean(nillable), Boolean.parseBoolean(readonly), default_value, jpaCascade);
    logger.debug("read: " + field.toString());

    // add optional properties
    if (!description.isEmpty())
    {
      field.setDescription(description.trim());
    }
    if (hidden.equals("true"))
    {
      field.setHidden(true);
    }
    if (!default_code.isEmpty())
    {
      field.setDefaultCode(default_code);
    }
    if (filter.equals("true"))
    {
      logger.warn("filter set for field '" + name + "' of entity '" + entity.getName() + "'");
      logger.warn(filterfield + " " + filtertype + " " + filtervalue);
      logger.warn(System.currentTimeMillis() + " - filter bool: '" + Boolean.parseBoolean(filter) + "'");
      if ((filtertype != null && filtertype.isEmpty()) || (filterfield != null && filterfield.isEmpty()))
      {
        throw new MolgenisModelException("field '" + name + "' of entity '" + entity.getName()
            + "': when the filter is set to true, the filtertype, filterfield and filtervalue must be set");
      }
      if (filtervalue != null && filtervalue.isEmpty())
      {
        logger.warn("no value specified for filter in field '" + name + "' of entity '" + entity.getName()
            + "'");
      }
      field.setFilter(Boolean.parseBoolean(filter));
      field.setFiltertype(filtertype);
      field.setFilterfield(filterfield);
      field.setFiltervalue(filtervalue);
    }

    // add type dependent properties
    if (type.equals("string"))
    {
      if (!length.isEmpty())
      {
        field.setVarCharLength(Integer.parseInt(length));
      }
      else
      {
        field.setVarCharLength(255);
      }
    }
    else if (type.equals("enum"))
    {
      Vector<String> options = new Vector<String>();
      StringTokenizer tokenizer = new StringTokenizer(enum_options, ",");
      while (tokenizer.hasMoreElements())
      {
        options.add(tokenizer.nextToken().trim());
      }
      if (options.size() < 1)
      {
        throw new MolgenisModelException("enum_options must be ',' delimited for field '" + field.getName()
            + "' of entity '" + entity.getName() + "'");
      }

      field.setEnumOptions(options);
    }
    else if (type.equals("xref") || type.equals("mref"))
    {
      // xref must be defined unless mref_name is set
      // caveat, can be both ends!!!
      if (mref_name.isEmpty() && xref_entity.isEmpty())
      {
        throw new MolgenisModelException("xref_entity must be set for xref field '" + field.getName()
            + "' of entity '" + entity.getName() + "'");
      }

      List<String> xref_labels = null;
      if (xref_label != null)
      {
        xref_labels = Arrays.asList(xref_label.split(","));
      }

      field.setXRefVariables(xref_entity, xref_field, xref_labels);

      // optional custom naming instead of default
      // necessary when using existing database
      if (type.equals("mref"))
      {
        if (!mref_name.isEmpty())
        {
          field.setMrefName(mref_name);
        }
        if (!mref_localid.isEmpty())
        {
          field.setMrefLocalid(mref_localid);
        }
        if (!mref_remoteid.isEmpty())
        {
          field.setMrefRemoteid(mref_remoteid);
        }
      }

      if (!element.getAttribute("xref_cascade").isEmpty())
      {
        if (element.getAttribute("xref_cascade").equalsIgnoreCase("true"))
        {
          field.setXrefCascade(true);
        }
        else
        {
          throw new MolgenisModelException("Unknown option on xref_cascade: '"
              + element.getAttribute("xref_cascade") + "'");
        }
      }
    }

    // add the field to entity
    try
    {
      entity.addField(field);

    }
    catch (Exception e)
    {
      throw new MolgenisModelException("duplicate field '" + field.getName() + "' in entity '" + entity.getName()
          + "'");
    }

    // check whether this field has a short-hand for index
    if (index.equals("true"))
    {
      Index i = new Index(name);
      try
      {
        i.addField(name);
      }
      catch (Exception e)
      {
        throw new MolgenisModelException("duplicate field '" + field.getName() + "' in entity '"
            + entity.getName() + "'");
      }

      entity.addIndex(i);
    }

    // check whether this field has a short-hand for unique
    if (unique.equals("true"))
    {
      entity.addKey(field.getName(), null);
    }

    // parse annotations (used by JPA)
    if (element.getChildNodes().getLength() >= 1)
    {
      String annotations = org.apache.commons.lang.StringUtils.deleteWhitespace(
          element.getChildNodes().item(1).getTextContent()).trim();
      field.setAnnotations(annotations);
    }

  }
View Full Code Here

        if (hide_fields != null && !hide_fields.isEmpty())
        {
          String[] hiddenFieldArray = hide_fields.split(",");
          for (String field : hiddenFieldArray)
          {
            Field f = entity.getAllField(field.trim());
            if (f == null)
            {
              throw new MolgenisModelException("Could not find field '" + field
                  + "' defined in hide_fields='" + element.getAttribute("hide_fields")
                  + "' in form '" + form.getName() + "'");
            }
            // use name from 'f' to correct for case problems
            form.getHideFields().add(f.getName());
          }
        }

        // COMPACT_FIELDS
        if (!element.getAttribute("compact_view").isEmpty())
        {
          String[] fields = element.getAttribute("compact_view").split(",");
          // check if the fields are there
          List<String> compact_fields = new ArrayList<String>();
          for (String field : fields)
          {
            Field f = entity.getAllField(field);
            if (f == null)
            {
              throw new MolgenisModelException("Could not find field '" + field
                  + "' defined in compact_view='" + element.getAttribute("compact_view")
                  + "' in form '" + form.getName() + "'");
            }
            // use name from 'f' to correct for case problems

            compact_fields.add(form.getEntity().getName() + "_" + f.getName());
          }
          form.setCompactView(compact_fields);
        }
      }
      else if (element.getTagName().equals("tree"))
View Full Code Here

    String simpleName = this.getEntityClass().getSimpleName();
    org.molgenis.model.elements.Entity entity = db.getMetaData().getEntity(simpleName);
    Vector<Field> allFields = entity.getAllFields();
    for (Iterator<Field> it = entity.getAllFields().iterator(); it.hasNext();)
    {
      Field field = it.next();
      if (field.isSystem() || field.isHidden()) it.remove();
    }
    return allFields;
  }
View Full Code Here

    {
      for (Entity iface : entity.getImplements())
      {
        for (Field mref : iface.getFieldsOf(new MrefField()))
        {
          Field f = new Field(mref);
          f.setEntity(entity);

          String mrefName = entity.getName() + "_" + f.getName();
          if (mrefName.length() > 30)
          {
            mrefName = mrefName.substring(0, 25) + Integer.toString(mrefName.hashCode()).substring(0, 5);
          }
          f.setMrefName(mrefName);
          entity.addField(0, f);
        }
      }
    }
View Full Code Here

    {
      List<String> hideFields = form.getHideFields();
      for (String fieldName : hideFields)
      {
        Entity entity = form.getEntity();
        Field field = entity.getAllField(fieldName);
        if (field == null)
        {
          throw new MolgenisModelException("error in hide_fields for form name=" + form.getName()
              + ": cannot find field '" + fieldName + "' in form entity='" + entity.getName() + "'");
        }
        else
        {
          if (!form.getReadOnly() && field.isNillable() == false && !field.isAuto()
              && field.getDefaultValue().equals(""))
          {

            logger.warn("you can get trouble with hiding field '" + fieldName + "' for form name="
                + form.getName()
                + ": record is not null and doesn't have a default value (unless decorator fixes this!");
View Full Code Here

TOP

Related Classes of org.molgenis.model.elements.Field

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.