Package org.geomajas.layer.feature.attribute

Examples of org.geomajas.layer.feature.attribute.ManyToOneAttribute


    this.name = attribute;
  }

  @SuppressWarnings("unchecked")
  public Attribute<AssociationValue> instantiate() {
    return new ManyToOneAttribute(getValue());
  }
View Full Code Here


  public void testManyToOneAttribute() throws LayerException {
    Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>();
    FeatureBean bean = new FeatureBean();
    AssociationValue value = new AssociationValue(new LongAttribute(),new HashMap<String, Attribute<?>>(), false);
    value.getAllAttributes().put("stringAttr",new StringAttribute("mto"));
    attributes.put("manyToOneAttr", new ManyToOneAttribute(value));
    service.setAttributes(bean, layerBeans.getLayerInfo().getFeatureInfo(), new DummyMapper(), attributes);
    Assert.assertNotNull(bean.getManyToOneAttr());
    Assert.assertEquals("mto",bean.getManyToOneAttr().getStringAttr());
    // test replacing
    ManyToOneAttributeBean original = new ManyToOneAttributeBean();
View Full Code Here

  public void testNonEditable() throws LayerException {
    Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>();
    FeatureBean bean = new FeatureBean();
    AssociationValue value = new AssociationValue(new LongAttribute(),new HashMap<String, Attribute<?>>(), false);
    value.getAllAttributes().put("stringAttr",new StringAttribute("mto"));
    attributes.put("manyToOneAttr", new ManyToOneAttribute(value));
    attributes.put("stringAttr", new StringAttribute("top"));
    service.setAttributes(bean, layerNonEditableBeans.getLayerInfo().getFeatureInfo(), new DummyMapper(), attributes);
    Assert.assertNotNull(bean.getManyToOneAttr());
    Assert.assertNull(bean.getManyToOneAttr().getStringAttr());
    Assert.assertNull(bean.getStringAttr());
View Full Code Here

      return getRecursiveAttribute(entity == null ? null : entity.getChild(name),
          associationAttributeInfo.getFeature(), Arrays.copyOfRange(path, 1, path.length));
    } else {
      switch (associationAttributeInfo.getType()) {
        case MANY_TO_ONE:
          ManyToOneAttribute manyToOne = new ManyToOneAttribute();
          if (entity != null) {
            Entity oneEntity = entity.getChild(associationAttributeInfo.getName());
            AssociationValue value = getAssociationValue(oneEntity, associationAttributeInfo);
            manyToOne.setValue(value);
          }
          return manyToOne;
        case ONE_TO_MANY:
          OneToManyAttribute oneToMany = new OneToManyAttribute();
          if (entity != null) {
View Full Code Here

  @Test
  public void testCreate() throws LayerException {
    Object o = featureModel.newInstance();
    OneToManyAttribute many = new OneToManyAttribute(new ArrayList<AssociationValue>());
    ManyToOneAttribute one = new ManyToOneAttribute(new AssociationValue(null, new HashMap<String, Attribute<?>>(),
        false));

    // create 2 manyInMany
    OneToManyAttribute manyInMany = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInMany1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany1.getAllAttributes().put("textAttr", new StringAttribute("manyInMany1"));
    manyInMany.getValue().add(manyInMany1);
    AssociationValue manyInMany2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany2.getAllAttributes().put("textAttr", new StringAttribute("manyInMany2"));
    manyInMany.getValue().add(manyInMany2);

    // create oneInMany
    ManyToOneAttribute oneInMany = new ManyToOneAttribute();
    AssociationValue oneInManyValue = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    oneInManyValue.getAllAttributes().put("textAttr", new StringAttribute("oneInMany"));
    oneInMany.setValue(oneInManyValue);

    // create 2 manyInOne
    OneToManyAttribute manyInOne = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInOne1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne1.getAllAttributes().put("textAttr", new StringAttribute("manyInOne1"));
    manyInOne.getValue().add(manyInOne1);
    AssociationValue manyInOne2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne2.getAllAttributes().put("textAttr", new StringAttribute("manyInOne2"));
    manyInOne.getValue().add(manyInOne2);

    // create oneInOne
    ManyToOneAttribute oneInOne = new ManyToOneAttribute();
    AssociationValue oneInOneValue = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    oneInOneValue.getAllAttributes().put("textAttr", new StringAttribute("oneInOne"));
    oneInOne.setValue(oneInOneValue);

    // create 2 many
    AssociationValue many1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    AssociationValue many2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    // add manyInMany to many1
View Full Code Here

    OneToManyAttribute many = new OneToManyAttribute(new ArrayList<AssociationValue>());
    // create empty and add
    AssociationValue many1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    many.getValue().add(many1);
    // create an existing one-in-many and add
    ManyToOneAttribute oneInMany2 = new ManyToOneAttribute();
    AssociationValue oneInManyValue = new AssociationValue(new LongAttribute(oneInMany1.getId()), new HashMap<String, Attribute<?>>(), false);
    oneInMany2.setValue(oneInManyValue);
    AssociationValue many2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    many2.getAllAttributes().put("oneInMany", oneInMany2);
    many.getValue().add(many2);
    // add many
    attributes.put("many", many);
    featureModel.setAttributes(o, attributes);
   
    // check text attr
    Object feature = layer.create(o);
    OneToManyAttribute attr = (OneToManyAttribute)featureModel.getAttribute(feature, "many");
    AssociationValue val = attr.getValue().get(1);
    ManyToOneAttribute one = (ManyToOneAttribute)val.getAllAttributes().get("oneInMany");
    Assert.assertEquals("existing1", one.getValue().getAttributeValue("textAttr"));

  }
View Full Code Here

        } else if (associationMap.containsKey(entry.getKey())) {
          AssociationAttribute<?> association = (AssociationAttribute<?>) attribute;
          AssociationAttributeInfo associationAttributeInfo = associationMap.get(entry.getKey());
          switch (associationAttributeInfo.getType()) {
            case MANY_TO_ONE:
              association = (association == null ? new ManyToOneAttribute() : association);
              addManyToOne(entry.getKey(), associationMap.get(entry.getKey()),
                  (ManyToOneAttribute) association);
              break;
            case ONE_TO_MANY:
              association = (association == null ? new OneToManyAttribute() : association);
View Full Code Here

  // -------------------------------------------------------------------------

  private Attribute<?> toAssociationDto(Object value, AssociationAttributeInfo associationAttributeInfo)
      throws GeomajasException {
    if (associationAttributeInfo.getType() == AssociationType.MANY_TO_ONE) {
      return new ManyToOneAttribute(createAssociationValue(value, associationAttributeInfo));
    } else if (associationAttributeInfo.getType() == AssociationType.ONE_TO_MANY) {
      // Value should be an array of objects...
      List<AssociationValue> associationValues = new ArrayList<AssociationValue>();
      if (value != null && value instanceof Object[]) {
        Object[] array = (Object[]) value;
View Full Code Here

    attributes.put(PARAM_INT_ATTR, new IntegerAttribute(100));
    attributes.put(PARAM_FLOAT_ATTR, new FloatAttribute(100.0f));
    attributes.put(PARAM_DOUBLE_ATTR, new DoubleAttribute(100.0));
    attributes.put(PARAM_DATE_ATTR, new DateAttribute(date));

    return new ManyToOneAttribute(new AssociationValue(new LongAttribute(id), attributes));
  }
View Full Code Here

    layer.getFeatureModel().setAttributes(detached, attributes);
    layer.saveOrUpdate(detached);

    feature = layer.read(f1.getId().toString());
    ManyToOneAttribute manytoOne = (ManyToOneAttribute) layer.getFeatureModel().getAttribute(feature, MTO);
    Assert.assertNotNull(manytoOne.getValue());
    Assert.assertNotNull(manytoOne.getValue().getId()); // Test for ID
  }
View Full Code Here

TOP

Related Classes of org.geomajas.layer.feature.attribute.ManyToOneAttribute

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.